Debian Codegraph @

gnu-efi/inc/x86_64/efibind.h

raw
1 /*++
2
3 Copyright (c) 1998 Intel Corporation
4
5 Module Name:
6
7 efefind.h
8
9 Abstract:
10
11 EFI to compile bindings
12
13
14
15
16 Revision History
17
18 --*/
19 #ifndef X86_64_EFI_BIND
20 #define X86_64_EFI_BIND
21 #ifndef __GNUC__
22 #pragma pack()
23 #endif
24
25 #if defined(_MSC_VER)
26 #define HAVE_USE_MS_ABI 1
27 #elif defined(GNU_EFI_USE_MS_ABI)
28 #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))||(defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 2)))
29 #define HAVE_USE_MS_ABI 1
30 #else
31 #error Compiler is too old for GNU_EFI_USE_MS_ABI
32 #endif
33 #endif
34
35 //
36 // Basic int types of various widths
37 //
38
39 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) && !defined(__cplusplus)
40
41 // No ANSI C 1999/2000 stdint.h integer width declarations
42
43 #if defined(_MSC_EXTENSIONS)
44
45 // Use Microsoft C compiler integer width declarations
46
47 typedef unsigned __int64 uint64_t;
48 typedef __int64 int64_t;
49 typedef unsigned __int32 uint32_t;
50 typedef __int32 int32_t;
51 typedef unsigned short uint16_t;
52 typedef short int16_t;
53 typedef unsigned char uint8_t;
54 typedef char int8_t;
55 #elif defined(__GNUC__)
56 typedef int __attribute__((__mode__(__DI__))) int64_t;
57 typedef unsigned int __attribute__((__mode__(__DI__))) uint64_t;
58 typedef unsigned int uint32_t;
59 typedef int int32_t;
60 typedef unsigned short uint16_t;
61 typedef short int16_t;
62 typedef unsigned char uint8_t;
63 typedef signed char int8_t;
64 #elif defined(UNIX_LP64)
65
66 /* Use LP64 programming model from C_FLAGS for integer width declarations */
67
68 typedef unsigned long uint64_t;
69 typedef long int64_t;
70 typedef unsigned int uint32_t;
71 typedef int int32_t;
72 typedef unsigned short uint16_t;
73 typedef short int16_t;
74 typedef unsigned char uint8_t;
75 typedef char int8_t;
76 #else
77
78 /* Assume P64 programming model from C_FLAGS for integer width declarations */
79
80 typedef unsigned long long uint64_t __attribute__((aligned (8)));
81 typedef long long int64_t __attribute__((aligned (8)));
82 typedef unsigned int uint32_t;
83 typedef int int32_t;
84 typedef unsigned short uint16_t;
85 typedef short int16_t;
86 typedef unsigned char uint8_t;
87 typedef char int8_t;
88 #endif
89 typedef uint64_t uintptr_t;
90 typedef int64_t intptr_t;
91 #else
92 #include <stdint.h>
93 #endif
94
95 //
96 // Basic EFI types of various widths
97 //
98
99
100 typedef uint64_t UINT64;
101 typedef int64_t INT64;
102
103 #ifndef _BASETSD_H_
104 typedef uint32_t UINT32;
105 typedef int32_t INT32;
106 #endif
107
108 typedef uint16_t UINT16;
109 typedef uint16_t CHAR16;
110 typedef int16_t INT16;
111
112 typedef uint8_t UINT8;
113 typedef char CHAR8;
114 typedef int8_t INT8;
115
116 #undef VOID
117 #define VOID void
118
119
120 typedef int64_t INTN;
121 typedef uint64_t UINTN;
122
123 #ifdef EFI_NT_EMULATOR
124 #define POST_CODE(_Data)
125 #else
126 #ifdef EFI_DEBUG
127 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al
128 #else
129 #define POST_CODE(_Data)
130 #endif
131 #endif
132
133 #define EFIERR(a) (0x8000000000000000 | a)
134 #define EFI_ERROR_MASK 0x8000000000000000
135 #define EFIERR_OEM(a) (0xc000000000000000 | a)
136
137
138 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
139 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
140
141 #ifdef EFI_NT_EMULATOR
142 #define BREAKPOINT() __asm { int 3 }
143 #else
144 #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
145 #endif
146
147 //
148 // Pointers must be aligned to these address to function
149 //
150
151 #define MIN_ALIGNMENT_SIZE 4
152
153 #define ALIGN_VARIABLE(Value ,Adjustment) \
154 (UINTN)Adjustment = 0; \
155 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
156 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
157 Value = (UINTN)Value + (UINTN)Adjustment
158
159
160 //
161 // Define macros to build data structure signatures from characters.
162 //
163
164 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
165 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
166 #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))
167 //
168 // To export & import functions in the EFI emulator environment
169 //
170
171 #ifdef EFI_NT_EMULATOR
172 #define EXPORTAPI __declspec( dllexport )
173 #else
174 #define EXPORTAPI
175 #endif
176
177
178 //
179 // EFIAPI - prototype calling convention for EFI function pointers
180 // BOOTSERVICE - prototype for implementation of a boot service interface
181 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
182 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
183 // RUNTIME_CODE - pragma macro for declaring runtime code
184 //
185
186 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
187 #ifdef _MSC_EXTENSIONS
188 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
189 #elif defined(HAVE_USE_MS_ABI)
190 // Force amd64/ms calling conventions.
191 #define EFIAPI __attribute__((ms_abi))
192 #else
193 #define EFIAPI // Substitute expresion to force C calling convention
194 #endif
195 #endif
196
197 #define BOOTSERVICE
198 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a
199 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a
200 #define RUNTIMESERVICE
201 #define RUNTIMEFUNCTION
202
203
204 #define RUNTIME_CODE(a) alloc_text("rtcode", a)
205 #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
206 #define END_RUNTIME_DATA() data_seg("")
207
208 #define VOLATILE volatile
209
210 #define MEMORY_FENCE()
211
212 #ifdef EFI_NT_EMULATOR
213
214 //
215 // To help ensure proper coding of integrated drivers, they are
216 // compiled as DLLs. In NT they require a dll init entry pointer.
217 // The macro puts a stub entry point into the DLL so it will load.
218 //
219
220 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
221 UINTN \
222 __stdcall \
223 _DllMainCRTStartup ( \
224 UINTN Inst, \
225 UINTN reason_for_call, \
226 VOID *rserved \
227 ) \
228 { \
229 return 1; \
230 } \
231 \
232 int \
233 EXPORTAPI \
234 __cdecl \
235 InitializeDriver ( \
236 void *ImageHandle, \
237 void *SystemTable \
238 ) \
239 { \
240 return InitFunction(ImageHandle, SystemTable); \
241 }
242
243
244 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
245 (_if)->LoadInternal(type, name, NULL)
246
247 #else // EFI_NT_EMULATOR
248
249 //
250 // When build similiar to FW, then link everything together as
251 // one big module. For the MSVC toolchain, we simply tell the
252 // linker what our driver init function is using /ENTRY.
253 //
254 #if defined(_MSC_EXTENSIONS)
255 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
256 __pragma(comment(linker, "/ENTRY:" # InitFunction))
257 #else
258 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
259 UINTN \
260 InitializeDriver ( \
261 VOID *ImageHandle, \
262 VOID *SystemTable \
263 ) \
264 { \
265 return InitFunction(ImageHandle, \
266 SystemTable); \
267 } \
268 \
269 EFI_STATUS efi_main( \
270 EFI_HANDLE image, \
271 EFI_SYSTEM_TABLE *systab \
272 ) __attribute__((weak, \
273 alias ("InitializeDriver")));
274 #endif
275
276 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
277 (_if)->LoadInternal(type, name, entry)
278
279 #endif // EFI_NT_EMULATOR
280
281 //
282 // Some compilers don't support the forward reference construct:
283 // typedef struct XXXXX
284 //
285 // The following macro provide a workaround for such cases.
286 //
287 #ifdef NO_INTERFACE_DECL
288 #define INTERFACE_DECL(x)
289 #else
290 #if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
291 #define INTERFACE_DECL(x) struct x
292 #else
293 #define INTERFACE_DECL(x) typedef struct x
294 #endif
295 #endif
296
297 /* for x86_64, EFI_FUNCTION_WRAPPER must be defined */
298 #if defined(HAVE_USE_MS_ABI)
299 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
300 #else
301 /*
302 Credits for macro-magic:
303 https://groups.google.com/forum/?fromgroups#!topic/comp.std.c/d-6Mj5Lko_s
304 http://efesx.com/2010/08/31/overloading-macros/
305 */
306 #define __VA_NARG__(...) \
307 __VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N())
308 #define __VA_NARG_(...) \
309 __VA_ARG_N(__VA_ARGS__)
310 #define __VA_ARG_N( \
311 _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,N,...) N
312 #define __RSEQ_N() \
313 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
314
315 #define __VA_ARG_NSUFFIX__(prefix,...) \
316 __VA_ARG_NSUFFIX_N(prefix, __VA_NARG__(__VA_ARGS__))
317 #define __VA_ARG_NSUFFIX_N(prefix,nargs) \
318 __VA_ARG_NSUFFIX_N_(prefix, nargs)
319 #define __VA_ARG_NSUFFIX_N_(prefix,nargs) \
320 prefix ## nargs
321
322 /* Prototypes of EFI cdecl -> stdcall trampolines */
323 UINT64 efi_call0(void *func);
324 UINT64 efi_call1(void *func, UINT64 arg1);
325 UINT64 efi_call2(void *func, UINT64 arg1, UINT64 arg2);
326 UINT64 efi_call3(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3);
327 UINT64 efi_call4(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
328 UINT64 arg4);
329 UINT64 efi_call5(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
330 UINT64 arg4, UINT64 arg5);
331 UINT64 efi_call6(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
332 UINT64 arg4, UINT64 arg5, UINT64 arg6);
333 UINT64 efi_call7(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
334 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7);
335 UINT64 efi_call8(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
336 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7,
337 UINT64 arg8);
338 UINT64 efi_call9(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
339 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7,
340 UINT64 arg8, UINT64 arg9);
341 UINT64 efi_call10(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
342 UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7,
343 UINT64 arg8, UINT64 arg9, UINT64 arg10);
344
345 /* Front-ends to efi_callX to avoid compiler warnings */
346 #define _cast64_efi_call0(f) \
347 efi_call0(f)
348 #define _cast64_efi_call1(f,a1) \
349 efi_call1(f, (UINT64)(a1))
350 #define _cast64_efi_call2(f,a1,a2) \
351 efi_call2(f, (UINT64)(a1), (UINT64)(a2))
352 #define _cast64_efi_call3(f,a1,a2,a3) \
353 efi_call3(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3))
354 #define _cast64_efi_call4(f,a1,a2,a3,a4) \
355 efi_call4(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4))
356 #define _cast64_efi_call5(f,a1,a2,a3,a4,a5) \
357 efi_call5(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
358 (UINT64)(a5))
359 #define _cast64_efi_call6(f,a1,a2,a3,a4,a5,a6) \
360 efi_call6(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
361 (UINT64)(a5), (UINT64)(a6))
362 #define _cast64_efi_call7(f,a1,a2,a3,a4,a5,a6,a7) \
363 efi_call7(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
364 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7))
365 #define _cast64_efi_call8(f,a1,a2,a3,a4,a5,a6,a7,a8) \
366 efi_call8(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
367 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8))
368 #define _cast64_efi_call9(f,a1,a2,a3,a4,a5,a6,a7,a8,a9) \
369 efi_call9(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
370 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
371 (UINT64)(a9))
372 #define _cast64_efi_call10(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
373 efi_call10(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \
374 (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
375 (UINT64)(a9), (UINT64)(a10))
376
377 /* main wrapper (va_num ignored) */
378 #define uefi_call_wrapper(func,va_num,...) \
379 __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func , ##__VA_ARGS__)
380
381 #endif
382
383 #if defined(HAVE_USE_MS_ABI) && !defined(_MSC_EXTENSIONS)
384 #define EFI_FUNCTION __attribute__((ms_abi))
385 #else
386 #define EFI_FUNCTION
387 #endif
388
389 #ifdef _MSC_EXTENSIONS
390 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP
391 #endif
392
393 #endif