3 Copyright (c) 1998 Intel Corporation
11 EFI to compile bindings
19 #ifndef X86_64_EFI_BIND
20 #define X86_64_EFI_BIND
25 #if defined(GNU_EFI_USE_MS_ABI)
26 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
27 #define HAVE_USE_MS_ABI 1
29 #error Compiler is too old for GNU_EFI_USE_MS_ABI
34 // Basic int types of various widths
37 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
39 // No ANSI C 1999/2000 stdint.h integer width declarations
41 #if defined(_MSC_EXTENSIONS)
43 // Use Microsoft C compiler integer width declarations
45 typedef unsigned __int64 uint64_t;
46 typedef __int64 int64_t;
47 typedef unsigned __int32 uint32_t;
48 typedef __int32 int32_t;
49 typedef unsigned short uint16_t;
50 typedef short int16_t;
51 typedef unsigned char uint8_t;
53 #elif defined(__GNUC__)
54 typedef unsigned long long uint64_t __attribute__((aligned (8)));
55 typedef long long int64_t __attribute__((aligned (8)));
56 typedef unsigned int uint32_t;
58 typedef unsigned short uint16_t;
59 typedef short int16_t;
60 typedef unsigned char uint8_t;
62 #elif defined(UNIX_LP64)
64 /* Use LP64 programming model from C_FLAGS for integer width declarations */
66 typedef unsigned long uint64_t;
68 typedef unsigned int uint32_t;
70 typedef unsigned short uint16_t;
71 typedef short int16_t;
72 typedef unsigned char uint8_t;
76 /* Assume P64 programming model from C_FLAGS for integer width declarations */
78 typedef unsigned long long uint64_t __attribute__((aligned (8)));
79 typedef long long int64_t __attribute__((aligned (8)));
80 typedef unsigned int uint32_t;
82 typedef unsigned short uint16_t;
83 typedef short int16_t;
84 typedef unsigned char uint8_t;
87 #elif defined(__GNUC__)
88 #include <stdint-gcc.h>
92 // Basic EFI types of various widths
95 #ifndef __WCHAR_TYPE__
96 # define __WCHAR_TYPE__ short
99 typedef uint64_t UINT64;
100 typedef int64_t INT64;
103 typedef uint32_t UINT32;
104 typedef int32_t INT32;
107 typedef uint16_t UINT16;
108 typedef int16_t INT16;
109 typedef uint8_t UINT8;
111 typedef __WCHAR_TYPE__ WCHAR;
117 typedef int64_t INTN;
118 typedef uint64_t UINTN;
120 #ifdef EFI_NT_EMULATOR
121 #define POST_CODE(_Data)
124 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
126 #define POST_CODE(_Data)
130 #define EFIERR(a) (0x8000000000000000 | a)
131 #define EFI_ERROR_MASK 0x8000000000000000
132 #define EFIERR_OEM(a) (0xc000000000000000 | a)
135 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
136 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
138 #ifdef EFI_NT_EMULATOR
139 #define BREAKPOINT() __asm { int 3 }
141 #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
145 // Pointers must be aligned to these address to function
148 #define MIN_ALIGNMENT_SIZE 4
150 #define ALIGN_VARIABLE(Value ,Adjustment) \
151 (UINTN)Adjustment = 0; \
152 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
153 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
154 Value = (UINTN)Value + (UINTN)Adjustment
158 // Define macros to build data structure signatures from characters.
161 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
162 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
163 #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))
165 // To export & import functions in the EFI emulator environment
168 #ifdef EFI_NT_EMULATOR
169 #define EXPORTAPI __declspec( dllexport )
176 // EFIAPI - prototype calling convention for EFI function pointers
177 // BOOTSERVICE - prototype for implementation of a boot service interface
178 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
179 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
180 // RUNTIME_CODE - pragma macro for declaring runtime code
183 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
184 #ifdef _MSC_EXTENSIONS
185 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
186 #elif defined(HAVE_USE_MS_ABI)
187 // Force amd64/ms calling conventions.
188 #define EFIAPI __attribute__((ms_abi))
190 #define EFIAPI // Substitute expresion to force C calling convention
195 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
196 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
197 #define RUNTIMESERVICE
198 #define RUNTIMEFUNCTION
201 #define RUNTIME_CODE(a) alloc_text("rtcode", a)
202 #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
203 #define END_RUNTIME_DATA() data_seg("")
205 #define VOLATILE volatile
207 #define MEMORY_FENCE()
209 #ifdef EFI_NT_EMULATOR
212 // To help ensure proper coding of integrated drivers, they are
213 // compiled as DLLs. In NT they require a dll init entry pointer.
214 // The macro puts a stub entry point into the DLL so it will load.
217 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
220 _DllMainCRTStartup ( \
222 UINTN reason_for_call, \
237 return InitFunction(ImageHandle, SystemTable); \
241 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
242 (_if)->LoadInternal(type, name, NULL)
244 #else // EFI_NT_EMULATOR
247 // When build similiar to FW, then link everything together as
251 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
258 return InitFunction(ImageHandle, \
262 EFI_STATUS efi_main( \
264 EFI_SYSTEM_TABLE *systab \
265 ) __attribute__((weak, \
266 alias ("InitializeDriver")));
268 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
269 (_if)->LoadInternal(type, name, entry)
274 // Some compilers don't support the forward reference construct:
275 // typedef struct XXXXX
277 // The following macro provide a workaround for such cases.
279 #ifdef NO_INTERFACE_DECL
280 #define INTERFACE_DECL(x)
283 #define INTERFACE_DECL(x) struct x
285 #define INTERFACE_DECL(x) typedef struct x
289 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
290 #if defined(HAVE_USE_MS_ABI)
291 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
293 UINTN uefi_call_wrapper(void *func, unsigned long va_num, ...);
295 #define EFI_FUNCTION __attribute__((ms_abi))
297 #ifdef _MSC_EXTENSIONS
298 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP