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