efibind.h revision 1.2
1/* $NetBSD: efibind.h,v 1.2 2018/08/18 20:17:51 jmcneill Exp $ */ 2 3/* 4 * Copright (C) 2014 - 2015 Linaro Ltd. 5 * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice and this list of conditions, without modification. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * Alternatively, this software may be distributed under the terms of the 16 * GNU General Public License as published by the Free Software Foundation; 17 * either version 2 of the License, or (at your option) any later version. 18 */ 19 20#if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )) 21 22// ANSI C 1999/2000 stdint.h integer width declarations 23 24typedef unsigned long uint64_t; 25typedef long int64_t; 26typedef unsigned int uint32_t; 27typedef int int32_t; 28typedef unsigned short uint16_t; 29typedef short int16_t; 30typedef unsigned char uint8_t; 31typedef signed char int8_t; // unqualified 'char' is unsigned on ARM 32 33#elif defined(__NetBSD__) 34#include <sys/stdint.h> 35#else 36#include <stdint.h> 37#endif 38 39// 40// Basic EFI types of various widths 41// 42 43#ifndef __WCHAR_TYPE__ 44# define __WCHAR_TYPE__ short 45#endif 46 47typedef uint64_t UINT64; 48typedef int64_t INT64; 49 50typedef uint32_t UINT32; 51typedef int32_t INT32; 52 53typedef uint16_t UINT16; 54typedef int16_t INT16; 55typedef uint8_t UINT8; 56typedef int8_t INT8; 57typedef __WCHAR_TYPE__ WCHAR; 58 59#undef VOID 60#define VOID void 61 62typedef int64_t INTN; 63typedef uint64_t UINTN; 64 65#define EFIERR(a) (0x8000000000000000 | a) 66#define EFI_ERROR_MASK 0x8000000000000000 67#define EFIERR_OEM(a) (0xc000000000000000 | a) 68 69#define BAD_POINTER 0xFBFBFBFBFBFBFBFB 70#define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 71 72#define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32 73 74// 75// Pointers must be aligned to these address to function 76// 77 78#define MIN_ALIGNMENT_SIZE 8 79 80#define ALIGN_VARIABLE(Value ,Adjustment) \ 81 (UINTN)Adjustment = 0; \ 82 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 83 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 84 Value = (UINTN)Value + (UINTN)Adjustment 85 86 87// 88// Define macros to build data structure signatures from characters. 89// 90 91#define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 92#define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 93#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)) 94 95// 96// EFIAPI - prototype calling convention for EFI function pointers 97// BOOTSERVICE - prototype for implementation of a boot service interface 98// RUNTIMESERVICE - prototype for implementation of a runtime service interface 99// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 100// RUNTIME_CODE - pragma macro for declaring runtime code 101// 102 103#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 104#define EFIAPI // Substitute expresion to force C calling convention 105#endif 106 107#define BOOTSERVICE 108#define RUNTIMESERVICE 109#define RUNTIMEFUNCTION 110 111 112#define RUNTIME_CODE(a) alloc_text("rtcode", a) 113#define BEGIN_RUNTIME_DATA() data_seg("rtdata") 114#define END_RUNTIME_DATA() data_seg("") 115 116#define VOLATILE volatile 117 118#define MEMORY_FENCE __sync_synchronize 119 120// 121// When build similiar to FW, then link everything together as 122// one big module. For the MSVC toolchain, we simply tell the 123// linker what our driver init function is using /ENTRY. 124// 125#if defined(_MSC_EXTENSIONS) 126#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 127 __pragma(comment(linker, "/ENTRY:" # InitFunction)) 128#else 129#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 130 UINTN \ 131 InitializeDriver ( \ 132 VOID *ImageHandle, \ 133 VOID *SystemTable \ 134 ) \ 135 { \ 136 return InitFunction(ImageHandle, \ 137 SystemTable); \ 138 } \ 139 \ 140 EFI_STATUS efi_main( \ 141 EFI_HANDLE image, \ 142 EFI_SYSTEM_TABLE *systab \ 143 ) __attribute__((weak, \ 144 alias ("InitializeDriver"))); 145#endif 146 147#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 148 (_if)->LoadInternal(type, name, entry) 149 150 151// 152// Some compilers don't support the forward reference construct: 153// typedef struct XXXXX 154// 155// The following macro provide a workaround for such cases. 156 157#define INTERFACE_DECL(x) struct x 158 159#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 160#define EFI_FUNCTION 161