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 */ 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 int64_t INTN; 110 typedef uint64_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) (0x8000000000000000 | a) 123 #define EFI_ERROR_MASK 0x8000000000000000 124 #define EFIERR_OEM(a) (0xc000000000000000 | a) 125 126 127 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 128 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 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 #ifdef __amd64__ 162 #define EFIAPI __attribute__((ms_abi)) 163 #endif 164 165 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 166 #ifdef _MSC_EXTENSIONS 167 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 168 #else 169 #define EFIAPI // Substitute expresion to force C calling convention 170 #endif 171 #endif 172 173 #define BOOTSERVICE 174 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a 175 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a 176 #define RUNTIMESERVICE 177 #define RUNTIMEFUNCTION 178 179 180 #define RUNTIME_CODE(a) alloc_text("rtcode", a) 181 #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 182 #define END_RUNTIME_DATA() data_seg("") 183 184 #define VOLATILE volatile 185 186 #define MEMORY_FENCE() 187 188 #ifdef EFI_NO_INTERFACE_DECL 189 #define EFI_FORWARD_DECLARATION(x) 190 #define EFI_INTERFACE_DECL(x) 191 #else 192 #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x 193 #define EFI_INTERFACE_DECL(x) typedef struct x 194 #endif 195 196 #ifdef EFI_NT_EMULATOR 197 198 // 199 // To help ensure proper coding of integrated drivers, they are 200 // compiled as DLLs. In NT they require a dll init entry pointer. 201 // The macro puts a stub entry point into the DLL so it will load. 202 // 203 204 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 205 EFI_STATUS \ 206 InitFunction ( \ 207 EFI_HANDLE ImageHandle, \ 208 EFI_SYSTEM_TABLE *SystemTable \ 209 ); \ 210 \ 211 UINTN \ 212 __stdcall \ 213 _DllMainCRTStartup ( \ 214 UINTN Inst, \ 215 UINTN reason_for_call, \ 216 VOID *rserved \ 217 ) \ 218 { \ 219 return 1; \ 220 } \ 221 \ 222 int \ 223 __declspec( dllexport ) \ 224 __cdecl \ 225 InitializeDriver ( \ 226 void *ImageHandle, \ 227 void *SystemTable \ 228 ) \ 229 { \ 230 return InitFunction(ImageHandle, SystemTable); \ 231 } 232 233 234 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 235 (_if)->LoadInternal(type, name, NULL) 236 237 #else // EFI_NT_EMULATOR 238 239 // 240 // When building similar to FW, link everything together as 241 // one big module. 242 // 243 244 #define EFI_DRIVER_ENTRY_POINT(InitFunction) 245 246 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 247 (_if)->LoadInternal(type, name, entry) 248 249 #endif // EFI_FW_NT 250 251 #ifdef __FreeBSD__ 252 #define INTERFACE_DECL(x) struct x 253 #else 254 // 255 // Some compilers don't support the forward reference construct: 256 // typedef struct XXXXX 257 // 258 // The following macro provide a workaround for such cases. 259 // 260 #ifdef NO_INTERFACE_DECL 261 #define INTERFACE_DECL(x) 262 #else 263 #define INTERFACE_DECL(x) typedef struct x 264 #endif 265 #endif /* __FreeBSD__ */ 266 267 #ifdef _MSC_EXTENSIONS 268 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP 269 #endif 270 271