efibind.h revision 1.4 1 /* $NetBSD: efibind.h,v 1.4 2019/09/13 20:56:29 tnn Exp $ */
2
3 /*++
4
5 Copyright (c) 1998 Intel Corporation
6
7 Module Name:
8
9 efefind.h
10
11 Abstract:
12
13 EFI to compile bindings
14
15
16
17
18 Revision History
19
20 --*/
21
22 #ifndef __GNUC__
23 #pragma pack()
24 #endif
25
26 //
27 // Basic int types of various widths
28 //
29
30 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
31
32 // No ANSI C 1999/2000 stdint.h integer width declarations
33
34 #if defined(_MSC_EXTENSIONS)
35
36 // Use Microsoft C compiler integer width declarations
37
38 typedef unsigned __int64 uint64_t;
39 typedef __int64 int64_t;
40 typedef unsigned __int32 uint32_t;
41 typedef __int32 int32_t;
42 typedef unsigned short uint16_t;
43 typedef short int16_t;
44 typedef unsigned char uint8_t;
45 typedef char int8_t;
46 #elif defined(__GNUC__)
47 typedef int __attribute__((__mode__(__DI__))) int64_t;
48 typedef unsigned int __attribute__((__mode__(__DI__))) uint64_t;
49 typedef unsigned int uint32_t;
50 typedef int int32_t;
51 typedef unsigned short uint16_t;
52 typedef short int16_t;
53 typedef unsigned char uint8_t;
54 typedef signed char int8_t;
55 #elif defined(UNIX_LP64)
56
57 /* Use LP64 programming model from C_FLAGS for integer width declarations */
58
59 typedef unsigned long uint64_t;
60 typedef long int64_t;
61 typedef unsigned int uint32_t;
62 typedef int int32_t;
63 typedef unsigned short uint16_t;
64 typedef short int16_t;
65 typedef unsigned char uint8_t;
66 typedef char int8_t;
67 #else
68
69 /* Assume P64 programming model from C_FLAGS for integer width declarations */
70
71 typedef unsigned long long uint64_t __attribute__((aligned (8)));
72 typedef long long int64_t __attribute__((aligned (8)));
73 typedef unsigned int uint32_t;
74 typedef int int32_t;
75 typedef unsigned short uint16_t;
76 typedef short int16_t;
77 typedef unsigned char uint8_t;
78 typedef char int8_t;
79 #endif
80 #elif defined(__NetBSD__)
81 #include <sys/stdint.h>
82 #elif defined(__GNUC__)
83 #include <stdint.h>
84 #endif
85
86 //
87 // Basic EFI types of various widths
88 //
89
90 #ifndef __WCHAR_TYPE__
91 # define __WCHAR_TYPE__ short
92 #endif
93
94 #ifndef __ACTYPES_H__
95 typedef uint64_t UINT64;
96 typedef int64_t INT64;
97
98 #ifndef _BASETSD_H_
99 typedef uint32_t UINT32;
100 typedef int32_t INT32;
101 #endif
102
103 typedef uint16_t UINT16;
104 typedef int16_t INT16;
105 typedef uint8_t UINT8;
106 typedef int8_t INT8;
107 #endif /* __ACTYPES_H__ */
108 typedef __WCHAR_TYPE__ WCHAR;
109
110 #undef VOID
111 #define VOID void
112
113
114 typedef int32_t INTN;
115 typedef uint32_t UINTN;
116
117 #ifdef EFI_NT_EMULATOR
118 #define POST_CODE(_Data)
119 #else
120 #ifdef EFI_DEBUG
121 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
122 #else
123 #define POST_CODE(_Data)
124 #endif
125 #endif
126
127 #define EFIERR(a) (0x80000000 | a)
128 #define EFI_ERROR_MASK 0x80000000
129 #define EFIERR_OEM(a) (0xc0000000 | a)
130
131
132 #define BAD_POINTER 0xFBFBFBFB
133 #define MAX_ADDRESS 0xFFFFFFFF
134
135 #ifdef EFI_NT_EMULATOR
136 #define BREAKPOINT() __asm { int 3 }
137 #else
138 #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
139 #endif
140
141 //
142 // Pointers must be aligned to these address to function
143 //
144
145 #define MIN_ALIGNMENT_SIZE 4
146
147 #define ALIGN_VARIABLE(Value ,Adjustment) \
148 (UINTN)Adjustment = 0; \
149 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
150 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
151 Value = (UINTN)Value + (UINTN)Adjustment
152
153
154 //
155 // Define macros to build data structure signatures from characters.
156 //
157
158 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
159 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
160 #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))
161 //
162 // To export & import functions in the EFI emulator environment
163 //
164
165 #ifdef EFI_NT_EMULATOR
166 #define EXPORTAPI __declspec( dllexport )
167 #else
168 #define EXPORTAPI
169 #endif
170
171
172 //
173 // EFIAPI - prototype calling convention for EFI function pointers
174 // BOOTSERVICE - prototype for implementation of a boot service interface
175 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
176 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
177 // RUNTIME_CODE - pragma macro for declaring runtime code
178 //
179
180 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
181 #ifdef _MSC_EXTENSIONS
182 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
183 #else
184 #define EFIAPI // Substitute expresion to force C calling convention
185 #endif
186 #endif
187
188 #define BOOTSERVICE
189 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
190 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
191 #define RUNTIMESERVICE
192 #define RUNTIMEFUNCTION
193
194
195 #define RUNTIME_CODE(a) alloc_text("rtcode", a)
196 #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
197 #define END_RUNTIME_DATA() data_seg("")
198
199 #define VOLATILE volatile
200
201 #define MEMORY_FENCE()
202
203 #ifdef EFI_NT_EMULATOR
204
205 //
206 // To help ensure proper coding of integrated drivers, they are
207 // compiled as DLLs. In NT they require a dll init entry pointer.
208 // The macro puts a stub entry point into the DLL so it will load.
209 //
210
211 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
212 UINTN \
213 __stdcall \
214 _DllMainCRTStartup ( \
215 UINTN Inst, \
216 UINTN reason_for_call, \
217 VOID *rserved \
218 ) \
219 { \
220 return 1; \
221 } \
222 \
223 int \
224 EXPORTAPI \
225 __cdecl \
226 InitializeDriver ( \
227 void *ImageHandle, \
228 void *SystemTable \
229 ) \
230 { \
231 return InitFunction(ImageHandle, SystemTable); \
232 }
233
234
235 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
236 (_if)->LoadInternal(type, name, NULL)
237
238 #else // EFI_NT_EMULATOR
239
240 //
241 // When build similiar to FW, then link everything together as
242 // one big module. For the MSVC toolchain, we simply tell the
243 // linker what our driver init function is using /ENTRY.
244 //
245 #if defined(_MSC_EXTENSIONS)
246 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
247 __pragma(comment(linker, "/ENTRY:" # InitFunction))
248 #else
249 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
250 UINTN \
251 InitializeDriver ( \
252 VOID *ImageHandle, \
253 VOID *SystemTable \
254 ) \
255 { \
256 return InitFunction(ImageHandle, \
257 SystemTable); \
258 } \
259 \
260 EFI_STATUS efi_main( \
261 EFI_HANDLE image, \
262 EFI_SYSTEM_TABLE *systab \
263 ) __attribute__((weak, \
264 alias ("InitializeDriver")));
265 #endif
266
267 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
268 (_if)->LoadInternal(type, name, entry)
269
270 #endif // EFI_FW_NT
271
272 //
273 // Some compilers don't support the forward reference construct:
274 // typedef struct XXXXX
275 //
276 // The following macro provide a workaround for such cases.
277 //
278 #ifdef NO_INTERFACE_DECL
279 #define INTERFACE_DECL(x)
280 #else
281 #if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
282 #define INTERFACE_DECL(x) struct x
283 #else
284 #define INTERFACE_DECL(x) typedef struct x
285 #endif
286 #endif
287
288 /* No efi call wrapper for IA32 architecture */
289 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
290 #define EFI_FUNCTION
291
292 #ifdef _MSC_EXTENSIONS
293 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP
294 #endif
295
296