1 /*++ 2 3 Copyright (c) 1999 - 2003 Intel Corporation. All rights reserved 4 This software and associated documentation (if any) is furnished 5 under a license and may only be used or copied in accordance 6 with the terms of the license. Except as permitted by such 7 license, no part of this software or documentation may be 8 reproduced, stored in a retrieval system, or transmitted in any 9 form or by any means without the express written consent of 10 Intel Corporation. 11 12 Module Name: 13 14 efefind.h 15 16 Abstract: 17 18 EFI to compile bindings 19 20 21 22 23 Revision History 24 25 --*/ 26 27 #pragma pack() 28 29 30 #ifdef __FreeBSD__ 31 #include <sys/stdint.h> 32 #else 33 // 34 // Basic int types of various widths 35 // 36 37 #if (__STDC_VERSION__ < 199901L ) 38 39 // No ANSI C 1999/2000 stdint.h integer width declarations 40 41 #ifdef _MSC_EXTENSIONS 42 43 // Use Microsoft C compiler integer width declarations 44 45 typedef unsigned __int64 uint64_t; 46 typedef __int64 int64_t; 47 typedef unsigned __int32 uint32_t; 48 typedef __int32 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 #else 54 #ifdef UNIX_LP64 55 56 // Use LP64 programming model from C_FLAGS for integer width declarations 57 58 typedef unsigned long uint64_t; 59 typedef long int64_t; 60 typedef unsigned int uint32_t; 61 typedef int int32_t; 62 typedef unsigned short uint16_t; 63 typedef short int16_t; 64 typedef unsigned char uint8_t; 65 typedef char int8_t; 66 #else 67 68 // Assume P64 programming model from C_FLAGS for integer width declarations 69 70 typedef unsigned long long uint64_t; 71 typedef long long int64_t; 72 typedef unsigned int uint32_t; 73 typedef int int32_t; 74 typedef unsigned short uint16_t; 75 typedef short int16_t; 76 typedef unsigned char uint8_t; 77 typedef char int8_t; 78 #endif 79 #endif 80 #endif 81 #endif /* __FreeBSD__ */ 82 83 // 84 // Basic EFI types of various widths 85 // 86 87 #ifndef ACPI_THREAD_ID /* ACPI's definitions are fine, use those */ 88 #define ACPI_USE_SYSTEM_INTTYPES 1 /* Tell ACPI we've defined types */ 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 103 #endif 104 105 #undef VOID 106 #define VOID void 107 108 109 typedef int32_t INTN; 110 typedef uint32_t UINTN; 111 112 #ifdef EFI_NT_EMULATOR 113 #define POST_CODE(_Data) 114 #else 115 #ifdef EFI_DEBUG 116 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al 117 #else 118 #define POST_CODE(_Data) 119 #endif 120 #endif 121 122 #define EFIERR(a) (0x80000000 | a) 123 #define EFI_ERROR_MASK 0x80000000 124 #define EFIERR_OEM(a) (0xc0000000 | a) 125 126 127 #define BAD_POINTER 0xFBFBFBFB 128 #define MAX_ADDRESS 0xFFFFFFFF 129 130 #define BREAKPOINT() __asm { int 3 } 131 132 // 133 // Pointers must be aligned to these address to function 134 // 135 136 #define MIN_ALIGNMENT_SIZE 4 137 138 #define ALIGN_VARIABLE(Value ,Adjustment) \ 139 (UINTN)Adjustment = 0; \ 140 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 141 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 142 Value = (UINTN)Value + (UINTN)Adjustment 143 144 145 // 146 // Define macros to build data structure signatures from characters. 147 // 148 149 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 150 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 151 #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)) 152 153 // 154 // EFIAPI - prototype calling convention for EFI function pointers 155 // BOOTSERVICE - prototype for implementation of a boot service interface 156 // RUNTIMESERVICE - prototype for implementation of a runtime service interface 157 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 158 // RUNTIME_CODE - pragma macro for declaring runtime code 159 // 160 161 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 162 #ifdef _MSC_EXTENSIONS 163 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 164 #else 165 #define EFIAPI // Substitute expresion to force C calling convention 166 #endif 167 #endif 168 169 #define BOOTSERVICE 170 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a 171 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a 172 #define RUNTIMESERVICE 173 #define RUNTIMEFUNCTION 174 175 176 #define RUNTIME_CODE(a) alloc_text("rtcode", a) 177 #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 178 #define END_RUNTIME_DATA() data_seg() 179 180 #define VOLATILE volatile 181 182 #define MEMORY_FENCE() 183 184 #ifdef EFI_NO_INTERFACE_DECL 185 #define EFI_FORWARD_DECLARATION(x) 186 #define EFI_INTERFACE_DECL(x) 187 #else 188 #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x 189 #define EFI_INTERFACE_DECL(x) typedef struct x 190 #endif 191 192 #ifdef EFI_NT_EMULATOR 193 194 // 195 // To help ensure proper coding of integrated drivers, they are 196 // compiled as DLLs. In NT they require a dll init entry pointer. 197 // The macro puts a stub entry point into the DLL so it will load. 198 // 199 200 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 201 EFI_STATUS \ 202 InitFunction ( \ 203 EFI_HANDLE ImageHandle, \ 204 EFI_SYSTEM_TABLE *SystemTable \ 205 ); \ 206 \ 207 UINTN \ 208 __stdcall \ 209 _DllMainCRTStartup ( \ 210 UINTN Inst, \ 211 UINTN reason_for_call, \ 212 VOID *rserved \ 213 ) \ 214 { \ 215 return 1; \ 216 } \ 217 \ 218 int \ 219 __declspec( dllexport ) \ 220 __cdecl \ 221 InitializeDriver ( \ 222 void *ImageHandle, \ 223 void *SystemTable \ 224 ) \ 225 { \ 226 return InitFunction(ImageHandle, SystemTable); \ 227 } 228 229 230 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 231 (_if)->LoadInternal(type, name, NULL) 232 233 #else // EFI_NT_EMULATOR 234 235 // 236 // When build similar to FW, then link everything together as 237 // one big module. 238 // 239 240 #define EFI_DRIVER_ENTRY_POINT(InitFunction) 241 242 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 243 (_if)->LoadInternal(type, name, entry) 244 245 #endif // EFI_FW_NT 246 247 #ifdef __FreeBSD__ 248 #define INTERFACE_DECL(x) struct x 249 #else 250 // 251 // Some compilers don't support the forward reference construct: 252 // typedef struct XXXXX 253 // 254 // The following macro provide a workaround for such cases. 255 // 256 #ifdef NO_INTERFACE_DECL 257 #define INTERFACE_DECL(x) 258 #else 259 #define INTERFACE_DECL(x) typedef struct x 260 #endif 261 #endif /* __FreeBSD__ */ 262 263 #ifdef _MSC_EXTENSIONS 264 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP 265 #endif 266 267