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 ) && !defined(__cplusplus) 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 typedef uint32_t uintptr_t; 79 typedef int32_t intptr_t; 80 #elif defined(__GNUC__) 81 #include <stdint.h> 82 #endif 83 84 // 85 // Basic EFI types of various widths 86 // 87 88 #ifndef __WCHAR_TYPE__ 89 # define __WCHAR_TYPE__ short 90 #endif 91 92 typedef uint64_t UINT64; 93 typedef int64_t INT64; 94 95 #ifndef _BASETSD_H_ 96 typedef uint32_t UINT32; 97 typedef int32_t INT32; 98 #endif 99 100 typedef uint16_t UINT16; 101 typedef int16_t INT16; 102 typedef uint8_t UINT8; 103 typedef int8_t INT8; 104 typedef __WCHAR_TYPE__ WCHAR; 105 106 #undef VOID 107 #define VOID void 108 109 110 typedef int32_t INTN; 111 typedef uint32_t UINTN; 112 113 #ifdef EFI_NT_EMULATOR 114 #define POST_CODE(_Data) 115 #else 116 #ifdef EFI_DEBUG 117 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al 118 #else 119 #define POST_CODE(_Data) 120 #endif 121 #endif 122 123 #define EFIERR(a) (0x80000000 | a) 124 #define EFI_ERROR_MASK 0x80000000 125 #define EFIERR_OEM(a) (0xc0000000 | a) 126 127 128 #define BAD_POINTER 0xFBFBFBFB 129 #define MAX_ADDRESS 0xFFFFFFFF 130 131 #ifdef EFI_NT_EMULATOR 132 #define BREAKPOINT() __asm { int 3 } 133 #else 134 #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32 135 #endif 136 137 // 138 // Pointers must be aligned to these address to function 139 // 140 141 #define MIN_ALIGNMENT_SIZE 4 142 143 #define ALIGN_VARIABLE(Value ,Adjustment) \ 144 (UINTN)Adjustment = 0; \ 145 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 146 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 147 Value = (UINTN)Value + (UINTN)Adjustment 148 149 150 // 151 // Define macros to build data structure signatures from characters. 152 // 153 154 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 155 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 156 #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)) 157 // 158 // To export & import functions in the EFI emulator environment 159 // 160 161 #ifdef EFI_NT_EMULATOR 162 #define EXPORTAPI __declspec( dllexport ) 163 #else 164 #define EXPORTAPI 165 #endif 166 167 168 // 169 // EFIAPI - prototype calling convention for EFI function pointers 170 // BOOTSERVICE - prototype for implementation of a boot service interface 171 // RUNTIMESERVICE - prototype for implementation of a runtime service interface 172 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 173 // RUNTIME_CODE - pragma macro for declaring runtime code 174 // 175 176 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 177 #ifdef _MSC_EXTENSIONS 178 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 179 #else 180 #define EFIAPI // Substitute expresion to force C calling convention 181 #endif 182 #endif 183 184 #define BOOTSERVICE 185 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a 186 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a 187 #define RUNTIMESERVICE 188 #define RUNTIMEFUNCTION 189 190 191 #define RUNTIME_CODE(a) alloc_text("rtcode", a) 192 #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 193 #define END_RUNTIME_DATA() data_seg("") 194 195 #define VOLATILE volatile 196 197 #define MEMORY_FENCE() 198 199 #ifdef EFI_NT_EMULATOR 200 201 // 202 // To help ensure proper coding of integrated drivers, they are 203 // compiled as DLLs. In NT they require a dll init entry pointer. 204 // The macro puts a stub entry point into the DLL so it will load. 205 // 206 207 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 208 UINTN \ 209 __stdcall \ 210 _DllMainCRTStartup ( \ 211 UINTN Inst, \ 212 UINTN reason_for_call, \ 213 VOID *rserved \ 214 ) \ 215 { \ 216 return 1; \ 217 } \ 218 \ 219 int \ 220 EXPORTAPI \ 221 __cdecl \ 222 InitializeDriver ( \ 223 void *ImageHandle, \ 224 void *SystemTable \ 225 ) \ 226 { \ 227 return InitFunction(ImageHandle, SystemTable); \ 228 } 229 230 231 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 232 (_if)->LoadInternal(type, name, NULL) 233 234 #else // EFI_NT_EMULATOR 235 236 // 237 // When build similiar to FW, then link everything together as 238 // one big module. For the MSVC toolchain, we simply tell the 239 // linker what our driver init function is using /ENTRY. 240 // 241 #if defined(_MSC_EXTENSIONS) 242 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 243 __pragma(comment(linker, "/ENTRY:" # InitFunction)) 244 #else 245 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 246 UINTN \ 247 InitializeDriver ( \ 248 VOID *ImageHandle, \ 249 VOID *SystemTable \ 250 ) \ 251 { \ 252 return InitFunction(ImageHandle, \ 253 SystemTable); \ 254 } \ 255 \ 256 EFI_STATUS efi_main( \ 257 EFI_HANDLE image, \ 258 EFI_SYSTEM_TABLE *systab \ 259 ) __attribute__((weak, \ 260 alias ("InitializeDriver"))); 261 #endif 262 263 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 264 (_if)->LoadInternal(type, name, entry) 265 266 #endif // EFI_FW_NT 267 268 // 269 // Some compilers don't support the forward reference construct: 270 // typedef struct XXXXX 271 // 272 // The following macro provide a workaround for such cases. 273 // 274 #ifdef NO_INTERFACE_DECL 275 #define INTERFACE_DECL(x) 276 #else 277 #if defined(__GNUC__) || defined(_MSC_EXTENSIONS) 278 #define INTERFACE_DECL(x) struct x 279 #else 280 #define INTERFACE_DECL(x) typedef struct x 281 #endif 282 #endif 283 284 /* No efi call wrapper for IA32 architecture */ 285 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 286 #define EFI_FUNCTION 287 288 #ifdef _MSC_EXTENSIONS 289 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP 290 #endif 291 292