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