3 Copyright (c) 1998 Intel Corporation
11 EFI to compile bindings
25 // Basic int types of various widths
28 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
30 // No ANSI C 1999/2000 stdint.h integer width declarations
32 #if defined(_MSC_EXTENSIONS)
34 // Use Microsoft C compiler integer width declarations
36 typedef unsigned __int64
uint64_t;
37 typedef __int64
int64_t;
38 typedef unsigned __int32
uint32_t;
39 typedef __int32
int32_t;
40 typedef unsigned short uint16_t;
41 typedef short int16_t;
42 typedef unsigned char uint8_t;
44 #elif defined(__GNUC__)
45 typedef int __attribute__((__mode__(__DI__
))) int64_t;
46 typedef unsigned int __attribute__((__mode__(__DI__
))) uint64_t;
47 typedef unsigned int uint32_t;
49 typedef unsigned short uint16_t;
50 typedef short int16_t;
51 typedef unsigned char uint8_t;
52 typedef signed char int8_t;
53 #elif defined(UNIX_LP64)
55 /* Use LP64 programming model from C_FLAGS for integer width declarations */
57 typedef unsigned long uint64_t;
59 typedef unsigned int uint32_t;
61 typedef unsigned short uint16_t;
62 typedef short int16_t;
63 typedef unsigned char uint8_t;
67 /* Assume P64 programming model from C_FLAGS for integer width declarations */
69 typedef unsigned long long uint64_t __attribute__((aligned (8)));
70 typedef long long int64_t __attribute__((aligned (8)));
71 typedef unsigned int uint32_t;
73 typedef unsigned short uint16_t;
74 typedef short int16_t;
75 typedef unsigned char uint8_t;
78 #elif defined(__GNUC__)
83 // Basic EFI types of various widths
86 #ifndef __WCHAR_TYPE__
87 # define __WCHAR_TYPE__ short
90 typedef uint64_t UINT64
;
91 typedef int64_t INT64
;
94 typedef uint32_t UINT32
;
95 typedef int32_t INT32
;
98 typedef uint16_t UINT16
;
99 typedef int16_t INT16
;
100 typedef uint8_t UINT8
;
102 typedef __WCHAR_TYPE__ WCHAR
;
108 typedef int32_t INTN
;
109 typedef uint32_t UINTN
;
111 #ifdef EFI_NT_EMULATOR
112 #define POST_CODE(_Data)
115 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
117 #define POST_CODE(_Data)
121 #define EFIERR(a) (0x80000000 | a)
122 #define EFI_ERROR_MASK 0x80000000
123 #define EFIERR_OEM(a) (0xc0000000 | a)
126 #define BAD_POINTER 0xFBFBFBFB
127 #define MAX_ADDRESS 0xFFFFFFFF
129 #ifdef EFI_NT_EMULATOR
130 #define BREAKPOINT() __asm { int 3 }
132 #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
136 // Pointers must be aligned to these address to function
139 #define MIN_ALIGNMENT_SIZE 4
141 #define ALIGN_VARIABLE(Value ,Adjustment) \
142 (UINTN)Adjustment = 0; \
143 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
144 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
145 Value = (UINTN)Value + (UINTN)Adjustment
149 // Define macros to build data structure signatures from characters.
152 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
153 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
154 #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))
156 // To export & import functions in the EFI emulator environment
159 #ifdef EFI_NT_EMULATOR
160 #define EXPORTAPI __declspec( dllexport )
167 // EFIAPI - prototype calling convention for EFI function pointers
168 // BOOTSERVICE - prototype for implementation of a boot service interface
169 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
170 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
171 // RUNTIME_CODE - pragma macro for declaring runtime code
174 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
175 #ifdef _MSC_EXTENSIONS
176 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
178 #define EFIAPI // Substitute expresion to force C calling convention
183 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
184 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
185 #define RUNTIMESERVICE
186 #define RUNTIMEFUNCTION
189 #define RUNTIME_CODE(a) alloc_text("rtcode", a)
190 #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
191 #define END_RUNTIME_DATA() data_seg("")
193 #define VOLATILE volatile
195 #define MEMORY_FENCE()
197 #ifdef EFI_NT_EMULATOR
200 // To help ensure proper coding of integrated drivers, they are
201 // compiled as DLLs. In NT they require a dll init entry pointer.
202 // The macro puts a stub entry point into the DLL so it will load.
205 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
208 _DllMainCRTStartup ( \
210 UINTN reason_for_call, \
225 return InitFunction(ImageHandle, SystemTable); \
229 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
230 (_if)->LoadInternal(type, name, NULL)
232 #else // EFI_NT_EMULATOR
235 // When build similiar to FW, then link everything together as
239 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
246 return InitFunction(ImageHandle, \
250 EFI_STATUS efi_main( \
252 EFI_SYSTEM_TABLE *systab \
253 ) __attribute__((weak, \
254 alias ("InitializeDriver")));
256 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
257 (_if)->LoadInternal(type, name, entry)
262 // Some compilers don't support the forward reference construct:
263 // typedef struct XXXXX
265 // The following macro provide a workaround for such cases.
267 #ifdef NO_INTERFACE_DECL
268 #define INTERFACE_DECL(x)
271 #define INTERFACE_DECL(x) struct x
273 #define INTERFACE_DECL(x) typedef struct x
277 /* No efi call wrapper for IA32 architecture */
278 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
281 #ifdef _MSC_EXTENSIONS
282 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP