efibind.h 8.6 KB

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