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