efibind.h revision 1.2
11.2Sjmcneill/* $NetBSD: efibind.h,v 1.2 2018/08/18 20:17:51 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 uint64_t; 251.1Sjmcneilltypedef 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.2Sjmcneill#elif defined(__NetBSD__) 341.2Sjmcneill#include <sys/stdint.h> 351.1Sjmcneill#else 361.1Sjmcneill#include <stdint.h> 371.1Sjmcneill#endif 381.1Sjmcneill 391.1Sjmcneill// 401.1Sjmcneill// Basic EFI types of various widths 411.1Sjmcneill// 421.1Sjmcneill 431.1Sjmcneill#ifndef __WCHAR_TYPE__ 441.1Sjmcneill# define __WCHAR_TYPE__ short 451.1Sjmcneill#endif 461.1Sjmcneill 471.1Sjmcneilltypedef uint64_t UINT64; 481.1Sjmcneilltypedef int64_t INT64; 491.1Sjmcneill 501.1Sjmcneilltypedef uint32_t UINT32; 511.1Sjmcneilltypedef int32_t INT32; 521.1Sjmcneill 531.1Sjmcneilltypedef uint16_t UINT16; 541.1Sjmcneilltypedef int16_t INT16; 551.1Sjmcneilltypedef uint8_t UINT8; 561.1Sjmcneilltypedef int8_t INT8; 571.1Sjmcneilltypedef __WCHAR_TYPE__ WCHAR; 581.1Sjmcneill 591.1Sjmcneill#undef VOID 601.1Sjmcneill#define VOID void 611.1Sjmcneill 621.1Sjmcneilltypedef int64_t INTN; 631.1Sjmcneilltypedef uint64_t UINTN; 641.1Sjmcneill 651.1Sjmcneill#define EFIERR(a) (0x8000000000000000 | a) 661.1Sjmcneill#define EFI_ERROR_MASK 0x8000000000000000 671.1Sjmcneill#define EFIERR_OEM(a) (0xc000000000000000 | a) 681.1Sjmcneill 691.1Sjmcneill#define BAD_POINTER 0xFBFBFBFBFBFBFBFB 701.1Sjmcneill#define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 711.1Sjmcneill 721.1Sjmcneill#define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32 731.1Sjmcneill 741.1Sjmcneill// 751.1Sjmcneill// Pointers must be aligned to these address to function 761.1Sjmcneill// 771.1Sjmcneill 781.1Sjmcneill#define MIN_ALIGNMENT_SIZE 8 791.1Sjmcneill 801.1Sjmcneill#define ALIGN_VARIABLE(Value ,Adjustment) \ 811.1Sjmcneill (UINTN)Adjustment = 0; \ 821.1Sjmcneill if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 831.1Sjmcneill (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 841.1Sjmcneill Value = (UINTN)Value + (UINTN)Adjustment 851.1Sjmcneill 861.1Sjmcneill 871.1Sjmcneill// 881.1Sjmcneill// Define macros to build data structure signatures from characters. 891.1Sjmcneill// 901.1Sjmcneill 911.1Sjmcneill#define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 921.1Sjmcneill#define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 931.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)) 941.1Sjmcneill 951.1Sjmcneill// 961.1Sjmcneill// EFIAPI - prototype calling convention for EFI function pointers 971.1Sjmcneill// BOOTSERVICE - prototype for implementation of a boot service interface 981.1Sjmcneill// RUNTIMESERVICE - prototype for implementation of a runtime service interface 991.1Sjmcneill// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 1001.1Sjmcneill// RUNTIME_CODE - pragma macro for declaring runtime code 1011.1Sjmcneill// 1021.1Sjmcneill 1031.1Sjmcneill#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 1041.1Sjmcneill#define EFIAPI // Substitute expresion to force C calling convention 1051.1Sjmcneill#endif 1061.1Sjmcneill 1071.1Sjmcneill#define BOOTSERVICE 1081.1Sjmcneill#define RUNTIMESERVICE 1091.1Sjmcneill#define RUNTIMEFUNCTION 1101.1Sjmcneill 1111.1Sjmcneill 1121.1Sjmcneill#define RUNTIME_CODE(a) alloc_text("rtcode", a) 1131.1Sjmcneill#define BEGIN_RUNTIME_DATA() data_seg("rtdata") 1141.1Sjmcneill#define END_RUNTIME_DATA() data_seg("") 1151.1Sjmcneill 1161.1Sjmcneill#define VOLATILE volatile 1171.1Sjmcneill 1181.1Sjmcneill#define MEMORY_FENCE __sync_synchronize 1191.1Sjmcneill 1201.1Sjmcneill// 1211.1Sjmcneill// When build similiar to FW, then link everything together as 1221.1Sjmcneill// one big module. For the MSVC toolchain, we simply tell the 1231.1Sjmcneill// linker what our driver init function is using /ENTRY. 1241.1Sjmcneill// 1251.1Sjmcneill#if defined(_MSC_EXTENSIONS) 1261.1Sjmcneill#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 1271.1Sjmcneill __pragma(comment(linker, "/ENTRY:" # InitFunction)) 1281.1Sjmcneill#else 1291.1Sjmcneill#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 1301.1Sjmcneill UINTN \ 1311.1Sjmcneill InitializeDriver ( \ 1321.1Sjmcneill VOID *ImageHandle, \ 1331.1Sjmcneill VOID *SystemTable \ 1341.1Sjmcneill ) \ 1351.1Sjmcneill { \ 1361.1Sjmcneill return InitFunction(ImageHandle, \ 1371.1Sjmcneill SystemTable); \ 1381.1Sjmcneill } \ 1391.1Sjmcneill \ 1401.1Sjmcneill EFI_STATUS efi_main( \ 1411.1Sjmcneill EFI_HANDLE image, \ 1421.1Sjmcneill EFI_SYSTEM_TABLE *systab \ 1431.1Sjmcneill ) __attribute__((weak, \ 1441.1Sjmcneill alias ("InitializeDriver"))); 1451.1Sjmcneill#endif 1461.1Sjmcneill 1471.1Sjmcneill#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 1481.1Sjmcneill (_if)->LoadInternal(type, name, entry) 1491.1Sjmcneill 1501.1Sjmcneill 1511.1Sjmcneill// 1521.1Sjmcneill// Some compilers don't support the forward reference construct: 1531.1Sjmcneill// typedef struct XXXXX 1541.1Sjmcneill// 1551.1Sjmcneill// The following macro provide a workaround for such cases. 1561.1Sjmcneill 1571.1Sjmcneill#define INTERFACE_DECL(x) struct x 1581.1Sjmcneill 1591.1Sjmcneill#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 1601.1Sjmcneill#define EFI_FUNCTION 161