efibind.h revision 143250
177943Sdfr/* $FreeBSD: head/sys/boot/efi/include/i386/efibind.h 143250 2005-03-07 15:38:37Z stefanf $ */
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
2496893Smarcel/*
2596893Smarcel * Basic int types of various widths
2696893Smarcel */
2777943Sdfr
2877943Sdfr#if (__STDC_VERSION__ < 199901L )
2977943Sdfr
3096893Smarcel/* No ANSI C 1999/2000 stdint.h integer width declarations */
3177943Sdfr
3277943Sdfr    #if _MSC_EXTENSIONS
3377943Sdfr
3496893Smarcel/* 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
4796893Smarcel/* 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
5996893Smarcel/* 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
7396893Smarcel/*
7496893Smarcel * Basic EFI types of various widths
7596893Smarcel */
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
11996893Smarcel    #define BREAKPOINT()        while (TRUE);
12077943Sdfr#endif
12177943Sdfr
12296893Smarcel/*
12396893Smarcel * Pointers must be aligned to these address to function
12496893Smarcel */
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
13596893Smarcel/*
13696893Smarcel * Define macros to build data structure signatures from characters.
13796893Smarcel */
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
14396893Smarcel/*
14496893Smarcel * To export & import functions in the EFI emulator environment
14596893Smarcel */
14696893Smarcel
14777943Sdfr#if EFI_NT_EMULATOR
14877943Sdfr    #define EXPORTAPI           __declspec( dllexport )
14977943Sdfr#else
15077943Sdfr    #define EXPORTAPI
15177943Sdfr#endif
15277943Sdfr
15377943Sdfr
15496893Smarcel/*
15596893Smarcel * EFIAPI - prototype calling convention for EFI function pointers
15696893Smarcel * BOOTSERVICE - prototype for implementation of a boot service interface
15796893Smarcel * RUNTIMESERVICE - prototype for implementation of a runtime service interface
15896893Smarcel * RUNTIMEFUNCTION - prototype for implementation of a runtime function that
15996893Smarcel *	is not a service
16096893Smarcel * RUNTIME_CODE - pragma macro for declaring runtime code
16196893Smarcel */
16277943Sdfr
16396893Smarcel/* Forces EFI calling conventions reguardless of compiler options */
16496893Smarcel#ifndef EFIAPI
16577943Sdfr    #if _MSC_EXTENSIONS
16696893Smarcel        #define EFIAPI __cdecl
16777943Sdfr    #else
16896893Smarcel        #define EFIAPI
16977943Sdfr    #endif
17077943Sdfr#endif
17177943Sdfr
17277943Sdfr#define BOOTSERVICE
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")
17977943Sdfr#define END_RUNTIME_DATA()      data_seg("")
18077943Sdfr
18177943Sdfr#define VOLATILE    volatile
18277943Sdfr
18377943Sdfr#define MEMORY_FENCE()
18477943Sdfr
18577943Sdfr#ifdef EFI_NT_EMULATOR
18677943Sdfr
18796893Smarcel/*
18896893Smarcel * To help ensure proper coding of integrated drivers, they are
18996893Smarcel * compiled as DLLs.  In NT they require a dll init entry pointer.
19096893Smarcel * The macro puts a stub entry point into the DLL so it will load.
19196893Smarcel */
19277943Sdfr
19377943Sdfr#define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
19477943Sdfr    UINTN                                       \
19577943Sdfr    __stdcall                                   \
19677943Sdfr    _DllMainCRTStartup (                        \
19777943Sdfr        UINTN    Inst,                          \
19877943Sdfr        UINTN    reason_for_call,               \
19977943Sdfr        VOID    *rserved                        \
20077943Sdfr        )                                       \
20177943Sdfr    {                                           \
20277943Sdfr        return 1;                               \
20377943Sdfr    }                                           \
20477943Sdfr                                                \
20577943Sdfr    int                                         \
20677943Sdfr    EXPORTAPI                                   \
20777943Sdfr    __cdecl                                     \
20877943Sdfr    InitializeDriver (                          \
20977943Sdfr        void *ImageHandle,                      \
21077943Sdfr        void *SystemTable                       \
21177943Sdfr        )                                       \
21277943Sdfr    {                                           \
21377943Sdfr        return InitFunction(ImageHandle, SystemTable);       \
21477943Sdfr    }
21577943Sdfr
21677943Sdfr
21777943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
21877943Sdfr        (_if)->LoadInternal(type, name, NULL)
21977943Sdfr
22096893Smarcel#else /* EFI_NT_EMULATOR */
22177943Sdfr
22296893Smarcel/*
22396893Smarcel * When build similiar to FW, then link everything together as
22496893Smarcel * one big module.
22596893Smarcel */
22677943Sdfr
22777943Sdfr    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
22877943Sdfr
22977943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
23077943Sdfr            (_if)->LoadInternal(type, name, entry)
23177943Sdfr
23296893Smarcel#endif /* EFI_FW_NT */
23377943Sdfr
234143250Sstefanf#define INTERFACE_DECL(x) struct x
23577943Sdfr
23677943Sdfr#if _MSC_EXTENSIONS
23796893Smarcel#pragma warning ( disable : 4731 )
23877943Sdfr#endif
23977943Sdfr
240