efibind.h revision 1.1
11.1Sjmcneill/* $NetBSD: efibind.h,v 1.1 2018/08/16 18:17:47 jmcneill Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/* 41.1Sjmcneill * Copright (C) 2014 - 2015 Linaro Ltd. 51.1Sjmcneill * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org> 61.1Sjmcneill * 71.1Sjmcneill * Redistribution and use in source and binary forms, with or without 81.1Sjmcneill * modification, are permitted provided that the following conditions 91.1Sjmcneill * are met: 101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright 111.1Sjmcneill * notice and this list of conditions, without modification. 121.1Sjmcneill * 2. The name of the author may not be used to endorse or promote products 131.1Sjmcneill * derived from this software without specific prior written permission. 141.1Sjmcneill * 151.1Sjmcneill * Alternatively, this software may be distributed under the terms of the 161.1Sjmcneill * GNU General Public License as published by the Free Software Foundation; 171.1Sjmcneill * either version 2 of the License, or (at your option) any later version. 181.1Sjmcneill */ 191.1Sjmcneill 201.1Sjmcneill#if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )) 211.1Sjmcneill 221.1Sjmcneill// ANSI C 1999/2000 stdint.h integer width declarations 231.1Sjmcneill 241.1Sjmcneilltypedef unsigned long long uint64_t; 251.1Sjmcneilltypedef long long int64_t; 261.1Sjmcneilltypedef unsigned int uint32_t; 271.1Sjmcneilltypedef int int32_t; 281.1Sjmcneilltypedef unsigned short uint16_t; 291.1Sjmcneilltypedef short int16_t; 301.1Sjmcneilltypedef unsigned char uint8_t; 311.1Sjmcneilltypedef signed char int8_t; // unqualified 'char' is unsigned on ARM 321.1Sjmcneill 331.1Sjmcneill#else 341.1Sjmcneill#include <stdint.h> 351.1Sjmcneill#endif 361.1Sjmcneill 371.1Sjmcneill/* 381.1Sjmcneill * This prevents GCC from emitting GOT based relocations, and use R_ARM_REL32 391.1Sjmcneill * relative relocations instead, which are more suitable for static binaries. 401.1Sjmcneill */ 411.1Sjmcneill#ifdef __GNUC__ 421.1Sjmcneill#pragma GCC visibility push (hidden) 431.1Sjmcneill#endif 441.1Sjmcneill 451.1Sjmcneill// 461.1Sjmcneill// Basic EFI types of various widths 471.1Sjmcneill// 481.1Sjmcneill 491.1Sjmcneill#ifndef __WCHAR_TYPE__ 501.1Sjmcneill# define __WCHAR_TYPE__ short 511.1Sjmcneill#endif 521.1Sjmcneill 531.1Sjmcneilltypedef uint64_t UINT64; 541.1Sjmcneilltypedef int64_t INT64; 551.1Sjmcneill 561.1Sjmcneilltypedef uint32_t UINT32; 571.1Sjmcneilltypedef int32_t INT32; 581.1Sjmcneill 591.1Sjmcneilltypedef uint16_t UINT16; 601.1Sjmcneilltypedef int16_t INT16; 611.1Sjmcneilltypedef uint8_t UINT8; 621.1Sjmcneilltypedef int8_t INT8; 631.1Sjmcneilltypedef __WCHAR_TYPE__ WCHAR; 641.1Sjmcneill 651.1Sjmcneill#undef VOID 661.1Sjmcneill#define VOID void 671.1Sjmcneill 681.1Sjmcneilltypedef int32_t INTN; 691.1Sjmcneilltypedef uint32_t UINTN; 701.1Sjmcneill 711.1Sjmcneill#define EFIERR(a) (0x80000000 | a) 721.1Sjmcneill#define EFI_ERROR_MASK 0x80000000 731.1Sjmcneill#define EFIERR_OEM(a) (0xc0000000 | a) 741.1Sjmcneill 751.1Sjmcneill#define BAD_POINTER 0xFBFBFBFB 761.1Sjmcneill#define MAX_ADDRESS 0xFFFFFFFF 771.1Sjmcneill 781.1Sjmcneill#define BREAKPOINT() while (TRUE); 791.1Sjmcneill 801.1Sjmcneill// 811.1Sjmcneill// Pointers must be aligned to these address to function 821.1Sjmcneill// 831.1Sjmcneill 841.1Sjmcneill#define MIN_ALIGNMENT_SIZE 4 851.1Sjmcneill 861.1Sjmcneill#define ALIGN_VARIABLE(Value ,Adjustment) \ 871.1Sjmcneill (UINTN)Adjustment = 0; \ 881.1Sjmcneill if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 891.1Sjmcneill (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 901.1Sjmcneill Value = (UINTN)Value + (UINTN)Adjustment 911.1Sjmcneill 921.1Sjmcneill 931.1Sjmcneill// 941.1Sjmcneill// Define macros to build data structure signatures from characters. 951.1Sjmcneill// 961.1Sjmcneill 971.1Sjmcneill#define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 981.1Sjmcneill#define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 991.1Sjmcneill#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)) 1001.1Sjmcneill 1011.1Sjmcneill// 1021.1Sjmcneill// EFIAPI - prototype calling convention for EFI function pointers 1031.1Sjmcneill// BOOTSERVICE - prototype for implementation of a boot service interface 1041.1Sjmcneill// RUNTIMESERVICE - prototype for implementation of a runtime service interface 1051.1Sjmcneill// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 1061.1Sjmcneill// RUNTIME_CODE - pragma macro for declaring runtime code 1071.1Sjmcneill// 1081.1Sjmcneill 1091.1Sjmcneill#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 1101.1Sjmcneill#define EFIAPI // Substitute expresion to force C calling convention 1111.1Sjmcneill#endif 1121.1Sjmcneill 1131.1Sjmcneill#define BOOTSERVICE 1141.1Sjmcneill#define RUNTIMESERVICE 1151.1Sjmcneill#define RUNTIMEFUNCTION 1161.1Sjmcneill 1171.1Sjmcneill 1181.1Sjmcneill#define RUNTIME_CODE(a) alloc_text("rtcode", a) 1191.1Sjmcneill#define BEGIN_RUNTIME_DATA() data_seg("rtdata") 1201.1Sjmcneill#define END_RUNTIME_DATA() data_seg("") 1211.1Sjmcneill 1221.1Sjmcneill#define VOLATILE volatile 1231.1Sjmcneill 1241.1Sjmcneill#define MEMORY_FENCE __sync_synchronize 1251.1Sjmcneill 1261.1Sjmcneill// 1271.1Sjmcneill// When build similiar to FW, then link everything together as 1281.1Sjmcneill// one big module. For the MSVC toolchain, we simply tell the 1291.1Sjmcneill// linker what our driver init function is using /ENTRY. 1301.1Sjmcneill// 1311.1Sjmcneill#if defined(_MSC_EXTENSIONS) 1321.1Sjmcneill#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 1331.1Sjmcneill __pragma(comment(linker, "/ENTRY:" # InitFunction)) 1341.1Sjmcneill#else 1351.1Sjmcneill#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 1361.1Sjmcneill UINTN \ 1371.1Sjmcneill InitializeDriver ( \ 1381.1Sjmcneill VOID *ImageHandle, \ 1391.1Sjmcneill VOID *SystemTable \ 1401.1Sjmcneill ) \ 1411.1Sjmcneill { \ 1421.1Sjmcneill return InitFunction(ImageHandle, \ 1431.1Sjmcneill SystemTable); \ 1441.1Sjmcneill } \ 1451.1Sjmcneill \ 1461.1Sjmcneill EFI_STATUS efi_main( \ 1471.1Sjmcneill EFI_HANDLE image, \ 1481.1Sjmcneill EFI_SYSTEM_TABLE *systab \ 1491.1Sjmcneill ) __attribute__((weak, \ 1501.1Sjmcneill alias ("InitializeDriver"))); 1511.1Sjmcneill#endif 1521.1Sjmcneill 1531.1Sjmcneill#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 1541.1Sjmcneill (_if)->LoadInternal(type, name, entry) 1551.1Sjmcneill 1561.1Sjmcneill 1571.1Sjmcneill// 1581.1Sjmcneill// Some compilers don't support the forward reference construct: 1591.1Sjmcneill// typedef struct XXXXX 1601.1Sjmcneill// 1611.1Sjmcneill// The following macro provide a workaround for such cases. 1621.1Sjmcneill 1631.1Sjmcneill#define INTERFACE_DECL(x) struct x 1641.1Sjmcneill 1651.1Sjmcneill#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 1661.1Sjmcneill#define EFI_FUNCTION 167