efibind.h 7.1 KB

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