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