efibind.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copright (C) 2014 - 2015 Linaro Ltd.
  3. * Author: Ard Biesheuvel <[email protected]>
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice and this list of conditions, without modification.
  10. * 2. The name of the author may not be used to endorse or promote products
  11. * derived from this software without specific prior written permission.
  12. *
  13. * Alternatively, this software may be distributed under the terms of the
  14. * GNU General Public License as published by the Free Software Foundation;
  15. * either version 2 of the License, or (at your option) any later version.
  16. */
  17. #if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )) && !defined(__cplusplus)
  18. // ANSI C 1999/2000 stdint.h integer width declarations
  19. typedef unsigned long uint64_t;
  20. typedef long int64_t;
  21. typedef unsigned int uint32_t;
  22. typedef int int32_t;
  23. typedef unsigned short uint16_t;
  24. typedef short int16_t;
  25. typedef unsigned char uint8_t;
  26. typedef signed char int8_t; // unqualified 'char' is unsigned on ARM
  27. typedef uint64_t uintptr_t;
  28. typedef int64_t intptr_t;
  29. #else
  30. #include <stdint.h>
  31. #endif
  32. //
  33. // Basic EFI types of various widths
  34. //
  35. #include <stddef.h>
  36. typedef wchar_t CHAR16;
  37. #define WCHAR CHAR16
  38. typedef uint64_t UINT64;
  39. typedef int64_t INT64;
  40. typedef uint32_t UINT32;
  41. typedef int32_t INT32;
  42. typedef uint16_t UINT16;
  43. typedef int16_t INT16;
  44. typedef uint8_t UINT8;
  45. typedef char CHAR8;
  46. typedef int8_t INT8;
  47. #undef VOID
  48. typedef void VOID;
  49. typedef int64_t INTN;
  50. typedef uint64_t UINTN;
  51. #define EFIERR(a) (0x8000000000000000 | a)
  52. #define EFI_ERROR_MASK 0x8000000000000000
  53. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  54. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  55. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  56. #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
  57. //
  58. // Pointers must be aligned to these address to function
  59. //
  60. #define MIN_ALIGNMENT_SIZE 8
  61. #define ALIGN_VARIABLE(Value ,Adjustment) \
  62. (UINTN)Adjustment = 0; \
  63. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  64. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  65. Value = (UINTN)Value + (UINTN)Adjustment
  66. //
  67. // Define macros to build data structure signatures from characters.
  68. //
  69. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  70. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  71. #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
  72. //
  73. // EFIAPI - prototype calling convention for EFI function pointers
  74. // BOOTSERVICE - prototype for implementation of a boot service interface
  75. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  76. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  77. // RUNTIME_CODE - pragma macro for declaring runtime code
  78. //
  79. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  80. #define EFIAPI // Substitute expresion to force C calling convention
  81. #endif
  82. #define BOOTSERVICE
  83. #define RUNTIMESERVICE
  84. #define RUNTIMEFUNCTION
  85. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  86. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  87. #define END_RUNTIME_DATA() data_seg("")
  88. #define VOLATILE volatile
  89. #define MEMORY_FENCE __sync_synchronize
  90. //
  91. // When build similiar to FW, then link everything together as
  92. // one big module. For the MSVC toolchain, we simply tell the
  93. // linker what our driver init function is using /ENTRY.
  94. //
  95. #if defined(_MSC_EXTENSIONS)
  96. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  97. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  98. #else
  99. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  100. UINTN \
  101. InitializeDriver ( \
  102. VOID *ImageHandle, \
  103. VOID *SystemTable \
  104. ) \
  105. { \
  106. return InitFunction(ImageHandle, \
  107. SystemTable); \
  108. } \
  109. \
  110. EFI_STATUS efi_main( \
  111. EFI_HANDLE image, \
  112. EFI_SYSTEM_TABLE *systab \
  113. ) __attribute__((weak, \
  114. alias ("InitializeDriver")));
  115. #endif
  116. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  117. (_if)->LoadInternal(type, name, entry)
  118. //
  119. // Some compilers don't support the forward reference construct:
  120. // typedef struct XXXXX
  121. //
  122. // The following macro provide a workaround for such cases.
  123. #define INTERFACE_DECL(x) struct x
  124. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  125. #define EFI_FUNCTION