efibind.h revision 1.2
1/* $NetBSD: efibind.h,v 1.2 2014/04/01 16:22:45 jakllsch 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// When build similiar to FW, then link everything together as 188// one big module. 189// 190 191#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 192 UINTN \ 193 InitializeDriver ( \ 194 VOID *ImageHandle, \ 195 VOID *SystemTable \ 196 ) \ 197 { \ 198 return InitFunction(ImageHandle, \ 199 SystemTable); \ 200 } \ 201 \ 202 EFI_STATUS efi_main( \ 203 EFI_HANDLE image, \ 204 EFI_SYSTEM_TABLE *systab \ 205 ) __attribute__((weak, \ 206 alias ("InitializeDriver"))); 207 208#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 209 (_if)->LoadInternal(type, name, entry) 210 211// 212// Some compilers don't support the forward reference construct: 213// typedef struct XXXXX 214// 215// The following macro provide a workaround for such cases. 216// 217#ifdef NO_INTERFACE_DECL 218#define INTERFACE_DECL(x) 219#else 220#ifdef __GNUC__ 221#define INTERFACE_DECL(x) struct x 222#else 223#define INTERFACE_DECL(x) typedef struct x 224#endif 225#endif 226 227/* No efi call wrapper for IA32 architecture */ 228#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 229#define EFI_FUNCTION 230