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