177943Sdfr/* $FreeBSD: stable/11/stand/efi/include/i386/efibind.h 298826 2016-04-30 00:26:38Z pfg $ */
277943Sdfr/*++
377943Sdfr
4163898SmarcelCopyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5163898SmarcelThis software and associated documentation (if any) is furnished
6163898Smarcelunder a license and may only be used or copied in accordance
7163898Smarcelwith the terms of the license. Except as permitted by such
8163898Smarcellicense, no part of this software or documentation may be
9163898Smarcelreproduced, stored in a retrieval system, or transmitted in any
10163898Smarcelform or by any means without the express written consent of
11163898SmarcelIntel Corporation.
1277943Sdfr
1377943SdfrModule Name:
1477943Sdfr
1577943Sdfr    efefind.h
1677943Sdfr
1777943SdfrAbstract:
1877943Sdfr
1977943Sdfr    EFI to compile bindings
2077943Sdfr
2177943Sdfr
2277943Sdfr
2377943Sdfr
2477943SdfrRevision History
2577943Sdfr
2677943Sdfr--*/
2777943Sdfr
2877943Sdfr#pragma pack()
2977943Sdfr
3077943Sdfr
31163898Smarcel#ifdef __FreeBSD__
32163898Smarcel#include <sys/stdint.h>
33163898Smarcel#else
34163898Smarcel//
35163898Smarcel// Basic int types of various widths
36163898Smarcel//
3777943Sdfr
3877943Sdfr#if (__STDC_VERSION__ < 199901L )
3977943Sdfr
40292625Semaste    // No ANSI C 1999/2000 stdint.h integer width declarations
4177943Sdfr
42293268Ssmh    #ifdef _MSC_EXTENSIONS
4377943Sdfr
44292625Semaste        // Use Microsoft C compiler integer width declarations
4577943Sdfr
4677943Sdfr        typedef unsigned __int64    uint64_t;
4777943Sdfr        typedef __int64             int64_t;
4877943Sdfr        typedef unsigned __int32    uint32_t;
4977943Sdfr        typedef __int32             int32_t;
5077943Sdfr        typedef unsigned short      uint16_t;
5177943Sdfr        typedef short               int16_t;
5277943Sdfr        typedef unsigned char       uint8_t;
5377943Sdfr        typedef char                int8_t;
54292625Semaste    #else
5577943Sdfr        #ifdef UNIX_LP64
5677943Sdfr
57292625Semaste            // Use LP64 programming model from C_FLAGS for integer width declarations
5877943Sdfr
5977943Sdfr            typedef unsigned long       uint64_t;
6077943Sdfr            typedef long                int64_t;
6177943Sdfr            typedef unsigned int        uint32_t;
6277943Sdfr            typedef int                 int32_t;
6377943Sdfr            typedef unsigned short      uint16_t;
6477943Sdfr            typedef short               int16_t;
6577943Sdfr            typedef unsigned char       uint8_t;
6677943Sdfr            typedef char                int8_t;
6777943Sdfr        #else
6877943Sdfr
69292625Semaste            // Assume P64 programming model from C_FLAGS for integer width declarations
7077943Sdfr
7177943Sdfr            typedef unsigned long long  uint64_t;
7277943Sdfr            typedef long long           int64_t;
7377943Sdfr            typedef unsigned int        uint32_t;
7477943Sdfr            typedef int                 int32_t;
7577943Sdfr            typedef unsigned short      uint16_t;
7677943Sdfr            typedef short               int16_t;
7777943Sdfr            typedef unsigned char       uint8_t;
7877943Sdfr            typedef char                int8_t;
7977943Sdfr        #endif
8077943Sdfr    #endif
8177943Sdfr#endif
82163898Smarcel#endif	/* __FreeBSD__ */
8377943Sdfr
84163898Smarcel//
85163898Smarcel// Basic EFI types of various widths
86163898Smarcel//
8777943Sdfr
88279038Simp#ifndef ACPI_THREAD_ID		/* ACPI's definitions are fine, use those */
89279038Simp#define ACPI_USE_SYSTEM_INTTYPES 1	/* Tell ACPI we've defined types */
90279038Simp
9177943Sdfrtypedef uint64_t   UINT64;
9277943Sdfrtypedef int64_t    INT64;
9377943Sdfr
9477943Sdfr#ifndef _BASETSD_H_
9577943Sdfr    typedef uint32_t   UINT32;
9677943Sdfr    typedef int32_t    INT32;
9777943Sdfr#endif
9877943Sdfr
9977943Sdfrtypedef uint16_t   UINT16;
10077943Sdfrtypedef int16_t    INT16;
10177943Sdfrtypedef uint8_t    UINT8;
10277943Sdfrtypedef int8_t     INT8;
10377943Sdfr
104279038Simp#endif
10577943Sdfr
10677943Sdfr#undef VOID
10777943Sdfr#define VOID    void
10877943Sdfr
10977943Sdfr
11077943Sdfrtypedef int32_t    INTN;
11177943Sdfrtypedef uint32_t   UINTN;
11277943Sdfr
11377943Sdfr#ifdef EFI_NT_EMULATOR
11477943Sdfr    #define POST_CODE(_Data)
115292625Semaste#else
11677943Sdfr    #ifdef EFI_DEBUG
11777943Sdfr#define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
11877943Sdfr    #else
11977943Sdfr        #define POST_CODE(_Data)
120292625Semaste    #endif
12177943Sdfr#endif
12277943Sdfr
12377943Sdfr#define EFIERR(a)           (0x80000000 | a)
12477943Sdfr#define EFI_ERROR_MASK      0x80000000
125292625Semaste#define EFIERR_OEM(a)       (0xc0000000 | a)
12677943Sdfr
12777943Sdfr
12877943Sdfr#define BAD_POINTER         0xFBFBFBFB
12977943Sdfr#define MAX_ADDRESS         0xFFFFFFFF
13077943Sdfr
131163898Smarcel#define BREAKPOINT()        __asm { int 3 }
13277943Sdfr
133163898Smarcel//
134163898Smarcel// Pointers must be aligned to these address to function
135163898Smarcel//
13677943Sdfr
13777943Sdfr#define MIN_ALIGNMENT_SIZE  4
13877943Sdfr
13977943Sdfr#define ALIGN_VARIABLE(Value ,Adjustment) \
14077943Sdfr            (UINTN)Adjustment = 0; \
14177943Sdfr            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
14277943Sdfr                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
14377943Sdfr            Value = (UINTN)Value + (UINTN)Adjustment
14477943Sdfr
14577943Sdfr
146163898Smarcel//
147163898Smarcel// Define macros to build data structure signatures from characters.
148163898Smarcel//
14977943Sdfr
15077943Sdfr#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
15177943Sdfr#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
15277943Sdfr#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))
15377943Sdfr
154163898Smarcel//
155163898Smarcel// EFIAPI - prototype calling convention for EFI function pointers
156163898Smarcel// BOOTSERVICE - prototype for implementation of a boot service interface
157163898Smarcel// RUNTIMESERVICE - prototype for implementation of a runtime service interface
158163898Smarcel// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
159292625Semaste// RUNTIME_CODE - pragma macro for declaring runtime code
160163898Smarcel//
16196893Smarcel
162292625Semaste#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
163293268Ssmh    #ifdef _MSC_EXTENSIONS
164292625Semaste        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
16577943Sdfr    #else
166292625Semaste        #define EFIAPI          // Substitute expresion to force C calling convention
16777943Sdfr    #endif
16877943Sdfr#endif
16977943Sdfr
17077943Sdfr#define BOOTSERVICE
171163898Smarcel//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
172163898Smarcel//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
17377943Sdfr#define RUNTIMESERVICE
17477943Sdfr#define RUNTIMEFUNCTION
17577943Sdfr
17677943Sdfr
17777943Sdfr#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
17877943Sdfr#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
179163898Smarcel#define END_RUNTIME_DATA()      data_seg()
18077943Sdfr
18177943Sdfr#define VOLATILE    volatile
18277943Sdfr
183292625Semaste#define MEMORY_FENCE()
18477943Sdfr
185163898Smarcel#ifdef EFI_NO_INTERFACE_DECL
186163898Smarcel  #define EFI_FORWARD_DECLARATION(x)
187163898Smarcel  #define EFI_INTERFACE_DECL(x)
188163898Smarcel#else
189163898Smarcel  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
190163898Smarcel  #define EFI_INTERFACE_DECL(x) typedef struct x
191163898Smarcel#endif
192163898Smarcel
19377943Sdfr#ifdef EFI_NT_EMULATOR
19477943Sdfr
195163898Smarcel//
196163898Smarcel// To help ensure proper coding of integrated drivers, they are
197163898Smarcel// compiled as DLLs.  In NT they require a dll init entry pointer.
198163898Smarcel// The macro puts a stub entry point into the DLL so it will load.
199163898Smarcel//
20077943Sdfr
201163898Smarcel#define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
202163898Smarcel    EFI_STATUS                                          \
203163898Smarcel    InitFunction (                                      \
204163898Smarcel      EFI_HANDLE  ImageHandle,                          \
205163898Smarcel      EFI_SYSTEM_TABLE  *SystemTable                    \
206163898Smarcel      );                                                \
207163898Smarcel                                                        \
208163898Smarcel    UINTN                                               \
209163898Smarcel    __stdcall                                           \
210163898Smarcel    _DllMainCRTStartup (                                \
211163898Smarcel        UINTN    Inst,                                  \
212163898Smarcel        UINTN    reason_for_call,                       \
213163898Smarcel        VOID    *rserved                                \
214163898Smarcel        )                                               \
215163898Smarcel    {                                                   \
216163898Smarcel        return 1;                                       \
217163898Smarcel    }                                                   \
218163898Smarcel                                                        \
219163898Smarcel    int                                                 \
220163898Smarcel    __declspec( dllexport )                             \
221163898Smarcel    __cdecl                                             \
222163898Smarcel    InitializeDriver (                                  \
223163898Smarcel        void *ImageHandle,                              \
224163898Smarcel        void *SystemTable                               \
225163898Smarcel        )                                               \
226163898Smarcel    {                                                   \
227163898Smarcel        return InitFunction(ImageHandle, SystemTable);  \
22877943Sdfr    }
22977943Sdfr
23077943Sdfr
23177943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
232292625Semaste        (_if)->LoadInternal(type, name, NULL)
23377943Sdfr
234292625Semaste#else // EFI_NT_EMULATOR
23577943Sdfr
236163898Smarcel//
237298826Spfg// When build similar to FW, then link everything together as
238163898Smarcel// one big module.
239163898Smarcel//
24077943Sdfr
24177943Sdfr    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
24277943Sdfr
24377943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
24477943Sdfr            (_if)->LoadInternal(type, name, entry)
24577943Sdfr
246292625Semaste#endif // EFI_FW_NT
24777943Sdfr
248163898Smarcel#ifdef __FreeBSD__
249143250Sstefanf#define INTERFACE_DECL(x) struct x
250163898Smarcel#else
251163898Smarcel//
252163898Smarcel// Some compilers don't support the forward reference construct:
253163898Smarcel//  typedef struct XXXXX
254163898Smarcel//
255163898Smarcel// The following macro provide a workaround for such cases.
256163898Smarcel//
257163898Smarcel#ifdef NO_INTERFACE_DECL
258163898Smarcel#define INTERFACE_DECL(x)
259163898Smarcel#else
260163898Smarcel#define INTERFACE_DECL(x) typedef struct x
261163898Smarcel#endif
262163898Smarcel#endif	/* __FreeBSD__ */
26377943Sdfr
264293268Ssmh#ifdef _MSC_EXTENSIONS
265163898Smarcel#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
26677943Sdfr#endif
26777943Sdfr
268