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