efibind.h revision 1.1
1/* $NetBSD: efibind.h,v 1.1 2018/08/16 18:17:47 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 long uint64_t; 25typedef long 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#else 34#include <stdint.h> 35#endif 36 37/* 38 * This prevents GCC from emitting GOT based relocations, and use R_ARM_REL32 39 * relative relocations instead, which are more suitable for static binaries. 40 */ 41#ifdef __GNUC__ 42#pragma GCC visibility push (hidden) 43#endif 44 45// 46// Basic EFI types of various widths 47// 48 49#ifndef __WCHAR_TYPE__ 50# define __WCHAR_TYPE__ short 51#endif 52 53typedef uint64_t UINT64; 54typedef int64_t INT64; 55 56typedef uint32_t UINT32; 57typedef int32_t INT32; 58 59typedef uint16_t UINT16; 60typedef int16_t INT16; 61typedef uint8_t UINT8; 62typedef int8_t INT8; 63typedef __WCHAR_TYPE__ WCHAR; 64 65#undef VOID 66#define VOID void 67 68typedef int32_t INTN; 69typedef uint32_t UINTN; 70 71#define EFIERR(a) (0x80000000 | a) 72#define EFI_ERROR_MASK 0x80000000 73#define EFIERR_OEM(a) (0xc0000000 | a) 74 75#define BAD_POINTER 0xFBFBFBFB 76#define MAX_ADDRESS 0xFFFFFFFF 77 78#define BREAKPOINT() while (TRUE); 79 80// 81// Pointers must be aligned to these address to function 82// 83 84#define MIN_ALIGNMENT_SIZE 4 85 86#define ALIGN_VARIABLE(Value ,Adjustment) \ 87 (UINTN)Adjustment = 0; \ 88 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 89 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 90 Value = (UINTN)Value + (UINTN)Adjustment 91 92 93// 94// Define macros to build data structure signatures from characters. 95// 96 97#define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 98#define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 99#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)) 100 101// 102// EFIAPI - prototype calling convention for EFI function pointers 103// BOOTSERVICE - prototype for implementation of a boot service interface 104// RUNTIMESERVICE - prototype for implementation of a runtime service interface 105// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 106// RUNTIME_CODE - pragma macro for declaring runtime code 107// 108 109#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 110#define EFIAPI // Substitute expresion to force C calling convention 111#endif 112 113#define BOOTSERVICE 114#define RUNTIMESERVICE 115#define RUNTIMEFUNCTION 116 117 118#define RUNTIME_CODE(a) alloc_text("rtcode", a) 119#define BEGIN_RUNTIME_DATA() data_seg("rtdata") 120#define END_RUNTIME_DATA() data_seg("") 121 122#define VOLATILE volatile 123 124#define MEMORY_FENCE __sync_synchronize 125 126// 127// When build similiar to FW, then link everything together as 128// one big module. For the MSVC toolchain, we simply tell the 129// linker what our driver init function is using /ENTRY. 130// 131#if defined(_MSC_EXTENSIONS) 132#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 133 __pragma(comment(linker, "/ENTRY:" # InitFunction)) 134#else 135#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 136 UINTN \ 137 InitializeDriver ( \ 138 VOID *ImageHandle, \ 139 VOID *SystemTable \ 140 ) \ 141 { \ 142 return InitFunction(ImageHandle, \ 143 SystemTable); \ 144 } \ 145 \ 146 EFI_STATUS efi_main( \ 147 EFI_HANDLE image, \ 148 EFI_SYSTEM_TABLE *systab \ 149 ) __attribute__((weak, \ 150 alias ("InitializeDriver"))); 151#endif 152 153#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 154 (_if)->LoadInternal(type, name, entry) 155 156 157// 158// Some compilers don't support the forward reference construct: 159// typedef struct XXXXX 160// 161// The following macro provide a workaround for such cases. 162 163#define INTERFACE_DECL(x) struct x 164 165#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 166#define EFI_FUNCTION 167