efibind.h 8.9 KB

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