Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:05

0001 /* $FreeBSD$ */
0002 /*++
0003 
0004 Copyright (c)  1999 - 2003 Intel Corporation. All rights reserved
0005 This software and associated documentation (if any) is furnished
0006 under a license and may only be used or copied in accordance
0007 with the terms of the license. Except as permitted by such
0008 license, no part of this software or documentation may be
0009 reproduced, stored in a retrieval system, or transmitted in any
0010 form or by any means without the express written consent of
0011 Intel Corporation.
0012 
0013 Module Name:
0014 
0015     efefind.h
0016 
0017 Abstract:
0018 
0019     EFI to compile bindings
0020 
0021 
0022 
0023 
0024 Revision History
0025 
0026 --*/
0027 
0028 #pragma pack()
0029 
0030 
0031 #ifdef __FreeBSD__
0032 #include <sys/stdint.h>
0033 #elif __rtems__
0034 #include <stdint.h>
0035 #else
0036 //
0037 // Basic int types of various widths
0038 //
0039 
0040 #if (__STDC_VERSION__ < 199901L )
0041 
0042     // No ANSI C 1999/2000 stdint.h integer width declarations 
0043 
0044     #ifdef _MSC_EXTENSIONS
0045 
0046         // Use Microsoft C compiler integer width declarations 
0047 
0048         typedef unsigned __int64    uint64_t;
0049         typedef __int64             int64_t;
0050         typedef unsigned __int32    uint32_t;
0051         typedef __int32             int32_t;
0052         typedef unsigned short      uint16_t;
0053         typedef short               int16_t;
0054         typedef unsigned char       uint8_t;
0055         typedef char                int8_t;
0056     #else             
0057         #ifdef UNIX_LP64
0058 
0059             // Use LP64 programming model from C_FLAGS for integer width declarations 
0060 
0061             typedef unsigned long       uint64_t;
0062             typedef long                int64_t;
0063             typedef unsigned int        uint32_t;
0064             typedef int                 int32_t;
0065             typedef unsigned short      uint16_t;
0066             typedef short               int16_t;
0067             typedef unsigned char       uint8_t;
0068             typedef char                int8_t;
0069         #else
0070 
0071             // Assume P64 programming model from C_FLAGS for integer width declarations 
0072 
0073             typedef unsigned long long  uint64_t;
0074             typedef long long           int64_t;
0075             typedef unsigned int        uint32_t;
0076             typedef int                 int32_t;
0077             typedef unsigned short      uint16_t;
0078             typedef short               int16_t;
0079             typedef unsigned char       uint8_t;
0080             typedef char                int8_t;
0081         #endif
0082     #endif
0083 #endif
0084 #endif  /* __FreeBSD__ */
0085 
0086 //
0087 // Basic EFI types of various widths
0088 //
0089 
0090 #ifndef ACPI_THREAD_ID      /* ACPI's definitions are fine */
0091 #define ACPI_USE_SYSTEM_INTTYPES 1  /* Tell ACPI we've defined types */
0092 
0093 typedef uint64_t   UINT64;
0094 typedef int64_t    INT64;
0095 
0096 #ifndef _BASETSD_H_
0097     typedef uint32_t   UINT32;
0098     typedef int32_t    INT32;
0099 #endif
0100 
0101 typedef uint16_t   UINT16;
0102 typedef int16_t    INT16;
0103 typedef uint8_t    UINT8;
0104 typedef int8_t     INT8;
0105 
0106 #endif
0107 
0108 #undef VOID
0109 #define VOID    void
0110 
0111 
0112 typedef int64_t    INTN;
0113 typedef uint64_t   UINTN;
0114 
0115 #ifdef EFI_NT_EMULATOR
0116     #define POST_CODE(_Data)
0117 #else    
0118     #ifdef EFI_DEBUG
0119 #define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
0120     #else
0121         #define POST_CODE(_Data)
0122     #endif  
0123 #endif
0124 
0125 #define EFIERR(a)           (0x8000000000000000 | a)
0126 #define EFI_ERROR_MASK      0x8000000000000000
0127 #define EFIERR_OEM(a)       (0xc000000000000000 | a)      
0128 
0129 
0130 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
0131 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
0132 
0133 #define BREAKPOINT()        __asm { int 3 }
0134 
0135 //
0136 // Pointers must be aligned to these address to function
0137 //
0138 
0139 #define MIN_ALIGNMENT_SIZE  4
0140 
0141 #define ALIGN_VARIABLE(Value ,Adjustment) \
0142             (UINTN)Adjustment = 0; \
0143             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
0144                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
0145             Value = (UINTN)Value + (UINTN)Adjustment
0146 
0147 
0148 //
0149 // Define macros to build data structure signatures from characters.
0150 //
0151 
0152 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
0153 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
0154 #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))
0155 
0156 //
0157 // EFIAPI - prototype calling convention for EFI function pointers
0158 // BOOTSERVICE - prototype for implementation of a boot service interface
0159 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
0160 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
0161 // RUNTIME_CODE - pragma macro for declaring runtime code    
0162 //
0163 
0164 #ifdef  __amd64__
0165 #define EFIAPI  __attribute__((ms_abi))
0166 #endif
0167 
0168 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options 
0169     #ifdef _MSC_EXTENSIONS
0170         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler 
0171     #else
0172         #define EFIAPI          // Substitute expresion to force C calling convention 
0173     #endif
0174 #endif
0175 
0176 #define BOOTSERVICE
0177 //#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
0178 //#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
0179 #define RUNTIMESERVICE
0180 #define RUNTIMEFUNCTION
0181 
0182 
0183 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
0184 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
0185 #define END_RUNTIME_DATA()      data_seg("")
0186 
0187 #define VOLATILE    volatile
0188 
0189 #define MEMORY_FENCE()    
0190 
0191 #ifdef EFI_NO_INTERFACE_DECL
0192   #define EFI_FORWARD_DECLARATION(x)
0193   #define EFI_INTERFACE_DECL(x)
0194 #else
0195   #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
0196   #define EFI_INTERFACE_DECL(x) typedef struct x
0197 #endif
0198 
0199 #ifdef EFI_NT_EMULATOR
0200 
0201 //
0202 // To help ensure proper coding of integrated drivers, they are
0203 // compiled as DLLs.  In NT they require a dll init entry pointer.
0204 // The macro puts a stub entry point into the DLL so it will load.
0205 //
0206 
0207 #define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
0208     EFI_STATUS                                          \
0209     InitFunction (                                      \
0210       EFI_HANDLE  ImageHandle,                          \
0211       EFI_SYSTEM_TABLE  *SystemTable                    \
0212       );                                                \
0213                                                         \
0214     UINTN                                               \
0215     __stdcall                                           \
0216     _DllMainCRTStartup (                                \
0217         UINTN    Inst,                                  \
0218         UINTN    reason_for_call,                       \
0219         VOID    *rserved                                \
0220         )                                               \
0221     {                                                   \
0222         return 1;                                       \
0223     }                                                   \
0224                                                         \
0225     int                                                 \
0226     __declspec( dllexport )                             \
0227     __cdecl                                             \
0228     InitializeDriver (                                  \
0229         void *ImageHandle,                              \
0230         void *SystemTable                               \
0231         )                                               \
0232     {                                                   \
0233         return InitFunction(ImageHandle, SystemTable);  \
0234     }
0235 
0236 
0237     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
0238         (_if)->LoadInternal(type, name, NULL)             
0239 
0240 #else // EFI_NT_EMULATOR 
0241 
0242 //
0243 // When building similar to FW, link everything together as
0244 // one big module.
0245 //
0246 
0247     #define EFI_DRIVER_ENTRY_POINT(InitFunction)
0248 
0249     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
0250             (_if)->LoadInternal(type, name, entry)
0251 
0252 #endif // EFI_FW_NT 
0253 
0254 #ifdef __FreeBSD__
0255 #define INTERFACE_DECL(x) struct x
0256 #elif __rtems__
0257 #define INTERFACE_DECL(x) struct x
0258 #else
0259 //
0260 // Some compilers don't support the forward reference construct:
0261 //  typedef struct XXXXX
0262 //
0263 // The following macro provide a workaround for such cases.
0264 //
0265 #ifdef NO_INTERFACE_DECL
0266 #define INTERFACE_DECL(x)
0267 #else
0268 #define INTERFACE_DECL(x) typedef struct x
0269 #endif
0270 #endif  /* __FreeBSD__ */
0271 
0272 #ifdef _MSC_EXTENSIONS
0273 #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
0274 #endif
0275