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