1/* $FreeBSD$ */
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    #ifdef _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#ifndef ACPI_THREAD_ID		/* ACPI's definitions are fine */
89#define ACPI_USE_SYSTEM_INTTYPES 1	/* Tell ACPI we've defined types */
90
91typedef uint64_t   UINT64;
92typedef int64_t    INT64;
93
94#ifndef _BASETSD_H_
95    typedef uint32_t   UINT32;
96    typedef int32_t    INT32;
97#endif
98
99typedef uint16_t   UINT16;
100typedef int16_t    INT16;
101typedef uint8_t    UINT8;
102typedef int8_t     INT8;
103
104#endif
105
106#undef VOID
107#define VOID    void
108
109
110typedef int64_t    INTN;
111typedef uint64_t   UINTN;
112
113#ifdef EFI_NT_EMULATOR
114    #define POST_CODE(_Data)
115#else
116    #ifdef EFI_DEBUG
117#define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
118    #else
119        #define POST_CODE(_Data)
120    #endif
121#endif
122
123#define EFIERR(a)           (0x8000000000000000 | a)
124#define EFI_ERROR_MASK      0x8000000000000000
125#define EFIERR_OEM(a)       (0xc000000000000000 | a)
126
127
128#define BAD_POINTER         0xFBFBFBFBFBFBFBFB
129#define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
130
131#define BREAKPOINT()        __asm { int 3 }
132
133//
134// Pointers must be aligned to these address to function
135//
136
137#define MIN_ALIGNMENT_SIZE  4
138
139#define ALIGN_VARIABLE(Value ,Adjustment) \
140            (UINTN)Adjustment = 0; \
141            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
142                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
143            Value = (UINTN)Value + (UINTN)Adjustment
144
145
146//
147// Define macros to build data structure signatures from characters.
148//
149
150#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
151#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
152#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))
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 is not a service
159// RUNTIME_CODE - pragma macro for declaring runtime code
160//
161
162#ifdef	__amd64__
163#define	EFIAPI	__attribute__((ms_abi))
164#endif
165
166#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
167    #ifdef _MSC_EXTENSIONS
168        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
169    #else
170        #define EFIAPI          // Substitute expresion to force C calling convention
171    #endif
172#endif
173
174#define BOOTSERVICE
175//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
176//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
177#define RUNTIMESERVICE
178#define RUNTIMEFUNCTION
179
180
181#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
182#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
183#define END_RUNTIME_DATA()      data_seg("")
184
185#define VOLATILE    volatile
186
187#define MEMORY_FENCE()
188
189#ifdef EFI_NO_INTERFACE_DECL
190  #define EFI_FORWARD_DECLARATION(x)
191  #define EFI_INTERFACE_DECL(x)
192#else
193  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
194  #define EFI_INTERFACE_DECL(x) typedef struct x
195#endif
196
197#ifdef EFI_NT_EMULATOR
198
199//
200// To help ensure proper coding of integrated drivers, they are
201// compiled as DLLs.  In NT they require a dll init entry pointer.
202// The macro puts a stub entry point into the DLL so it will load.
203//
204
205#define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
206    EFI_STATUS                                          \
207    InitFunction (                                      \
208      EFI_HANDLE  ImageHandle,                          \
209      EFI_SYSTEM_TABLE  *SystemTable                    \
210      );                                                \
211                                                        \
212    UINTN                                               \
213    __stdcall                                           \
214    _DllMainCRTStartup (                                \
215        UINTN    Inst,                                  \
216        UINTN    reason_for_call,                       \
217        VOID    *rserved                                \
218        )                                               \
219    {                                                   \
220        return 1;                                       \
221    }                                                   \
222                                                        \
223    int                                                 \
224    __declspec( dllexport )                             \
225    __cdecl                                             \
226    InitializeDriver (                                  \
227        void *ImageHandle,                              \
228        void *SystemTable                               \
229        )                                               \
230    {                                                   \
231        return InitFunction(ImageHandle, SystemTable);  \
232    }
233
234
235    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
236        (_if)->LoadInternal(type, name, NULL)
237
238#else // EFI_NT_EMULATOR
239
240//
241// When building similar to FW, link everything together as
242// one big module.
243//
244
245    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
246
247    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
248            (_if)->LoadInternal(type, name, entry)
249
250#endif // EFI_FW_NT
251
252#ifdef __FreeBSD__
253#define INTERFACE_DECL(x) struct x
254#else
255//
256// Some compilers don't support the forward reference construct:
257//  typedef struct XXXXX
258//
259// The following macro provide a workaround for such cases.
260//
261#ifdef NO_INTERFACE_DECL
262#define INTERFACE_DECL(x)
263#else
264#define INTERFACE_DECL(x) typedef struct x
265#endif
266#endif	/* __FreeBSD__ */
267
268#ifdef _MSC_EXTENSIONS
269#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
270#endif
271
272