efibind.h revision 77943
1/* $FreeBSD: head/sys/boot/efi/include/i386/efibind.h 77943 2001-06-09 16:49:51Z dfr $ */
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);    // Make it hang on Bios[Dbg]32
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// To export & import functions in the EFI emulator environment
144//
145
146#if EFI_NT_EMULATOR
147    #define EXPORTAPI           __declspec( dllexport )
148#else
149    #define EXPORTAPI
150#endif
151
152
153//
154// EFIAPI - prototype calling convention for EFI function pointers
155// BOOTSERVICE - prototype for implementation of a boot service interface
156// RUNTIMESERVICE - prototype for implementation of a runtime service interface
157// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
158// RUNTIME_CODE - pragma macro for declaring runtime code
159//
160
161#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
162    #if _MSC_EXTENSIONS
163        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
164    #else
165        #define EFIAPI          // Substitute expresion to force C calling convention
166    #endif
167#endif
168
169#define BOOTSERVICE
170//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
171//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
172#define RUNTIMESERVICE
173#define RUNTIMEFUNCTION
174
175
176#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
177#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
178#define END_RUNTIME_DATA()      data_seg("")
179
180#define VOLATILE    volatile
181
182#define MEMORY_FENCE()
183
184#ifdef EFI_NT_EMULATOR
185
186//
187// To help ensure proper coding of integrated drivers, they are
188// compiled as DLLs.  In NT they require a dll init entry pointer.
189// The macro puts a stub entry point into the DLL so it will load.
190//
191
192#define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
193    UINTN                                       \
194    __stdcall                                   \
195    _DllMainCRTStartup (                        \
196        UINTN    Inst,                          \
197        UINTN    reason_for_call,               \
198        VOID    *rserved                        \
199        )                                       \
200    {                                           \
201        return 1;                               \
202    }                                           \
203                                                \
204    int                                         \
205    EXPORTAPI                                   \
206    __cdecl                                     \
207    InitializeDriver (                          \
208        void *ImageHandle,                      \
209        void *SystemTable                       \
210        )                                       \
211    {                                           \
212        return InitFunction(ImageHandle, SystemTable);       \
213    }
214
215
216    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
217        (_if)->LoadInternal(type, name, NULL)
218
219#else // EFI_NT_EMULATOR
220
221//
222// When build similiar to FW, then link everything together as
223// one big module.
224//
225
226    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
227
228    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
229            (_if)->LoadInternal(type, name, entry)
230
231#endif // EFI_FW_NT
232
233//
234// Some compilers don't support the forward reference construct:
235//  typedef struct XXXXX
236//
237// The following macro provide a workaround for such cases.
238//
239#ifdef NO_INTERFACE_DECL
240#define INTERFACE_DECL(x)
241#else
242#define INTERFACE_DECL(x) typedef struct x
243#endif
244
245#if _MSC_EXTENSIONS
246#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
247#endif
248
249