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