routed - Apply FreeBSD-SA-14:21.routed
[dragonfly.git] / sys / boot / efi / include / i386 / efibind.h
1 /*
2  * $FreeBSD: src/sys/boot/efi/include/i386/efibind.h,v 1.2 2002/05/19 03:17:22 marcel Exp $
3  * $DragonFly: src/sys/boot/efi/include/i386/efibind.h,v 1.1 2003/11/10 06:08:32 dillon Exp $
4  */
5 /*++
6
7 Copyright (c) 1998  Intel Corporation
8
9 Module Name:
10
11     efefind.h
12
13 Abstract:
14
15     EFI to compile bindings
16
17
18
19
20 Revision History
21
22 --*/
23
24 #pragma pack()
25
26
27 /*
28  * Basic int types of various widths
29  */
30
31 #if (__STDC_VERSION__ < 199901L )
32
33 /* No ANSI C 1999/2000 stdint.h integer width declarations */
34
35     #if _MSC_EXTENSIONS
36
37 /* Use Microsoft C compiler integer width declarations */
38
39         typedef unsigned __int64    uint64_t;
40         typedef __int64             int64_t;
41         typedef unsigned __int32    uint32_t;
42         typedef __int32             int32_t;
43         typedef unsigned short      uint16_t;
44         typedef short               int16_t;
45         typedef unsigned char       uint8_t;
46         typedef char                int8_t;
47     #else             
48         #ifdef UNIX_LP64
49
50 /* Use LP64 programming model from C_FLAGS for integer width declarations */
51
52             typedef unsigned long       uint64_t;
53             typedef long                int64_t;
54             typedef unsigned int        uint32_t;
55             typedef int                 int32_t;
56             typedef unsigned short      uint16_t;
57             typedef short               int16_t;
58             typedef unsigned char       uint8_t;
59             typedef char                int8_t;
60         #else
61
62 /* Assume P64 programming model from C_FLAGS for integer width declarations */
63
64             typedef unsigned long long  uint64_t;
65             typedef long long           int64_t;
66             typedef unsigned int        uint32_t;
67             typedef int                 int32_t;
68             typedef unsigned short      uint16_t;
69             typedef short               int16_t;
70             typedef unsigned char       uint8_t;
71             typedef char                int8_t;
72         #endif
73     #endif
74 #endif
75
76 /*
77  * Basic EFI types of various widths
78  */
79
80 typedef uint64_t   UINT64;
81 typedef int64_t    INT64;
82
83 #ifndef _BASETSD_H_
84     typedef uint32_t   UINT32;
85     typedef int32_t    INT32;
86 #endif
87
88 typedef uint16_t   UINT16;
89 typedef int16_t    INT16;
90 typedef uint8_t    UINT8;
91 typedef int8_t     INT8;
92
93
94 #undef VOID
95 #define VOID    void
96
97
98 typedef int32_t    INTN;
99 typedef uint32_t   UINTN;
100
101 #ifdef EFI_NT_EMULATOR
102     #define POST_CODE(_Data)
103 #else    
104     #ifdef EFI_DEBUG
105 #define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
106     #else
107         #define POST_CODE(_Data)
108     #endif  
109 #endif
110
111 #define EFIERR(a)           (0x80000000 | a)
112 #define EFI_ERROR_MASK      0x80000000
113 #define EFIERR_OEM(a)       (0xc0000000 | a)      
114
115
116 #define BAD_POINTER         0xFBFBFBFB
117 #define MAX_ADDRESS         0xFFFFFFFF
118
119 #ifdef EFI_NT_EMULATOR
120     #define BREAKPOINT()        __asm { int 3 }
121 #else
122     #define BREAKPOINT()        while (TRUE);
123 #endif
124
125 /*
126  * Pointers must be aligned to these address to function
127  */
128
129 #define MIN_ALIGNMENT_SIZE  4
130
131 #define ALIGN_VARIABLE(Value ,Adjustment) \
132             (UINTN)Adjustment = 0; \
133             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
134                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
135             Value = (UINTN)Value + (UINTN)Adjustment
136
137
138 /*
139  * Define macros to build data structure signatures from characters.
140  */
141
142 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
143 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
144 #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))
145
146 /*
147  * To export & import functions in the EFI emulator environment
148  */
149
150 #if EFI_NT_EMULATOR
151     #define EXPORTAPI           __declspec( dllexport )
152 #else
153     #define EXPORTAPI
154 #endif
155
156
157 /*
158  * EFIAPI - prototype calling convention for EFI function pointers
159  * BOOTSERVICE - prototype for implementation of a boot service interface
160  * RUNTIMESERVICE - prototype for implementation of a runtime service interface
161  * RUNTIMEFUNCTION - prototype for implementation of a runtime function that
162  *      is not a service
163  * RUNTIME_CODE - pragma macro for declaring runtime code    
164  */
165
166 /* Forces EFI calling conventions reguardless of compiler options */
167 #ifndef EFIAPI
168     #if _MSC_EXTENSIONS
169         #define EFIAPI __cdecl
170     #else
171         #define EFIAPI
172     #endif
173 #endif
174
175 #define BOOTSERVICE
176 #define RUNTIMESERVICE
177 #define RUNTIMEFUNCTION
178
179
180 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
181 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
182 #define END_RUNTIME_DATA()      data_seg("")
183
184 #define VOLATILE    volatile
185
186 #define MEMORY_FENCE()    
187
188 #ifdef EFI_NT_EMULATOR
189
190 /*
191  * To help ensure proper coding of integrated drivers, they are
192  * compiled as DLLs.  In NT they require a dll init entry pointer.
193  * The macro puts a stub entry point into the DLL so it will load.
194  */
195
196 #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
197     UINTN                                       \
198     __stdcall                                   \
199     _DllMainCRTStartup (                        \
200         UINTN    Inst,                          \
201         UINTN    reason_for_call,               \
202         VOID    *rserved                        \
203         )                                       \
204     {                                           \
205         return 1;                               \
206     }                                           \
207                                                 \
208     int                                         \
209     EXPORTAPI                                   \
210     __cdecl                                     \
211     InitializeDriver (                          \
212         void *ImageHandle,                      \
213         void *SystemTable                       \
214         )                                       \
215     {                                           \
216         return InitFunction(ImageHandle, SystemTable);       \
217     }
218
219
220     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
221         (_if)->LoadInternal(type, name, NULL)             
222
223 #else /* EFI_NT_EMULATOR */
224
225 /*
226  * When build similiar to FW, then link everything together as
227  * one big module.
228  */
229
230     #define EFI_DRIVER_ENTRY_POINT(InitFunction)
231
232     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
233             (_if)->LoadInternal(type, name, entry)
234
235 #endif /* EFI_FW_NT */
236
237 /*
238  * Some compilers don't support the forward reference construct:
239  *  typedef struct XXXXX
240  *
241  * The following macro provide a workaround for such cases.
242  */
243 #ifdef NO_INTERFACE_DECL
244 #define INTERFACE_DECL(x)
245 #else
246 #define INTERFACE_DECL(x) typedef struct x
247 #endif
248
249 #if _MSC_EXTENSIONS
250 #pragma warning ( disable : 4731 )
251 #endif
252