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