]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/boot/efi/include/amd64/efibind.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / boot / efi / include / amd64 / efibind.h
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     #if _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 typedef uint64_t   UINT64;
89 typedef int64_t    INT64;
90
91 #ifndef _BASETSD_H_
92     typedef uint32_t   UINT32;
93     typedef int32_t    INT32;
94 #endif
95
96 typedef uint16_t   UINT16;
97 typedef int16_t    INT16;
98 typedef uint8_t    UINT8;
99 typedef int8_t     INT8;
100
101
102 #undef VOID
103 #define VOID    void
104
105
106 typedef int64_t    INTN;
107 typedef uint64_t   UINTN;
108
109 #ifdef EFI_NT_EMULATOR
110     #define POST_CODE(_Data)
111 #else    
112     #ifdef EFI_DEBUG
113 #define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
114     #else
115         #define POST_CODE(_Data)
116     #endif  
117 #endif
118
119 #define EFIERR(a)           (0x8000000000000000 | a)
120 #define EFI_ERROR_MASK      0x8000000000000000
121 #define EFIERR_OEM(a)       (0xc000000000000000 | a)      
122
123
124 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
125 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
126
127 #define BREAKPOINT()        __asm { int 3 }
128
129 //
130 // Pointers must be aligned to these address to function
131 //
132
133 #define MIN_ALIGNMENT_SIZE  4
134
135 #define ALIGN_VARIABLE(Value ,Adjustment) \
136             (UINTN)Adjustment = 0; \
137             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
138                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
139             Value = (UINTN)Value + (UINTN)Adjustment
140
141
142 //
143 // Define macros to build data structure signatures from characters.
144 //
145
146 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
147 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
148 #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))
149
150 //
151 // EFIAPI - prototype calling convention for EFI function pointers
152 // BOOTSERVICE - prototype for implementation of a boot service interface
153 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
154 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
155 // RUNTIME_CODE - pragma macro for declaring runtime code    
156 //
157
158 #ifdef  __amd64__
159 #define EFIAPI  __attribute__((ms_abi))
160 #endif
161
162 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options 
163     #if _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 similiar 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 #if _MSC_EXTENSIONS
265 #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
266 #endif
267