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