xref: /freebsd/stand/efi/include/i386/efibind.h (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1 /* $FreeBSD$ */
2 /*++
3 
4 Copyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5 This software and associated documentation (if any) is furnished
6 under a license and may only be used or copied in accordance
7 with the terms of the license. Except as permitted by such
8 license, no part of this software or documentation may be
9 reproduced, stored in a retrieval system, or transmitted in any
10 form or by any means without the express written consent of
11 Intel Corporation.
12 
13 Module Name:
14 
15     efefind.h
16 
17 Abstract:
18 
19     EFI to compile bindings
20 
21 
22 
23 
24 Revision History
25 
26 --*/
27 
28 #pragma pack()
29 
30 
31 #ifdef __FreeBSD__
32 #include <sys/stdint.h>
33 #else
34 //
35 // Basic int types of various widths
36 //
37 
38 #if (__STDC_VERSION__ < 199901L )
39 
40     // No ANSI C 1999/2000 stdint.h integer width declarations
41 
42     #ifdef _MSC_EXTENSIONS
43 
44         // Use Microsoft C compiler integer width declarations
45 
46         typedef unsigned __int64    uint64_t;
47         typedef __int64             int64_t;
48         typedef unsigned __int32    uint32_t;
49         typedef __int32             int32_t;
50         typedef unsigned short      uint16_t;
51         typedef short               int16_t;
52         typedef unsigned char       uint8_t;
53         typedef char                int8_t;
54     #else
55         #ifdef 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;
72             typedef long long           int64_t;
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     #endif
81 #endif
82 #endif	/* __FreeBSD__ */
83 
84 //
85 // Basic EFI types of various widths
86 //
87 
88 #ifndef ACPI_THREAD_ID		/* ACPI's definitions are fine, use those */
89 #define ACPI_USE_SYSTEM_INTTYPES 1	/* Tell ACPI we've defined types */
90 
91 typedef uint64_t   UINT64;
92 typedef int64_t    INT64;
93 
94 #ifndef _BASETSD_H_
95     typedef uint32_t   UINT32;
96     typedef int32_t    INT32;
97 #endif
98 
99 typedef uint16_t   UINT16;
100 typedef int16_t    INT16;
101 typedef uint8_t    UINT8;
102 typedef int8_t     INT8;
103 
104 #endif
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 #define BREAKPOINT()        __asm { int 3 }
132 
133 //
134 // Pointers must be aligned to these address to function
135 //
136 
137 #define MIN_ALIGNMENT_SIZE  4
138 
139 #define ALIGN_VARIABLE(Value ,Adjustment) \
140             (UINTN)Adjustment = 0; \
141             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
142                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
143             Value = (UINTN)Value + (UINTN)Adjustment
144 
145 
146 //
147 // Define macros to build data structure signatures from characters.
148 //
149 
150 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
151 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
152 #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))
153 
154 //
155 // EFIAPI - prototype calling convention for EFI function pointers
156 // BOOTSERVICE - prototype for implementation of a boot service interface
157 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
158 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
159 // RUNTIME_CODE - pragma macro for declaring runtime code
160 //
161 
162 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
163     #ifdef _MSC_EXTENSIONS
164         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
165     #else
166         #define EFIAPI          // Substitute expresion to force C calling convention
167     #endif
168 #endif
169 
170 #define BOOTSERVICE
171 //#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
172 //#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
173 #define RUNTIMESERVICE
174 #define RUNTIMEFUNCTION
175 
176 
177 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
178 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
179 #define END_RUNTIME_DATA()      data_seg()
180 
181 #define VOLATILE    volatile
182 
183 #define MEMORY_FENCE()
184 
185 #ifdef EFI_NO_INTERFACE_DECL
186   #define EFI_FORWARD_DECLARATION(x)
187   #define EFI_INTERFACE_DECL(x)
188 #else
189   #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
190   #define EFI_INTERFACE_DECL(x) typedef struct x
191 #endif
192 
193 #ifdef EFI_NT_EMULATOR
194 
195 //
196 // To help ensure proper coding of integrated drivers, they are
197 // compiled as DLLs.  In NT they require a dll init entry pointer.
198 // The macro puts a stub entry point into the DLL so it will load.
199 //
200 
201 #define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
202     EFI_STATUS                                          \
203     InitFunction (                                      \
204       EFI_HANDLE  ImageHandle,                          \
205       EFI_SYSTEM_TABLE  *SystemTable                    \
206       );                                                \
207                                                         \
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     __declspec( dllexport )                             \
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 similar to FW, then link everything together as
238 // one big module.
239 //
240 
241     #define EFI_DRIVER_ENTRY_POINT(InitFunction)
242 
243     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
244             (_if)->LoadInternal(type, name, entry)
245 
246 #endif // EFI_FW_NT
247 
248 #ifdef __FreeBSD__
249 #define INTERFACE_DECL(x) struct x
250 #else
251 //
252 // Some compilers don't support the forward reference construct:
253 //  typedef struct XXXXX
254 //
255 // The following macro provide a workaround for such cases.
256 //
257 #ifdef NO_INTERFACE_DECL
258 #define INTERFACE_DECL(x)
259 #else
260 #define INTERFACE_DECL(x) typedef struct x
261 #endif
262 #endif	/* __FreeBSD__ */
263 
264 #ifdef _MSC_EXTENSIONS
265 #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
266 #endif
267 
268