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