1263115Semaste/* $FreeBSD: stable/11/stand/efi/include/amd64/efibind.h 298826 2016-04-30 00:26:38Z pfg $ */
2263115Semaste/*++
3263115Semaste
4263115SemasteCopyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5263115SemasteThis software and associated documentation (if any) is furnished
6263115Semasteunder a license and may only be used or copied in accordance
7263115Semastewith the terms of the license. Except as permitted by such
8263115Semastelicense, no part of this software or documentation may be
9263115Semastereproduced, stored in a retrieval system, or transmitted in any
10263115Semasteform or by any means without the express written consent of
11263115SemasteIntel Corporation.
12263115Semaste
13263115SemasteModule Name:
14263115Semaste
15263115Semaste    efefind.h
16263115Semaste
17263115SemasteAbstract:
18263115Semaste
19263115Semaste    EFI to compile bindings
20263115Semaste
21263115Semaste
22263115Semaste
23263115Semaste
24263115SemasteRevision History
25263115Semaste
26263115Semaste--*/
27263115Semaste
28263115Semaste#pragma pack()
29263115Semaste
30263115Semaste
31263115Semaste#ifdef __FreeBSD__
32263115Semaste#include <sys/stdint.h>
33263115Semaste#else
34263115Semaste//
35263115Semaste// Basic int types of various widths
36263115Semaste//
37263115Semaste
38263115Semaste#if (__STDC_VERSION__ < 199901L )
39263115Semaste
40292625Semaste    // No ANSI C 1999/2000 stdint.h integer width declarations
41263115Semaste
42293268Ssmh    #ifdef _MSC_EXTENSIONS
43263115Semaste
44292625Semaste        // Use Microsoft C compiler integer width declarations
45263115Semaste
46263115Semaste        typedef unsigned __int64    uint64_t;
47263115Semaste        typedef __int64             int64_t;
48263115Semaste        typedef unsigned __int32    uint32_t;
49263115Semaste        typedef __int32             int32_t;
50263115Semaste        typedef unsigned short      uint16_t;
51263115Semaste        typedef short               int16_t;
52263115Semaste        typedef unsigned char       uint8_t;
53263115Semaste        typedef char                int8_t;
54292625Semaste    #else
55263115Semaste        #ifdef UNIX_LP64
56263115Semaste
57292625Semaste            // Use LP64 programming model from C_FLAGS for integer width declarations
58263115Semaste
59263115Semaste            typedef unsigned long       uint64_t;
60263115Semaste            typedef long                int64_t;
61263115Semaste            typedef unsigned int        uint32_t;
62263115Semaste            typedef int                 int32_t;
63263115Semaste            typedef unsigned short      uint16_t;
64263115Semaste            typedef short               int16_t;
65263115Semaste            typedef unsigned char       uint8_t;
66263115Semaste            typedef char                int8_t;
67263115Semaste        #else
68263115Semaste
69292625Semaste            // Assume P64 programming model from C_FLAGS for integer width declarations
70263115Semaste
71263115Semaste            typedef unsigned long long  uint64_t;
72263115Semaste            typedef long long           int64_t;
73263115Semaste            typedef unsigned int        uint32_t;
74263115Semaste            typedef int                 int32_t;
75263115Semaste            typedef unsigned short      uint16_t;
76263115Semaste            typedef short               int16_t;
77263115Semaste            typedef unsigned char       uint8_t;
78263115Semaste            typedef char                int8_t;
79263115Semaste        #endif
80263115Semaste    #endif
81263115Semaste#endif
82263115Semaste#endif	/* __FreeBSD__ */
83263115Semaste
84263115Semaste//
85263115Semaste// Basic EFI types of various widths
86263115Semaste//
87263115Semaste
88279038Simp#ifndef ACPI_THREAD_ID		/* ACPI's definitions are fine */
89279038Simp#define ACPI_USE_SYSTEM_INTTYPES 1	/* Tell ACPI we've defined types */
90279038Simp
91263115Semastetypedef uint64_t   UINT64;
92263115Semastetypedef int64_t    INT64;
93263115Semaste
94263115Semaste#ifndef _BASETSD_H_
95263115Semaste    typedef uint32_t   UINT32;
96263115Semaste    typedef int32_t    INT32;
97263115Semaste#endif
98263115Semaste
99263115Semastetypedef uint16_t   UINT16;
100263115Semastetypedef int16_t    INT16;
101263115Semastetypedef uint8_t    UINT8;
102263115Semastetypedef int8_t     INT8;
103263115Semaste
104279038Simp#endif
105263115Semaste
106263115Semaste#undef VOID
107263115Semaste#define VOID    void
108263115Semaste
109263115Semaste
110263115Semastetypedef int64_t    INTN;
111263115Semastetypedef uint64_t   UINTN;
112263115Semaste
113263115Semaste#ifdef EFI_NT_EMULATOR
114263115Semaste    #define POST_CODE(_Data)
115292625Semaste#else
116263115Semaste    #ifdef EFI_DEBUG
117263115Semaste#define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
118263115Semaste    #else
119263115Semaste        #define POST_CODE(_Data)
120292625Semaste    #endif
121263115Semaste#endif
122263115Semaste
123263115Semaste#define EFIERR(a)           (0x8000000000000000 | a)
124263115Semaste#define EFI_ERROR_MASK      0x8000000000000000
125292625Semaste#define EFIERR_OEM(a)       (0xc000000000000000 | a)
126263115Semaste
127263115Semaste
128263115Semaste#define BAD_POINTER         0xFBFBFBFBFBFBFBFB
129263115Semaste#define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
130263115Semaste
131263115Semaste#define BREAKPOINT()        __asm { int 3 }
132263115Semaste
133263115Semaste//
134263115Semaste// Pointers must be aligned to these address to function
135263115Semaste//
136263115Semaste
137263115Semaste#define MIN_ALIGNMENT_SIZE  4
138263115Semaste
139263115Semaste#define ALIGN_VARIABLE(Value ,Adjustment) \
140263115Semaste            (UINTN)Adjustment = 0; \
141263115Semaste            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
142263115Semaste                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
143263115Semaste            Value = (UINTN)Value + (UINTN)Adjustment
144263115Semaste
145263115Semaste
146263115Semaste//
147263115Semaste// Define macros to build data structure signatures from characters.
148263115Semaste//
149263115Semaste
150263115Semaste#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
151263115Semaste#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
152263115Semaste#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))
153263115Semaste
154263115Semaste//
155263115Semaste// EFIAPI - prototype calling convention for EFI function pointers
156263115Semaste// BOOTSERVICE - prototype for implementation of a boot service interface
157263115Semaste// RUNTIMESERVICE - prototype for implementation of a runtime service interface
158263115Semaste// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
159292625Semaste// RUNTIME_CODE - pragma macro for declaring runtime code
160263115Semaste//
161263115Semaste
162263115Semaste#ifdef	__amd64__
163263115Semaste#define	EFIAPI	__attribute__((ms_abi))
164263115Semaste#endif
165263115Semaste
166292625Semaste#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
167293268Ssmh    #ifdef _MSC_EXTENSIONS
168292625Semaste        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
169263115Semaste    #else
170292625Semaste        #define EFIAPI          // Substitute expresion to force C calling convention
171263115Semaste    #endif
172263115Semaste#endif
173263115Semaste
174263115Semaste#define BOOTSERVICE
175263115Semaste//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
176263115Semaste//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
177263115Semaste#define RUNTIMESERVICE
178263115Semaste#define RUNTIMEFUNCTION
179263115Semaste
180263115Semaste
181263115Semaste#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
182263115Semaste#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
183263115Semaste#define END_RUNTIME_DATA()      data_seg("")
184263115Semaste
185263115Semaste#define VOLATILE    volatile
186263115Semaste
187292625Semaste#define MEMORY_FENCE()
188263115Semaste
189263115Semaste#ifdef EFI_NO_INTERFACE_DECL
190263115Semaste  #define EFI_FORWARD_DECLARATION(x)
191263115Semaste  #define EFI_INTERFACE_DECL(x)
192263115Semaste#else
193263115Semaste  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
194263115Semaste  #define EFI_INTERFACE_DECL(x) typedef struct x
195263115Semaste#endif
196263115Semaste
197263115Semaste#ifdef EFI_NT_EMULATOR
198263115Semaste
199263115Semaste//
200263115Semaste// To help ensure proper coding of integrated drivers, they are
201263115Semaste// compiled as DLLs.  In NT they require a dll init entry pointer.
202263115Semaste// The macro puts a stub entry point into the DLL so it will load.
203263115Semaste//
204263115Semaste
205263115Semaste#define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
206263115Semaste    EFI_STATUS                                          \
207263115Semaste    InitFunction (                                      \
208263115Semaste      EFI_HANDLE  ImageHandle,                          \
209263115Semaste      EFI_SYSTEM_TABLE  *SystemTable                    \
210263115Semaste      );                                                \
211263115Semaste                                                        \
212263115Semaste    UINTN                                               \
213263115Semaste    __stdcall                                           \
214263115Semaste    _DllMainCRTStartup (                                \
215263115Semaste        UINTN    Inst,                                  \
216263115Semaste        UINTN    reason_for_call,                       \
217263115Semaste        VOID    *rserved                                \
218263115Semaste        )                                               \
219263115Semaste    {                                                   \
220263115Semaste        return 1;                                       \
221263115Semaste    }                                                   \
222263115Semaste                                                        \
223263115Semaste    int                                                 \
224263115Semaste    __declspec( dllexport )                             \
225263115Semaste    __cdecl                                             \
226263115Semaste    InitializeDriver (                                  \
227263115Semaste        void *ImageHandle,                              \
228263115Semaste        void *SystemTable                               \
229263115Semaste        )                                               \
230263115Semaste    {                                                   \
231263115Semaste        return InitFunction(ImageHandle, SystemTable);  \
232263115Semaste    }
233263115Semaste
234263115Semaste
235263115Semaste    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
236292625Semaste        (_if)->LoadInternal(type, name, NULL)
237263115Semaste
238292625Semaste#else // EFI_NT_EMULATOR
239263115Semaste
240263115Semaste//
241298826Spfg// When building similar to FW, link everything together as
242263115Semaste// one big module.
243263115Semaste//
244263115Semaste
245263115Semaste    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
246263115Semaste
247263115Semaste    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
248263115Semaste            (_if)->LoadInternal(type, name, entry)
249263115Semaste
250292625Semaste#endif // EFI_FW_NT
251263115Semaste
252263115Semaste#ifdef __FreeBSD__
253263115Semaste#define INTERFACE_DECL(x) struct x
254263115Semaste#else
255263115Semaste//
256263115Semaste// Some compilers don't support the forward reference construct:
257263115Semaste//  typedef struct XXXXX
258263115Semaste//
259263115Semaste// The following macro provide a workaround for such cases.
260263115Semaste//
261263115Semaste#ifdef NO_INTERFACE_DECL
262263115Semaste#define INTERFACE_DECL(x)
263263115Semaste#else
264263115Semaste#define INTERFACE_DECL(x) typedef struct x
265263115Semaste#endif
266263115Semaste#endif	/* __FreeBSD__ */
267263115Semaste
268293268Ssmh#ifdef _MSC_EXTENSIONS
269263115Semaste#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
270263115Semaste#endif
271263115Semaste
272