efibind.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. #include <stddef.h>
  66. typedef wchar_t CHAR16;
  67. #define WCHAR CHAR16
  68. typedef uint64_t UINT64;
  69. typedef int64_t INT64;
  70. #ifndef _BASETSD_H_
  71. typedef uint32_t UINT32;
  72. typedef int32_t INT32;
  73. #endif
  74. typedef uint16_t UINT16;
  75. typedef int16_t INT16;
  76. typedef uint8_t UINT8;
  77. typedef char CHAR8;
  78. typedef int8_t INT8;
  79. #undef VOID
  80. typedef void VOID;
  81. typedef int32_t INTN;
  82. typedef uint32_t UINTN;
  83. #ifdef EFI_NT_EMULATOR
  84. #define POST_CODE(_Data)
  85. #else
  86. #ifdef EFI_DEBUG
  87. #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
  88. #else
  89. #define POST_CODE(_Data)
  90. #endif
  91. #endif
  92. #define EFIERR(a) (0x80000000 | a)
  93. #define EFI_ERROR_MASK 0x80000000
  94. #define EFIERR_OEM(a) (0xc0000000 | a)
  95. #define BAD_POINTER 0xFBFBFBFB
  96. #define MAX_ADDRESS 0xFFFFFFFF
  97. #ifdef EFI_NT_EMULATOR
  98. #define BREAKPOINT() __asm { int 3 }
  99. #else
  100. #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
  101. #endif
  102. //
  103. // Pointers must be aligned to these address to function
  104. //
  105. #define MIN_ALIGNMENT_SIZE 4
  106. #define ALIGN_VARIABLE(Value ,Adjustment) \
  107. (UINTN)Adjustment = 0; \
  108. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  109. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  110. Value = (UINTN)Value + (UINTN)Adjustment
  111. //
  112. // Define macros to build data structure signatures from characters.
  113. //
  114. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  115. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  116. #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))
  117. //
  118. // To export & import functions in the EFI emulator environment
  119. //
  120. #ifdef EFI_NT_EMULATOR
  121. #define EXPORTAPI __declspec( dllexport )
  122. #else
  123. #define EXPORTAPI
  124. #endif
  125. //
  126. // EFIAPI - prototype calling convention for EFI function pointers
  127. // BOOTSERVICE - prototype for implementation of a boot service interface
  128. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  129. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  130. // RUNTIME_CODE - pragma macro for declaring runtime code
  131. //
  132. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  133. #ifdef _MSC_EXTENSIONS
  134. #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
  135. #else
  136. #define EFIAPI // Substitute expresion to force C calling convention
  137. #endif
  138. #endif
  139. #define BOOTSERVICE
  140. //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
  141. //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
  142. #define RUNTIMESERVICE
  143. #define RUNTIMEFUNCTION
  144. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  145. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  146. #define END_RUNTIME_DATA() data_seg("")
  147. #define VOLATILE volatile
  148. #define MEMORY_FENCE()
  149. #ifdef EFI_NT_EMULATOR
  150. //
  151. // To help ensure proper coding of integrated drivers, they are
  152. // compiled as DLLs. In NT they require a dll init entry pointer.
  153. // The macro puts a stub entry point into the DLL so it will load.
  154. //
  155. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  156. UINTN \
  157. __stdcall \
  158. _DllMainCRTStartup ( \
  159. UINTN Inst, \
  160. UINTN reason_for_call, \
  161. VOID *rserved \
  162. ) \
  163. { \
  164. return 1; \
  165. } \
  166. \
  167. int \
  168. EXPORTAPI \
  169. __cdecl \
  170. InitializeDriver ( \
  171. void *ImageHandle, \
  172. void *SystemTable \
  173. ) \
  174. { \
  175. return InitFunction(ImageHandle, SystemTable); \
  176. }
  177. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  178. (_if)->LoadInternal(type, name, NULL)
  179. #else // EFI_NT_EMULATOR
  180. //
  181. // When build similiar to FW, then link everything together as
  182. // one big module. For the MSVC toolchain, we simply tell the
  183. // linker what our driver init function is using /ENTRY.
  184. //
  185. #if defined(_MSC_EXTENSIONS)
  186. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  187. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  188. #else
  189. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  190. UINTN \
  191. InitializeDriver ( \
  192. VOID *ImageHandle, \
  193. VOID *SystemTable \
  194. ) \
  195. { \
  196. return InitFunction(ImageHandle, \
  197. SystemTable); \
  198. } \
  199. \
  200. EFI_STATUS efi_main( \
  201. EFI_HANDLE image, \
  202. EFI_SYSTEM_TABLE *systab \
  203. ) __attribute__((weak, \
  204. alias ("InitializeDriver")));
  205. #endif
  206. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  207. (_if)->LoadInternal(type, name, entry)
  208. #endif // EFI_FW_NT
  209. //
  210. // Some compilers don't support the forward reference construct:
  211. // typedef struct XXXXX
  212. //
  213. // The following macro provide a workaround for such cases.
  214. //
  215. #ifdef NO_INTERFACE_DECL
  216. #define INTERFACE_DECL(x)
  217. #else
  218. #if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
  219. #define INTERFACE_DECL(x) struct x
  220. #else
  221. #define INTERFACE_DECL(x) typedef struct x
  222. #endif
  223. #endif
  224. /* No efi call wrapper for IA32 architecture */
  225. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  226. #define EFI_FUNCTION
  227. #ifdef _MSC_EXTENSIONS
  228. #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP
  229. #endif