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