efibind.h revision 77943
177943Sdfr/* $FreeBSD: head/sys/boot/efi/include/i386/efibind.h 77943 2001-06-09 16:49:51Z dfr $ */
277943Sdfr/*++
377943Sdfr
477943SdfrCopyright (c) 1998  Intel Corporation
577943Sdfr
677943SdfrModule Name:
777943Sdfr
877943Sdfr    efefind.h
977943Sdfr
1077943SdfrAbstract:
1177943Sdfr
1277943Sdfr    EFI to compile bindings
1377943Sdfr
1477943Sdfr
1577943Sdfr
1677943Sdfr
1777943SdfrRevision History
1877943Sdfr
1977943Sdfr--*/
2077943Sdfr
2177943Sdfr#pragma pack()
2277943Sdfr
2377943Sdfr
2477943Sdfr//
2577943Sdfr// Basic int types of various widths
2677943Sdfr//
2777943Sdfr
2877943Sdfr#if (__STDC_VERSION__ < 199901L )
2977943Sdfr
3077943Sdfr    // No ANSI C 1999/2000 stdint.h integer width declarations
3177943Sdfr
3277943Sdfr    #if _MSC_EXTENSIONS
3377943Sdfr
3477943Sdfr        // Use Microsoft C compiler integer width declarations
3577943Sdfr
3677943Sdfr        typedef unsigned __int64    uint64_t;
3777943Sdfr        typedef __int64             int64_t;
3877943Sdfr        typedef unsigned __int32    uint32_t;
3977943Sdfr        typedef __int32             int32_t;
4077943Sdfr        typedef unsigned short      uint16_t;
4177943Sdfr        typedef short               int16_t;
4277943Sdfr        typedef unsigned char       uint8_t;
4377943Sdfr        typedef char                int8_t;
4477943Sdfr    #else
4577943Sdfr        #ifdef UNIX_LP64
4677943Sdfr
4777943Sdfr            // Use LP64 programming model from C_FLAGS for integer width declarations
4877943Sdfr
4977943Sdfr            typedef unsigned long       uint64_t;
5077943Sdfr            typedef long                int64_t;
5177943Sdfr            typedef unsigned int        uint32_t;
5277943Sdfr            typedef int                 int32_t;
5377943Sdfr            typedef unsigned short      uint16_t;
5477943Sdfr            typedef short               int16_t;
5577943Sdfr            typedef unsigned char       uint8_t;
5677943Sdfr            typedef char                int8_t;
5777943Sdfr        #else
5877943Sdfr
5977943Sdfr            // Assume P64 programming model from C_FLAGS for integer width declarations
6077943Sdfr
6177943Sdfr            typedef unsigned long long  uint64_t;
6277943Sdfr            typedef long long           int64_t;
6377943Sdfr            typedef unsigned int        uint32_t;
6477943Sdfr            typedef int                 int32_t;
6577943Sdfr            typedef unsigned short      uint16_t;
6677943Sdfr            typedef short               int16_t;
6777943Sdfr            typedef unsigned char       uint8_t;
6877943Sdfr            typedef char                int8_t;
6977943Sdfr        #endif
7077943Sdfr    #endif
7177943Sdfr#endif
7277943Sdfr
7377943Sdfr//
7477943Sdfr// Basic EFI types of various widths
7577943Sdfr//
7677943Sdfr
7777943Sdfrtypedef uint64_t   UINT64;
7877943Sdfrtypedef int64_t    INT64;
7977943Sdfr
8077943Sdfr#ifndef _BASETSD_H_
8177943Sdfr    typedef uint32_t   UINT32;
8277943Sdfr    typedef int32_t    INT32;
8377943Sdfr#endif
8477943Sdfr
8577943Sdfrtypedef uint16_t   UINT16;
8677943Sdfrtypedef int16_t    INT16;
8777943Sdfrtypedef uint8_t    UINT8;
8877943Sdfrtypedef int8_t     INT8;
8977943Sdfr
9077943Sdfr
9177943Sdfr#undef VOID
9277943Sdfr#define VOID    void
9377943Sdfr
9477943Sdfr
9577943Sdfrtypedef int32_t    INTN;
9677943Sdfrtypedef uint32_t   UINTN;
9777943Sdfr
9877943Sdfr#ifdef EFI_NT_EMULATOR
9977943Sdfr    #define POST_CODE(_Data)
10077943Sdfr#else
10177943Sdfr    #ifdef EFI_DEBUG
10277943Sdfr#define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
10377943Sdfr    #else
10477943Sdfr        #define POST_CODE(_Data)
10577943Sdfr    #endif
10677943Sdfr#endif
10777943Sdfr
10877943Sdfr#define EFIERR(a)           (0x80000000 | a)
10977943Sdfr#define EFI_ERROR_MASK      0x80000000
11077943Sdfr#define EFIERR_OEM(a)       (0xc0000000 | a)
11177943Sdfr
11277943Sdfr
11377943Sdfr#define BAD_POINTER         0xFBFBFBFB
11477943Sdfr#define MAX_ADDRESS         0xFFFFFFFF
11577943Sdfr
11677943Sdfr#ifdef EFI_NT_EMULATOR
11777943Sdfr    #define BREAKPOINT()        __asm { int 3 }
11877943Sdfr#else
11977943Sdfr    #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
12077943Sdfr#endif
12177943Sdfr
12277943Sdfr//
12377943Sdfr// Pointers must be aligned to these address to function
12477943Sdfr//
12577943Sdfr
12677943Sdfr#define MIN_ALIGNMENT_SIZE  4
12777943Sdfr
12877943Sdfr#define ALIGN_VARIABLE(Value ,Adjustment) \
12977943Sdfr            (UINTN)Adjustment = 0; \
13077943Sdfr            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
13177943Sdfr                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
13277943Sdfr            Value = (UINTN)Value + (UINTN)Adjustment
13377943Sdfr
13477943Sdfr
13577943Sdfr//
13677943Sdfr// Define macros to build data structure signatures from characters.
13777943Sdfr//
13877943Sdfr
13977943Sdfr#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
14077943Sdfr#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
14177943Sdfr#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))
14277943Sdfr//
14377943Sdfr// To export & import functions in the EFI emulator environment
14477943Sdfr//
14577943Sdfr
14677943Sdfr#if EFI_NT_EMULATOR
14777943Sdfr    #define EXPORTAPI           __declspec( dllexport )
14877943Sdfr#else
14977943Sdfr    #define EXPORTAPI
15077943Sdfr#endif
15177943Sdfr
15277943Sdfr
15377943Sdfr//
15477943Sdfr// EFIAPI - prototype calling convention for EFI function pointers
15577943Sdfr// BOOTSERVICE - prototype for implementation of a boot service interface
15677943Sdfr// RUNTIMESERVICE - prototype for implementation of a runtime service interface
15777943Sdfr// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
15877943Sdfr// RUNTIME_CODE - pragma macro for declaring runtime code
15977943Sdfr//
16077943Sdfr
16177943Sdfr#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
16277943Sdfr    #if _MSC_EXTENSIONS
16377943Sdfr        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
16477943Sdfr    #else
16577943Sdfr        #define EFIAPI          // Substitute expresion to force C calling convention
16677943Sdfr    #endif
16777943Sdfr#endif
16877943Sdfr
16977943Sdfr#define BOOTSERVICE
17077943Sdfr//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
17177943Sdfr//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
17277943Sdfr#define RUNTIMESERVICE
17377943Sdfr#define RUNTIMEFUNCTION
17477943Sdfr
17577943Sdfr
17677943Sdfr#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
17777943Sdfr#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
17877943Sdfr#define END_RUNTIME_DATA()      data_seg("")
17977943Sdfr
18077943Sdfr#define VOLATILE    volatile
18177943Sdfr
18277943Sdfr#define MEMORY_FENCE()
18377943Sdfr
18477943Sdfr#ifdef EFI_NT_EMULATOR
18577943Sdfr
18677943Sdfr//
18777943Sdfr// To help ensure proper coding of integrated drivers, they are
18877943Sdfr// compiled as DLLs.  In NT they require a dll init entry pointer.
18977943Sdfr// The macro puts a stub entry point into the DLL so it will load.
19077943Sdfr//
19177943Sdfr
19277943Sdfr#define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
19377943Sdfr    UINTN                                       \
19477943Sdfr    __stdcall                                   \
19577943Sdfr    _DllMainCRTStartup (                        \
19677943Sdfr        UINTN    Inst,                          \
19777943Sdfr        UINTN    reason_for_call,               \
19877943Sdfr        VOID    *rserved                        \
19977943Sdfr        )                                       \
20077943Sdfr    {                                           \
20177943Sdfr        return 1;                               \
20277943Sdfr    }                                           \
20377943Sdfr                                                \
20477943Sdfr    int                                         \
20577943Sdfr    EXPORTAPI                                   \
20677943Sdfr    __cdecl                                     \
20777943Sdfr    InitializeDriver (                          \
20877943Sdfr        void *ImageHandle,                      \
20977943Sdfr        void *SystemTable                       \
21077943Sdfr        )                                       \
21177943Sdfr    {                                           \
21277943Sdfr        return InitFunction(ImageHandle, SystemTable);       \
21377943Sdfr    }
21477943Sdfr
21577943Sdfr
21677943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
21777943Sdfr        (_if)->LoadInternal(type, name, NULL)
21877943Sdfr
21977943Sdfr#else // EFI_NT_EMULATOR
22077943Sdfr
22177943Sdfr//
22277943Sdfr// When build similiar to FW, then link everything together as
22377943Sdfr// one big module.
22477943Sdfr//
22577943Sdfr
22677943Sdfr    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
22777943Sdfr
22877943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
22977943Sdfr            (_if)->LoadInternal(type, name, entry)
23077943Sdfr
23177943Sdfr#endif // EFI_FW_NT
23277943Sdfr
23377943Sdfr//
23477943Sdfr// Some compilers don't support the forward reference construct:
23577943Sdfr//  typedef struct XXXXX
23677943Sdfr//
23777943Sdfr// The following macro provide a workaround for such cases.
23877943Sdfr//
23977943Sdfr#ifdef NO_INTERFACE_DECL
24077943Sdfr#define INTERFACE_DECL(x)
24177943Sdfr#else
24277943Sdfr#define INTERFACE_DECL(x) typedef struct x
24377943Sdfr#endif
24477943Sdfr
24577943Sdfr#if _MSC_EXTENSIONS
24677943Sdfr#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
24777943Sdfr#endif
24877943Sdfr
249