efibind.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. efefind.h
  5. Abstract:
  6. EFI to compile bindings
  7. Revision History
  8. --*/
  9. #ifndef X86_64_EFI_BIND
  10. #define X86_64_EFI_BIND
  11. #ifndef __GNUC__
  12. #pragma pack()
  13. #endif
  14. #if defined(GNU_EFI_USE_MS_ABI)
  15. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
  16. #define HAVE_USE_MS_ABI 1
  17. #else
  18. #error Compiler is too old for GNU_EFI_USE_MS_ABI
  19. #endif
  20. #endif
  21. //
  22. // Basic int types of various widths
  23. //
  24. #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
  25. // No ANSI C 1999/2000 stdint.h integer width declarations
  26. #if defined(_MSC_EXTENSIONS)
  27. // Use Microsoft C compiler integer width declarations
  28. typedef unsigned __int64 uint64_t;
  29. typedef __int64 int64_t;
  30. typedef unsigned __int32 uint32_t;
  31. typedef __int32 int32_t;
  32. typedef unsigned short uint16_t;
  33. typedef short int16_t;
  34. typedef unsigned char uint8_t;
  35. typedef char int8_t;
  36. #elif defined(__GNUC__)
  37. typedef unsigned long long uint64_t __attribute__((aligned (8)));
  38. typedef long long int64_t __attribute__((aligned (8)));
  39. typedef unsigned int uint32_t;
  40. typedef int int32_t;
  41. typedef unsigned short uint16_t;
  42. typedef short int16_t;
  43. typedef unsigned char uint8_t;
  44. typedef char int8_t;
  45. #elif defined(UNIX_LP64)
  46. /* Use LP64 programming model from C_FLAGS for integer width declarations */
  47. typedef unsigned long uint64_t;
  48. typedef long int64_t;
  49. typedef unsigned int uint32_t;
  50. typedef int int32_t;
  51. typedef unsigned short uint16_t;
  52. typedef short int16_t;
  53. typedef unsigned char uint8_t;
  54. typedef char int8_t;
  55. #else
  56. /* Assume P64 programming model from C_FLAGS for integer width declarations */
  57. typedef unsigned long long uint64_t __attribute__((aligned (8)));
  58. typedef long long int64_t __attribute__((aligned (8)));
  59. typedef unsigned int uint32_t;
  60. typedef int int32_t;
  61. typedef unsigned short uint16_t;
  62. typedef short int16_t;
  63. typedef unsigned char uint8_t;
  64. typedef char int8_t;
  65. #endif
  66. #elif defined(__GNUC__)
  67. #include <stdint-gcc.h>
  68. #endif
  69. //
  70. // Basic EFI types of various widths
  71. //
  72. #ifndef __WCHAR_TYPE__
  73. # define __WCHAR_TYPE__ short
  74. #endif
  75. typedef uint64_t UINT64;
  76. typedef int64_t INT64;
  77. #ifndef _BASETSD_H_
  78. typedef uint32_t UINT32;
  79. typedef int32_t INT32;
  80. #endif
  81. typedef uint16_t UINT16;
  82. typedef int16_t INT16;
  83. typedef uint8_t UINT8;
  84. typedef int8_t INT8;
  85. typedef __WCHAR_TYPE__ WCHAR;
  86. #undef VOID
  87. #define VOID void
  88. typedef int64_t INTN;
  89. typedef uint64_t UINTN;
  90. #ifdef EFI_NT_EMULATOR
  91. #define POST_CODE(_Data)
  92. #else
  93. #ifdef EFI_DEBUG
  94. #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
  95. #else
  96. #define POST_CODE(_Data)
  97. #endif
  98. #endif
  99. #define EFIERR(a) (0x8000000000000000 | a)
  100. #define EFI_ERROR_MASK 0x8000000000000000
  101. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  102. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  103. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  104. #ifdef EFI_NT_EMULATOR
  105. #define BREAKPOINT() __asm { int 3 }
  106. #else
  107. #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
  108. #endif
  109. //
  110. // Pointers must be aligned to these address to function
  111. //
  112. #define MIN_ALIGNMENT_SIZE 4
  113. #define ALIGN_VARIABLE(Value ,Adjustment) \
  114. (UINTN)Adjustment = 0; \
  115. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  116. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  117. Value = (UINTN)Value + (UINTN)Adjustment
  118. //
  119. // Define macros to build data structure signatures from characters.
  120. //
  121. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  122. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  123. #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))
  124. //
  125. // To export & import functions in the EFI emulator environment
  126. //
  127. #ifdef EFI_NT_EMULATOR
  128. #define EXPORTAPI __declspec( dllexport )
  129. #else
  130. #define EXPORTAPI
  131. #endif
  132. //
  133. // EFIAPI - prototype calling convention for EFI function pointers
  134. // BOOTSERVICE - prototype for implementation of a boot service interface
  135. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  136. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  137. // RUNTIME_CODE - pragma macro for declaring runtime code
  138. //
  139. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  140. #ifdef _MSC_EXTENSIONS
  141. #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
  142. #elif defined(HAVE_USE_MS_ABI)
  143. // Force amd64/ms calling conventions.
  144. #define EFIAPI __attribute__((ms_abi))
  145. #else
  146. #define EFIAPI // Substitute expresion to force C calling convention
  147. #endif
  148. #endif
  149. #define BOOTSERVICE
  150. //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
  151. //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
  152. #define RUNTIMESERVICE
  153. #define RUNTIMEFUNCTION
  154. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  155. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  156. #define END_RUNTIME_DATA() data_seg("")
  157. #define VOLATILE volatile
  158. #define MEMORY_FENCE()
  159. #ifdef EFI_NT_EMULATOR
  160. //
  161. // To help ensure proper coding of integrated drivers, they are
  162. // compiled as DLLs. In NT they require a dll init entry pointer.
  163. // The macro puts a stub entry point into the DLL so it will load.
  164. //
  165. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  166. UINTN \
  167. __stdcall \
  168. _DllMainCRTStartup ( \
  169. UINTN Inst, \
  170. UINTN reason_for_call, \
  171. VOID *rserved \
  172. ) \
  173. { \
  174. return 1; \
  175. } \
  176. \
  177. int \
  178. EXPORTAPI \
  179. __cdecl \
  180. InitializeDriver ( \
  181. void *ImageHandle, \
  182. void *SystemTable \
  183. ) \
  184. { \
  185. return InitFunction(ImageHandle, SystemTable); \
  186. }
  187. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  188. (_if)->LoadInternal(type, name, NULL)
  189. #else // EFI_NT_EMULATOR
  190. //
  191. // When build similiar to FW, then link everything together as
  192. // one big module.
  193. //
  194. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  195. UINTN \
  196. InitializeDriver ( \
  197. VOID *ImageHandle, \
  198. VOID *SystemTable \
  199. ) \
  200. { \
  201. return InitFunction(ImageHandle, \
  202. SystemTable); \
  203. } \
  204. \
  205. EFI_STATUS efi_main( \
  206. EFI_HANDLE image, \
  207. EFI_SYSTEM_TABLE *systab \
  208. ) __attribute__((weak, \
  209. alias ("InitializeDriver")));
  210. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  211. (_if)->LoadInternal(type, name, entry)
  212. #endif // EFI_FW_NT
  213. //
  214. // Some compilers don't support the forward reference construct:
  215. // typedef struct XXXXX
  216. //
  217. // The following macro provide a workaround for such cases.
  218. //
  219. #ifdef NO_INTERFACE_DECL
  220. #define INTERFACE_DECL(x)
  221. #else
  222. #ifdef __GNUC__
  223. #define INTERFACE_DECL(x) struct x
  224. #else
  225. #define INTERFACE_DECL(x) typedef struct x
  226. #endif
  227. #endif
  228. /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
  229. #if defined(HAVE_USE_MS_ABI)
  230. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  231. #else
  232. UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...);
  233. #endif
  234. #define EFI_FUNCTION __attribute__((ms_abi))
  235. #ifdef _MSC_EXTENSIONS
  236. #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP
  237. #endif
  238. #endif