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 unsigned long long uint64_t __attribute__((aligned (8))); 46 typedef long long int64_t __attribute__((aligned (8))); 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 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 #endif 79 80 // 81 // Basic EFI types of various widths 82 // 83 84 #ifndef __WCHAR_TYPE__ 85 # define __WCHAR_TYPE__ short 86 #endif 87 88 typedef uint64_t UINT64; 89 typedef int64_t INT64; 90 91 #ifndef _BASETSD_H_ 92 typedef uint32_t UINT32; 93 typedef int32_t INT32; 94 #endif 95 96 typedef uint16_t UINT16; 97 typedef int16_t INT16; 98 typedef uint8_t UINT8; 99 typedef int8_t INT8; 100 typedef __WCHAR_TYPE__ WCHAR; 101 102 #undef VOID 103 #define VOID void 104 105 106 typedef int64_t INTN; 107 typedef uint64_t UINTN; 108 109 #ifdef EFI_NT_EMULATOR 110 #define POST_CODE(_Data) 111 #else 112 #ifdef EFI_DEBUG 113 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al 114 #else 115 #define POST_CODE(_Data) 116 #endif 117 #endif 118 119 #define EFIERR(a) (0x8000000000000000 | a) 120 #define EFI_ERROR_MASK 0x8000000000000000 121 #define EFIERR_OEM(a) (0xc000000000000000 | a) 122 123 124 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 125 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 126 127 #ifdef EFI_NT_EMULATOR 128 #define BREAKPOINT() __asm { int 3 } 129 #else 130 #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32 131 #endif 132 133 // 134 // Pointers must be aligned to these address to function 135 // 136 137 #define MIN_ALIGNMENT_SIZE 4 138 139 #define ALIGN_VARIABLE(Value ,Adjustment) \ 140 (UINTN)Adjustment = 0; \ 141 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 142 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 143 Value = (UINTN)Value + (UINTN)Adjustment 144 145 146 // 147 // Define macros to build data structure signatures from characters. 148 // 149 150 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 151 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 152 #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)) 153 // 154 // To export & import functions in the EFI emulator environment 155 // 156 157 #ifdef EFI_NT_EMULATOR 158 #define EXPORTAPI __declspec( dllexport ) 159 #else 160 #define EXPORTAPI 161 #endif 162 163 164 // 165 // EFIAPI - prototype calling convention for EFI function pointers 166 // BOOTSERVICE - prototype for implementation of a boot service interface 167 // RUNTIMESERVICE - prototype for implementation of a runtime service interface 168 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 169 // RUNTIME_CODE - pragma macro for declaring runtime code 170 // 171 172 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 173 #ifdef _MSC_EXTENSIONS 174 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 175 #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) 176 #define EFIAPI __attribute__((__ms_abi__)) // Force Microsoft ABI 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. 237 // 238 239 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 240 UINTN \ 241 InitializeDriver ( \ 242 VOID *ImageHandle, \ 243 VOID *SystemTable \ 244 ) \ 245 { \ 246 return InitFunction(ImageHandle, \ 247 SystemTable); \ 248 } \ 249 \ 250 EFI_STATUS efi_main( \ 251 EFI_HANDLE image, \ 252 EFI_SYSTEM_TABLE *systab \ 253 ) __attribute__((weak, \ 254 alias ("InitializeDriver"))); 255 256 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 257 (_if)->LoadInternal(type, name, entry) 258 259 #endif // EFI_FW_NT 260 261 // 262 // Some compilers don't support the forward reference construct: 263 // typedef struct XXXXX 264 // 265 // The following macro provide a workaround for such cases. 266 // 267 #ifdef NO_INTERFACE_DECL 268 #define INTERFACE_DECL(x) 269 #else 270 #ifdef __GNUC__ 271 #define INTERFACE_DECL(x) struct x 272 #else 273 #define INTERFACE_DECL(x) typedef struct x 274 #endif 275 #endif 276 277 #ifdef _MSC_EXTENSIONS 278 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP 279 #endif 280 281