efibind.h 7.4 KB

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