efibind.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #pragma pack()
  10. //
  11. // Basic int types of various widths
  12. //
  13. #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) && !defined(__cplusplus)
  14. // No ANSI C 1999/2000 stdint.h integer width declarations
  15. #ifdef _MSC_EXTENSIONS
  16. // Use Microsoft C compiler integer width declarations
  17. typedef unsigned __int64 uint64_t;
  18. typedef __int64 int64_t;
  19. typedef unsigned __int32 uint32_t;
  20. typedef __int32 int32_t;
  21. typedef unsigned __int16 uint16_t;
  22. typedef __int16 int16_t;
  23. typedef unsigned __int8 uint8_t;
  24. typedef __int8 int8_t;
  25. #elif defined(UNIX_LP64)
  26. // Use LP64 programming model from C_FLAGS for integer width declarations
  27. typedef unsigned long uint64_t;
  28. typedef long int64_t;
  29. typedef unsigned int uint32_t;
  30. typedef int int32_t;
  31. typedef unsigned short uint16_t;
  32. typedef short int16_t;
  33. typedef unsigned char uint8_t;
  34. typedef char int8_t;
  35. #else
  36. // Assume P64 programming model from C_FLAGS for integer width declarations
  37. typedef unsigned long long uint64_t;
  38. typedef long long int64_t;
  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. #endif
  46. typedef uint64_t uintptr_t;
  47. typedef int64_t intptr_t;
  48. #elif defined(__GNUC__)
  49. #include <stdint.h>
  50. #endif
  51. //
  52. // Basic EFI types of various widths
  53. //
  54. #include <stddef.h>
  55. typedef wchar_t CHAR16;
  56. #define WCHAR CHAR16
  57. typedef uint64_t UINT64;
  58. typedef int64_t INT64;
  59. typedef uint32_t UINT32;
  60. typedef int32_t INT32;
  61. typedef uint16_t UINT16;
  62. typedef int16_t INT16;
  63. typedef uint8_t UINT8;
  64. typedef char CHAR8;
  65. typedef int8_t INT8;
  66. #undef VOID
  67. typedef void VOID;
  68. typedef int64_t INTN;
  69. typedef uint64_t UINTN;
  70. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  71. // BugBug: Code to debug
  72. //
  73. #define BIT63 0x8000000000000000
  74. #define PLATFORM_IOBASE_ADDRESS (0xffffc000000 | BIT63)
  75. #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
  76. //
  77. // Macro's with casts make this much easier to use and read.
  78. //
  79. #define PORT_TO_MEM8D(_Port) (*(UINT8 *)(PORT_TO_MEMD(_Port)))
  80. #define POST_CODE(_Data) (PORT_TO_MEM8D(0x80) = (_Data))
  81. //
  82. // BugBug: End Debug Code!!!
  83. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84. #define EFIERR(a) (0x8000000000000000 | a)
  85. #define EFI_ERROR_MASK 0x8000000000000000
  86. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  87. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  88. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  89. #define BREAKPOINT() while (TRUE)
  90. //
  91. // Pointers must be aligned to these address to function
  92. // you will get an alignment fault if this value is less than 8
  93. //
  94. #define MIN_ALIGNMENT_SIZE 8
  95. #define ALIGN_VARIABLE(Value , Adjustment) \
  96. (UINTN) Adjustment = 0; \
  97. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  98. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  99. Value = (UINTN)Value + (UINTN)Adjustment
  100. //
  101. // Define macros to create data structure signatures.
  102. //
  103. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  104. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  105. #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))
  106. //
  107. // To export & import functions in the EFI emulator environment
  108. //
  109. #define EXPORTAPI
  110. //
  111. // EFIAPI - prototype calling convention for EFI function pointers
  112. // BOOTSERVICE - prototype for implementation of a boot service interface
  113. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  114. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  115. // RUNTIME_CODE - pragma macro for declaring runtime code
  116. //
  117. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  118. #ifdef _MSC_EXTENSIONS
  119. #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
  120. #else
  121. #define EFIAPI // Substitute expresion to force C calling convention
  122. #endif
  123. #endif
  124. #define BOOTSERVICE
  125. #define RUNTIMESERVICE
  126. #define RUNTIMEFUNCTION
  127. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  128. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  129. #define END_RUNTIME_DATA() data_seg("")
  130. #define VOLATILE volatile
  131. //
  132. // BugBug: Need to find out if this is portable accross compliers.
  133. //
  134. #ifdef __GNUC__
  135. #define MEMORY_FENCE() __asm__ __volatile__ ("mf.a" ::: "memory")
  136. #else
  137. void __mf (void);
  138. #pragma intrinsic (__mf)
  139. #define MEMORY_FENCE() __mf()
  140. #endif
  141. //
  142. // When build similiar to FW, then link everything together as
  143. // one big module. For the MSVC toolchain, we simply tell the
  144. // linker what our driver init function is using /ENTRY.
  145. //
  146. #if defined(_MSC_EXTENSIONS)
  147. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  148. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  149. #else
  150. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  151. UINTN \
  152. InitializeDriver ( \
  153. VOID *ImageHandle, \
  154. VOID *SystemTable \
  155. ) \
  156. { \
  157. return InitFunction(ImageHandle, \
  158. SystemTable); \
  159. } \
  160. \
  161. EFI_STATUS efi_main( \
  162. EFI_HANDLE image, \
  163. EFI_SYSTEM_TABLE *systab \
  164. ) __attribute__((weak, \
  165. alias ("InitializeDriver")));
  166. #endif
  167. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  168. (_if)->LoadInternal(type, name, entry)
  169. //
  170. // Some compilers don't support the forward reference construct:
  171. // typedef struct XXXXX
  172. //
  173. // The following macro provide a workaround for such cases.
  174. //
  175. #ifdef NO_INTERFACE_DECL
  176. #define INTERFACE_DECL(x)
  177. #else
  178. #if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
  179. #define INTERFACE_DECL(x) struct x
  180. #else
  181. #define INTERFACE_DECL(x) typedef struct x
  182. #endif
  183. #endif
  184. /* No efi call wrapper for IA32 architecture */
  185. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  186. #define EFI_FUNCTION