1 /* 2 * Copyright (c) 2017-2025 Netflix, Inc. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #ifndef _SYS_EFI_EDK2_H_ 8 #define _SYS_EFI_EDK2_H_ 9 10 /* 11 * Defines to adjust the types that EDK2 uses for FreeBSD so we can 12 * use the code and headers mostly unchanged. The headers are imported 13 * all into one directory to avoid case issues with filenames and 14 * included. The actual code is heavily modified since it has too many 15 * annoying dependencies that are difficult to satisfy. 16 */ 17 18 #include <stdlib.h> 19 #include <stdint.h> 20 21 typedef int8_t INT8; 22 typedef int16_t INT16; 23 typedef int32_t INT32; 24 typedef int64_t INT64; 25 typedef intptr_t INTN; 26 typedef uint8_t UINT8; 27 typedef uint16_t UINT16; 28 typedef uint32_t UINT32; 29 typedef uint64_t UINT64; 30 typedef uintptr_t UINTN; 31 //typedef uintptr_t EFI_PHYSICAL_ADDRESS; 32 //typedef uint32_t EFI_IPv4_ADDRESS; 33 //typedef uint8_t EFI_MAC_ADDRESS[6]; 34 //typedef uint8_t EFI_IPv6_ADDRESS[16]; 35 typedef uint8_t CHAR8; 36 typedef uint16_t CHAR16; 37 typedef UINT8 BOOLEAN; 38 typedef void VOID; 39 //typedef uuid_t GUID; 40 //typedef uuid_t EFI_GUID; 41 42 /* We can't actually call this stuff, so snip out API syntactic sugar */ 43 #define INTERFACE_DECL(x) struct x 44 #ifdef _STANDALONE 45 #if defined(__amd64__) 46 #define EFIAPI __attribute__((ms_abi)) 47 #endif 48 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 49 #ifdef _MSC_EXTENSIONS 50 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 51 #else 52 #define EFIAPI // Substitute expresion to force C calling convention 53 #endif 54 #endif 55 #else 56 #define EFIAPI 57 #endif 58 #define IN 59 #define OUT 60 #define CONST const 61 #define OPTIONAL 62 //#define TRUE 1 63 //#define FALSE 0 64 65 /* 66 * EDK2 has fine definitions for these, so let it define them. 67 */ 68 #undef NULL 69 #undef EFI_PAGE_SIZE 70 #undef EFI_PAGE_MASK 71 72 /* 73 * Note: the EDK2 code assumed #pragma packed works and PACKED is a 74 * workaround for some old toolchain issues for EDK2 that aren't 75 * relevent to FreeBSD. 76 */ 77 #define PACKED 78 79 /* 80 * For userland and the kernel, we're not compiling for the UEFI boot time 81 * (which use ms abi conventions on amd64), tell EDK2 to define VA_START 82 * correctly. For the boot loader, we can't do that, so don't. 83 */ 84 #ifndef _STANDALONE 85 #define NO_MSABI_VA_FUNCS 1 86 #endif 87 88 /* 89 * Finally, we need to define the processor we are in EDK2 terms. 90 */ 91 #if defined(__i386__) 92 #define MDE_CPU_IA32 93 #elif defined(__amd64__) 94 #define MDE_CPU_X64 95 #elif defined(__arm__) 96 #define MDE_CPU_ARM 97 #elif defined(__aarch64__) 98 #define MDE_CPU_AARCH64 99 #elif defined(__riscv) 100 #define MDE_CPU_RISCV64 101 #endif 102 /* FreeBSD doesn't have/use MDE_CPU_EBC or MDE_CPU_IPF (ia64) */ 103 104 #if __SIZEOF_LONG__ == 4 105 #define MAX_BIT 0x80000000 106 #else 107 #define MAX_BIT 0x8000000000000000 108 #endif 109 110 /* 111 * Sometimes EFI is included after sys/param.h, and that causes a collision. We 112 * get a collision the other way too, so when including both, you have to 113 * include sys/param.h first. 114 */ 115 #undef MAX 116 #undef MIN 117 118 #endif /* _SYS_EFI_EDK2_H_ */ 119