Home | History | Annotate | Line # | Download | only in ia32
efibind.h revision 1.2
      1  1.2  jakllsch /*	$NetBSD: efibind.h,v 1.2 2014/04/01 16:22:45 jakllsch Exp $	*/
      2  1.1  jakllsch 
      3  1.1  jakllsch /*++
      4  1.1  jakllsch 
      5  1.1  jakllsch Copyright (c) 1998  Intel Corporation
      6  1.1  jakllsch 
      7  1.1  jakllsch Module Name:
      8  1.1  jakllsch 
      9  1.1  jakllsch     efefind.h
     10  1.1  jakllsch 
     11  1.1  jakllsch Abstract:
     12  1.1  jakllsch 
     13  1.1  jakllsch     EFI to compile bindings
     14  1.1  jakllsch 
     15  1.1  jakllsch 
     16  1.1  jakllsch 
     17  1.1  jakllsch 
     18  1.1  jakllsch Revision History
     19  1.1  jakllsch 
     20  1.1  jakllsch --*/
     21  1.1  jakllsch 
     22  1.1  jakllsch #ifndef __GNUC__
     23  1.1  jakllsch #pragma pack()
     24  1.1  jakllsch #endif
     25  1.1  jakllsch 
     26  1.1  jakllsch //
     27  1.1  jakllsch // Basic int types of various widths
     28  1.1  jakllsch //
     29  1.1  jakllsch 
     30  1.1  jakllsch #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
     31  1.1  jakllsch 
     32  1.1  jakllsch     // No ANSI C 1999/2000 stdint.h integer width declarations
     33  1.1  jakllsch 
     34  1.1  jakllsch     #if defined(_MSC_EXTENSIONS)
     35  1.1  jakllsch 
     36  1.1  jakllsch         // Use Microsoft C compiler integer width declarations
     37  1.1  jakllsch 
     38  1.1  jakllsch         typedef unsigned __int64    uint64_t;
     39  1.1  jakllsch         typedef __int64             int64_t;
     40  1.1  jakllsch         typedef unsigned __int32    uint32_t;
     41  1.1  jakllsch         typedef __int32             int32_t;
     42  1.1  jakllsch         typedef unsigned short      uint16_t;
     43  1.1  jakllsch         typedef short               int16_t;
     44  1.1  jakllsch         typedef unsigned char       uint8_t;
     45  1.1  jakllsch         typedef char                int8_t;
     46  1.1  jakllsch     #elif defined(__GNUC__)
     47  1.1  jakllsch         typedef int __attribute__((__mode__(__DI__)))           int64_t;
     48  1.1  jakllsch         typedef unsigned int __attribute__((__mode__(__DI__)))  uint64_t;
     49  1.1  jakllsch         typedef unsigned int        uint32_t;
     50  1.1  jakllsch         typedef int                 int32_t;
     51  1.1  jakllsch         typedef unsigned short      uint16_t;
     52  1.1  jakllsch         typedef short               int16_t;
     53  1.1  jakllsch         typedef unsigned char       uint8_t;
     54  1.1  jakllsch         typedef signed char         int8_t;
     55  1.1  jakllsch     #elif defined(UNIX_LP64)
     56  1.1  jakllsch 
     57  1.1  jakllsch         /*  Use LP64 programming model from C_FLAGS for integer width declarations */
     58  1.1  jakllsch 
     59  1.1  jakllsch        typedef unsigned long       uint64_t;
     60  1.1  jakllsch        typedef long                int64_t;
     61  1.1  jakllsch        typedef unsigned int        uint32_t;
     62  1.1  jakllsch        typedef int                 int32_t;
     63  1.1  jakllsch        typedef unsigned short      uint16_t;
     64  1.1  jakllsch        typedef short               int16_t;
     65  1.1  jakllsch        typedef unsigned char       uint8_t;
     66  1.1  jakllsch        typedef char                int8_t;
     67  1.1  jakllsch     #else
     68  1.1  jakllsch 
     69  1.1  jakllsch        /*  Assume P64 programming model from C_FLAGS for integer width declarations */
     70  1.1  jakllsch 
     71  1.1  jakllsch        typedef unsigned long long  uint64_t __attribute__((aligned (8)));
     72  1.1  jakllsch        typedef long long           int64_t __attribute__((aligned (8)));
     73  1.1  jakllsch        typedef unsigned int        uint32_t;
     74  1.1  jakllsch        typedef int                 int32_t;
     75  1.1  jakllsch        typedef unsigned short      uint16_t;
     76  1.1  jakllsch        typedef short               int16_t;
     77  1.1  jakllsch        typedef unsigned char       uint8_t;
     78  1.1  jakllsch        typedef char                int8_t;
     79  1.1  jakllsch     #endif
     80  1.2  jakllsch #elif defined(__NetBSD__)
     81  1.2  jakllsch     #include <sys/stdint.h>
     82  1.1  jakllsch #elif defined(__GNUC__)
     83  1.1  jakllsch     #include <stdint.h>
     84  1.1  jakllsch #endif
     85  1.1  jakllsch 
     86  1.1  jakllsch //
     87  1.1  jakllsch // Basic EFI types of various widths
     88  1.1  jakllsch //
     89  1.1  jakllsch 
     90  1.1  jakllsch #ifndef __WCHAR_TYPE__
     91  1.1  jakllsch # define __WCHAR_TYPE__ short
     92  1.1  jakllsch #endif
     93  1.1  jakllsch 
     94  1.1  jakllsch typedef uint64_t   UINT64;
     95  1.1  jakllsch typedef int64_t    INT64;
     96  1.1  jakllsch 
     97  1.1  jakllsch #ifndef _BASETSD_H_
     98  1.1  jakllsch     typedef uint32_t   UINT32;
     99  1.1  jakllsch     typedef int32_t    INT32;
    100  1.1  jakllsch #endif
    101  1.1  jakllsch 
    102  1.1  jakllsch typedef uint16_t   UINT16;
    103  1.1  jakllsch typedef int16_t    INT16;
    104  1.1  jakllsch typedef uint8_t    UINT8;
    105  1.1  jakllsch typedef int8_t     INT8;
    106  1.1  jakllsch typedef __WCHAR_TYPE__ WCHAR;
    107  1.1  jakllsch 
    108  1.1  jakllsch #undef VOID
    109  1.1  jakllsch #define VOID    void
    110  1.1  jakllsch 
    111  1.1  jakllsch 
    112  1.1  jakllsch typedef int32_t    INTN;
    113  1.1  jakllsch typedef uint32_t   UINTN;
    114  1.1  jakllsch 
    115  1.1  jakllsch #ifdef EFI_NT_EMULATOR
    116  1.1  jakllsch     #define POST_CODE(_Data)
    117  1.1  jakllsch #else
    118  1.1  jakllsch     #ifdef EFI_DEBUG
    119  1.1  jakllsch #define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
    120  1.1  jakllsch     #else
    121  1.1  jakllsch         #define POST_CODE(_Data)
    122  1.1  jakllsch     #endif
    123  1.1  jakllsch #endif
    124  1.1  jakllsch 
    125  1.1  jakllsch #define EFIERR(a)           (0x80000000 | a)
    126  1.1  jakllsch #define EFI_ERROR_MASK      0x80000000
    127  1.1  jakllsch #define EFIERR_OEM(a)       (0xc0000000 | a)
    128  1.1  jakllsch 
    129  1.1  jakllsch 
    130  1.1  jakllsch #define BAD_POINTER         0xFBFBFBFB
    131  1.1  jakllsch #define MAX_ADDRESS         0xFFFFFFFF
    132  1.1  jakllsch 
    133  1.1  jakllsch #ifdef EFI_NT_EMULATOR
    134  1.1  jakllsch     #define BREAKPOINT()        __asm { int 3 }
    135  1.1  jakllsch #else
    136  1.1  jakllsch     #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
    137  1.1  jakllsch #endif
    138  1.1  jakllsch 
    139  1.1  jakllsch //
    140  1.1  jakllsch // Pointers must be aligned to these address to function
    141  1.1  jakllsch //
    142  1.1  jakllsch 
    143  1.1  jakllsch #define MIN_ALIGNMENT_SIZE  4
    144  1.1  jakllsch 
    145  1.1  jakllsch #define ALIGN_VARIABLE(Value ,Adjustment) \
    146  1.1  jakllsch             (UINTN)Adjustment = 0; \
    147  1.1  jakllsch             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
    148  1.1  jakllsch                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
    149  1.1  jakllsch             Value = (UINTN)Value + (UINTN)Adjustment
    150  1.1  jakllsch 
    151  1.1  jakllsch 
    152  1.1  jakllsch //
    153  1.1  jakllsch // Define macros to build data structure signatures from characters.
    154  1.1  jakllsch //
    155  1.1  jakllsch 
    156  1.1  jakllsch #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
    157  1.1  jakllsch #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
    158  1.1  jakllsch #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))
    159  1.1  jakllsch //
    160  1.1  jakllsch // To export & import functions in the EFI emulator environment
    161  1.1  jakllsch //
    162  1.1  jakllsch 
    163  1.1  jakllsch #ifdef EFI_NT_EMULATOR
    164  1.1  jakllsch     #define EXPORTAPI           __declspec( dllexport )
    165  1.1  jakllsch #else
    166  1.1  jakllsch     #define EXPORTAPI
    167  1.1  jakllsch #endif
    168  1.1  jakllsch 
    169  1.1  jakllsch 
    170  1.1  jakllsch //
    171  1.1  jakllsch // EFIAPI - prototype calling convention for EFI function pointers
    172  1.1  jakllsch // BOOTSERVICE - prototype for implementation of a boot service interface
    173  1.1  jakllsch // RUNTIMESERVICE - prototype for implementation of a runtime service interface
    174  1.1  jakllsch // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
    175  1.1  jakllsch // RUNTIME_CODE - pragma macro for declaring runtime code
    176  1.1  jakllsch //
    177  1.1  jakllsch 
    178  1.1  jakllsch #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
    179  1.1  jakllsch     #ifdef _MSC_EXTENSIONS
    180  1.1  jakllsch         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
    181  1.1  jakllsch     #else
    182  1.1  jakllsch         #define EFIAPI          // Substitute expresion to force C calling convention
    183  1.1  jakllsch     #endif
    184  1.1  jakllsch #endif
    185  1.1  jakllsch 
    186  1.1  jakllsch #define BOOTSERVICE
    187  1.1  jakllsch //#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
    188  1.1  jakllsch //#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
    189  1.1  jakllsch #define RUNTIMESERVICE
    190  1.1  jakllsch #define RUNTIMEFUNCTION
    191  1.1  jakllsch 
    192  1.1  jakllsch 
    193  1.1  jakllsch #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
    194  1.1  jakllsch #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
    195  1.1  jakllsch #define END_RUNTIME_DATA()      data_seg("")
    196  1.1  jakllsch 
    197  1.1  jakllsch #define VOLATILE    volatile
    198  1.1  jakllsch 
    199  1.1  jakllsch #define MEMORY_FENCE()
    200  1.1  jakllsch 
    201  1.1  jakllsch #ifdef EFI_NT_EMULATOR
    202  1.1  jakllsch 
    203  1.1  jakllsch //
    204  1.1  jakllsch // To help ensure proper coding of integrated drivers, they are
    205  1.1  jakllsch // compiled as DLLs.  In NT they require a dll init entry pointer.
    206  1.1  jakllsch // The macro puts a stub entry point into the DLL so it will load.
    207  1.1  jakllsch //
    208  1.1  jakllsch 
    209  1.1  jakllsch #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
    210  1.1  jakllsch     UINTN                                       \
    211  1.1  jakllsch     __stdcall                                   \
    212  1.1  jakllsch     _DllMainCRTStartup (                        \
    213  1.1  jakllsch         UINTN    Inst,                          \
    214  1.1  jakllsch         UINTN    reason_for_call,               \
    215  1.1  jakllsch         VOID    *rserved                        \
    216  1.1  jakllsch         )                                       \
    217  1.1  jakllsch     {                                           \
    218  1.1  jakllsch         return 1;                               \
    219  1.1  jakllsch     }                                           \
    220  1.1  jakllsch                                                 \
    221  1.1  jakllsch     int                                         \
    222  1.1  jakllsch     EXPORTAPI                                   \
    223  1.1  jakllsch     __cdecl                                     \
    224  1.1  jakllsch     InitializeDriver (                          \
    225  1.1  jakllsch         void *ImageHandle,                      \
    226  1.1  jakllsch         void *SystemTable                       \
    227  1.1  jakllsch         )                                       \
    228  1.1  jakllsch     {                                           \
    229  1.1  jakllsch         return InitFunction(ImageHandle, SystemTable);       \
    230  1.1  jakllsch     }
    231  1.1  jakllsch 
    232  1.1  jakllsch 
    233  1.1  jakllsch     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
    234  1.1  jakllsch         (_if)->LoadInternal(type, name, NULL)
    235  1.1  jakllsch 
    236  1.1  jakllsch #else // EFI_NT_EMULATOR
    237  1.1  jakllsch 
    238  1.1  jakllsch //
    239  1.1  jakllsch // When build similiar to FW, then link everything together as
    240  1.1  jakllsch // one big module.
    241  1.1  jakllsch //
    242  1.1  jakllsch 
    243  1.1  jakllsch     #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
    244  1.1  jakllsch         UINTN                                       \
    245  1.1  jakllsch         InitializeDriver (                          \
    246  1.1  jakllsch             VOID    *ImageHandle,                   \
    247  1.1  jakllsch             VOID    *SystemTable                    \
    248  1.1  jakllsch             )                                       \
    249  1.1  jakllsch         {                                           \
    250  1.1  jakllsch             return InitFunction(ImageHandle,        \
    251  1.1  jakllsch                     SystemTable);                   \
    252  1.1  jakllsch         }                                           \
    253  1.1  jakllsch                                                     \
    254  1.1  jakllsch         EFI_STATUS efi_main(                        \
    255  1.1  jakllsch             EFI_HANDLE image,                       \
    256  1.1  jakllsch             EFI_SYSTEM_TABLE *systab                \
    257  1.1  jakllsch             ) __attribute__((weak,                  \
    258  1.1  jakllsch                     alias ("InitializeDriver")));
    259  1.1  jakllsch 
    260  1.1  jakllsch     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
    261  1.1  jakllsch             (_if)->LoadInternal(type, name, entry)
    262  1.1  jakllsch 
    263  1.1  jakllsch #endif // EFI_FW_NT
    264  1.1  jakllsch 
    265  1.1  jakllsch //
    266  1.1  jakllsch // Some compilers don't support the forward reference construct:
    267  1.1  jakllsch //  typedef struct XXXXX
    268  1.1  jakllsch //
    269  1.1  jakllsch // The following macro provide a workaround for such cases.
    270  1.1  jakllsch //
    271  1.1  jakllsch #ifdef NO_INTERFACE_DECL
    272  1.1  jakllsch #define INTERFACE_DECL(x)
    273  1.1  jakllsch #else
    274  1.1  jakllsch #ifdef __GNUC__
    275  1.1  jakllsch #define INTERFACE_DECL(x) struct x
    276  1.1  jakllsch #else
    277  1.1  jakllsch #define INTERFACE_DECL(x) typedef struct x
    278  1.1  jakllsch #endif
    279  1.1  jakllsch #endif
    280  1.1  jakllsch 
    281  1.1  jakllsch /* No efi call wrapper for IA32 architecture */
    282  1.1  jakllsch #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
    283  1.1  jakllsch #define EFI_FUNCTION
    284  1.1  jakllsch 
    285  1.1  jakllsch #ifdef _MSC_EXTENSIONS
    286  1.1  jakllsch #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
    287  1.1  jakllsch #endif
    288  1.1  jakllsch 
    289