4 Copyright (c) 1999 - 2003 Intel Corporation. All rights reserved
5 This software and associated documentation (if any) is furnished
6 under a license and may only be used or copied in accordance
7 with the terms of the license. Except as permitted by such
8 license, no part of this software or documentation may be
9 reproduced, stored in a retrieval system, or transmitted in any
10 form or by any means without the express written consent of
19 EFI to compile bindings
32 #include <sys/stdint.h>
35 // Basic int types of various widths
38 #if (__STDC_VERSION__ < 199901L )
40 // No ANSI C 1999/2000 stdint.h integer width declarations
44 // Use Microsoft C compiler integer width declarations
46 typedef unsigned __int64 uint64_t;
47 typedef __int64 int64_t;
48 typedef unsigned __int32 uint32_t;
49 typedef __int32 int32_t;
50 typedef unsigned short uint16_t;
51 typedef short int16_t;
52 typedef unsigned char uint8_t;
57 // Use LP64 programming model from C_FLAGS for integer width declarations
59 typedef unsigned long uint64_t;
61 typedef unsigned int uint32_t;
63 typedef unsigned short uint16_t;
64 typedef short int16_t;
65 typedef unsigned char uint8_t;
69 // Assume P64 programming model from C_FLAGS for integer width declarations
71 typedef unsigned long long uint64_t;
72 typedef long long int64_t;
73 typedef unsigned int uint32_t;
75 typedef unsigned short uint16_t;
76 typedef short int16_t;
77 typedef unsigned char uint8_t;
82 #endif /* __FreeBSD__ */
85 // Basic EFI types of various widths
88 typedef uint64_t UINT64;
89 typedef int64_t INT64;
92 typedef uint32_t UINT32;
93 typedef int32_t INT32;
96 typedef uint16_t UINT16;
97 typedef int16_t INT16;
98 typedef uint8_t UINT8;
106 typedef int32_t INTN;
107 typedef uint32_t UINTN;
109 #ifdef EFI_NT_EMULATOR
110 #define POST_CODE(_Data)
113 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
115 #define POST_CODE(_Data)
119 #define EFIERR(a) (0x80000000 | a)
120 #define EFI_ERROR_MASK 0x80000000
121 #define EFIERR_OEM(a) (0xc0000000 | a)
124 #define BAD_POINTER 0xFBFBFBFB
125 #define MAX_ADDRESS 0xFFFFFFFF
127 #define BREAKPOINT() __asm { int 3 }
130 // Pointers must be aligned to these address to function
133 #define MIN_ALIGNMENT_SIZE 4
135 #define ALIGN_VARIABLE(Value ,Adjustment) \
136 (UINTN)Adjustment = 0; \
137 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
138 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
139 Value = (UINTN)Value + (UINTN)Adjustment
143 // Define macros to build data structure signatures from characters.
146 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
147 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
148 #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))
151 // EFIAPI - prototype calling convention for EFI function pointers
152 // BOOTSERVICE - prototype for implementation of a boot service interface
153 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
154 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
155 // RUNTIME_CODE - pragma macro for declaring runtime code
158 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
160 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
162 #define EFIAPI // Substitute expresion to force C calling convention
167 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
168 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
169 #define RUNTIMESERVICE
170 #define RUNTIMEFUNCTION
173 #define RUNTIME_CODE(a) alloc_text("rtcode", a)
174 #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
175 #define END_RUNTIME_DATA() data_seg()
177 #define VOLATILE volatile
179 #define MEMORY_FENCE()
181 #ifdef EFI_NO_INTERFACE_DECL
182 #define EFI_FORWARD_DECLARATION(x)
183 #define EFI_INTERFACE_DECL(x)
185 #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
186 #define EFI_INTERFACE_DECL(x) typedef struct x
189 #ifdef EFI_NT_EMULATOR
192 // To help ensure proper coding of integrated drivers, they are
193 // compiled as DLLs. In NT they require a dll init entry pointer.
194 // The macro puts a stub entry point into the DLL so it will load.
197 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
200 EFI_HANDLE ImageHandle, \
201 EFI_SYSTEM_TABLE *SystemTable \
206 _DllMainCRTStartup ( \
208 UINTN reason_for_call, \
216 __declspec( dllexport ) \
223 return InitFunction(ImageHandle, SystemTable); \
227 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
228 (_if)->LoadInternal(type, name, NULL)
230 #else // EFI_NT_EMULATOR
233 // When build similiar to FW, then link everything together as
237 #define EFI_DRIVER_ENTRY_POINT(InitFunction)
239 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
240 (_if)->LoadInternal(type, name, entry)
245 #define INTERFACE_DECL(x) struct x
248 // Some compilers don't support the forward reference construct:
249 // typedef struct XXXXX
251 // The following macro provide a workaround for such cases.
253 #ifdef NO_INTERFACE_DECL
254 #define INTERFACE_DECL(x)
256 #define INTERFACE_DECL(x) typedef struct x
258 #endif /* __FreeBSD__ */
261 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP