efibind.h revision 163898
1/* $FreeBSD: head/sys/boot/efi/include/i386/efibind.h 163898 2006-11-02 02:42:48Z marcel $ */
2/*++
3
4Copyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5This software and associated documentation (if any) is furnished
6under a license and may only be used or copied in accordance
7with the terms of the license. Except as permitted by such
8license, no part of this software or documentation may be
9reproduced, stored in a retrieval system, or transmitted in any
10form or by any means without the express written consent of
11Intel Corporation.
12
13Module Name:
14
15    efefind.h
16
17Abstract:
18
19    EFI to compile bindings
20
21
22
23
24Revision 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
88typedef uint64_t   UINT64;
89typedef int64_t    INT64;
90
91#ifndef _BASETSD_H_
92    typedef uint32_t   UINT32;
93    typedef int32_t    INT32;
94#endif
95
96typedef uint16_t   UINT16;
97typedef int16_t    INT16;
98typedef uint8_t    UINT8;
99typedef int8_t     INT8;
100
101
102#undef VOID
103#define VOID    void
104
105
106typedef int32_t    INTN;
107typedef uint32_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)           (0x80000000 | a)
120#define EFI_ERROR_MASK      0x80000000
121#define EFIERR_OEM(a)       (0xc0000000 | a)
122
123
124#define BAD_POINTER         0xFBFBFBFB
125#define MAX_ADDRESS         0xFFFFFFFF
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#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
159    #if _MSC_EXTENSIONS
160        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
161    #else
162        #define EFIAPI          // Substitute expresion to force C calling convention
163    #endif
164#endif
165
166#define BOOTSERVICE
167//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
168//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
169#define RUNTIMESERVICE
170#define RUNTIMEFUNCTION
171
172
173#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
174#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
175#define END_RUNTIME_DATA()      data_seg()
176
177#define VOLATILE    volatile
178
179#define MEMORY_FENCE()
180
181#ifdef EFI_NO_INTERFACE_DECL
182  #define EFI_FORWARD_DECLARATION(x)
183  #define EFI_INTERFACE_DECL(x)
184#else
185  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
186  #define EFI_INTERFACE_DECL(x) typedef struct x
187#endif
188
189#ifdef EFI_NT_EMULATOR
190
191//
192// To help ensure proper coding of integrated drivers, they are
193// compiled as DLLs.  In NT they require a dll init entry pointer.
194// The macro puts a stub entry point into the DLL so it will load.
195//
196
197#define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
198    EFI_STATUS                                          \
199    InitFunction (                                      \
200      EFI_HANDLE  ImageHandle,                          \
201      EFI_SYSTEM_TABLE  *SystemTable                    \
202      );                                                \
203                                                        \
204    UINTN                                               \
205    __stdcall                                           \
206    _DllMainCRTStartup (                                \
207        UINTN    Inst,                                  \
208        UINTN    reason_for_call,                       \
209        VOID    *rserved                                \
210        )                                               \
211    {                                                   \
212        return 1;                                       \
213    }                                                   \
214                                                        \
215    int                                                 \
216    __declspec( dllexport )                             \
217    __cdecl                                             \
218    InitializeDriver (                                  \
219        void *ImageHandle,                              \
220        void *SystemTable                               \
221        )                                               \
222    {                                                   \
223        return InitFunction(ImageHandle, SystemTable);  \
224    }
225
226
227    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
228        (_if)->LoadInternal(type, name, NULL)
229
230#else // EFI_NT_EMULATOR
231
232//
233// When build similiar to FW, then link everything together as
234// one big module.
235//
236
237    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
238
239    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
240            (_if)->LoadInternal(type, name, entry)
241
242#endif // EFI_FW_NT
243
244#ifdef __FreeBSD__
245#define INTERFACE_DECL(x) struct x
246#else
247//
248// Some compilers don't support the forward reference construct:
249//  typedef struct XXXXX
250//
251// The following macro provide a workaround for such cases.
252//
253#ifdef NO_INTERFACE_DECL
254#define INTERFACE_DECL(x)
255#else
256#define INTERFACE_DECL(x) typedef struct x
257#endif
258#endif	/* __FreeBSD__ */
259
260#if _MSC_EXTENSIONS
261#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
262#endif
263
264