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 #pragma pack() 21 22 23 // 24 // Basic int types of various widths 25 // 26 27 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) 28 29 // No ANSI C 1999/2000 stdint.h integer width declarations 30 31 #ifdef _MSC_EXTENSIONS 32 // Use Microsoft C compiler integer width declarations 33 34 typedef unsigned __int64 uint64_t; 35 typedef __int64 int64_t; 36 typedef unsigned __int32 uint32_t; 37 typedef __int32 int32_t; 38 typedef unsigned __int16 uint16_t; 39 typedef __int16 int16_t; 40 typedef unsigned __int8 uint8_t; 41 typedef __int8 int8_t; 42 #elif defined(UNIX_LP64) 43 // Use LP64 programming model from C_FLAGS for integer width declarations 44 45 typedef unsigned long uint64_t; 46 typedef long int64_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 char int8_t; 53 #else 54 // Assume P64 programming model from C_FLAGS for integer width declarations 55 56 typedef unsigned long long uint64_t; 57 typedef long long int64_t; 58 typedef unsigned int uint32_t; 59 typedef int int32_t; 60 typedef unsigned short uint16_t; 61 typedef short int16_t; 62 typedef unsigned char uint8_t; 63 typedef char int8_t; 64 #endif 65 #elif defined(__GNUC__) 66 #include <stdint.h> 67 #endif 68 69 // 70 // Basic EFI types of various widths 71 // 72 #ifndef __WCHAR_TYPE__ 73 # define __WCHAR_TYPE__ short 74 #endif 75 76 77 typedef uint64_t UINT64; 78 typedef int64_t INT64; 79 typedef uint32_t UINT32; 80 typedef int32_t INT32; 81 typedef uint16_t UINT16; 82 typedef int16_t INT16; 83 typedef uint8_t UINT8; 84 typedef int8_t INT8; 85 typedef __WCHAR_TYPE__ WCHAR; 86 87 88 #undef VOID 89 #define VOID void 90 91 92 typedef int64_t INTN; 93 typedef uint64_t UINTN; 94 95 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 96 // BugBug: Code to debug 97 // 98 #define BIT63 0x8000000000000000 99 100 #define PLATFORM_IOBASE_ADDRESS (0xffffc000000 | BIT63) 101 #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) ) 102 103 // 104 // Macro's with casts make this much easier to use and read. 105 // 106 #define PORT_TO_MEM8D(_Port) (*(UINT8 *)(PORT_TO_MEMD(_Port))) 107 #define POST_CODE(_Data) (PORT_TO_MEM8D(0x80) = (_Data)) 108 // 109 // BugBug: End Debug Code!!! 110 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 111 112 #define EFIERR(a) (0x8000000000000000 | a) 113 #define EFI_ERROR_MASK 0x8000000000000000 114 #define EFIERR_OEM(a) (0xc000000000000000 | a) 115 116 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 117 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 118 119 #define BREAKPOINT() while (TRUE) 120 121 // 122 // Pointers must be aligned to these address to function 123 // you will get an alignment fault if this value is less than 8 124 // 125 #define MIN_ALIGNMENT_SIZE 8 126 127 #define ALIGN_VARIABLE(Value , Adjustment) \ 128 (UINTN) Adjustment = 0; \ 129 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 130 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 131 Value = (UINTN)Value + (UINTN)Adjustment 132 133 // 134 // Define macros to create data structure signatures. 135 // 136 137 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 138 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 139 #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)) 140 // 141 // To export & import functions in the EFI emulator environment 142 // 143 144 #define EXPORTAPI 145 146 // 147 // EFIAPI - prototype calling convention for EFI function pointers 148 // BOOTSERVICE - prototype for implementation of a boot service interface 149 // RUNTIMESERVICE - prototype for implementation of a runtime service interface 150 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 151 // RUNTIME_CODE - pragma macro for declaring runtime code 152 // 153 154 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 155 #ifdef _MSC_EXTENSIONS 156 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 157 #else 158 #define EFIAPI // Substitute expresion to force C calling convention 159 #endif 160 #endif 161 162 #define BOOTSERVICE 163 #define RUNTIMESERVICE 164 #define RUNTIMEFUNCTION 165 166 #define RUNTIME_CODE(a) alloc_text("rtcode", a) 167 #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 168 #define END_RUNTIME_DATA() data_seg("") 169 170 #define VOLATILE volatile 171 172 // 173 // BugBug: Need to find out if this is portable accross compliers. 174 // 175 #ifdef __GNUC__ 176 #define MEMORY_FENCE() __asm__ __volatile__ ("mf.a" ::: "memory") 177 #else 178 void __mf (void); 179 #pragma intrinsic (__mf) 180 #define MEMORY_FENCE() __mf() 181 #endif 182 183 // 184 // When build similiar to FW, then link everything together as 185 // one big module. For the MSVC toolchain, we simply tell the 186 // linker what our driver init function is using /ENTRY. 187 // 188 #if defined(_MSC_EXTENSIONS) 189 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 190 __pragma(comment(linker, "/ENTRY:" # InitFunction)) 191 #else 192 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 193 UINTN \ 194 InitializeDriver ( \ 195 VOID *ImageHandle, \ 196 VOID *SystemTable \ 197 ) \ 198 { \ 199 return InitFunction(ImageHandle, \ 200 SystemTable); \ 201 } \ 202 \ 203 EFI_STATUS efi_main( \ 204 EFI_HANDLE image, \ 205 EFI_SYSTEM_TABLE *systab \ 206 ) __attribute__((weak, \ 207 alias ("InitializeDriver"))); 208 #endif 209 210 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 211 (_if)->LoadInternal(type, name, entry) 212 213 // 214 // Some compilers don't support the forward reference construct: 215 // typedef struct XXXXX 216 // 217 // The following macro provide a workaround for such cases. 218 // 219 #ifdef NO_INTERFACE_DECL 220 #define INTERFACE_DECL(x) 221 #else 222 #ifdef __GNUC__ 223 #define INTERFACE_DECL(x) struct x 224 #else 225 #define INTERFACE_DECL(x) typedef struct x 226 #endif 227 #endif 228 229 /* No efi call wrapper for IA32 architecture */ 230 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 231 #define EFI_FUNCTION 232