├── .gitignore ├── EFI ├── BOOT │ └── BOOTx64.efi └── OC │ ├── OpenCore.efi │ ├── ACPI │ ├── SSDT-AWAC.aml │ ├── SSDT-PLUG-DRTNIA.aml │ └── SSDT-EC-USBX-DESKTOP.aml │ ├── Drivers │ ├── OpenHfsPlus.efi │ ├── OpenRuntime.efi │ └── ResetNvramEntry.efi │ └── Kexts │ ├── Lilu.kext │ └── Contents │ │ ├── MacOS │ │ └── Lilu │ │ ├── Resources │ │ ├── Headers │ │ │ ├── kern_config.hpp │ │ │ ├── kern_compat.hpp │ │ │ ├── kern_policy.hpp │ │ │ ├── plugin_start.hpp │ │ │ ├── kern_version.hpp │ │ │ ├── hde32.h │ │ │ ├── kern_file.hpp │ │ │ ├── kern_efi.hpp │ │ │ ├── hde64.h │ │ │ ├── kern_compression.hpp │ │ │ ├── kern_crypto.hpp │ │ │ ├── kern_time.hpp │ │ │ ├── capstone │ │ │ │ ├── platform.h │ │ │ │ ├── xcore.h │ │ │ │ └── sparc.h │ │ │ ├── kern_disasm.hpp │ │ │ ├── kern_nvram.hpp │ │ │ ├── kern_rtc.hpp │ │ │ ├── kern_iokit.hpp │ │ │ ├── kern_mach.hpp │ │ │ ├── kern_devinfo.hpp │ │ │ ├── kern_api.hpp │ │ │ └── kern_cpu.hpp │ │ └── Library │ │ │ ├── wrappers │ │ │ ├── entry64.S │ │ │ ├── entry32.S │ │ │ ├── wrappers.inc │ │ │ └── build.tool │ │ │ └── plugin_start.cpp │ │ └── Info.plist │ ├── AppleALC.kext │ └── Contents │ │ └── MacOS │ │ └── AppleALC │ ├── SMCSuperIO.kext │ └── Contents │ │ ├── MacOS │ │ └── SMCSuperIO │ │ └── Info.plist │ ├── USBToolBox.kext │ └── Contents │ │ ├── MacOS │ │ └── USBToolBox │ │ └── Info.plist │ ├── VirtualSMC.kext │ └── Contents │ │ ├── MacOS │ │ └── VirtualSMC │ │ ├── Resources │ │ └── VirtualSMCSDK │ │ │ ├── AppleSmcBridge.hpp │ │ │ ├── kern_keyvalue.hpp │ │ │ ├── kern_value.hpp │ │ │ ├── kern_smcinfo.hpp │ │ │ └── kern_vsmcapi.hpp │ │ └── Info.plist │ ├── SMCProcessor.kext │ └── Contents │ │ ├── MacOS │ │ └── SMCProcessor │ │ └── Info.plist │ ├── WhateverGreen.kext │ └── Contents │ │ ├── MacOS │ │ └── WhateverGreen │ │ └── Info.plist │ └── USBMapMSIz590i.kext │ └── Contents │ └── Info.plist └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ._.contentFlavour 3 | ._.DS_Store 4 | .contentFlavour 5 | .DS_Store 6 | ._* 7 | 8 | -------------------------------------------------------------------------------- /EFI/BOOT/BOOTx64.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/BOOT/BOOTx64.efi -------------------------------------------------------------------------------- /EFI/OC/OpenCore.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/OpenCore.efi -------------------------------------------------------------------------------- /EFI/OC/ACPI/SSDT-AWAC.aml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/ACPI/SSDT-AWAC.aml -------------------------------------------------------------------------------- /EFI/OC/Drivers/OpenHfsPlus.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Drivers/OpenHfsPlus.efi -------------------------------------------------------------------------------- /EFI/OC/Drivers/OpenRuntime.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Drivers/OpenRuntime.efi -------------------------------------------------------------------------------- /EFI/OC/ACPI/SSDT-PLUG-DRTNIA.aml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/ACPI/SSDT-PLUG-DRTNIA.aml -------------------------------------------------------------------------------- /EFI/OC/Drivers/ResetNvramEntry.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Drivers/ResetNvramEntry.efi -------------------------------------------------------------------------------- /EFI/OC/ACPI/SSDT-EC-USBX-DESKTOP.aml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/ACPI/SSDT-EC-USBX-DESKTOP.aml -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/MacOS/Lilu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/Lilu.kext/Contents/MacOS/Lilu -------------------------------------------------------------------------------- /EFI/OC/Kexts/AppleALC.kext/Contents/MacOS/AppleALC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/AppleALC.kext/Contents/MacOS/AppleALC -------------------------------------------------------------------------------- /EFI/OC/Kexts/SMCSuperIO.kext/Contents/MacOS/SMCSuperIO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/SMCSuperIO.kext/Contents/MacOS/SMCSuperIO -------------------------------------------------------------------------------- /EFI/OC/Kexts/USBToolBox.kext/Contents/MacOS/USBToolBox: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/USBToolBox.kext/Contents/MacOS/USBToolBox -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/MacOS/VirtualSMC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/VirtualSMC.kext/Contents/MacOS/VirtualSMC -------------------------------------------------------------------------------- /EFI/OC/Kexts/SMCProcessor.kext/Contents/MacOS/SMCProcessor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/SMCProcessor.kext/Contents/MacOS/SMCProcessor -------------------------------------------------------------------------------- /EFI/OC/Kexts/WhateverGreen.kext/Contents/MacOS/WhateverGreen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malibio/msi-z590i-unify-opencore/HEAD/EFI/OC/Kexts/WhateverGreen.kext/Contents/MacOS/WhateverGreen -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_config.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_config.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_config_hpp 9 | #define kern_config_hpp 10 | 11 | /** 12 | * Enable kext patching support 13 | */ 14 | #define LILU_KEXTPATCH_SUPPORT 1 15 | 16 | /** 17 | * Enable compression and decompression support 18 | */ 19 | #define LILU_COMPRESSION_SUPPORT 1 20 | 21 | /** 22 | * Enable advanced disassembly API based on capstone 23 | */ 24 | // #define LILU_ADVANCED_DISASSEMBLY 1 25 | 26 | /** 27 | * Specify custom initialisation code 28 | * Use these in plugins in Xcode Project Preprocessor Macros section. 29 | */ 30 | // #define LILU_CUSTOM_IOKIT_INIT 1 31 | // #define LILU_CUSTOM_KMOD_INIT 1 32 | 33 | #endif /* kern_config_hpp */ 34 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/Resources/VirtualSMCSDK/AppleSmcBridge.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // AppleSmcBridge.hpp 3 | // AppleSmcBridge 4 | // 5 | // Copyright © 2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef AppleSmcBridge_hpp 9 | #define AppleSmcBridge_hpp 10 | 11 | #include 12 | 13 | using CHAR8 = char; 14 | using UINT8 = uint8_t; 15 | using UINT16 = uint16_t; 16 | using UINT32 = uint32_t; 17 | 18 | static constexpr uint8_t BIT0 = 0b00000001; 19 | static constexpr uint8_t BIT1 = 0b00000010; 20 | static constexpr uint8_t BIT2 = 0b00000100; 21 | static constexpr uint8_t BIT3 = 0b00001000; 22 | static constexpr uint8_t BIT4 = 0b00010000; 23 | static constexpr uint8_t BIT5 = 0b00100000; 24 | static constexpr uint8_t BIT6 = 0b01000000; 25 | static constexpr uint8_t BIT7 = 0b10000000; 26 | 27 | extern "C" { 28 | #include "AppleSmc.h" 29 | } 30 | 31 | #endif /* AppleSmcBridge_hpp */ 32 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Library/wrappers/entry64.S: -------------------------------------------------------------------------------- 1 | # 2 | # entry64.S 3 | # Lilu 4 | # 5 | # Copyright © 2018 vit9696. All rights reserved. 6 | # 7 | 8 | .text 9 | .global _main 10 | _main: 11 | push %rbp 12 | mov %rsp, %rbp 13 | # ensure 16-byte alignment 14 | and $0xfffffffffffffff0, %rsp 15 | # int main(int argc, const char* argv[], const char* envp[], const char* apple[]); 16 | push %rdi 17 | push %rsi 18 | push %rdx 19 | push %rcx 20 | call *booter(%rip) 21 | xor %eax, %eax 22 | pop %rcx 23 | pop %rdx 24 | pop %rsi 25 | pop %rdi 26 | mov %rbp, %rsp 27 | pop %rbp 28 | jmp *entrypoint(%rip) 29 | # original entrypoint (main) 30 | entrypoint: 31 | .word 0xFFFF 32 | .word 0xFFFF 33 | .word 0xFFFF 34 | .word 0xFFFF 35 | # entrypoint-compatible wrapper 36 | booter: 37 | .word 0xFFFF 38 | .word 0xFFFF 39 | .word 0xFFFF 40 | .word 0xFFFF 41 | _end: 42 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Library/wrappers/entry32.S: -------------------------------------------------------------------------------- 1 | # 2 | # entry32.S 3 | # Lilu 4 | # 5 | # Copyright © 2018 vit9696. All rights reserved. 6 | # 7 | 8 | .text 9 | .global _main 10 | _main: 11 | push %ebp 12 | mov %esp, %ebp 13 | # ensure 16-byte alignment 14 | and $0xfffffff0, %esp 15 | # int main(int argc, const char* argv[], const char* envp[], const char* apple[]); 16 | push 20(%ebp) 17 | push 16(%ebp) 18 | push 12(%ebp) 19 | push 8(%ebp) 20 | call get_booter 21 | # entrypoint-compatible wrapper 22 | booter: 23 | .word 0xFFFF 24 | .word 0xFFFF 25 | get_booter: 26 | pop %edx 27 | mov (%edx), %edx 28 | call *%edx 29 | xor %eax, %eax 30 | mov %ebp, %esp 31 | pop %ebp 32 | call get_entrypoint 33 | # original entrypoint (main) 34 | entrypoint: 35 | .word 0xFFFF 36 | .word 0xFFFF 37 | get_entrypoint: 38 | pop %edx 39 | mov (%edx), %edx 40 | jmp *%edx 41 | _end: 42 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_compat.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_compat.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_compat_hpp 9 | #define kern_compat_hpp 10 | 11 | #include 12 | #include 13 | 14 | // Legacy compatibility layer created to avoid 10.13 SDK macros 15 | // unsupported in older systems and improperly guarded due to 16 | // Availability.h header not being. Currently these macros 17 | // are left to avoid compilation errors. 18 | #define lilu_os_memcpy memcpy 19 | #define lilu_os_memmove memmove 20 | #define lilu_os_strncpy strncpy 21 | #define lilu_os_strncat strncat 22 | #define lilu_os_strlcat strlcat 23 | #define lilu_os_strlcpy strlcpy 24 | #define lilu_os_strcat strcat 25 | #define lilu_os_bcopy bcopy 26 | 27 | // This may not be nice but will protect users from changes in KernInfo strcture. 28 | #ifndef LILU_DISABLE_BRACE_WARNINGS 29 | #pragma clang diagnostic error "-Wmissing-braces" 30 | #endif 31 | 32 | #if defined(__i386__) 33 | #define lilu_strtou strtoul 34 | 35 | #elif defined(__x86_64__) 36 | #define lilu_strtou strtouq 37 | 38 | #else 39 | #error Unsupported arch. 40 | #endif 41 | 42 | #endif /* kern_compat_hpp */ 43 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Library/wrappers/wrappers.inc: -------------------------------------------------------------------------------- 1 | // 2 | // wrappers.inc 3 | // Lilu 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | // This is an autogenerated file, do not edit! 9 | static uint8_t entryWrapper32[] = { 10 | 0x55, 0x89, 0xe5, 0x83, 0xe4, 0xf0, 0xff, 0x75, 0x14, 0xff, 0x75, 0x10, 11 | 0xff, 0x75, 0x0c, 0xff, 0x75, 0x08, 0xe8, 0x04, 0x00, 0x00, 0x00, 0xff, 12 | 0xff, 0xff, 0xff, 0x5a, 0x8b, 0x12, 0xff, 0xd2, 0x31, 0xc0, 0x89, 0xec, 13 | 0x5d, 0xe8, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x5a, 0x8b, 14 | 0x12, 0xff, 0xe2 15 | }; 16 | static uint8_t entryWrapper64[] = { 17 | 0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xe4, 0xf0, 0x57, 0x56, 0x52, 0x51, 18 | 0xff, 0x15, 0x18, 0x00, 0x00, 0x00, 0x31, 0xc0, 0x59, 0x5a, 0x5e, 0x5f, 19 | 0x48, 0x89, 0xec, 0x5d, 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 20 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 21 | 0xff, 0xff 22 | }; 23 | static_assert(sizeof(entryWrapper32) == 51, "Invalid entryWrapper32 size"); 24 | static_assert(sizeof(entryWrapper64) == 50, "Invalid entryWrapper64 size"); 25 | static constexpr size_t EntryWrapper32Booter {0x00000017}; 26 | static constexpr size_t EntryWrapper64Booter {0x000000000000002a}; 27 | static constexpr size_t EntryWrapper32Entry {0x0000002a}; 28 | static constexpr size_t EntryWrapper64Entry {0x0000000000000022}; 29 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_policy.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_policy.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_policy_hpp 9 | #define kern_policy_hpp 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #if defined(__x86_64__) 21 | class Policy { 22 | /** 23 | * TrustedBSD Policy handle 24 | */ 25 | mac_policy_handle_t policyHandle {0}; 26 | 27 | /** 28 | * TrustedBSD policy configuration 29 | */ 30 | mac_policy_conf policyConf; 31 | public: 32 | /** 33 | * Compile-time policy constructor 34 | * 35 | * @param name policy name literal 36 | * @param descr policy description literal 37 | * @param ops policy functions 38 | */ 39 | constexpr Policy(const char *name, const char *descr, struct mac_policy_ops *ops) : policyConf{ 40 | .mpc_name = name, 41 | .mpc_fullname = descr, 42 | .mpc_labelnames = nullptr, 43 | .mpc_labelname_count = 0, 44 | .mpc_ops = ops, 45 | // Our policies are loaded very early and are static. We cannot unload them. 46 | .mpc_loadtime_flags = 0 /*MPC_LOADTIME_FLAG_UNLOADOK*/, 47 | .mpc_field_off = nullptr, 48 | .mpc_runtime_flags = 0 49 | } { } 50 | 51 | /** 52 | * Registers TrustedBSD policy 53 | * 54 | * @return true on success 55 | */ 56 | EXPORT bool registerPolicy(); 57 | 58 | /** 59 | * Unregisters TrustedBSD policy if allowed 60 | * 61 | * @return true on success 62 | */ 63 | EXPORT bool unregisterPolicy(); 64 | }; 65 | #endif 66 | 67 | #endif /* kern_policy_hpp */ 68 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/plugin_start.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_start.hpp 3 | // AppleALC 4 | // 5 | // Copyright © 2016 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_start_hpp 9 | #define kern_start_hpp 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | struct PluginConfiguration { 17 | const char *product; // Product name (e.g. xStringify(PRODUCT_NAME)) 18 | size_t version; // Product version (e.g. parseModuleVersion(xStringify(MODULE_VERSION))) 19 | uint32_t runmode; // Product supported environments (e.g. LiluAPI::AllowNormal) 20 | const char **disableArg; // Pointer to disabling boot arguments array 21 | size_t disableArgNum; // Number of disabling boot arguments 22 | const char **debugArg; // Pointer to debug boot arguments array 23 | size_t debugArgNum; // Number of debug boot arguments 24 | const char **betaArg; // Pointer to beta boot arguments array 25 | size_t betaArgNum; // Number of beta boot arguments 26 | KernelVersion minKernel; // Minimal required kernel version 27 | KernelVersion maxKernel; // Maximum supported kernel version 28 | void (*pluginStart)(); // Main function 29 | }; 30 | 31 | #ifndef LILU_CUSTOM_KMOD_INIT 32 | 33 | extern PluginConfiguration ADDPR(config); 34 | 35 | extern bool ADDPR(startSuccess); 36 | 37 | #endif /* LILU_CUSTOM_KMOD_INIT */ 38 | 39 | #ifndef LILU_CUSTOM_IOKIT_INIT 40 | 41 | class EXPORT PRODUCT_NAME : public IOService { 42 | OSDeclareDefaultStructors(PRODUCT_NAME) 43 | public: 44 | IOService *probe(IOService *provider, SInt32 *score) override; 45 | bool start(IOService *provider) override; 46 | void stop(IOService *provider) override; 47 | }; 48 | 49 | extern PRODUCT_NAME *ADDPR(selfInstance); 50 | 51 | #endif /* LILU_CUSTOM_IOKIT_INIT */ 52 | 53 | #endif /* kern_start_hpp */ 54 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/USBToolBox.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 20G527 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | USBToolBox 11 | CFBundleIdentifier 12 | com.dhinakg.USBToolBox.kext 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | USBToolBox 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleSupportedPlatforms 20 | 21 | MacOSX 22 | 23 | CFBundleVersion 24 | 1.1.1 25 | DTCompiler 26 | com.apple.compilers.llvm.clang.1_0 27 | DTPlatformBuild 28 | 12E507 29 | DTPlatformName 30 | macosx 31 | DTPlatformVersion 32 | 11.3 33 | DTSDKBuild 34 | 20E214 35 | DTSDKName 36 | macosx11.3 37 | DTXcode 38 | 1251 39 | DTXcodeBuild 40 | 12E507 41 | IOKitPersonalities 42 | 43 | LSMinimumSystemVersion 44 | 10.11 45 | NSHumanReadableCopyright 46 | Copyright © 2020-2021 Dhinak G. All rights reserved. 47 | OSBundleCompatibleVersion 48 | 1.0.0 49 | OSBundleLibraries 50 | 51 | com.apple.driver.AppleUSBHostMergeProperties 52 | 1.0 53 | com.apple.iokit.IOPCIFamily 54 | 2.9 55 | com.apple.kpi.iokit 56 | 15.0.0 57 | com.apple.kpi.libkern 58 | 15.0.0 59 | 60 | OSBundleRequired 61 | Root 62 | 63 | 64 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_version.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_version.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2020 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_version_hpp 9 | #define kern_version_hpp 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | /** 17 | * Slightly non-standard helpers to get the date in a YYYY-MM-DD format. 18 | */ 19 | template 20 | inline constexpr char getBuildYear() { 21 | static_assert(i < 4, "Year consists of four digits"); 22 | return __DATE__[7+i]; 23 | } 24 | 25 | template 26 | inline constexpr char getBuildMonth() { 27 | static_assert(i < 2, "Month consists of two digits"); 28 | auto mon = static_cast(__DATE__[0]) 29 | | (static_cast(__DATE__[1]) << 8U) 30 | | (static_cast(__DATE__[2]) << 16U) 31 | | (static_cast(__DATE__[3]) << 24U); 32 | switch (mon) { 33 | case ' naJ': 34 | return "01"[i]; 35 | case ' beF': 36 | return "02"[i]; 37 | case ' raM': 38 | return "03"[i]; 39 | case ' rpA': 40 | return "04"[i]; 41 | case ' yaM': 42 | return "05"[i]; 43 | case ' nuJ': 44 | return "06"[i]; 45 | case ' luJ': 46 | return "07"[i]; 47 | case ' guA': 48 | return "08"[i]; 49 | case ' peS': 50 | return "09"[i]; 51 | case ' tcO': 52 | return "10"[i]; 53 | case ' voN': 54 | return "11"[i]; 55 | case ' ceD': 56 | return "12"[i]; 57 | default: 58 | return '0'; 59 | } 60 | } 61 | 62 | template 63 | inline constexpr char getBuildDay() { 64 | static_assert(i < 2, "Day consists of two digits"); 65 | if (i == 0 && __DATE__[4+i] == ' ') 66 | return '0'; 67 | return __DATE__[4+i]; 68 | } 69 | 70 | #if !defined(LILU_CUSTOM_KMOD_INIT) || !defined(LILU_CUSTOM_IOKIT_INIT) || defined(LILU_USE_KEXT_VERSION) 71 | 72 | static const char kextVersion[] { 73 | #ifdef DEBUG 74 | 'D', 'B', 'G', '-', 75 | #else 76 | 'R', 'E', 'L', '-', 77 | #endif 78 | xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-', 79 | getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-', 80 | getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0' 81 | }; 82 | 83 | #endif 84 | 85 | #endif /* kern_version_hpp */ 86 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Library/wrappers/build.tool: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # build.tool 4 | # Lilu 5 | # 6 | # Copyright © 2018 vit9696. All rights reserved. 7 | # 8 | 9 | cd $(dirname "$0") || exit 1 10 | 11 | rm -f *.o *.bin wrappers.inc entry32 entry64 12 | 13 | clang -m32 -c entry32.S || exit 1 14 | clang -m64 -c entry64.S || exit 1 15 | 16 | clang -m32 entry32.o -o entry32 || exit 1 17 | clang -m64 entry64.o -o entry64 || exit 1 18 | 19 | if [ "$(nm entry32.o | grep '00000000 T _main')" == "" ] || [ "$(nm entry64.o | grep '0000000000000000 T _main')" == "" ]; then 20 | echo "Invalid main address" 21 | exit 1 22 | fi 23 | 24 | otool -t entry32 | grep -E '^0000' | sed 's#^[0-9a-f]*##' | xxd -r -p > entry32.bin 25 | otool -t entry64 | grep -E '^0000' | sed 's#^[0-9a-f]*##' | xxd -r -p > entry64.bin 26 | 27 | sz32=$(stat -f '%z' entry32.bin) 28 | sz64=$(stat -f '%z' entry64.bin) 29 | 30 | btr32=$(nm entry32.o | grep -E 't booter$' | cut -f1 -d' ') 31 | btr64=$(nm entry64.o | grep -E 't booter$' | cut -f1 -d' ') 32 | 33 | ep32=$(nm entry32.o | grep -E 't entrypoint$' | cut -f1 -d' ') 34 | ep64=$(nm entry64.o | grep -E 't entrypoint$' | cut -f1 -d' ') 35 | 36 | echo '//' > wrappers.inc 37 | echo '// wrappers.inc' >> wrappers.inc 38 | echo '// Lilu' >> wrappers.inc 39 | echo '//' >> wrappers.inc 40 | echo '// Copyright © 2018 vit9696. All rights reserved.' >> wrappers.inc 41 | echo '//' >> wrappers.inc 42 | echo '' >> wrappers.inc 43 | echo '// This is an autogenerated file, do not edit!' >> wrappers.inc 44 | echo 'static uint8_t entryWrapper32[] = {' >> wrappers.inc 45 | cat entry32.bin | xxd -i >> wrappers.inc 46 | echo '};' >> wrappers.inc 47 | echo 'static uint8_t entryWrapper64[] = {' >> wrappers.inc 48 | cat entry64.bin | xxd -i >> wrappers.inc 49 | echo '};' >> wrappers.inc 50 | echo "static_assert(sizeof(entryWrapper32) == ${sz32}, \"Invalid entryWrapper32 size\");" >> wrappers.inc 51 | echo "static_assert(sizeof(entryWrapper64) == ${sz64}, \"Invalid entryWrapper64 size\");" >> wrappers.inc 52 | echo "static constexpr size_t EntryWrapper32Booter {0x${btr32}};" >> wrappers.inc 53 | echo "static constexpr size_t EntryWrapper64Booter {0x${btr64}};" >> wrappers.inc 54 | echo "static constexpr size_t EntryWrapper32Entry {0x${ep32}};" >> wrappers.inc 55 | echo "static constexpr size_t EntryWrapper64Entry {0x${ep64}};" >> wrappers.inc 56 | 57 | rm -f *.o *.bin entry32 entry64 58 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | #include 14 | 15 | #define F_MODRM 0x00000001 16 | #define F_SIB 0x00000002 17 | #define F_IMM8 0x00000004 18 | #define F_IMM16 0x00000008 19 | #define F_IMM32 0x00000010 20 | #define F_DISP8 0x00000020 21 | #define F_DISP16 0x00000040 22 | #define F_DISP32 0x00000080 23 | #define F_RELATIVE 0x00000100 24 | #define F_2IMM16 0x00000800 25 | #define F_ERROR 0x00001000 26 | #define F_ERROR_OPCODE 0x00002000 27 | #define F_ERROR_LENGTH 0x00004000 28 | #define F_ERROR_LOCK 0x00008000 29 | #define F_ERROR_OPERAND 0x00010000 30 | #define F_PREFIX_REPNZ 0x01000000 31 | #define F_PREFIX_REPX 0x02000000 32 | #define F_PREFIX_REP 0x03000000 33 | #define F_PREFIX_66 0x04000000 34 | #define F_PREFIX_67 0x08000000 35 | #define F_PREFIX_LOCK 0x10000000 36 | #define F_PREFIX_SEG 0x20000000 37 | #define F_PREFIX_ANY 0x3f000000 38 | 39 | #define PREFIX_SEGMENT_CS 0x2e 40 | #define PREFIX_SEGMENT_SS 0x36 41 | #define PREFIX_SEGMENT_DS 0x3e 42 | #define PREFIX_SEGMENT_ES 0x26 43 | #define PREFIX_SEGMENT_FS 0x64 44 | #define PREFIX_SEGMENT_GS 0x65 45 | #define PREFIX_LOCK 0xf0 46 | #define PREFIX_REPNZ 0xf2 47 | #define PREFIX_REPX 0xf3 48 | #define PREFIX_OPERAND_SIZE 0x66 49 | #define PREFIX_ADDRESS_SIZE 0x67 50 | 51 | #pragma pack(push,1) 52 | 53 | typedef struct { 54 | uint8_t len; 55 | uint8_t p_rep; 56 | uint8_t p_lock; 57 | uint8_t p_seg; 58 | uint8_t p_66; 59 | uint8_t p_67; 60 | uint8_t opcode; 61 | uint8_t opcode2; 62 | uint8_t modrm; 63 | uint8_t modrm_mod; 64 | uint8_t modrm_reg; 65 | uint8_t modrm_rm; 66 | uint8_t sib; 67 | uint8_t sib_scale; 68 | uint8_t sib_index; 69 | uint8_t sib_base; 70 | union { 71 | uint8_t imm8; 72 | uint16_t imm16; 73 | uint32_t imm32; 74 | } imm; 75 | union { 76 | uint8_t disp8; 77 | uint16_t disp16; 78 | uint32_t disp32; 79 | } disp; 80 | uint32_t flags; 81 | } hde32s; 82 | 83 | #pragma pack(pop) 84 | 85 | #ifdef __cplusplus 86 | extern "C" { 87 | #endif 88 | 89 | /* __cdecl */ 90 | unsigned int hde32_disasm(const void *code, hde32s *hs); 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* _HDE32_H_ */ 97 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_file.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_file.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_file_hpp 9 | #define kern_file_hpp 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace FileIO { 18 | /** 19 | * Reads file data at path 20 | * 21 | * @param path full file path 22 | * @param size bytes read 23 | * 24 | * @return allocated buffer on success or nullptr on error 25 | */ 26 | EXPORT uint8_t *readFileToBuffer(const char *path, size_t &size); 27 | 28 | /** 29 | * Read file data from a vnode 30 | * 31 | * @param buffer output buffer 32 | * @param off file offset 33 | * @param sz bytes to read 34 | * @param vnode file node 35 | * @param ctxt filesystem context 36 | * 37 | * @return 0 on success 38 | */ 39 | EXPORT int readFileData(void *buffer, off_t off, size_t sz, vnode_t vnode, vfs_context_t ctxt); 40 | 41 | /** 42 | * Read file size from a vnode 43 | * 44 | * @param vnode file node 45 | * @param ctxt filesystem context 46 | * 47 | * @return file size or 0 48 | */ 49 | EXPORT size_t readFileSize(vnode_t vnode, vfs_context_t ctxt); 50 | 51 | /** 52 | * Writes buffer to a file at path 53 | * 54 | * @param path full file path 55 | * @param buffer input buffer 56 | * @param size bytes write 57 | * @param fmode file opening mode 58 | * @param cmode file permissions 59 | * 60 | * @return 0 on success 61 | */ 62 | EXPORT int writeBufferToFile(const char *path, void *buffer, size_t size, int fmode=O_TRUNC | O_CREAT | FWRITE | O_NOFOLLOW, int cmode=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 63 | 64 | /** 65 | * Write file data to a vnode 66 | * 67 | * @param buffer input buffer 68 | * @param off file offset 69 | * @param size bytes to write 70 | * @param vnode file node 71 | * @param ctxt filesystem context 72 | * 73 | * @return 0 on success 74 | */ 75 | EXPORT int writeFileData(void *buffer, off_t off, size_t size, vnode_t vnode, vfs_context_t ctxt); 76 | 77 | /** 78 | * Perform file i/o through a vnode 79 | * 80 | * @param buffer input buffer 81 | * @param off file offset 82 | * @param size bytes to write 83 | * @param vnode file node 84 | * @param ctxt filesystem context 85 | * @param write write to buffer otherwise read 86 | * 87 | * @return 0 on success 88 | */ 89 | int performFileIO(void *buffer, off_t off, size_t size, vnode_t vnode, vfs_context_t ctxt, bool write); 90 | } 91 | 92 | #endif /* kern_file_hpp */ 93 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_efi.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_efi.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_efi_h 9 | #define kern_efi_h 10 | 11 | #include 12 | 13 | #include 14 | 15 | /** 16 | * Convert 32-bit EFI errors provided by Apple to 64-bit EFI errors 17 | */ 18 | #define EFI_ERROR64(x) (((x) & ~(1ULL << 31)) | (1ULL << 63)) 19 | static_assert(EFI_LOAD_ERROR == 0x80000001 && EFI_ERROR64(EFI_LOAD_ERROR) == 0x8000000000000001, 20 | "Apple has finally upgraded EFI headers!"); 21 | 22 | class EfiRuntimeServices { 23 | IOLock *accessLock {nullptr}; 24 | static EfiRuntimeServices *instance; 25 | private: 26 | bool is32BitEFI {false}; 27 | void *efiRuntimeServices {nullptr}; 28 | 29 | /** 30 | * Set EFI runtime services table pointer 31 | */ 32 | void setRuntimeServices(); 33 | 34 | public: 35 | /** 36 | * Activates EFI Runtime Services 37 | */ 38 | static void activate(); 39 | 40 | /** 41 | * Lilu custom GUIDs exports, see OcSupportPkg/Include/Guid/OcVariables.h 42 | */ 43 | EXPORT static const EFI_GUID LiluVendorGuid; 44 | EXPORT static const EFI_GUID LiluReadOnlyGuid; 45 | EXPORT static const EFI_GUID LiluWriteOnlyGuid; 46 | 47 | /** 48 | * Get EFI Runtime Services wrapper if supported 49 | * 50 | * @param lock lock instance during the run, must be put back 51 | * 52 | * @return wrapper instance 53 | */ 54 | EXPORT static EfiRuntimeServices *get(bool lock=false); 55 | 56 | /** 57 | * Put EFI Runtime Services wrapper to unlock 58 | */ 59 | EXPORT void put(); 60 | 61 | /** 62 | * Perform system reset (does not return on success) 63 | * 64 | * @param type reset type 65 | */ 66 | EXPORT void resetSystem(EFI_RESET_TYPE type); 67 | 68 | /** 69 | * Obtain EFI variable, invokes EFI_RUNTIME_SERVICES::GetVariable. 70 | * 71 | * @param name variable name 72 | * @param guid vendor guid 73 | * @param attr variable attributes 74 | * @param size data buffer size updated on read 75 | * @param data read data 76 | * 77 | * @return EFI_STATUS code 78 | */ 79 | EXPORT uint64_t getVariable(const char16_t *name, const EFI_GUID *guid, uint32_t *attr, uint64_t *size, void *data); 80 | 81 | /** 82 | * Set EFI variable, invokes EFI_RUNTIME_SERVICES::SetVariable. 83 | * 84 | * @param name variable name 85 | * @param guid vendor guid 86 | * @param attr variable attributes 87 | * @param size data buffer size 88 | * @param data data to write 89 | * 90 | * @return EFI_STATUS code 91 | */ 92 | EXPORT uint64_t setVariable(const char16_t *name, const EFI_GUID *guid, uint32_t attr, uint64_t size, void *data); 93 | }; 94 | 95 | #endif /* kern_efi_h */ 96 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | #include 14 | 15 | #define F_MODRM 0x00000001 16 | #define F_SIB 0x00000002 17 | #define F_IMM8 0x00000004 18 | #define F_IMM16 0x00000008 19 | #define F_IMM32 0x00000010 20 | #define F_IMM64 0x00000020 21 | #define F_DISP8 0x00000040 22 | #define F_DISP16 0x00000080 23 | #define F_DISP32 0x00000100 24 | #define F_RELATIVE 0x00000200 25 | #define F_ERROR 0x00001000 26 | #define F_ERROR_OPCODE 0x00002000 27 | #define F_ERROR_LENGTH 0x00004000 28 | #define F_ERROR_LOCK 0x00008000 29 | #define F_ERROR_OPERAND 0x00010000 30 | #define F_PREFIX_REPNZ 0x01000000 31 | #define F_PREFIX_REPX 0x02000000 32 | #define F_PREFIX_REP 0x03000000 33 | #define F_PREFIX_66 0x04000000 34 | #define F_PREFIX_67 0x08000000 35 | #define F_PREFIX_LOCK 0x10000000 36 | #define F_PREFIX_SEG 0x20000000 37 | #define F_PREFIX_REX 0x40000000 38 | #define F_PREFIX_ANY 0x7f000000 39 | 40 | #define PREFIX_SEGMENT_CS 0x2e 41 | #define PREFIX_SEGMENT_SS 0x36 42 | #define PREFIX_SEGMENT_DS 0x3e 43 | #define PREFIX_SEGMENT_ES 0x26 44 | #define PREFIX_SEGMENT_FS 0x64 45 | #define PREFIX_SEGMENT_GS 0x65 46 | #define PREFIX_LOCK 0xf0 47 | #define PREFIX_REPNZ 0xf2 48 | #define PREFIX_REPX 0xf3 49 | #define PREFIX_OPERAND_SIZE 0x66 50 | #define PREFIX_ADDRESS_SIZE 0x67 51 | 52 | #pragma pack(push,1) 53 | 54 | typedef struct { 55 | uint8_t len; 56 | uint8_t p_rep; 57 | uint8_t p_lock; 58 | uint8_t p_seg; 59 | uint8_t p_66; 60 | uint8_t p_67; 61 | uint8_t rex; 62 | uint8_t rex_w; 63 | uint8_t rex_r; 64 | uint8_t rex_x; 65 | uint8_t rex_b; 66 | uint8_t opcode; 67 | uint8_t opcode2; 68 | uint8_t modrm; 69 | uint8_t modrm_mod; 70 | uint8_t modrm_reg; 71 | uint8_t modrm_rm; 72 | uint8_t sib; 73 | uint8_t sib_scale; 74 | uint8_t sib_index; 75 | uint8_t sib_base; 76 | union { 77 | uint8_t imm8; 78 | uint16_t imm16; 79 | uint32_t imm32; 80 | uint64_t imm64; 81 | } imm; 82 | union { 83 | uint8_t disp8; 84 | uint16_t disp16; 85 | uint32_t disp32; 86 | } disp; 87 | uint32_t flags; 88 | } hde64s; 89 | 90 | #pragma pack(pop) 91 | 92 | #ifdef __cplusplus 93 | extern "C" { 94 | #endif 95 | 96 | /* Note, code should point to at least 32 valid bytes. */ 97 | unsigned int hde64_disasm(const void *code, hde64s *hs); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* _HDE64_H_ */ 104 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_compression.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_compression.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_compression_hpp 9 | #define kern_compression_hpp 10 | 11 | #include 12 | 13 | #ifdef LILU_COMPRESSION_SUPPORT 14 | 15 | #include 16 | #include 17 | 18 | namespace Compression { 19 | 20 | /** 21 | * Compression constants and modes 22 | */ 23 | static constexpr uint32_t Magic {0x706D6F63}; //comp 24 | static constexpr uint32_t ModeLZVN {0x6E767A6C}; //lzvn 25 | static constexpr uint32_t ModeLZSS {0x73737A6C}; //lzss 26 | static constexpr uint32_t ModeZLIB {0x9C787A6C}; //zlib 27 | 28 | /** 29 | * Compressed header structure 30 | */ 31 | struct Header { 32 | uint32_t magic; 33 | uint32_t compression; 34 | uint32_t hash; // adler32 35 | uint32_t decompressed; 36 | uint32_t compressed; 37 | uint32_t version; 38 | uint32_t padding[90]; 39 | }; 40 | 41 | /** 42 | * Typed decompressing function (currently for lzvn, lzss, and zlib) 43 | * 44 | * @param compression compression type 45 | * @param dstlen decompression buffer size 46 | * @param src compressed data 47 | * @param srclen compressed data size 48 | * @param buffer preallocated buffer to use 49 | * 50 | * @return decompressed buffer (must be freeded by Buffer::deleter if not preallocated) 51 | */ 52 | EXPORT uint8_t *decompress(uint32_t compression, uint32_t dstlen, const uint8_t *src, uint32_t srclen, uint8_t *buffer=nullptr); 53 | 54 | /** 55 | * Typed decompressing function (currently for lzvn, lzss, and zlib) 56 | * 57 | * @param compression compression type 58 | * @param dstlen decompression buffer size, actual decompressed size on success 59 | * @param src compressed data 60 | * @param srclen compressed data size 61 | * @param buffer preallocated buffer to use 62 | * 63 | * @return decompressed buffer (must be freeded by Buffer::deleter if not preallocated) 64 | */ 65 | EXPORT uint8_t *decompress(uint32_t compression, uint32_t *dstlen, const uint8_t *src, uint32_t srclen, uint8_t *buffer=nullptr); 66 | 67 | /** 68 | * Typed compressing function (currently for lzss) 69 | * 70 | * @param compression compression type 71 | * @param dstlen maximum compression buffer size 72 | * @param src uncompressed data 73 | * @param srclen uncompressed data size 74 | * @param buffer preallocated buffer to use 75 | * 76 | * @return compressed buffer with its actual size in dstlen (must be freeded by Buffer::deleter if not preallocated) 77 | */ 78 | EXPORT uint8_t *compress(uint32_t compression, uint32_t &dstlen, const uint8_t *src, uint32_t srclen, uint8_t *buffer=nullptr); 79 | 80 | } 81 | 82 | #endif /* LILU_COMPRESSION_SUPPORT */ 83 | 84 | #endif /* kern_compression_hpp */ 85 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_crypto.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_crypto.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_crypto_h 9 | #define kern_crypto_h 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Crypto { 16 | /** 17 | * Currently this is equal to both key size and block size 18 | */ 19 | static constexpr uint32_t BlockSize = 16; 20 | 21 | /** 22 | * Currently this is guaranteed hash size 23 | */ 24 | static constexpr uint32_t MinDigestSize = 32; 25 | 26 | /** 27 | * Encrypted data format 28 | */ 29 | struct PACKED Encrypted { 30 | uint8_t iv[BlockSize]; // Initialisation vector 31 | struct PACKED Data { 32 | uint32_t size; // Actual encrypted buffer size 33 | uint8_t buf[BlockSize - sizeof(uint32_t)]; // Encrypted buffer >= BlockSize 34 | }; 35 | 36 | union { 37 | Data enc; 38 | uint8_t buf[BlockSize]; 39 | }; 40 | }; 41 | 42 | /** 43 | * Securely erase memory buffer 44 | * Based off cc_clear from corecrypto (src/cc_clear.c) 45 | * 46 | * @param len buffer length 47 | * @param dst buffer pointer 48 | */ 49 | inline void zeroMemory(size_t len, void *dst) { 50 | auto vptr = reinterpret_cast(dst); 51 | while (len--) 52 | *vptr++ = '\0'; 53 | } 54 | 55 | /** 56 | * Generates cryptographically secure encryption key (from /dev/random) 57 | * 58 | * @return generated key of at least BlockSize bits long (must be freeded by Buffer::deleter) or nullptr 59 | */ 60 | EXPORT uint8_t *genUniqueKey(uint32_t size=BlockSize); 61 | 62 | /** 63 | * Encrypts data of specified size and stores in Encrypted format 64 | * 65 | * @param key encryption key returned by genUniqueKey 66 | * @param src source data 67 | * @param size data size, encrypted size is returned on success 68 | * 69 | * @return encrypted data in Encrypted format (must be freed by Buffer::deleter) or nullptr 70 | */ 71 | EXPORT uint8_t *encrypt(const uint8_t *key, const uint8_t *src, uint32_t &size); 72 | 73 | /** 74 | * Decrypts data of specified size stored in Encrypted format 75 | * 76 | * @param key encryption key returned by genUniqueKey 77 | * @param src source data 78 | * @param size data size, decrypted size is returned on success 79 | * 80 | * @return decrypted data (must be freed by Buffer::deleter) or nullptr 81 | */ 82 | EXPORT uint8_t *decrypt(const uint8_t *key, const uint8_t *src, uint32_t &size); 83 | 84 | /** 85 | * Calculate digest of given size 86 | * 87 | * @param src source data 88 | * @param size data size 89 | * 90 | * @return digest hash of at least MinDigestSize bytes (must be freeded by Buffer::deleter) or nullptr 91 | */ 92 | EXPORT uint8_t *hash(const uint8_t *src, uint32_t size); 93 | } 94 | 95 | #endif /* kern_crypto_h */ 96 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/SMCSuperIO.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 20G624 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | SMCSuperIO 11 | CFBundleIdentifier 12 | ru.joedm.SMCSuperIO 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | SMCSuperIO 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 1.3.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleSupportedPlatforms 24 | 25 | MacOSX 26 | 27 | CFBundleVersion 28 | 1.3.0 29 | DTCompiler 30 | com.apple.compilers.llvm.clang.1_0 31 | DTPlatformBuild 32 | 13C100 33 | DTPlatformName 34 | macosx 35 | DTPlatformVersion 36 | 12.1 37 | DTSDKBuild 38 | 21C46 39 | DTSDKName 40 | macosx12.1 41 | DTXcode 42 | 1321 43 | DTXcodeBuild 44 | 13C100 45 | IOKitPersonalities 46 | 47 | ru.joedm.SMCSuperIO 48 | 49 | CFBundleIdentifier 50 | ru.joedm.SMCSuperIO 51 | IOClass 52 | SMCSuperIO 53 | IOMatchCategory 54 | SMCSuperIO 55 | IOPCIClassMatch 56 | 0x06010000&0xffff0000 57 | IOProviderClass 58 | IOPCIDevice 59 | IOResourceMatch 60 | ACPI 61 | 62 | 63 | LSMinimumSystemVersion 64 | 10.6 65 | NSHumanReadableCopyright 66 | Copyright © 2018 joedm. All rights reserved. 67 | OSBundleCompatibleVersion 68 | 1.0 69 | OSBundleLibraries 70 | 71 | as.vit9696.Lilu 72 | 1.2.0 73 | as.vit9696.VirtualSMC 74 | 1.0.0 75 | com.apple.iokit.IOACPIFamily 76 | 1.0.0d1 77 | com.apple.kpi.bsd 78 | 10.0.0 79 | com.apple.kpi.dsep 80 | 10.0.0 81 | com.apple.kpi.iokit 82 | 10.0.0 83 | com.apple.kpi.libkern 84 | 10.0.0 85 | com.apple.kpi.mach 86 | 10.0.0 87 | com.apple.kpi.unsupported 88 | 10.0.0 89 | 90 | OSBundleRequired 91 | Root 92 | 93 | 94 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/SMCProcessor.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 20G624 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | SMCProcessor 11 | CFBundleIdentifier 12 | as.vit9696.SMCProcessor 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | SMCProcessor 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 1.3.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleSupportedPlatforms 24 | 25 | MacOSX 26 | 27 | CFBundleVersion 28 | 1.3.0 29 | DTCompiler 30 | com.apple.compilers.llvm.clang.1_0 31 | DTPlatformBuild 32 | 13C100 33 | DTPlatformName 34 | macosx 35 | DTPlatformVersion 36 | 12.1 37 | DTSDKBuild 38 | 21C46 39 | DTSDKName 40 | macosx12.1 41 | DTXcode 42 | 1321 43 | DTXcodeBuild 44 | 13C100 45 | IOKitPersonalities 46 | 47 | as.vit9696.SMCProcessor 48 | 49 | CFBundleIdentifier 50 | as.vit9696.SMCProcessor 51 | IOClass 52 | SMCProcessor 53 | IOMatchCategory 54 | SMCProcessor 55 | IONameMatch 56 | processor 57 | IOPropertyMatch 58 | 59 | processor-index 60 | 0 61 | 62 | IOProviderClass 63 | IOACPIPlatformDevice 64 | IOResourceMatch 65 | ACPI 66 | 67 | 68 | LSMinimumSystemVersion 69 | 10.7 70 | NSHumanReadableCopyright 71 | Copyright © 2018 vit9696. All rights reserved. 72 | OSBundleCompatibleVersion 73 | 1.0 74 | OSBundleLibraries 75 | 76 | as.vit9696.Lilu 77 | 1.2.0 78 | as.vit9696.VirtualSMC 79 | 1.0.0 80 | com.apple.iokit.IOACPIFamily 81 | 1.0.0d1 82 | com.apple.kpi.bsd 83 | 11.0.0 84 | com.apple.kpi.dsep 85 | 11.0.0 86 | com.apple.kpi.iokit 87 | 11.0.0 88 | com.apple.kpi.libkern 89 | 11.0.0 90 | com.apple.kpi.mach 91 | 11.0.0 92 | com.apple.kpi.unsupported 93 | 11.0.0 94 | 95 | OSBundleRequired 96 | Root 97 | 98 | 99 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 20G624 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | Lilu 11 | CFBundleIdentifier 12 | as.vit9696.Lilu 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | Lilu 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 1.6.1 21 | CFBundleSignature 22 | ???? 23 | CFBundleSupportedPlatforms 24 | 25 | MacOSX 26 | 27 | CFBundleVersion 28 | 1.6.1 29 | DTCompiler 30 | com.apple.compilers.llvm.clang.1_0 31 | DTPlatformBuild 32 | 13C100 33 | DTPlatformName 34 | macosx 35 | DTPlatformVersion 36 | 12.1 37 | DTSDKBuild 38 | 21C46 39 | DTSDKName 40 | macosx12.1 41 | DTXcode 42 | 1321 43 | DTXcodeBuild 44 | 13C100 45 | IOKitPersonalities 46 | 47 | as.vit9696.Lilu 48 | 49 | CFBundleIdentifier 50 | as.vit9696.Lilu 51 | IOClass 52 | Lilu 53 | IOMatchCategory 54 | Lilu 55 | IOProviderClass 56 | IOResources 57 | IOResourceMatch 58 | IOBSD 59 | 60 | 61 | LSMinimumSystemVersion 62 | 10.6 63 | NSHumanReadableCopyright 64 | Copyright © 2016-2020 vit9696. All rights reserved. 65 | OSBundleCompatibleVersion 66 | 1.2.0 67 | OSBundleLibraries 68 | 69 | com.apple.kernel.6.0 70 | 7.9.9 71 | com.apple.kpi.bsd 72 | 8.0.0 73 | com.apple.kpi.iokit 74 | 8.0.0 75 | com.apple.kpi.libkern 76 | 8.0.0 77 | com.apple.kpi.mach 78 | 8.0.0 79 | com.apple.kpi.unsupported 80 | 8.0.0 81 | 82 | OSBundleLibraries_x86_64 83 | 84 | com.apple.kpi.bsd 85 | 10.0.0 86 | com.apple.kpi.dsep 87 | 10.0.0 88 | com.apple.kpi.iokit 89 | 10.0.0 90 | com.apple.kpi.libkern 91 | 10.0.0 92 | com.apple.kpi.mach 93 | 10.0.0 94 | com.apple.kpi.unsupported 95 | 10.0.0 96 | 97 | OSBundleRequired 98 | Root 99 | 100 | 101 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_time.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_time.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_time_hpp 9 | #define kern_time_hpp 10 | 11 | #include 12 | 13 | /** 14 | * Obtain current system time in nanoseconds 15 | * 16 | * @return current time 17 | */ 18 | inline uint64_t getCurrentTimeNs() { 19 | uint64_t currt = 0; 20 | absolutetime_to_nanoseconds(mach_absolute_time(), &currt); 21 | return currt; 22 | } 23 | 24 | /** 25 | * Obtain current calendar system time in nanoseconds 26 | * 27 | * @return current time 28 | */ 29 | inline uint64_t getCalendarTimeNs() { 30 | clock_sec_t sc; 31 | clock_nsec_t ns; 32 | clock_get_calendar_nanotime(&sc, &ns); 33 | return static_cast(sc) * NSEC_PER_SEC + ns; 34 | } 35 | 36 | /** 37 | * Obtain time passed since some timestamp in nanoseconds 38 | * 39 | * @param start starting timestamp 40 | * @param current timestamp to check against (pass 0 for current time) 41 | * 42 | * @return delta or 0 (if current time equals or precedeces the start) 43 | */ 44 | inline uint64_t getTimeSinceNs(uint64_t start, uint64_t current = 0) { 45 | if (current == 0) 46 | current = getCurrentTimeNs(); 47 | if (current > start) 48 | return current - start; 49 | return 0; 50 | } 51 | 52 | /** 53 | * Obtain time left till a timestamp in the future in nanoseconds 54 | * 55 | * @param start starting timestamp 56 | * @param timeout timeout for the event 57 | * @param current timestamp to check against (pass 0 for current time) 58 | * 59 | * @return delta or 0 (if the timeout is over) 60 | */ 61 | inline uint64_t getTimeLeftNs(uint64_t start, uint64_t timeout, uint64_t current = 0) { 62 | if (current == 0) 63 | current = getCurrentTimeNs(); 64 | if (start + timeout > current) 65 | return start + timeout - current; 66 | return 0; 67 | } 68 | 69 | /** 70 | * Convert from nanoseconds to milliseconds 71 | * 72 | * @param t timestamp in ns 73 | * 74 | * @return timestamp in ms 75 | */ 76 | constexpr uint64_t convertNsToMs(uint64_t t) { 77 | return t / 1000000; 78 | } 79 | 80 | /** 81 | * Convert from nanoseconds to seconds 82 | * 83 | * @param t timestamp in ns 84 | * 85 | * @return timestamp in s 86 | */ 87 | constexpr uint64_t convertNsToSc(uint64_t t) { 88 | return t / 1000000000; 89 | } 90 | 91 | /** 92 | * Convert from milliseconds to seconds 93 | * 94 | * @param t timestamp in ms 95 | * 96 | * @return timestamp in s 97 | */ 98 | constexpr uint64_t convertMsToSc(uint64_t t) { 99 | return t / 1000; 100 | } 101 | 102 | /** 103 | * Convert from milliseconds to nanoseconds 104 | * 105 | * @param t timestamp in ms 106 | * 107 | * @return timestamp in ns 108 | */ 109 | constexpr uint64_t convertMsToNs(uint64_t t) { 110 | return t * 1000000; 111 | } 112 | 113 | /** 114 | * Convert from seconds to nanoseconds 115 | * 116 | * @param t timestamp in s 117 | * 118 | * @return timestamp in ns 119 | */ 120 | constexpr uint64_t convertScToNs(uint64_t t) { 121 | return t * 1000000000; 122 | } 123 | 124 | /** 125 | * Convert from seconds to milliseconds 126 | * 127 | * @param t timestamp in s 128 | * 129 | * @return timestamp in ms 130 | */ 131 | constexpr uint64_t convertScToMs(uint64_t t) { 132 | return t * 1000; 133 | } 134 | 135 | #endif /* kern_time_hpp */ 136 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Library/plugin_start.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // plugin_start.cpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef LILU_CUSTOM_KMOD_INIT 14 | bool ADDPR(startSuccess) = false; 15 | #else 16 | // Workaround custom kmod code and enable by default 17 | bool ADDPR(startSuccess) = true; 18 | #endif /* LILU_CUSTOM_KMOD_INIT */ 19 | 20 | bool ADDPR(debugEnabled) = false; 21 | uint32_t ADDPR(debugPrintDelay) = 0; 22 | 23 | #ifndef LILU_CUSTOM_IOKIT_INIT 24 | 25 | OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService) 26 | 27 | PRODUCT_NAME *ADDPR(selfInstance) = nullptr; 28 | 29 | IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) { 30 | ADDPR(selfInstance) = this; 31 | setProperty("VersionInfo", kextVersion); 32 | auto service = IOService::probe(provider, score); 33 | return ADDPR(startSuccess) ? service : nullptr; 34 | } 35 | 36 | bool PRODUCT_NAME::start(IOService *provider) { 37 | ADDPR(selfInstance) = this; 38 | if (!IOService::start(provider)) { 39 | SYSLOG("init", "failed to start the parent"); 40 | return false; 41 | } 42 | 43 | return ADDPR(startSuccess); 44 | } 45 | 46 | void PRODUCT_NAME::stop(IOService *provider) { 47 | ADDPR(selfInstance) = nullptr; 48 | IOService::stop(provider); 49 | } 50 | 51 | #endif /* LILU_CUSTOM_IOKIT_INIT */ 52 | 53 | #ifndef LILU_CUSTOM_KMOD_INIT 54 | 55 | EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) { 56 | // This is an ugly hack necessary on some systems where buffering kills most of debug output. 57 | lilu_get_boot_args("liludelay", &ADDPR(debugPrintDelay), sizeof(ADDPR(debugPrintDelay))); 58 | 59 | auto error = lilu.requestAccess(); 60 | if (error == LiluAPI::Error::NoError) { 61 | error = lilu.shouldLoad(ADDPR(config).product, ADDPR(config).version, ADDPR(config).runmode, ADDPR(config).disableArg, ADDPR(config).disableArgNum, 62 | ADDPR(config).debugArg, ADDPR(config).debugArgNum, ADDPR(config).betaArg, ADDPR(config).betaArgNum, ADDPR(config).minKernel, 63 | ADDPR(config).maxKernel, ADDPR(debugEnabled)); 64 | 65 | if (error == LiluAPI::Error::NoError) { 66 | DBGLOG("init", "%s bootstrap %s", xStringify(PRODUCT_NAME), kextVersion); 67 | (void)kextVersion; 68 | ADDPR(startSuccess) = true; 69 | ADDPR(config).pluginStart(); 70 | } else { 71 | SYSLOG("init", "parent said we should not continue %d", error); 72 | } 73 | 74 | lilu.releaseAccess(); 75 | } else { 76 | SYSLOG("init", "failed to call parent %d", error); 77 | } 78 | 79 | for (size_t i = 0; i < ADDPR(config).debugArgNum; i++) { 80 | if (checkKernelArgument(ADDPR(config).debugArg[i])) { 81 | ADDPR(debugEnabled) = true; 82 | break; 83 | } 84 | } 85 | 86 | if (checkKernelArgument("-liludbgall")) 87 | ADDPR(debugEnabled) = true; 88 | 89 | // Report success but actually do not start and let I/O Kit unload us. 90 | // This works better and increases boot speed in some cases. 91 | return KERN_SUCCESS; 92 | } 93 | 94 | EXPORT extern "C" kern_return_t ADDPR(kern_stop)(kmod_info_t *, void *) { 95 | // It is not safe to unload Lilu plugins unless they were disabled! 96 | return ADDPR(startSuccess) ? KERN_FAILURE : KERN_SUCCESS; 97 | } 98 | 99 | #endif /* LILU_CUSTOM_KMOD_INIT */ 100 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/WhateverGreen.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 20G624 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | WhateverGreen 11 | CFBundleIdentifier 12 | as.vit9696.WhateverGreen 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | WhateverGreen 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 1.6.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleSupportedPlatforms 24 | 25 | MacOSX 26 | 27 | CFBundleVersion 28 | 1.6.0 29 | DTCompiler 30 | com.apple.compilers.llvm.clang.1_0 31 | DTPlatformBuild 32 | 13C100 33 | DTPlatformName 34 | macosx 35 | DTPlatformVersion 36 | 12.1 37 | DTSDKBuild 38 | 21C46 39 | DTSDKName 40 | macosx12.1 41 | DTXcode 42 | 1321 43 | DTXcodeBuild 44 | 13C100 45 | IOKitPersonalities 46 | 47 | NVHDAEnabler 48 | 49 | CFBundleIdentifier 50 | as.vit9696.WhateverGreen 51 | IOClass 52 | NVHDAEnabler 53 | IOMatchCategory 54 | IOFramebuffer 55 | IOPCIClassMatch 56 | 0x03000000&0xff000000 57 | IOPCIMatch 58 | 0x000010de&0x0000ffff 59 | IOProbeScore 60 | 300000 61 | IOProviderClass 62 | IOPCIDevice 63 | 64 | as.vit9696.WhateverGreen 65 | 66 | CFBundleIdentifier 67 | as.vit9696.WhateverGreen 68 | IOClass 69 | WhateverGreen 70 | IOMatchCategory 71 | WhateverGreen 72 | IOProviderClass 73 | IOResources 74 | IOResourceMatch 75 | IOKit 76 | 77 | 78 | LSMinimumSystemVersion 79 | 10.6 80 | NSHumanReadableCopyright 81 | Copyright © 2018 vit9696. All rights reserved. 82 | OSBundleCompatibleVersion 83 | 1.0 84 | OSBundleLibraries 85 | 86 | as.vit9696.Lilu 87 | 1.2.0 88 | com.apple.iokit.IOPCIFamily 89 | 1.0.0b1 90 | com.apple.kpi.bsd 91 | 10.0.0 92 | com.apple.kpi.dsep 93 | 10.0.0 94 | com.apple.kpi.iokit 95 | 10.0.0 96 | com.apple.kpi.libkern 97 | 10.0.0 98 | com.apple.kpi.mach 99 | 10.0.0 100 | com.apple.kpi.unsupported 101 | 10.0.0 102 | 103 | OSBundleRequired 104 | Root 105 | 106 | 107 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/Resources/VirtualSMCSDK/kern_keyvalue.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_keyvalue.hpp 3 | // VirtualSMC 4 | // 5 | // Copyright © 2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_keyvalue_hpp 9 | #define kern_keyvalue_hpp 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | struct VirtualSMCKeyValue { 16 | /** 17 | * Key name 18 | */ 19 | SMC_KEY key; 20 | 21 | /** 22 | * Key value 23 | */ 24 | _Atomic(VirtualSMCValue *) value = ATOMIC_VAR_INIT(nullptr); 25 | 26 | /** 27 | * Original value 28 | */ 29 | _Atomic(VirtualSMCValue *) backup = nullptr; 30 | 31 | /** 32 | * Should key value pair be serialisable 33 | * 34 | * @param confidential confidential serialisation stores are allowed 35 | * 36 | * @return true if should be saved 37 | */ 38 | bool serializable(bool confidential) const; 39 | 40 | /** 41 | * Get serialized size (normally key, size, key data) 42 | * 43 | * @return size in bytes 44 | */ 45 | size_t serializedSize() const; 46 | 47 | /** 48 | * Write serialized data to the buffer 49 | * 50 | * @param dst serialization buffer reference of at least serializedSize() 51 | */ 52 | void serialize(uint8_t *&dst) const; 53 | 54 | /** 55 | * Read serialized data 56 | * 57 | * @param src serialization buffer reference (increased) 58 | * @param size serialization buffer size (decreased) 59 | * @param name read key name 60 | * @param out read key data (must be preallocated) 61 | * @param outsz key data size 62 | * 63 | * @return true on succesful read 64 | */ 65 | static bool deserialize(const uint8_t *&src, uint32_t &size, SMC_KEY &name, SMC_DATA *out, SMC_DATA_SIZE &outsz); 66 | 67 | /** 68 | * Create key/value pair for storage 69 | * 70 | * @param k key name 71 | * @param v key value 72 | * 73 | * @return key/value pair 74 | */ 75 | static VirtualSMCKeyValue create(SMC_KEY k, VirtualSMCValue *v) { 76 | VirtualSMCKeyValue kv {k}; 77 | atomic_init(&kv.value, v); 78 | atomic_init(&kv.backup, nullptr); 79 | return kv; 80 | } 81 | 82 | /** 83 | * Key/value deleter responsible for freeing value dynamic memory 84 | * 85 | * @param kv key/value pair 86 | */ 87 | static void deleter(VirtualSMCKeyValue &kv) { 88 | // This is just an old compiler crash workaround, no need for atomicity here! 89 | auto v = atomic_load_explicit(&kv.value, memory_order_relaxed); 90 | auto b = atomic_load_explicit(&kv.backup, memory_order_relaxed); 91 | if (v) VirtualSMCValue::deleter(v); 92 | if (b) VirtualSMCValue::deleter(b); 93 | } 94 | 95 | /** 96 | * Key comparator for sorting 97 | * 98 | * @param a first key 99 | * @param b second key 100 | * 101 | * @return like qsort (<0 if a goes before b) 102 | */ 103 | static int compare(const SMC_KEY a, const SMC_KEY b) { 104 | if (a == b) 105 | return 0; 106 | else if (OSSwapInt32(a) < OSSwapInt32(b)) 107 | return -1; 108 | return 1; 109 | } 110 | 111 | /** 112 | * Key value comparator for sorting 113 | * 114 | * @param a opaque k/v pointer 115 | * @param b opaque k/v pointer 116 | * 117 | * @return like qsort (<0 if a goes before b) 118 | */ 119 | static int compare(const void *a, const void *b) { 120 | return compare(static_cast(a)->key, static_cast(b)->key); 121 | } 122 | }; 123 | 124 | 125 | #endif /* kern_keyvalue_hpp */ 126 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # msi-z590i-unify-opencore 2 | This repository contains the EFI content I used to run the latest OpenCore boot loader. I'll add more details below, but for now - if you know what you're doing - feel free to play with the EFI folder 3 | 4 | # Hardware 5 | Items that could affect your config.plist (if different from yours, you might need to do a bit of reading and/or troubleshooting ): 6 | - MSI Z590i Unify Motherboard (obviously) 7 | - Intel 11700K CPU 8 | - XFX Speedster SWFT 210 Radeon RX 6600 (though thinking of upgrading) 9 | - WD Black SN750 High Performance NVMe M.2 Internal 10 | - WLAN: BCM94360NG (bought it Amazon - look it up) 11 | 12 | Items SHOULD not require config adjustment: 13 | - Corsair Vengeance LPX 32GB (2 x 16GB) 14 | - Arctic Liquid Freezer II 120 15 | - Corsair SF600 PC Power Supply 16 | - Phanteks Enthoo Evolv Shift 2 Mini-ITX Case 17 | 18 | # Working 19 | - macOS Monterey 12.3.1 20 | 21 | ![system-info](https://user-images.githubusercontent.com/3272436/166143491-d6bbfe88-152a-40ed-aecd-7ebed0ffd6ef.png) 22 | 23 | - Wifi and Bluetooth (via BCM94360NG Wireless Card) 24 | - Audio via DisplayPort (didn't test the audio jacks) 25 | - USB: all ports available with my case 26 | - Thunderbolt 3/4 including Hot-plug (from my test it works, but I don't really have a TB4 device to test with) 27 | - Ethernet: works at 1Gbps speed (have not tested with 2.5Gbps because my router doesn't go as fast) 28 | - Airdrop 29 | - Sleep/Wake (via power button) 30 | - Shutdown 31 | - Restart 32 | 33 | # Performance 34 | Overall, I cannot really complain about the performace (see below). 35 | - From about during the beginning of 2022, I was getting this kind of performance 36 | ![geekbench-jan-2022](https://user-images.githubusercontent.com/3272436/166143800-88a34493-3ddd-4a5d-8653-eea550fc7848.png) 37 | 38 | - After a few macOS upgrades, it seems to have gone down a little: 39 | ![geekbench-recent-past](https://user-images.githubusercontent.com/3272436/166143807-e9e7bfea-bce4-4402-b8bd-fd45284a75c1.png) 40 | 41 | - A more recent Geekbench test resulting in improvements to the score: 42 | ![geekbench-recent](https://user-images.githubusercontent.com/3272436/172646642-ce288d47-7eeb-42e6-9a17-8c483e58a49b.png) 43 | 44 | 45 | # Not working 46 | - Sidecar (this is due to 11th Gen CPU's iGPU is not supported by Apple) 47 | 48 | # BIOS Settings 49 | The easiest way to ensure your BIOS is set up for installing macOS is to enable D.T.M 50 | - Switch to the Expert mode of you BIOS settings 51 | - Use the latest BIOS firmware from the MSI website 52 | - Load default settings, then go to the BETA RUNNER option 53 | ![advanced-mode-beta-runner](https://user-images.githubusercontent.com/3272436/166143042-d47b0531-40ee-4571-84fe-114463179b6a.png) 54 | 55 | - Enable D.T.M 56 | ![dtm-enabled](https://user-images.githubusercontent.com/3272436/166142966-0664a63c-c3b0-45f5-a9dd-d2d0c84f8213.png) 57 | - Save your BIOS settings, then reboot. 58 | 59 | # Installation instructions 60 | - Download the entire EFI folder found in this repo. 61 | - Use the OpenCore install guide WRT to [create a macOS installer USB stick](https://dortania.github.io/OpenCore-Install-Guide/installer-guide/mac-install.html). 62 | - Download [MountEFI](https://github.com/corpnewt/MountEFI), then mount your USB installer's EFI partition to copy the downloaded EFI folder there (yes, you'll end up with an EFI folder within the EFI drive). 63 | - Reboot to your installer USB stick, then follow instructions. 64 | - Once macOS installation completed, mount the EFI drive of your main installion hard disk drive to copy the EFI folder. 65 | - Follow this [guide](https://dortania.github.io/OpenCore-Install-Guide/config.plist/comet-lake.html#platforminfo) to change the SMBIOS info in your config file 66 | 67 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/platform.h: -------------------------------------------------------------------------------- 1 | /* Capstone Disassembly Engine */ 2 | /* By Axel Souchet & Nguyen Anh Quynh, 2014 */ 3 | 4 | #ifndef CAPSTONE_PLATFORM_H 5 | #define CAPSTONE_PLATFORM_H 6 | 7 | // handle C99 issue (for pre-2013 VisualStudio) 8 | #if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)) 9 | // MSVC 10 | 11 | // stdbool.h 12 | #if (_MSC_VER < 1800) || defined(_KERNEL_MODE) 13 | // this system does not have stdbool.h 14 | #ifndef __cplusplus 15 | typedef unsigned char bool; 16 | #define false 0 17 | #define true 1 18 | #endif 19 | 20 | #else 21 | // VisualStudio 2013+ -> C99 is supported 22 | #include 23 | #endif 24 | 25 | #else 26 | // not MSVC -> C99 is supported 27 | #include 28 | #endif 29 | 30 | 31 | // handle C99 issue (for pre-2013 VisualStudio) 32 | #if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE))) 33 | // this system does not have inttypes.h 34 | 35 | #if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE)) 36 | // this system does not have stdint.h 37 | typedef signed char int8_t; 38 | typedef signed short int16_t; 39 | typedef signed int int32_t; 40 | typedef unsigned char uint8_t; 41 | typedef unsigned short uint16_t; 42 | typedef unsigned int uint32_t; 43 | typedef signed long long int64_t; 44 | typedef unsigned long long uint64_t; 45 | 46 | #define INT8_MIN (-127i8 - 1) 47 | #define INT16_MIN (-32767i16 - 1) 48 | #define INT32_MIN (-2147483647i32 - 1) 49 | #define INT64_MIN (-9223372036854775807i64 - 1) 50 | #define INT8_MAX 127i8 51 | #define INT16_MAX 32767i16 52 | #define INT32_MAX 2147483647i32 53 | #define INT64_MAX 9223372036854775807i64 54 | #define UINT8_MAX 0xffui8 55 | #define UINT16_MAX 0xffffui16 56 | #define UINT32_MAX 0xffffffffui32 57 | #define UINT64_MAX 0xffffffffffffffffui64 58 | #endif 59 | 60 | #define __PRI_8_LENGTH_MODIFIER__ "hh" 61 | #define __PRI_64_LENGTH_MODIFIER__ "ll" 62 | 63 | #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d" 64 | #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i" 65 | #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o" 66 | #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u" 67 | #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x" 68 | #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X" 69 | 70 | #define PRId16 "hd" 71 | #define PRIi16 "hi" 72 | #define PRIo16 "ho" 73 | #define PRIu16 "hu" 74 | #define PRIx16 "hx" 75 | #define PRIX16 "hX" 76 | 77 | #if defined(_MSC_VER) && _MSC_VER <= 1700 78 | #define PRId32 "ld" 79 | #define PRIi32 "li" 80 | #define PRIo32 "lo" 81 | #define PRIu32 "lu" 82 | #define PRIx32 "lx" 83 | #define PRIX32 "lX" 84 | #else // OSX 85 | #define PRId32 "d" 86 | #define PRIi32 "i" 87 | #define PRIo32 "o" 88 | #define PRIu32 "u" 89 | #define PRIx32 "x" 90 | #define PRIX32 "X" 91 | #endif 92 | 93 | #if defined(_MSC_VER) && _MSC_VER <= 1700 94 | // redefine functions from inttypes.h used in cstool 95 | #define strtoull _strtoui64 96 | #endif 97 | 98 | #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d" 99 | #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i" 100 | #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o" 101 | #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u" 102 | #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x" 103 | #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X" 104 | 105 | #else 106 | // this system has inttypes.h by default 107 | #include 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/Resources/VirtualSMCSDK/kern_value.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_keyvalue.hpp 3 | // VirtualSMC 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_value_hpp 9 | #define kern_value_hpp 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | /** 17 | * Serialization level determining external value storage necessity 18 | */ 19 | enum class EXPORT SerializeLevel { 20 | None, 21 | Normal, 22 | Confidential, 23 | Default = Confidential 24 | }; 25 | 26 | class VirtualSMCKeystore; 27 | class VirtualSMCKeyValue; 28 | 29 | class EXPORT VirtualSMCValue { 30 | friend VirtualSMCKeystore; 31 | friend VirtualSMCKeyValue; 32 | protected: 33 | 34 | /** 35 | * Value contents retrieved by other protocols 36 | */ 37 | SMC_DATA data[SMC_MAX_DATA_SIZE] {}; 38 | 39 | /** 40 | * Actual value contents size (could be less than SMC_MAX_DATA_SIZE) 41 | */ 42 | SMC_DATA_SIZE size {}; 43 | 44 | /** 45 | * One of the enum types defined in AppleSmc.h specifying value type 46 | */ 47 | SMC_KEY_TYPE type {}; 48 | 49 | /** 50 | * Bitmask of key attributes defined in AppleSmc.h defining value abilities 51 | */ 52 | SMC_KEY_ATTRIBUTES attr {}; 53 | 54 | /** 55 | * Serialization level defining the necessity to serialize values on power events 56 | */ 57 | SerializeLevel serializeLevel {SerializeLevel::None}; 58 | 59 | /** 60 | * On read access, update the data if needed, and perform custom access control. 61 | * For base value, always allow the access if keystore allowed it. 62 | * 63 | * @return SmcSuccess if allowed 64 | */ 65 | virtual SMC_RESULT readAccess() { 66 | return SmcSuccess; 67 | } 68 | 69 | /** 70 | * On write access, update the data if needed, and perform custom access control. 71 | * For base value, always allow the access if keystore allowed it. 72 | * 73 | * @return SmcSuccess if allowed 74 | */ 75 | virtual SMC_RESULT writeAccess() { 76 | return SmcSuccess; 77 | } 78 | 79 | public: 80 | /** 81 | * Initialises a value with existing data. 82 | * 83 | * @param data Initial data, must be at least size bytes 84 | * @param size Amount of data bytes used, at most SMC_MAX_DATA_SIZE 85 | * @param type Value type 86 | * @param attr Value attributes 87 | * @param level Serialization necessity 88 | * 89 | * @return true on success 90 | */ 91 | EXPORT bool init(const SMC_DATA *data, SMC_DATA_SIZE size, SMC_KEY_TYPE type, SMC_KEY_ATTRIBUTES attr, SerializeLevel level = SerializeLevel::None); 92 | 93 | /** 94 | * Initialises a value with an OSDictionary. 95 | * Dictionary keys are described in VirtualKeystore::merge(const OSArray *) method. 96 | * 97 | * @param dict An OSDictionary that describes the value 98 | * 99 | * @return true on success 100 | */ 101 | EXPORT bool init(const OSDictionary *dict); 102 | 103 | /** 104 | * Obtain value contents 105 | * 106 | * @param size Amount of used bytes 107 | * 108 | * @return Pointer to the value data buffer. 109 | * 110 | * The buffer shall never be modified externally. 111 | */ 112 | const SMC_DATA *get(SMC_DATA_SIZE &size) const; 113 | 114 | /** 115 | * Update the internal buffer, assuming the same 116 | * amount of bytes is used for this value. 117 | * 118 | * @param src new contents 119 | */ 120 | virtual SMC_RESULT update(const SMC_DATA *src); 121 | 122 | /** 123 | * Checks serialization necessity 124 | * 125 | * @param confidential confidential information storage is allowed 126 | * 127 | * @retrurn true if the value needs to be serialized 128 | */ 129 | bool serializable(bool confidential) const { 130 | return serializeLevel == SerializeLevel::Normal || 131 | (serializeLevel == SerializeLevel::Confidential && confidential); 132 | } 133 | 134 | /** 135 | * It is not recommended to free created values but you can if you need 136 | */ 137 | virtual ~VirtualSMCValue() = default; 138 | 139 | /** 140 | * Used for storing values in evector 141 | * 142 | * @param inst value to be freed 143 | */ 144 | static void deleter(VirtualSMCValue *inst) { 145 | delete inst; 146 | } 147 | }; 148 | 149 | #endif /* kern_value_hpp */ 150 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/USBMapMSIz590i.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleGetInfoString 8 | v1.1 9 | CFBundleIdentifier 10 | com.dhinakg.USBToolBox.map 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | UTBMap 15 | CFBundlePackageType 16 | KEXT 17 | CFBundleShortVersionString 18 | 1.1 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.1 23 | IOKitPersonalities 24 | 25 | _SB.PC00.RP05.PXSX.TBDU.XHCI 26 | 27 | CFBundleIdentifier 28 | com.dhinakg.USBToolBox.kext 29 | IOClass 30 | USBToolBox 31 | IOMatchCategory 32 | USBToolBox 33 | IOPropertyMatch 34 | 35 | pcidebug 36 | 13:0:0 37 | 38 | IOProviderClass 39 | IOPCIDevice 40 | IOProviderMergeProperties 41 | 42 | port-count 43 | 44 | BAAAAA== 45 | 46 | ports 47 | 48 | SS01 49 | 50 | UsbConnector 51 | 255 52 | port 53 | 54 | AwAAAA== 55 | 56 | 57 | SS02 58 | 59 | UsbConnector 60 | 255 61 | port 62 | 63 | BAAAAA== 64 | 65 | 66 | 67 | 68 | 69 | _SB.PC00.XHCI 70 | 71 | CFBundleIdentifier 72 | com.dhinakg.USBToolBox.kext 73 | IOClass 74 | USBToolBox 75 | IOMatchCategory 76 | USBToolBox 77 | IOPropertyMatch 78 | 79 | pcidebug 80 | 0:20:0 81 | 82 | IOProviderClass 83 | IOPCIDevice 84 | IOProviderMergeProperties 85 | 86 | port-count 87 | 88 | GAAAAA== 89 | 90 | ports 91 | 92 | HS01 93 | 94 | UsbConnector 95 | 3 96 | port 97 | 98 | AQAAAA== 99 | 100 | 101 | HS02 102 | 103 | UsbConnector 104 | 3 105 | port 106 | 107 | AgAAAA== 108 | 109 | 110 | HS03 111 | 112 | UsbConnector 113 | 3 114 | port 115 | 116 | BQAAAA== 117 | 118 | 119 | HS04 120 | 121 | UsbConnector 122 | 3 123 | port 124 | 125 | BgAAAA== 126 | 127 | 128 | HS05 129 | 130 | UsbConnector 131 | 3 132 | port 133 | 134 | BwAAAA== 135 | 136 | 137 | HS06 138 | 139 | UsbConnector 140 | 3 141 | port 142 | 143 | CAAAAA== 144 | 145 | 146 | HS07 147 | 148 | UsbConnector 149 | 255 150 | port 151 | 152 | DgAAAA== 153 | 154 | 155 | SS01 156 | 157 | UsbConnector 158 | 3 159 | port 160 | 161 | EQAAAA== 162 | 163 | 164 | SS02 165 | 166 | UsbConnector 167 | 3 168 | port 169 | 170 | EgAAAA== 171 | 172 | 173 | SS03 174 | 175 | UsbConnector 176 | 3 177 | port 178 | 179 | FQAAAA== 180 | 181 | 182 | SS04 183 | 184 | UsbConnector 185 | 3 186 | port 187 | 188 | FgAAAA== 189 | 190 | 191 | SS05 192 | 193 | UsbConnector 194 | 3 195 | port 196 | 197 | FwAAAA== 198 | 199 | 200 | SS06 201 | 202 | UsbConnector 203 | 3 204 | port 205 | 206 | GAAAAA== 207 | 208 | 209 | 210 | 211 | 212 | 213 | OSBundleLibraries 214 | 215 | com.dhinakg.USBToolBox.kext 216 | 1.0.0 217 | 218 | OSBundleRequired 219 | Root 220 | 221 | 222 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/xcore.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPSTONE_XCORE_H 2 | #define CAPSTONE_XCORE_H 3 | 4 | /* Capstone Disassembly Engine */ 5 | /* By Nguyen Anh Quynh , 2014 */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #if !defined(_MSC_VER) || !defined(_KERNEL_MODE) 12 | #include 13 | #endif 14 | 15 | #include "platform.h" 16 | 17 | #ifdef _MSC_VER 18 | #pragma warning(disable:4201) 19 | #endif 20 | 21 | //> Operand type for instruction's operands 22 | typedef enum xcore_op_type { 23 | XCORE_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized). 24 | XCORE_OP_REG, // = CS_OP_REG (Register operand). 25 | XCORE_OP_IMM, // = CS_OP_IMM (Immediate operand). 26 | XCORE_OP_MEM, // = CS_OP_MEM (Memory operand). 27 | } xcore_op_type; 28 | 29 | // Instruction's operand referring to memory 30 | // This is associated with XCORE_OP_MEM operand type above 31 | typedef struct xcore_op_mem { 32 | uint8_t base; // base register 33 | uint8_t index; // index register 34 | int32_t disp; // displacement/offset value 35 | int direct; // +1: forward, -1: backward 36 | } xcore_op_mem; 37 | 38 | // Instruction operand 39 | typedef struct cs_xcore_op { 40 | xcore_op_type type; // operand type 41 | union { 42 | unsigned int reg; // register value for REG operand 43 | int32_t imm; // immediate value for IMM operand 44 | xcore_op_mem mem; // base/disp value for MEM operand 45 | }; 46 | } cs_xcore_op; 47 | 48 | // Instruction structure 49 | typedef struct cs_xcore { 50 | // Number of operands of this instruction, 51 | // or 0 when instruction has no operand. 52 | uint8_t op_count; 53 | cs_xcore_op operands[8]; // operands for this instruction. 54 | } cs_xcore; 55 | 56 | //> XCore registers 57 | typedef enum xcore_reg { 58 | XCORE_REG_INVALID = 0, 59 | 60 | XCORE_REG_CP, 61 | XCORE_REG_DP, 62 | XCORE_REG_LR, 63 | XCORE_REG_SP, 64 | XCORE_REG_R0, 65 | XCORE_REG_R1, 66 | XCORE_REG_R2, 67 | XCORE_REG_R3, 68 | XCORE_REG_R4, 69 | XCORE_REG_R5, 70 | XCORE_REG_R6, 71 | XCORE_REG_R7, 72 | XCORE_REG_R8, 73 | XCORE_REG_R9, 74 | XCORE_REG_R10, 75 | XCORE_REG_R11, 76 | 77 | //> pseudo registers 78 | XCORE_REG_PC, // pc 79 | 80 | // internal thread registers 81 | // see The-XMOS-XS1-Architecture(X7879A).pdf 82 | XCORE_REG_SCP, // save pc 83 | XCORE_REG_SSR, // save status 84 | XCORE_REG_ET, // exception type 85 | XCORE_REG_ED, // exception data 86 | XCORE_REG_SED, // save exception data 87 | XCORE_REG_KEP, // kernel entry pointer 88 | XCORE_REG_KSP, // kernel stack pointer 89 | XCORE_REG_ID, // thread ID 90 | 91 | XCORE_REG_ENDING, // <-- mark the end of the list of registers 92 | } xcore_reg; 93 | 94 | //> XCore instruction 95 | typedef enum xcore_insn { 96 | XCORE_INS_INVALID = 0, 97 | 98 | XCORE_INS_ADD, 99 | XCORE_INS_ANDNOT, 100 | XCORE_INS_AND, 101 | XCORE_INS_ASHR, 102 | XCORE_INS_BAU, 103 | XCORE_INS_BITREV, 104 | XCORE_INS_BLA, 105 | XCORE_INS_BLAT, 106 | XCORE_INS_BL, 107 | XCORE_INS_BF, 108 | XCORE_INS_BT, 109 | XCORE_INS_BU, 110 | XCORE_INS_BRU, 111 | XCORE_INS_BYTEREV, 112 | XCORE_INS_CHKCT, 113 | XCORE_INS_CLRE, 114 | XCORE_INS_CLRPT, 115 | XCORE_INS_CLRSR, 116 | XCORE_INS_CLZ, 117 | XCORE_INS_CRC8, 118 | XCORE_INS_CRC32, 119 | XCORE_INS_DCALL, 120 | XCORE_INS_DENTSP, 121 | XCORE_INS_DGETREG, 122 | XCORE_INS_DIVS, 123 | XCORE_INS_DIVU, 124 | XCORE_INS_DRESTSP, 125 | XCORE_INS_DRET, 126 | XCORE_INS_ECALLF, 127 | XCORE_INS_ECALLT, 128 | XCORE_INS_EDU, 129 | XCORE_INS_EEF, 130 | XCORE_INS_EET, 131 | XCORE_INS_EEU, 132 | XCORE_INS_ENDIN, 133 | XCORE_INS_ENTSP, 134 | XCORE_INS_EQ, 135 | XCORE_INS_EXTDP, 136 | XCORE_INS_EXTSP, 137 | XCORE_INS_FREER, 138 | XCORE_INS_FREET, 139 | XCORE_INS_GETD, 140 | XCORE_INS_GET, 141 | XCORE_INS_GETN, 142 | XCORE_INS_GETR, 143 | XCORE_INS_GETSR, 144 | XCORE_INS_GETST, 145 | XCORE_INS_GETTS, 146 | XCORE_INS_INCT, 147 | XCORE_INS_INIT, 148 | XCORE_INS_INPW, 149 | XCORE_INS_INSHR, 150 | XCORE_INS_INT, 151 | XCORE_INS_IN, 152 | XCORE_INS_KCALL, 153 | XCORE_INS_KENTSP, 154 | XCORE_INS_KRESTSP, 155 | XCORE_INS_KRET, 156 | XCORE_INS_LADD, 157 | XCORE_INS_LD16S, 158 | XCORE_INS_LD8U, 159 | XCORE_INS_LDA16, 160 | XCORE_INS_LDAP, 161 | XCORE_INS_LDAW, 162 | XCORE_INS_LDC, 163 | XCORE_INS_LDW, 164 | XCORE_INS_LDIVU, 165 | XCORE_INS_LMUL, 166 | XCORE_INS_LSS, 167 | XCORE_INS_LSUB, 168 | XCORE_INS_LSU, 169 | XCORE_INS_MACCS, 170 | XCORE_INS_MACCU, 171 | XCORE_INS_MJOIN, 172 | XCORE_INS_MKMSK, 173 | XCORE_INS_MSYNC, 174 | XCORE_INS_MUL, 175 | XCORE_INS_NEG, 176 | XCORE_INS_NOT, 177 | XCORE_INS_OR, 178 | XCORE_INS_OUTCT, 179 | XCORE_INS_OUTPW, 180 | XCORE_INS_OUTSHR, 181 | XCORE_INS_OUTT, 182 | XCORE_INS_OUT, 183 | XCORE_INS_PEEK, 184 | XCORE_INS_REMS, 185 | XCORE_INS_REMU, 186 | XCORE_INS_RETSP, 187 | XCORE_INS_SETCLK, 188 | XCORE_INS_SET, 189 | XCORE_INS_SETC, 190 | XCORE_INS_SETD, 191 | XCORE_INS_SETEV, 192 | XCORE_INS_SETN, 193 | XCORE_INS_SETPSC, 194 | XCORE_INS_SETPT, 195 | XCORE_INS_SETRDY, 196 | XCORE_INS_SETSR, 197 | XCORE_INS_SETTW, 198 | XCORE_INS_SETV, 199 | XCORE_INS_SEXT, 200 | XCORE_INS_SHL, 201 | XCORE_INS_SHR, 202 | XCORE_INS_SSYNC, 203 | XCORE_INS_ST16, 204 | XCORE_INS_ST8, 205 | XCORE_INS_STW, 206 | XCORE_INS_SUB, 207 | XCORE_INS_SYNCR, 208 | XCORE_INS_TESTCT, 209 | XCORE_INS_TESTLCL, 210 | XCORE_INS_TESTWCT, 211 | XCORE_INS_TSETMR, 212 | XCORE_INS_START, 213 | XCORE_INS_WAITEF, 214 | XCORE_INS_WAITET, 215 | XCORE_INS_WAITEU, 216 | XCORE_INS_XOR, 217 | XCORE_INS_ZEXT, 218 | 219 | XCORE_INS_ENDING, // <-- mark the end of the list of instructions 220 | } xcore_insn; 221 | 222 | //> Group of XCore instructions 223 | typedef enum xcore_insn_group { 224 | XCORE_GRP_INVALID = 0, // = CS_GRP_INVALID 225 | 226 | //> Generic groups 227 | // all jump instructions (conditional+direct+indirect jumps) 228 | XCORE_GRP_JUMP, // = CS_GRP_JUMP 229 | 230 | XCORE_GRP_ENDING, // <-- mark the end of the list of groups 231 | } xcore_insn_group; 232 | 233 | #ifdef __cplusplus 234 | } 235 | #endif 236 | 237 | #endif 238 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_disasm.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_disasm.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_disasm_hpp 9 | #define kern_disasm_hpp 10 | 11 | #include 12 | #include 13 | 14 | #if defined(__i386__) 15 | #include 16 | #elif defined(__x86_64__) 17 | #include 18 | #else 19 | #error Unsupported arch. 20 | #endif 21 | 22 | #ifdef LILU_ADVANCED_DISASSEMBLY 23 | #ifndef CAPSTONE_HAS_OSXKERNEL 24 | #define CAPSTONE_HAS_OSXKERNEL 1 25 | #endif 26 | #include 27 | #endif /* LILU_ADVANCED_DISASSEMBLY */ 28 | 29 | #include 30 | #include 31 | 32 | class Disassembler { 33 | #ifdef LILU_ADVANCED_DISASSEMBLY 34 | /** 35 | * Because captsone handle can be 0 36 | */ 37 | bool initialised {false}; 38 | 39 | /** 40 | * Internal capstone handle 41 | */ 42 | size_t handle {}; 43 | #endif 44 | 45 | /** 46 | * Max instruction size 47 | */ 48 | static constexpr size_t MaxInstruction {15}; 49 | public: 50 | 51 | #if defined(__i386__) 52 | using hde_t = hde32s; 53 | static constexpr auto hde_disasm = hde32_disasm; 54 | #elif defined(__x86_64__) 55 | using hde_t = hde64s; 56 | static constexpr auto hde_disasm = hde64_disasm; 57 | #else 58 | #error Unsupported arch. 59 | #endif 60 | 61 | /** 62 | * Return the real instruction size contained within min bytes 63 | * Unlike instructionSize this uses HDE engine and at the cost of reduced compatibility it is much faster 64 | * Note: instruction pointer should point to at least min + 32 valid bytes. 65 | * 66 | * @param ptr instruction pointer 67 | * @param min minimal possible size 68 | * 69 | * @return instruction size >= min on success or 0 70 | */ 71 | EXPORT static size_t quickInstructionSize(mach_vm_address_t ptr, size_t min); 72 | 73 | /* Note, code should point to at least 32 valid bytes. */ 74 | EXPORT static size_t hdeDisasm(mach_vm_address_t code, hde_t *hs); 75 | 76 | #ifdef LILU_ADVANCED_DISASSEMBLY 77 | 78 | /** 79 | * Initialise advanced dissassembling framework 80 | * 81 | * @param detailed debugging output necessity 82 | * 83 | * @return true on success 84 | */ 85 | EXPORT bool init(bool detailed=false); 86 | 87 | /** 88 | * Deinitialise advanced dissassembling framework, must be called regardless of the init error 89 | */ 90 | EXPORT void deinit(); 91 | 92 | /** 93 | * Reads size bytes from addr and disassembles them. 94 | * 95 | * @param addr Address to read from 96 | * @param size Size of buffer to read 97 | * @param result Disassembled instructions array. You must free it 98 | * 99 | * @return size of result 100 | */ 101 | EXPORT size_t disasmBuf(mach_vm_address_t addr, size_t size, cs_insn **result); 102 | 103 | /** 104 | * Return the real instruction size contained within min bytes 105 | * 106 | * @param ptr instruction pointer 107 | * @param min minimal possible size 108 | * 109 | * @return instruction size >= min on success or 0 110 | */ 111 | EXPORT size_t instructionSize(mach_vm_address_t ptr, size_t min); 112 | 113 | /** 114 | * Reads lookup_size bytes from addr and disassembles them. 115 | * After disassembling, tries to find num-th entry with call instruction, which argument is an immediate value (some address). 116 | * 117 | * @param addr Address to read from 118 | * @param num Number of call instruction to search for 119 | * @param lookup_size Number of bytes to read 120 | * 121 | * @note It is assumed that the operand contains a positive relative address. 122 | * 123 | * @return direct address of num-th call instruction on success, else 0 124 | */ 125 | EXPORT mach_vm_address_t disasmNthSub(mach_vm_address_t addr, size_t num, size_t lookup_size); 126 | 127 | /** 128 | * @brief Reads lookup_size bytes from addr and disassembles them. 129 | * 130 | * After disassembling, tries to find num-th entry with jmp instruction, which argument is an immediate value (some address). 131 | * 132 | * @param addr Address to read from 133 | * @param num Number of jmp instruction to search for 134 | * @param lookup_size Number of bytes to read 135 | * 136 | * @note It is assumed that the operand contains a positive relative address. 137 | * 138 | * @return direct address of num-th jmp instruction on success, else 0 139 | */ 140 | EXPORT mach_vm_address_t disasmNthJmp(mach_vm_address_t addr, size_t num, size_t lookup_size); 141 | 142 | /** 143 | * Reads lookup_size bytes from addr and disassembles them. 144 | * After disassembling, tries to find num-th entry of inst instruction. 145 | * 146 | * @param addr Addres to read from 147 | * @param ins Instruction code 148 | * @param num Number of ins instruction to search for 149 | * @param lookup_size Number of bytes to read 150 | * 151 | * @return address of found instruction on success, else 0 152 | */ 153 | EXPORT mach_vm_address_t disasmNthIns(mach_vm_address_t addr, x86_insn ins, size_t num, size_t lookup_size); 154 | 155 | /** 156 | * Disassembly matching structure 157 | */ 158 | struct DisasmSig { 159 | x86_insn ins; // instruction 160 | bool sub; // relevant only for X86_INS_CALL, if its arg is X86_OP_IMM 161 | bool addr; // if you want to return the address of exact inst in sig 162 | 163 | static DisasmSig *create() { return new DisasmSig; } 164 | static void deleter(DisasmSig *sig NONNULL) { delete sig; } 165 | }; 166 | 167 | /** 168 | * Reads lookup_size bytes from addr and disassembles them. 169 | * After disassembling, tries to find num-th entry of sig instruction pattern. 170 | * 171 | * @param addr Address to read from 172 | * @param sig Instruction pattern 173 | * @param num Order of pattern to search for 174 | * @param lookup_size Number of bytes to read 175 | * 176 | * @return direct address of pattern start on success, else 0 177 | */ 178 | EXPORT mach_vm_address_t disasmSig(mach_vm_address_t addr, evector &sig, size_t num, size_t lookup_size); 179 | 180 | #endif /* LILU_ADVANCED_DISASSEMBLY */ 181 | }; 182 | 183 | #endif /* kern_disasm_hpp */ 184 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/Resources/VirtualSMCSDK/kern_smcinfo.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_smcinfo.hpp 3 | // VirtualSMC 4 | // 5 | // Copyright © 2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_smcinfo_h 9 | #define kern_smcinfo_h 10 | 11 | #include 12 | 13 | #include 14 | 15 | class SMCInfo { 16 | /** 17 | * Device-specific reproducible random state 18 | */ 19 | uint64_t generatorState {}; 20 | 21 | public: 22 | 23 | /** 24 | * Size in bytes for SmcKeyTypeRev keys 25 | */ 26 | static constexpr SMC_DATA_SIZE RevisionSize = 6; 27 | 28 | /** 29 | * Size in bytes for branch keys (usually ch8*) 30 | */ 31 | static constexpr SMC_DATA_SIZE BranchSize = 8; 32 | 33 | /** 34 | * Size in bytes for hardware model name 35 | */ 36 | static constexpr SMC_DATA_SIZE ModelSize = 64; 37 | 38 | /** 39 | * Size in bytes for MAC value 40 | */ 41 | static constexpr SMC_DATA_SIZE MacSize = 6; 42 | 43 | /** 44 | * Size in bytes for Serial value 45 | */ 46 | static constexpr SMC_DATA_SIZE SerialSize = 16; 47 | 48 | /** 49 | * Size in bytes for Motherboard Serial value 50 | */ 51 | static constexpr SMC_DATA_SIZE MotherboardSerialSize = 17; 52 | 53 | /** 54 | * Device generation: 55 | * - V1 is Big Endian Hitachi 56 | * - V2 is Little Endian ARM 57 | * - Unspecified is used for autodetection code 58 | */ 59 | enum class Generation { 60 | Unspecified = 0, 61 | V1 = 1, 62 | V2 = 2, 63 | V3 = 3 64 | }; 65 | 66 | /** 67 | * Device memory layout information 68 | */ 69 | struct Memory { 70 | mach_vm_address_t start; 71 | mach_vm_size_t size; 72 | vm_prot_t prot; 73 | }; 74 | 75 | /** 76 | * Buffers describing device version information 77 | */ 78 | enum class Buffer { 79 | RevMain, 80 | RevFlasherBase, 81 | RevFlasherUpdate, 82 | Branch, 83 | Platform, 84 | HardwareModel, 85 | MacAddress, 86 | Serial, 87 | MotherboardSerial 88 | }; 89 | 90 | /** 91 | * Corresponds to REV key contents 92 | */ 93 | SMC_DATA main[RevisionSize] {}; 94 | 95 | /** 96 | * Corresponds to RVBF key contents 97 | */ 98 | SMC_DATA flasherBase[RevisionSize] {}; 99 | 100 | /** 101 | * Corresponds to RVUF key contents 102 | */ 103 | SMC_DATA flasherUpdate[RevisionSize] {}; 104 | 105 | /** 106 | * Corresponds to RBr key contents 107 | */ 108 | SMC_DATA branch[BranchSize] {}; 109 | 110 | /** 111 | * Corresponds to RPlt key contents 112 | */ 113 | SMC_DATA platform[BranchSize] {}; 114 | 115 | /** 116 | * Corresponds to SMC hardware model (aka compatible key) 117 | */ 118 | SMC_DATA hardwareModel[ModelSize] {}; 119 | 120 | /** 121 | * Corresponds to RMAC key contents 122 | */ 123 | SMC_DATA macAddress[MacSize] {}; 124 | 125 | /** 126 | * Corresponds to RSSN key contents 127 | */ 128 | SMC_DATA serial[SerialSize] {}; 129 | 130 | /** 131 | * Corresponds to RSSN key contents 132 | */ 133 | SMC_DATA motherboardSerial[MotherboardSerialSize] {}; 134 | 135 | /** 136 | * Get device generation based on obtained buffers 137 | * 138 | * @return device generation 139 | */ 140 | Generation getGeneration() const { 141 | if (main[0] == 1) 142 | return Generation::V1; 143 | else if (main[0] == 2) 144 | return Generation::V2; 145 | else if (main[0] == 3 || main[0] == 0) 146 | return Generation::V3; 147 | DBGLOG("smcinfo", "invalid generation %X, defaulting to V2", main[0]); 148 | return Generation::V2; 149 | } 150 | 151 | /** 152 | * Initialise reproducible pseudo-random number generator with device info 153 | */ 154 | void generatorSeed() { 155 | union { 156 | uint8_t arr[8]; 157 | uint64_t raw; 158 | } seed; 159 | 160 | seed.arr[0] = main[0]; 161 | seed.arr[1] = main[1]; 162 | seed.arr[2] = main[3]; 163 | seed.arr[3] = main[5]; 164 | seed.arr[4] = branch[0]; 165 | seed.arr[5] = branch[1]; 166 | seed.arr[6] = branch[2]; 167 | seed.arr[7] = branch[4]; 168 | 169 | generatorState = seed.raw ^ 0x106689D45497FDB5; 170 | } 171 | 172 | /** 173 | * Get next reproducible pseudo-random number based on device info 174 | * generatorSeed must be called before using this function 175 | * 176 | * @return pseudo-random number 177 | */ 178 | uint64_t generatorRand() { 179 | uint64_t x = generatorState; 180 | x ^= x >> 12; // a 181 | x ^= x << 25; // b 182 | x ^= x >> 27; // c 183 | generatorState = x; 184 | return x * 0x2545F4914F6CDD1D; 185 | } 186 | 187 | /** 188 | * Get device information buffer 189 | * 190 | * @param id buffer id 191 | * 192 | * @return pointer to the buffer 193 | */ 194 | SMC_DATA *getBuffer(Buffer id) { 195 | switch (id) { 196 | case Buffer::RevMain: 197 | return main; 198 | case Buffer::RevFlasherBase: 199 | return flasherBase; 200 | case Buffer::RevFlasherUpdate: 201 | return flasherUpdate; 202 | case Buffer::Branch: 203 | return branch; 204 | case Buffer::Platform: 205 | return platform; 206 | case Buffer::HardwareModel: 207 | return hardwareModel; 208 | case Buffer::MacAddress: 209 | return macAddress; 210 | case Buffer::Serial: 211 | return serial; 212 | case Buffer::MotherboardSerial: 213 | return motherboardSerial; 214 | } 215 | } 216 | 217 | /** 218 | * Get device information buffer size 219 | * 220 | * @param id buffer id 221 | * 222 | * @return buffer size 223 | */ 224 | SMC_DATA_SIZE getBufferSize(Buffer id) { 225 | switch (id) { 226 | case Buffer::RevMain: 227 | case Buffer::RevFlasherBase: 228 | case Buffer::RevFlasherUpdate: 229 | return RevisionSize; 230 | case Buffer::Branch: 231 | case Buffer::Platform: 232 | return BranchSize; 233 | case Buffer::HardwareModel: 234 | return ModelSize; 235 | case Buffer::MacAddress: 236 | return MacSize; 237 | case Buffer::Serial: 238 | return SerialSize; 239 | case Buffer::MotherboardSerial: 240 | return MotherboardSerialSize; 241 | } 242 | } 243 | 244 | /** 245 | * Check if the necessary buffer information was supplied previously 246 | * 247 | * @return true if version info is ok 248 | */ 249 | bool isValid() const { 250 | // Note, we do not check mac/serial validity, as they are optional! 251 | // Everything but platform was also removed by T2! 252 | return platform[0] && hardwareModel[0]; 253 | } 254 | }; 255 | 256 | #endif /* kern_smcinfo_h */ 257 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_nvram.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_nvram.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_nvram_hpp 9 | #define kern_nvram_hpp 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * Some of the most common GUIDs used for variable storage on macOS 19 | */ 20 | #define NVRAM_GLOBAL_GUID "8BE4DF61-93CA-11D2-AA0D-00E098032B8C" 21 | #define NVRAM_APPLE_BOOT_GUID "7C436110-AB2A-4BBB-A880-FE41995C9F82" 22 | #define NVRAM_APPLE_VENDOR_GUID "4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14" 23 | #define NVRAM_APPLE_FILEVAULT_GUID "8D63D4FE-BD3C-4AAD-881D-86FD974BC1DF" 24 | #define NVRAM_APPLE_PASSWORD_UI_GUID "9EBA2D25-BBE3-4AC2-A2C6-C87F44A1278C" 25 | 26 | /** 27 | * Custom GUIDs used for Lilu preferences 28 | * Must be kept in sync to OcSupportPkg/Include/Guid/OcVariables.h 29 | */ 30 | #define LILU_VENDOR_GUID "4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102" 31 | #define LILU_READ_ONLY_GUID "E09B9297-7928-4440-9AAB-D1F8536FBF0A" 32 | #define LILU_WRITE_ONLY_GUID "F0B9AF8F-2222-4840-8A37-ECF7CC8C12E1" 33 | 34 | /** 35 | * Prefix variable name with a GUID 36 | */ 37 | #define NVRAM_PREFIX(x, y) x ":" y 38 | 39 | class NVStorage { 40 | /** 41 | * Local nvram controller reference 42 | */ 43 | IORegistryEntry *dtEntry {nullptr}; 44 | 45 | public: 46 | /** 47 | * Compress data with a default compression algorithm 48 | * 49 | * @param src source data 50 | * @param size data size (updated with new size) 51 | * @param sensitive contains sensitive data 52 | * 53 | * @return compressed data (must be freed with Buffer::deleter) or nullptr 54 | */ 55 | EXPORT uint8_t *compress(const uint8_t *src, uint32_t &size, bool sensitive=false); 56 | 57 | /** 58 | * Decompress data compressed with compress 59 | * 60 | * @param src compressed data 61 | * @param size data size (updated with new size) 62 | * @param sensitive contains sensitive data 63 | * 64 | * @return decompressed data (must be freed with Buffer::deleter) or nullptr 65 | */ 66 | EXPORT uint8_t *decompress(const uint8_t *src, uint32_t &size, bool sensitive=false); 67 | 68 | /** 69 | * Value storage options 70 | */ 71 | enum Options { 72 | OptAuto = 0, // Default options 73 | OptRaw = 1, // i/o as raw buffer 74 | OptCompressed = 2, // Apply compression (see kern_compression.hpp) 75 | OptEncrypted = 4, // Apply encryption with device-unique key (see kern_crypto.hpp) 76 | OptChecksum = 8, // Append CRC32 checksum to the end 77 | OptSensitive = 16 // Value contains sensitive data 78 | }; 79 | 80 | /** 81 | * Prepended value header unless OptRaw is used 82 | * After the header the following fields should go: 83 | * uint8_t iv[16]; aes initialisation vector (if OptEncrypted is set) 84 | * uint32_t size; decryption size (if OptEncrypted is set, encrypted) 85 | * uint32_t size; decompression size (if OptCompressed is set, encrypted if OptEncrypted) 86 | * uint8_t data[]; content data (encrypted if OptEncrypted) 87 | * uint32_t crc32; CRC32 cheksum (if OptChecksum is set) 88 | */ 89 | struct PACKED Header { 90 | static constexpr uint16_t Magic = 0xC717; 91 | static constexpr uint8_t MaxVer = 1; 92 | using Checksum = uint32_t; 93 | 94 | uint16_t magic {Magic}; 95 | uint8_t version {MaxVer}; 96 | uint8_t opts {OptAuto}; 97 | }; 98 | 99 | /** 100 | * Attempt to connect to active nvram, may fail at early stages 101 | * 102 | * @return true on success 103 | */ 104 | EXPORT bool init(); 105 | 106 | /** 107 | * Relinquish resources used, must be called regardless of the init error 108 | */ 109 | EXPORT void deinit(); 110 | 111 | /** 112 | * Read data from nvram 113 | * 114 | * @param key key name 115 | * @param size amount of data read 116 | * @param opts bitmask of Options, may set option requirements 117 | * @param enckey encryption key (platform-defined if OptEncrypted is set) 118 | * 119 | * @return pointer to data (must be freed via Buffer::deleter), nullptr on failure 120 | */ 121 | EXPORT uint8_t *read(const char *key, uint32_t &size, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr); 122 | 123 | /** 124 | * Read data from nvram 125 | * 126 | * @param key key name 127 | * @param opts bitmask of Options, may set option requirements 128 | * @param enckey encryption key (platform-defined if OptEncrypted is set) 129 | * 130 | * @return pointer to data (must be freed via OSData::release), nullptr on failure 131 | */ 132 | EXPORT OSData *read(const char *key, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr); 133 | 134 | /** 135 | * Write data to nvram 136 | * 137 | * @param key key name 138 | * @param src source buffer 139 | * @param size buffer size 140 | * @param opts bitmask of Options 141 | * @param enckey encryption key (platform-defined if OptEncrypted is set) 142 | * 143 | * @return true on success 144 | */ 145 | EXPORT bool write(const char *key, const uint8_t *src, uint32_t sz, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr); 146 | 147 | /** 148 | * Write data to nvram 149 | * 150 | * @param key key name 151 | * @param data data object to write 152 | * @param opts bitmask of Options 153 | * @param enckey encryption key (platform-defined if OptEncrypted is set) 154 | * 155 | * @return true on success 156 | */ 157 | EXPORT bool write(const char *key, const OSData *data, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr); 158 | 159 | /** 160 | * Delete key from nvram 161 | * 162 | * @param key key name 163 | * @param sensitive sensitive data 164 | * 165 | * @return true on successful deletion or if key is missing 166 | */ 167 | EXPORT bool remove(const char *key, bool sensitive=false); 168 | 169 | /** 170 | * Synchronize with nvram controller 171 | * This method might fail if synchronisation was done recently. 172 | * 173 | * @return true if synchronised 174 | */ 175 | EXPORT bool sync(); 176 | 177 | /** 178 | * Exports nvram to a plist file 179 | * 180 | * @param filename file path 181 | * @oaram max max output size 182 | * @param sensitive contains sensitive data 183 | * 184 | * @return true if saved 185 | */ 186 | EXPORT bool save(const char *filename, uint32_t max=0x20000, bool sensitive=false); 187 | 188 | /** 189 | * Check whether key exists 190 | * 191 | * @param key key name 192 | * 193 | * @return true if key exists 194 | */ 195 | EXPORT bool exists(const char *key); 196 | }; 197 | 198 | #endif /* kern_nvram_hpp */ 199 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_rtc.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_rtc.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_rtc_h 9 | #define kern_rtc_h 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class RTCStorage { 17 | /** 18 | * Apple-specific RTC checksum addresses 19 | */ 20 | static constexpr uint8_t APPLERTC_HASHED_ADDR = 0x0E; 21 | static constexpr uint8_t APPLERTC_CHECKSUM_ADDR1 = 0x58; 22 | static constexpr uint8_t APPLERTC_CHECKSUM_ADDR2 = 0x59; 23 | 24 | /** 25 | * AppleRTC service handle 26 | */ 27 | IOService *rtcSrv {nullptr}; 28 | 29 | /** 30 | * Low-level RTC read (does not check memory availability). 31 | * 32 | * @param dev RTC ACPI device 33 | * @param offset offset 34 | * 35 | * @result read value 36 | */ 37 | static uint8_t readByte(IOACPIPlatformDevice *dev, uint8_t offset); 38 | 39 | /** 40 | * Low-level RTC write (does not check memory availability). 41 | * 42 | * @param dev RTC ACPI device 43 | * @param offset offset 44 | * @param value value 45 | */ 46 | static void writeByte(IOACPIPlatformDevice *dev, uint8_t offset, uint8_t value); 47 | public: 48 | /** 49 | * General access RTC ports on x86 systems. 50 | */ 51 | static constexpr uint8_t R_PCH_RTC_INDEX = 0x70; 52 | static constexpr uint8_t R_PCH_RTC_TARGET = 0x71; 53 | static constexpr uint8_t R_PCH_RTC_EXT_INDEX = 0x72; 54 | static constexpr uint8_t R_PCH_RTC_EXT_TARGET = 0x73; 55 | 56 | /** 57 | * RTC has N banks (we support up to 2) of memory. 58 | */ 59 | static constexpr uint8_t RTC_BANK_SIZE = 0x80; 60 | 61 | /** 62 | * Non-ext RTC index register uses higher bit for nmi. 63 | */ 64 | static constexpr uint8_t RTC_DATA_MASK = 0x7F; 65 | static constexpr uint8_t RTC_NMI_MASK = 0x80; 66 | 67 | /** 68 | * Time offsets. 69 | */ 70 | static constexpr uint8_t RTC_SEC = 0x00; 71 | static constexpr uint8_t RTC_MIN = 0x02; 72 | static constexpr uint8_t RTC_HOUR = 0x04; 73 | 74 | static constexpr uint8_t RTC_DAY = 0x07; 75 | static constexpr uint8_t RTC_MON = 0x08; 76 | static constexpr uint8_t RTC_YEAR = 0x09; 77 | 78 | #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5 79 | using t_UserClientExternalMethod = IOReturn (*)(IORegistryEntry *service, uint32_t selector, IOExternalMethodArguments * arguments, 80 | IOExternalMethodDispatch * dispatch, OSObject * target, void * reference); 81 | static constexpr size_t UserClientExternalMethodIndex = 0x129; 82 | #endif 83 | 84 | /** 85 | * Attempt to connect to active RTC service 86 | * 87 | * @param wait wait for service availability 88 | * 89 | * @return true on success 90 | */ 91 | EXPORT bool init(bool wait=true); 92 | 93 | /** 94 | * Release obtained RTC service 95 | */ 96 | EXPORT void deinit(); 97 | 98 | /** 99 | * Check whether extended (higher 128 bytes) is available 100 | * 101 | * @return true on success 102 | */ 103 | EXPORT bool checkExtendedMemory(); 104 | 105 | /** 106 | * Read memory from RTC 107 | * 108 | * @param off offset to read data from 109 | * @param size data size 110 | * @param buffer data buffer to read to 111 | * 112 | * @return true on success 113 | */ 114 | EXPORT bool read(uint64_t off, uint32_t size, uint8_t *buffer); 115 | 116 | /** 117 | * Write memory to RTC 118 | * 119 | * @param off offset to write data to 120 | * @param size data size 121 | * @param buffer data buffer to write from 122 | * 123 | * @return true on success 124 | */ 125 | EXPORT bool write(uint64_t off, uint32_t size, uint8_t *buffer); 126 | 127 | /** 128 | * Obtain RTC device for direct writing. 129 | * Written as inline to avoid IOACPIPlatformDevice dependency. 130 | * 131 | * @param name device name 132 | * 133 | * @return RTC ACPI device for I/O access, must be released 134 | */ 135 | static inline IOACPIPlatformDevice *getRTCDevice(const char *name = "PNP0B00") { 136 | IOService *rtcDev = nullptr; 137 | auto matching = IOService::nameMatching(name); 138 | if (matching) { 139 | #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6 140 | rtcDev = IOService::waitForService(matching); 141 | if (rtcDev) 142 | rtcDev->retain(); 143 | #else 144 | rtcDev = IOService::waitForMatchingService(matching); 145 | matching->release(); 146 | #endif 147 | 148 | } else { 149 | SYSLOG("rtc", "failed to allocate rtc device matching"); 150 | } 151 | 152 | if (rtcDev) { 153 | DBGLOG("rtc", "got rtc device"); 154 | auto acpiDev = OSDynamicCast(IOACPIPlatformDevice, rtcDev); 155 | if (acpiDev) { 156 | DBGLOG("rtc", "got rtc acpi device"); 157 | return acpiDev; 158 | } else { 159 | SYSLOG("rtc", "failed to obtain rtc acpi device"); 160 | rtcDev->release(); 161 | } 162 | } 163 | 164 | SYSLOG("rtc", "failed to get rtc device"); 165 | return nullptr; 166 | } 167 | 168 | /** 169 | * Directly read RTC memory (UNSAFE, usage with caution!) 170 | * 171 | * @param dev RTC device 172 | * @param off offset to read data from 173 | * @param size data size 174 | * @param buffer data buffer to read to 175 | * @param introff turn interrupts off 176 | * 177 | * @return true on success 178 | */ 179 | EXPORT static void readDirect(IOACPIPlatformDevice *dev, uint8_t off, uint16_t size, uint8_t *buffer, bool introff); 180 | 181 | /** 182 | * Directly write RTC memory (UNSAFE, usage with caution!) 183 | * 184 | * @param dev RTC device 185 | * @param off offset to read data from 186 | * @param size data size 187 | * @param buffer data buffer to read to 188 | * @param updatecrc recalculate crc on write 189 | * @param introff turn interrupts off 190 | * 191 | * @return true on success 192 | */ 193 | EXPORT static void writeDirect(IOACPIPlatformDevice *dev, uint8_t off, uint16_t size, uint8_t *buffer, bool updatecrc, bool introff); 194 | 195 | 196 | /** 197 | * Directly read RTC memory (UNSAFE, usage with caution!), this is just a compatibility function. 198 | * 199 | * @param off offset to read data from 200 | * @param size data size 201 | * @param buffer data buffer to read to 202 | * @param introff turn interrupts off 203 | * 204 | * @return true on success 205 | */ 206 | static inline bool readDirect(uint8_t off, uint16_t size, uint8_t *buffer, bool introff) { 207 | if (size > RTC_BANK_SIZE*2 - off) { 208 | SYSLOG("rtc", "reading unsupported size"); 209 | return false; 210 | } 211 | 212 | auto rtc = getRTCDevice(); 213 | if (rtc) { 214 | readDirect(rtc, off, size, buffer, introff); 215 | rtc->release(); 216 | return true; 217 | } 218 | 219 | return false; 220 | } 221 | 222 | /** 223 | * Directly write RTC memory (UNSAFE, usage with caution!), this is just a compatibility function. 224 | * 225 | * @param off offset to read data from 226 | * @param size data size 227 | * @param buffer data buffer to read to 228 | * @param updatecrc recalculate crc on write 229 | * @param introff turn interrupts off 230 | * 231 | * @return true on success 232 | */ 233 | static inline bool writeDirect(uint8_t off, uint16_t size, uint8_t *buffer, bool updatecrc, bool introff) { 234 | if (size > RTC_BANK_SIZE*2 - off) { 235 | SYSLOG("rtc", "writing unsupported size"); 236 | return false; 237 | } 238 | 239 | auto rtc = getRTCDevice(); 240 | if (rtc) { 241 | writeDirect(rtc, off, size, buffer, updatecrc, introff); 242 | rtc->release(); 243 | return true; 244 | } 245 | 246 | return false; 247 | } 248 | }; 249 | 250 | #endif /* kern_rtc_h */ 251 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 20G624 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | VirtualSMC 11 | CFBundleIdentifier 12 | as.vit9696.VirtualSMC 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | VirtualSMC 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 1.3.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleSupportedPlatforms 24 | 25 | MacOSX 26 | 27 | CFBundleVersion 28 | 1.3.0 29 | DTCompiler 30 | com.apple.compilers.llvm.clang.1_0 31 | DTPlatformBuild 32 | 13C100 33 | DTPlatformName 34 | macosx 35 | DTPlatformVersion 36 | 12.1 37 | DTSDKBuild 38 | 21C46 39 | DTSDKName 40 | macosx12.1 41 | DTXcode 42 | 1321 43 | DTXcodeBuild 44 | 13C100 45 | IOKitPersonalities 46 | 47 | as.vit9696.VirtualSMC 48 | 49 | CFBundleIdentifier 50 | as.vit9696.VirtualSMC 51 | IOClass 52 | VirtualSMC 53 | IODeviceMemory 54 | 55 | 56 | 57 | address 58 | 768 59 | length 60 | 32 61 | 62 | 63 | 64 | 65 | address 66 | 4277141504 67 | length 68 | 65536 69 | 70 | 71 | 72 | IOInterruptControllers 73 | 74 | io-apic-0 75 | 76 | IOInterruptSpecifiers 77 | 78 | 79 | BgAAAAAAAAA= 80 | 81 | 82 | IOMatchCategory 83 | IOACPIPlatformDevice 84 | IOName 85 | SMC 86 | IOProbeScore 87 | 60000 88 | IOProviderClass 89 | AppleACPIPlatformExpert 90 | Keystore 91 | 92 | Generic 93 | 94 | 95 | attr 96 | 97 | iA== 98 | 99 | comment 100 | Total fan number, this should be put to a plugin 101 | name 102 | 103 | Rk51bQ== 104 | 105 | type 106 | 107 | dWk4IA== 108 | 109 | value 110 | 111 | AA== 112 | 113 | 114 | 115 | attr 116 | 117 | gA== 118 | 119 | comment 120 | CPU plimit 121 | name 122 | 123 | TVNUYw== 124 | 125 | type 126 | 127 | dWk4IA== 128 | 129 | value 130 | 131 | AA== 132 | 133 | 134 | 135 | attr 136 | 137 | gA== 138 | 139 | comment 140 | FAN plimit (supposedly) 141 | name 142 | 143 | TVNUZg== 144 | 145 | type 146 | 147 | dWk4IA== 148 | 149 | value 150 | 151 | AA== 152 | 153 | 154 | 155 | attr 156 | 157 | gA== 158 | 159 | comment 160 | Memory plimit 161 | name 162 | 163 | TVNUbQ== 164 | 165 | type 166 | 167 | dWk4IA== 168 | 169 | value 170 | 171 | AA== 172 | 173 | 174 | 175 | attr 176 | 177 | gA== 178 | 179 | comment 180 | This should be 1 on laptops, and is overriden by sensors 181 | name 182 | 183 | QkFUUA== 184 | 185 | type 186 | 187 | ZmxhZw== 188 | 189 | value 190 | 191 | AA== 192 | 193 | 194 | 195 | attr 196 | 197 | gA== 198 | 199 | comment 200 | Only MacPros have custom illumination controllers 201 | name 202 | 203 | THNOTQ== 204 | 205 | type 206 | 207 | dWk4IA== 208 | 209 | value 210 | 211 | AA== 212 | 213 | 214 | 215 | GenericDesktopV1 216 | 217 | GenericDesktopV2 218 | 219 | GenericLaptopV1 220 | 221 | GenericLaptopV2 222 | 223 | GenericV1 224 | 225 | 226 | attr 227 | 228 | gA== 229 | 230 | comment 231 | GPU plimit 232 | name 233 | 234 | TVNUZw== 235 | 236 | type 237 | 238 | dWk4IA== 239 | 240 | value 241 | 242 | AA== 243 | 244 | 245 | 246 | GenericV2 247 | 248 | 249 | attr 250 | 251 | gA== 252 | 253 | comment 254 | E plimit (???) 255 | name 256 | 257 | TVNUZQ== 258 | 259 | type 260 | 261 | dWk4IA== 262 | 263 | value 264 | 265 | AA== 266 | 267 | 268 | 269 | attr 270 | 271 | gA== 272 | 273 | comment 274 | I plimit (???) 275 | name 276 | 277 | TVNUaQ== 278 | 279 | type 280 | 281 | dWk4IA== 282 | 283 | value 284 | 285 | AA== 286 | 287 | 288 | 289 | attr 290 | 291 | gA== 292 | 293 | comment 294 | J plimit (???) 295 | name 296 | 297 | TVNUag== 298 | 299 | type 300 | 301 | dWk4IA== 302 | 303 | value 304 | 305 | AA== 306 | 307 | 308 | 309 | 310 | ModelInfo 311 | 312 | GenericV1 313 | 314 | branch 315 | 316 | ajUyAAAAAAA= 317 | 318 | hwname 319 | 320 | c21jLXBpa2V0b24A 321 | 322 | platform 323 | 324 | ajUyAAAAAAA= 325 | 326 | rev 327 | 328 | AXQPAAAE 329 | 330 | revfb 331 | 332 | AXQPAAAE 333 | 334 | revfu 335 | 336 | AXQPAAAE 337 | 338 | 339 | GenericV2 340 | 341 | branch 342 | 343 | ajUyAAAAAAA= 344 | 345 | hwname 346 | 347 | c21jLWh1cm9ucml2ZXIA 348 | 349 | platform 350 | 351 | ajUyAAAAAAA= 352 | 353 | rev 354 | 355 | AigPAAAH 356 | 357 | revfb 358 | 359 | AigPAAAH 360 | 361 | revfu 362 | 363 | AigPAAAH 364 | 365 | 366 | GenericV3 367 | 368 | hwname 369 | 370 | c21jLWh1cm9ucml2ZXIA 371 | 372 | platform 373 | 374 | ajUyAAAAAAA= 375 | 376 | 377 | 378 | _STA 379 | 11 380 | name 381 | 382 | QVBQMDAwMQA= 383 | 384 | 385 | 386 | LSMinimumSystemVersion 387 | 10.6 388 | NSHumanReadableCopyright 389 | Copyright © 2017 vit9696. All rights reserved. 390 | OSBundleCompatibleVersion 391 | 1.0 392 | OSBundleLibraries 393 | 394 | as.vit9696.Lilu 395 | 1.2.0 396 | com.apple.iokit.IOACPIFamily 397 | 1.0.0d1 398 | com.apple.kernel.6.0 399 | 7.9.9 400 | com.apple.kpi.bsd 401 | 8.0.0 402 | com.apple.kpi.iokit 403 | 8.0.0 404 | com.apple.kpi.libkern 405 | 8.0.0 406 | com.apple.kpi.mach 407 | 8.0.0 408 | com.apple.kpi.unsupported 409 | 8.0.0 410 | 411 | OSBundleLibraries_x86_64 412 | 413 | as.vit9696.Lilu 414 | 1.2.0 415 | com.apple.iokit.IOACPIFamily 416 | 1.0.0d1 417 | com.apple.kpi.bsd 418 | 10.0.0 419 | com.apple.kpi.iokit 420 | 10.0.0 421 | com.apple.kpi.libkern 422 | 10.0.0 423 | com.apple.kpi.mach 424 | 10.0.0 425 | com.apple.kpi.unsupported 426 | 10.0.0 427 | 428 | OSBundleRequired 429 | Root 430 | 431 | 432 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_iokit.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_iokit.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_iokit_hpp 9 | #define kern_iokit_hpp 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace WIOKit { 19 | 20 | /** 21 | * AppleHDAEngine::getLocation teaches us to use loop infinitely when talking to IOReg 22 | * This feels mad and insane, since it may prevent the system from booting. 23 | * Although this had never happened, we will use a far bigger fail-safe stop value. 24 | */ 25 | static constexpr size_t bruteMax {40000000}; 26 | 27 | /** 28 | * Read typed OSData 29 | * 30 | * @param obj read object 31 | * @param value read value 32 | * @param name propert name 33 | * 34 | * @return true on success 35 | */ 36 | template 37 | inline bool getOSDataValue(const OSObject *obj, const char *name, T &value) { 38 | if (obj) { 39 | auto data = OSDynamicCast(OSData, obj); 40 | if (data && data->getLength() == sizeof(T)) { 41 | value = *static_cast(data->getBytesNoCopy()); 42 | DBGLOG("iokit", "getOSData %s has %llX value", name, static_cast(value)); 43 | return true; 44 | } else { 45 | SYSLOG("iokit", "getOSData %s has unexpected format", name); 46 | } 47 | } else { 48 | DBGLOG("iokit", "getOSData %s was not found", name); 49 | } 50 | return false; 51 | } 52 | 53 | /** 54 | * Read typed OSData through a temp type 55 | * 56 | * @param obj read object 57 | * @param value read value 58 | * @param name propert name 59 | * 60 | * @return true on success 61 | */ 62 | template 63 | inline bool getOSDataValue(const OSObject *obj, const char *name, T &value) { 64 | AS tmp; 65 | if (getOSDataValue(obj, name, tmp)) { 66 | value = static_cast(tmp); 67 | return true; 68 | } 69 | 70 | return false; 71 | } 72 | 73 | /** 74 | * Read typed OSData from IORegistryEntry 75 | * 76 | * @see getOSDataValue 77 | */ 78 | template 79 | inline bool getOSDataValue(const IORegistryEntry *sect, const char *name, T &value) { 80 | return getOSDataValue(sect->getProperty(name), name, value); 81 | } 82 | 83 | /** 84 | * Read typed OSData from IORegistryEntry 85 | * 86 | * @see getOSDataValue 87 | */ 88 | template 89 | inline bool getOSDataValue(const IORegistryEntry *sect, const char *name, T &value) { 90 | return getOSDataValue(sect->getProperty(name), name, value); 91 | } 92 | 93 | /** 94 | * Read typed OSData from IORegistryEntry 95 | * 96 | * @see getOSDataValue 97 | */ 98 | template 99 | inline bool getOSDataValue(const OSDictionary *dict, const char *name, T &value) { 100 | return getOSDataValue(dict->getObject(name), name, value); 101 | } 102 | 103 | /** 104 | * Read typed OSData from IORegistryEntry 105 | * 106 | * @see getOSDataValue 107 | */ 108 | template 109 | inline bool getOSDataValue(const OSDictionary *dict, const char *name, T &value) { 110 | return getOSDataValue(dict->getObject(name), name, value); 111 | } 112 | 113 | /** 114 | * Retrieve property object 115 | * 116 | * @param entry IORegistry entry 117 | * @param property property name 118 | * 119 | * @return property object (must be released) or nullptr 120 | */ 121 | EXPORT LIBKERN_RETURNS_RETAINED OSSerialize *getProperty(IORegistryEntry *entry, const char *property); 122 | 123 | /** 124 | * Model variants 125 | */ 126 | struct ComputerModel { 127 | enum { 128 | ComputerInvalid = 0x0, 129 | ComputerLaptop = 0x1, 130 | ComputerDesktop = 0x2, 131 | ComputerAny = ComputerLaptop | ComputerDesktop 132 | }; 133 | }; 134 | 135 | /** 136 | * PCI GPU Vendor identifiers 137 | */ 138 | struct VendorID { 139 | enum : uint16_t { 140 | ATIAMD = 0x1002, 141 | AMDZEN = 0x1022, 142 | NVIDIA = 0x10DE, 143 | Intel = 0x8086, 144 | VMware = 0x15AD, 145 | QEMU = 0x1B36, 146 | }; 147 | }; 148 | 149 | /** 150 | * PCI class codes 151 | */ 152 | struct ClassCode { 153 | enum : uint32_t { 154 | VGAController = 0x030000, 155 | // I have never seen this one, but laptops are evil. 156 | XGAController = 0x030100, 157 | // Some laptops use this for Optimus GPUs. 158 | Ex3DController = 0x030200, 159 | DisplayController = 0x038000, 160 | PCIBridge = 0x060400, 161 | // HDA device on some laptops like Acer Aspire VN7-592G (INSYDE). 162 | HDAMmDevice = 0x040100, 163 | // Watch out for PCISubclassMask, 0x040380 is common on laptops. 164 | HDADevice = 0x040300, 165 | // This does not seem to be documented. It works on Haswell at least. 166 | IMEI = 0x078000, 167 | // To ignore device subclasses. 168 | PCISubclassMask = 0xFFFF00, 169 | }; 170 | }; 171 | 172 | /** 173 | * Definitions of PCI Config Registers 174 | */ 175 | enum PCIRegister : uint8_t { 176 | kIOPCIConfigVendorID = 0x00, 177 | kIOPCIConfigDeviceID = 0x02, 178 | kIOPCIConfigCommand = 0x04, 179 | kIOPCIConfigStatus = 0x06, 180 | kIOPCIConfigRevisionID = 0x08, 181 | kIOPCIConfigClassCode = 0x09, 182 | kIOPCIConfigCacheLineSize = 0x0C, 183 | kIOPCIConfigLatencyTimer = 0x0D, 184 | kIOPCIConfigHeaderType = 0x0E, 185 | kIOPCIConfigBIST = 0x0F, 186 | kIOPCIConfigBaseAddress0 = 0x10, 187 | kIOPCIConfigBaseAddress1 = 0x14, 188 | kIOPCIConfigBaseAddress2 = 0x18, 189 | kIOPCIConfigBaseAddress3 = 0x1C, 190 | kIOPCIConfigBaseAddress4 = 0x20, 191 | kIOPCIConfigBaseAddress5 = 0x24, 192 | kIOPCIConfigCardBusCISPtr = 0x28, 193 | kIOPCIConfigSubSystemVendorID = 0x2C, 194 | kIOPCIConfigSubSystemID = 0x2E, 195 | kIOPCIConfigExpansionROMBase = 0x30, 196 | kIOPCIConfigCapabilitiesPtr = 0x34, 197 | kIOPCIConfigInterruptLine = 0x3C, 198 | kIOPCIConfigInterruptPin = 0x3D, 199 | kIOPCIConfigMinimumGrant = 0x3E, 200 | kIOPCIConfigMaximumLatency = 0x3F, 201 | kIOPCIConfigGraphicsControl = 0x50 202 | }; 203 | 204 | /** 205 | * Fixed offsets for PCI Config I/O virtual methods 206 | */ 207 | struct PCIConfigOffset { 208 | enum : size_t { 209 | ConfigRead32 = 0x10A, 210 | ConfigWrite32 = 0x10B, 211 | ConfigRead16 = 0x10C, 212 | ConfigWrite16 = 0x10D, 213 | ConfigRead8 = 0x10E, 214 | ConfigWrite8 = 0x10F, 215 | GetBusNumber = 0x11D, 216 | GetDeviceNumber = 0x11E, 217 | GetFunctionNumber = 0x11F 218 | }; 219 | }; 220 | 221 | /** 222 | * PCI Config I/O method prototypes 223 | */ 224 | using t_PCIConfigRead32 = uint32_t (*)(IORegistryEntry *service, uint32_t space, uint8_t offset); 225 | using t_PCIConfigRead16 = uint16_t (*)(IORegistryEntry *service, uint32_t space, uint8_t offset); 226 | using t_PCIConfigRead8 = uint8_t (*)(IORegistryEntry *service, uint32_t space, uint8_t offset); 227 | using t_PCIConfigWrite32 = void (*)(IORegistryEntry *service, uint32_t space, uint8_t offset, uint32_t data); 228 | using t_PCIConfigWrite16 = void (*)(IORegistryEntry *service, uint32_t space, uint8_t offset, uint16_t data); 229 | using t_PCIConfigWrite8 = void (*)(IORegistryEntry *service, uint32_t space, uint8_t offset, uint8_t data); 230 | using t_PCIGetBusNumber = uint8_t (*)(IORegistryEntry *service); 231 | using t_PCIGetDeviceNumber = uint8_t (*)(IORegistryEntry *service); 232 | using t_PCIGetFunctionNumber = uint8_t (*)(IORegistryEntry *service); 233 | 234 | /** 235 | * Await for device publishing in IOService plane 236 | * 237 | * @param obj wait for (PCI) object publishing 238 | * 239 | * @retval true on success 240 | */ 241 | EXPORT bool awaitPublishing(IORegistryEntry *obj); 242 | 243 | /** 244 | * Read PCI Config register 245 | * 246 | * @param service IOPCIDevice-compatible service. 247 | * @param reg PCI config register 248 | * @param space adress space 249 | * @param size read size for reading custom registers 250 | * 251 | * @return value read 252 | */ 253 | EXPORT uint32_t readPCIConfigValue(IORegistryEntry *service, uint32_t reg, uint32_t space = 0, uint32_t size = 0); 254 | 255 | /** 256 | * Retrieve PCI device address 257 | * 258 | * @param service IOPCIDevice-compatible service. 259 | * @param bus bus address 260 | * @param device device address 261 | * @param function function address 262 | */ 263 | EXPORT void getDeviceAddress(IORegistryEntry *service, uint8_t &bus, uint8_t &device, uint8_t &function); 264 | 265 | /** 266 | * Retrieve the computer type 267 | * 268 | * @return valid computer type or ComputerAny 269 | */ 270 | EXPORT int getComputerModel() DEPRECATE("Use BaseDeviceInfo"); 271 | 272 | /** 273 | * Retrieve computer model and/or board-id properties 274 | * 275 | * @param model model name output buffer or null 276 | * @param modelsz model name output buffer size 277 | * @param board board identifier output buffer or null 278 | * @param boardsz board identifier output buffer size 279 | * 280 | * @return true if relevant properties already are available, otherwise buffers are unchanged 281 | */ 282 | EXPORT bool getComputerInfo(char *model, size_t modelsz, char *board, size_t boardsz) DEPRECATE("Use BaseDeviceInfo"); 283 | 284 | /** 285 | * Retrieve an ioreg entry by path/prefix 286 | * 287 | * @param path an exact lookup path 288 | * @param prefix entry prefix at path 289 | * @param plane plane to lookup in 290 | * @param proc process every found entry with the method 291 | * @param brute kick ioreg until a value is found 292 | * @param user pass some value to the callback function 293 | * 294 | * @return entry pointer (must NOT be released) or nullptr (on failure or in proc mode) 295 | */ 296 | EXPORT LIBKERN_RETURNS_NOT_RETAINED IORegistryEntry *findEntryByPrefix(const char *path, const char *prefix, const IORegistryPlane *plane, bool (*proc)(void *, IORegistryEntry *)=nullptr, bool brute=false, void *user=nullptr); 297 | 298 | /** 299 | * Retrieve an ioreg entry by path/prefix 300 | * 301 | * @param entry an ioreg entry to look in 302 | * @param prefix entry prefix at path 303 | * @param plane plane to lookup in 304 | * @param proc process every found entry with the method 305 | * @param brute kick ioreg until a value is found 306 | * @param user pass some value to the callback function 307 | * 308 | * @return entry pointer (must NOT be released) or nullptr (on failure or in proc mode) 309 | */ 310 | EXPORT LIBKERN_RETURNS_NOT_RETAINED IORegistryEntry *findEntryByPrefix(IORegistryEntry *entry, const char *prefix, const IORegistryPlane *plane, bool (*proc)(void *, IORegistryEntry *)=nullptr, bool brute=false, void *user=nullptr); 311 | 312 | /** 313 | * Check if we are using prelinked kernel/kexts or not 314 | * 315 | * @return true when confirmed that we definitely are 316 | */ 317 | EXPORT bool usingPrelinkedCache(); 318 | 319 | /** 320 | * Properly rename the device 321 | * 322 | * @param entry device to rename 323 | * @param name new name 324 | * @param compat correct compatible 325 | * 326 | * @return true on success 327 | */ 328 | EXPORT bool renameDevice(IORegistryEntry *entry, const char *name, bool compat=true); 329 | } 330 | 331 | #endif /* kern_iokit_hpp */ 332 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_mach.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_mach.hpp 3 | // Lilu 4 | // 5 | // Certain parts of code are the subject of 6 | // copyright © 2011, 2012, 2013, 2014 fG!, reverser@put.as - http://reverse.put.as 7 | // Copyright © 2016-2017 vit9696. All rights reserved. 8 | // 9 | 10 | #ifndef kern_mach_hpp 11 | #define kern_mach_hpp 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | class MachInfo { 24 | #if defined(__i386__) 25 | using mach_header_native = mach_header; 26 | using segment_command_native = segment_command; 27 | using nlist_native = struct nlist; 28 | 29 | static constexpr uint8_t SegmentTypeNative {LC_SEGMENT}; 30 | static constexpr uint32_t MachMagicNative {MH_MAGIC}; 31 | static constexpr uint32_t MachCpuTypeNative {CPU_TYPE_I386}; 32 | 33 | #elif defined(__x86_64__) 34 | using mach_header_native = mach_header_64; 35 | using segment_command_native = segment_command_64; 36 | using nlist_native = struct nlist_64; 37 | 38 | static constexpr uint8_t SegmentTypeNative {LC_SEGMENT_64}; 39 | static constexpr uint32_t MachMagicNative {MH_MAGIC_64}; 40 | static constexpr uint32_t MachCpuTypeNative {CPU_TYPE_X86_64}; 41 | 42 | #else 43 | #error Unsupported arch. 44 | #endif 45 | 46 | mach_vm_address_t running_text_addr {0}; // the address of running __TEXT segment 47 | mach_vm_address_t disk_text_addr {0}; // the same address at from a file 48 | mach_vm_address_t kaslr_slide {0}; // the kernel aslr slide, computed as the difference between above's addresses 49 | uint8_t *file_buf {nullptr}; // read file data 50 | OSDictionary *prelink_dict {nullptr}; // read prealinked kext dictionary 51 | uint8_t *prelink_addr {nullptr}; // prelink text base address 52 | mach_vm_address_t prelink_vmaddr {0}; // prelink text base vm address (for kexts this is their actual slide) 53 | uint32_t file_buf_size {0}; // read file data size 54 | uint8_t *sym_buf {nullptr}; // pointer to buffer (normally __LINKEDIT) containing symbols to solve 55 | bool sym_buf_ro {false}; // sym_buf is read-only (not copy). 56 | uint64_t sym_fileoff {0}; // file offset of symbols (normally __LINKEDIT) so we can read 57 | size_t sym_size {0}; 58 | uint32_t symboltable_fileoff {0}; // file offset to symbol table - used to position inside the __LINKEDIT buffer 59 | uint32_t symboltable_nr_symbols {0}; 60 | uint32_t stringtable_fileoff {0}; // file offset to string table 61 | uint32_t stringtable_size {0}; 62 | mach_header_native *running_mh {nullptr}; // pointer to mach-o header of running kernel item 63 | mach_vm_address_t address_slots {0}; // pointer after mach-o header to store pointers 64 | mach_vm_address_t address_slots_end {0}; // pointer after mach-o header to store pointers 65 | off_t fat_offset {0}; // additional fat offset 66 | size_t memory_size {HeaderSize}; // memory size 67 | bool kaslr_slide_set {false}; // kaslr can be null, used for disambiguation 68 | bool allow_decompress {true}; // allows mach decompression 69 | bool prelink_slid {false}; // assume kaslr-slid kext addresses 70 | bool kernel_collection {false}; // kernel collection (11.0+) 71 | uint64_t self_uuid[2] {}; // saved uuid of the loaded kext or kernel 72 | 73 | /** 74 | * Kernel slide is aligned by 20 bits 75 | */ 76 | static constexpr size_t KASLRAlignment {0x100000}; 77 | 78 | /** 79 | * Retrieve LC_UUID command value from a mach header 80 | * 81 | * @param header mach header pointer 82 | * 83 | * @return UUID or nullptr 84 | */ 85 | uint64_t *getUUID(void *header); 86 | 87 | /** 88 | * Retrieve and preserve LC_UUID command value from a mach header 89 | * 90 | * @param header mach header pointer 91 | * 92 | * @return true on success 93 | */ 94 | bool loadUUID(void *header); 95 | 96 | /** 97 | * Enable/disable the Write Protection bit in CR0 register 98 | * 99 | * @param enable the desired value 100 | * 101 | * @return KERN_SUCCESS if succeeded 102 | */ 103 | static kern_return_t setWPBit(bool enable); 104 | 105 | /** 106 | * Retrieve the first pages of a binary at disk into a buffer 107 | * Version that uses KPI VFS functions and a ripped uio_createwithbuffer() from XNU 108 | * 109 | * @param buffer allocated buffer sized no less than HeaderSize 110 | * @param vnode file node 111 | * @param ctxt filesystem context 112 | * @param decompress enable decompression 113 | * @param off fat offset or 0 114 | * 115 | * @return KERN_SUCCESS if the read data contains 64-bit mach header 116 | */ 117 | kern_return_t readMachHeader(uint8_t *buffer, vnode_t vnode, vfs_context_t ctxt, off_t off=0); 118 | 119 | /** 120 | * Retrieve the whole symbol table (typically contained within the linkedit segment) into target buffer from kernel binary at disk 121 | * 122 | * @param vnode file node 123 | * @param ctxt filesystem context 124 | * 125 | * @return KERN_SUCCESS on success 126 | */ 127 | kern_return_t readSymbols(vnode_t vnode, vfs_context_t ctxt); 128 | 129 | /** 130 | * Retrieve necessary mach-o header information from the mach header 131 | * 132 | * @param header read header sized no less than HeaderSize 133 | */ 134 | void processMachHeader(void *header); 135 | 136 | /** 137 | * Load kext info dictionary and addresses if they were not loaded previously 138 | */ 139 | void updatePrelinkInfo(); 140 | 141 | /** 142 | * Lookup mach image in prelinked image 143 | * 144 | * @param identifier identifier 145 | * @param imageSize size of the returned buffer 146 | * @param slide actual slide for symbols (normally kaslr or 0) 147 | * @param missing set to true on successful prelink parsing when image is not needed 148 | * 149 | * @return pointer to const buffer on success or nullptr 150 | */ 151 | uint8_t *findImage(const char *identifier, uint32_t &imageSize, mach_vm_address_t &slide, bool &missing); 152 | 153 | MachInfo(bool asKernel, const char *id) : isKernel(asKernel), objectId(id) { 154 | DBGLOG("mach", "MachInfo asKernel %d object constructed", asKernel); 155 | } 156 | MachInfo(const MachInfo &) = delete; 157 | MachInfo &operator =(const MachInfo &) = delete; 158 | 159 | /** 160 | * Resolve mach data in the kernel via prelinked cache 161 | * 162 | * @param prelink prelink information source (i.e. Kernel MachInfo) 163 | * 164 | * @return KERN_SUCCESS if loaded 165 | */ 166 | kern_return_t initFromPrelinked(MachInfo *prelink); 167 | 168 | /** 169 | * Resolve mach data in the kernel via filesystem access 170 | * 171 | * @param paths filesystem paths for lookup 172 | * @param num the number of paths passed 173 | * 174 | * @return KERN_SUCCESS if loaded 175 | */ 176 | kern_return_t initFromFileSystem(const char * const paths[], size_t num); 177 | 178 | /** 179 | * Resolve mach data in the kernel via memory access 180 | * 181 | * @return KERN_SUCCESS if loaded 182 | */ 183 | kern_return_t initFromMemory(); 184 | 185 | public: 186 | 187 | /** 188 | * Each header is assumed to fit two pages 189 | */ 190 | static constexpr size_t HeaderSize {PAGE_SIZE_64*2}; 191 | 192 | /** 193 | * Representation mode (kernel/kext) 194 | */ 195 | EXPORT const bool isKernel; 196 | 197 | /** 198 | * Specified file identifier 199 | */ 200 | EXPORT const char *objectId {nullptr}; 201 | 202 | /** 203 | * MachInfo object generator 204 | * 205 | * @param asKernel this MachInfo represents a kernel 206 | * @param id kinfo identifier (e.g. CFBundleIdentifier) 207 | * 208 | * @return MachInfo object or nullptr 209 | */ 210 | static MachInfo *create(bool asKernel=false, const char *id=nullptr) { return new MachInfo(asKernel, id); } 211 | static void deleter(MachInfo *i NONNULL) { delete i; } 212 | 213 | /** 214 | * Resolve mach data in the kernel 215 | * 216 | * @param paths filesystem paths for lookup 217 | * @param num the number of paths passed 218 | * @param prelink prelink information source (i.e. Kernel MachInfo) 219 | * @param fsfallback fallback to reading from filesystem if prelink failed 220 | * 221 | * @return KERN_SUCCESS if loaded 222 | */ 223 | EXPORT kern_return_t init(const char * const paths[], size_t num = 1, MachInfo *prelink=nullptr, bool fsfallback=false); 224 | 225 | /** 226 | * Release the allocated memory, must be called regardless of the init error 227 | */ 228 | EXPORT void deinit(); 229 | 230 | /** 231 | * Retrieve the mach header and __TEXT addresses for KC mode 232 | * 233 | * @param slide load slide if calculating for kexts 234 | * 235 | * @return KERN_SUCCESS on success 236 | */ 237 | kern_return_t kcGetRunningAddresses(mach_vm_address_t slide); 238 | 239 | /** 240 | * Get address slot if present 241 | * 242 | * @return address slot on success 243 | * @return NULL on success 244 | */ 245 | mach_vm_address_t getAddressSlot(); 246 | 247 | /** 248 | * Retrieve the mach header and __TEXT addresses 249 | * 250 | * @param slide load slide if calculating for kexts 251 | * @param size memory size 252 | * @param force force address recalculation 253 | * 254 | * @return KERN_SUCCESS on success 255 | */ 256 | EXPORT kern_return_t getRunningAddresses(mach_vm_address_t slide=0, size_t size=0, bool force=false); 257 | 258 | /** 259 | * Set the mach header address 260 | * 261 | * @param slide load address 262 | * @param size memory size 263 | * 264 | * @return KERN_SUCCESS on success 265 | */ 266 | EXPORT kern_return_t setRunningAddresses(mach_vm_address_t slide=0, size_t size=0); 267 | 268 | /** 269 | * Retrieve running mach positions 270 | * 271 | * @param header pointer to header 272 | * @param size file size 273 | */ 274 | EXPORT void getRunningPosition(uint8_t * &header, size_t &size); 275 | 276 | /** 277 | * Solve a mach symbol (running addresses must be calculated) 278 | * 279 | * @param symbol symbol to solve 280 | * 281 | * @return running symbol address or 0 282 | */ 283 | EXPORT mach_vm_address_t solveSymbol(const char *symbol); 284 | 285 | /** 286 | * Find the kernel base address (mach-o header) 287 | * 288 | * @return kernel base address or 0 289 | */ 290 | EXPORT mach_vm_address_t findKernelBase(); 291 | 292 | /** 293 | * Compare the loaded kernel with the current UUID (see loadUUID) 294 | * 295 | * @param base image base, pass 0 to use kernel base 296 | * 297 | * @return true if image uuids match 298 | */ 299 | EXPORT bool isCurrentBinary(mach_vm_address_t base=0); 300 | 301 | /** 302 | * Enable/disable interrupt handling 303 | * this is similar to ml_set_interrupts_enabled except the return value 304 | * 305 | * @param enable the desired value 306 | * 307 | * @return true if changed the value and false if it is unchanged 308 | */ 309 | EXPORT static bool setInterrupts(bool enable); 310 | 311 | /** 312 | * Enable/disable kernel memory write protection 313 | * 314 | * @param enable the desired value 315 | * @param lock use spinlock to disable cpu preemption (see KernelPatcher::kernelWriteLock) 316 | * 317 | * @return KERN_SUCCESS if succeeded 318 | */ 319 | EXPORT static kern_return_t setKernelWriting(bool enable, IOSimpleLock *lock); 320 | 321 | /** 322 | * Find section bounds in a passed binary for provided cpu 323 | * 324 | * @param ptr pointer to a complete mach-o binary 325 | * @param sourceSize size of the mach-o binary 326 | * @param vmsegment returned vm segment pointer 327 | * @param vmsection returned vm section pointer 328 | * @param sectionptr returned section pointer 329 | * @param sectionSize returned section size or 0 on failure 330 | * @param segmentName segment name 331 | * @param sectionName section name 332 | * @param cpu cpu to look for in case of fat binaries 333 | */ 334 | EXPORT static void findSectionBounds(void *ptr, size_t sourceSize, vm_address_t &vmsegment, vm_address_t &vmsection, void *§ionptr, size_t §ionSize, const char *segmentName="__TEXT", const char *sectionName="__text", cpu_type_t cpu=CPU_TYPE_X86_64); 335 | 336 | /** 337 | * Request to free file buffer resources (not including linkedit symtable) 338 | */ 339 | void freeFileBufferResources(); 340 | 341 | /** 342 | * Get fat offset of the initialised image 343 | */ 344 | off_t getFatOffset() { 345 | return fat_offset; 346 | } 347 | }; 348 | 349 | #endif /* kern_mach_hpp */ 350 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/sparc.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPSTONE_SPARC_H 2 | #define CAPSTONE_SPARC_H 3 | 4 | /* Capstone Disassembly Engine */ 5 | /* By Nguyen Anh Quynh , 2014 */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #if !defined(_MSC_VER) || !defined(_KERNEL_MODE) 12 | #include 13 | #endif 14 | 15 | #include "platform.h" 16 | 17 | // GCC SPARC toolchain has a default macro called "sparc" which breaks 18 | // compilation 19 | #undef sparc 20 | 21 | #ifdef _MSC_VER 22 | #pragma warning(disable:4201) 23 | #endif 24 | 25 | //> Enums corresponding to Sparc condition codes, both icc's and fcc's. 26 | typedef enum sparc_cc { 27 | SPARC_CC_INVALID = 0, // invalid CC (default) 28 | //> Integer condition codes 29 | SPARC_CC_ICC_A = 8+256, // Always 30 | SPARC_CC_ICC_N = 0+256, // Never 31 | SPARC_CC_ICC_NE = 9+256, // Not Equal 32 | SPARC_CC_ICC_E = 1+256, // Equal 33 | SPARC_CC_ICC_G = 10+256, // Greater 34 | SPARC_CC_ICC_LE = 2+256, // Less or Equal 35 | SPARC_CC_ICC_GE = 11+256, // Greater or Equal 36 | SPARC_CC_ICC_L = 3+256, // Less 37 | SPARC_CC_ICC_GU = 12+256, // Greater Unsigned 38 | SPARC_CC_ICC_LEU = 4+256, // Less or Equal Unsigned 39 | SPARC_CC_ICC_CC = 13+256, // Carry Clear/Great or Equal Unsigned 40 | SPARC_CC_ICC_CS = 5+256, // Carry Set/Less Unsigned 41 | SPARC_CC_ICC_POS = 14+256, // Positive 42 | SPARC_CC_ICC_NEG = 6+256, // Negative 43 | SPARC_CC_ICC_VC = 15+256, // Overflow Clear 44 | SPARC_CC_ICC_VS = 7+256, // Overflow Set 45 | 46 | //> Floating condition codes 47 | SPARC_CC_FCC_A = 8+16+256, // Always 48 | SPARC_CC_FCC_N = 0+16+256, // Never 49 | SPARC_CC_FCC_U = 7+16+256, // Unordered 50 | SPARC_CC_FCC_G = 6+16+256, // Greater 51 | SPARC_CC_FCC_UG = 5+16+256, // Unordered or Greater 52 | SPARC_CC_FCC_L = 4+16+256, // Less 53 | SPARC_CC_FCC_UL = 3+16+256, // Unordered or Less 54 | SPARC_CC_FCC_LG = 2+16+256, // Less or Greater 55 | SPARC_CC_FCC_NE = 1+16+256, // Not Equal 56 | SPARC_CC_FCC_E = 9+16+256, // Equal 57 | SPARC_CC_FCC_UE = 10+16+256, // Unordered or Equal 58 | SPARC_CC_FCC_GE = 11+16+256, // Greater or Equal 59 | SPARC_CC_FCC_UGE = 12+16+256, // Unordered or Greater or Equal 60 | SPARC_CC_FCC_LE = 13+16+256, // Less or Equal 61 | SPARC_CC_FCC_ULE = 14+16+256, // Unordered or Less or Equal 62 | SPARC_CC_FCC_O = 15+16+256, // Ordered 63 | } sparc_cc; 64 | 65 | //> Branch hint 66 | typedef enum sparc_hint { 67 | SPARC_HINT_INVALID = 0, // no hint 68 | SPARC_HINT_A = 1 << 0, // annul delay slot instruction 69 | SPARC_HINT_PT = 1 << 1, // branch taken 70 | SPARC_HINT_PN = 1 << 2, // branch NOT taken 71 | } sparc_hint; 72 | 73 | //> Operand type for instruction's operands 74 | typedef enum sparc_op_type { 75 | SPARC_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized). 76 | SPARC_OP_REG, // = CS_OP_REG (Register operand). 77 | SPARC_OP_IMM, // = CS_OP_IMM (Immediate operand). 78 | SPARC_OP_MEM, // = CS_OP_MEM (Memory operand). 79 | } sparc_op_type; 80 | 81 | // Instruction's operand referring to memory 82 | // This is associated with SPARC_OP_MEM operand type above 83 | typedef struct sparc_op_mem { 84 | uint8_t base; // base register 85 | uint8_t index; // index register 86 | int32_t disp; // displacement/offset value 87 | } sparc_op_mem; 88 | 89 | // Instruction operand 90 | typedef struct cs_sparc_op { 91 | sparc_op_type type; // operand type 92 | union { 93 | unsigned int reg; // register value for REG operand 94 | int32_t imm; // immediate value for IMM operand 95 | sparc_op_mem mem; // base/disp value for MEM operand 96 | }; 97 | } cs_sparc_op; 98 | 99 | // Instruction structure 100 | typedef struct cs_sparc { 101 | sparc_cc cc; // code condition for this insn 102 | sparc_hint hint; // branch hint: encoding as bitwise OR of sparc_hint. 103 | // Number of operands of this instruction, 104 | // or 0 when instruction has no operand. 105 | uint8_t op_count; 106 | cs_sparc_op operands[4]; // operands for this instruction. 107 | } cs_sparc; 108 | 109 | //> SPARC registers 110 | typedef enum sparc_reg { 111 | SPARC_REG_INVALID = 0, 112 | 113 | SPARC_REG_F0, 114 | SPARC_REG_F1, 115 | SPARC_REG_F2, 116 | SPARC_REG_F3, 117 | SPARC_REG_F4, 118 | SPARC_REG_F5, 119 | SPARC_REG_F6, 120 | SPARC_REG_F7, 121 | SPARC_REG_F8, 122 | SPARC_REG_F9, 123 | SPARC_REG_F10, 124 | SPARC_REG_F11, 125 | SPARC_REG_F12, 126 | SPARC_REG_F13, 127 | SPARC_REG_F14, 128 | SPARC_REG_F15, 129 | SPARC_REG_F16, 130 | SPARC_REG_F17, 131 | SPARC_REG_F18, 132 | SPARC_REG_F19, 133 | SPARC_REG_F20, 134 | SPARC_REG_F21, 135 | SPARC_REG_F22, 136 | SPARC_REG_F23, 137 | SPARC_REG_F24, 138 | SPARC_REG_F25, 139 | SPARC_REG_F26, 140 | SPARC_REG_F27, 141 | SPARC_REG_F28, 142 | SPARC_REG_F29, 143 | SPARC_REG_F30, 144 | SPARC_REG_F31, 145 | SPARC_REG_F32, 146 | SPARC_REG_F34, 147 | SPARC_REG_F36, 148 | SPARC_REG_F38, 149 | SPARC_REG_F40, 150 | SPARC_REG_F42, 151 | SPARC_REG_F44, 152 | SPARC_REG_F46, 153 | SPARC_REG_F48, 154 | SPARC_REG_F50, 155 | SPARC_REG_F52, 156 | SPARC_REG_F54, 157 | SPARC_REG_F56, 158 | SPARC_REG_F58, 159 | SPARC_REG_F60, 160 | SPARC_REG_F62, 161 | SPARC_REG_FCC0, // Floating condition codes 162 | SPARC_REG_FCC1, 163 | SPARC_REG_FCC2, 164 | SPARC_REG_FCC3, 165 | SPARC_REG_FP, 166 | SPARC_REG_G0, 167 | SPARC_REG_G1, 168 | SPARC_REG_G2, 169 | SPARC_REG_G3, 170 | SPARC_REG_G4, 171 | SPARC_REG_G5, 172 | SPARC_REG_G6, 173 | SPARC_REG_G7, 174 | SPARC_REG_I0, 175 | SPARC_REG_I1, 176 | SPARC_REG_I2, 177 | SPARC_REG_I3, 178 | SPARC_REG_I4, 179 | SPARC_REG_I5, 180 | SPARC_REG_I7, 181 | SPARC_REG_ICC, // Integer condition codes 182 | SPARC_REG_L0, 183 | SPARC_REG_L1, 184 | SPARC_REG_L2, 185 | SPARC_REG_L3, 186 | SPARC_REG_L4, 187 | SPARC_REG_L5, 188 | SPARC_REG_L6, 189 | SPARC_REG_L7, 190 | SPARC_REG_O0, 191 | SPARC_REG_O1, 192 | SPARC_REG_O2, 193 | SPARC_REG_O3, 194 | SPARC_REG_O4, 195 | SPARC_REG_O5, 196 | SPARC_REG_O7, 197 | SPARC_REG_SP, 198 | SPARC_REG_Y, 199 | 200 | // special register 201 | SPARC_REG_XCC, 202 | 203 | SPARC_REG_ENDING, // <-- mark the end of the list of registers 204 | 205 | // extras 206 | SPARC_REG_O6 = SPARC_REG_SP, 207 | SPARC_REG_I6 = SPARC_REG_FP, 208 | } sparc_reg; 209 | 210 | //> SPARC instruction 211 | typedef enum sparc_insn { 212 | SPARC_INS_INVALID = 0, 213 | 214 | SPARC_INS_ADDCC, 215 | SPARC_INS_ADDX, 216 | SPARC_INS_ADDXCC, 217 | SPARC_INS_ADDXC, 218 | SPARC_INS_ADDXCCC, 219 | SPARC_INS_ADD, 220 | SPARC_INS_ALIGNADDR, 221 | SPARC_INS_ALIGNADDRL, 222 | SPARC_INS_ANDCC, 223 | SPARC_INS_ANDNCC, 224 | SPARC_INS_ANDN, 225 | SPARC_INS_AND, 226 | SPARC_INS_ARRAY16, 227 | SPARC_INS_ARRAY32, 228 | SPARC_INS_ARRAY8, 229 | SPARC_INS_B, 230 | SPARC_INS_JMP, 231 | SPARC_INS_BMASK, 232 | SPARC_INS_FB, 233 | SPARC_INS_BRGEZ, 234 | SPARC_INS_BRGZ, 235 | SPARC_INS_BRLEZ, 236 | SPARC_INS_BRLZ, 237 | SPARC_INS_BRNZ, 238 | SPARC_INS_BRZ, 239 | SPARC_INS_BSHUFFLE, 240 | SPARC_INS_CALL, 241 | SPARC_INS_CASX, 242 | SPARC_INS_CAS, 243 | SPARC_INS_CMASK16, 244 | SPARC_INS_CMASK32, 245 | SPARC_INS_CMASK8, 246 | SPARC_INS_CMP, 247 | SPARC_INS_EDGE16, 248 | SPARC_INS_EDGE16L, 249 | SPARC_INS_EDGE16LN, 250 | SPARC_INS_EDGE16N, 251 | SPARC_INS_EDGE32, 252 | SPARC_INS_EDGE32L, 253 | SPARC_INS_EDGE32LN, 254 | SPARC_INS_EDGE32N, 255 | SPARC_INS_EDGE8, 256 | SPARC_INS_EDGE8L, 257 | SPARC_INS_EDGE8LN, 258 | SPARC_INS_EDGE8N, 259 | SPARC_INS_FABSD, 260 | SPARC_INS_FABSQ, 261 | SPARC_INS_FABSS, 262 | SPARC_INS_FADDD, 263 | SPARC_INS_FADDQ, 264 | SPARC_INS_FADDS, 265 | SPARC_INS_FALIGNDATA, 266 | SPARC_INS_FAND, 267 | SPARC_INS_FANDNOT1, 268 | SPARC_INS_FANDNOT1S, 269 | SPARC_INS_FANDNOT2, 270 | SPARC_INS_FANDNOT2S, 271 | SPARC_INS_FANDS, 272 | SPARC_INS_FCHKSM16, 273 | SPARC_INS_FCMPD, 274 | SPARC_INS_FCMPEQ16, 275 | SPARC_INS_FCMPEQ32, 276 | SPARC_INS_FCMPGT16, 277 | SPARC_INS_FCMPGT32, 278 | SPARC_INS_FCMPLE16, 279 | SPARC_INS_FCMPLE32, 280 | SPARC_INS_FCMPNE16, 281 | SPARC_INS_FCMPNE32, 282 | SPARC_INS_FCMPQ, 283 | SPARC_INS_FCMPS, 284 | SPARC_INS_FDIVD, 285 | SPARC_INS_FDIVQ, 286 | SPARC_INS_FDIVS, 287 | SPARC_INS_FDMULQ, 288 | SPARC_INS_FDTOI, 289 | SPARC_INS_FDTOQ, 290 | SPARC_INS_FDTOS, 291 | SPARC_INS_FDTOX, 292 | SPARC_INS_FEXPAND, 293 | SPARC_INS_FHADDD, 294 | SPARC_INS_FHADDS, 295 | SPARC_INS_FHSUBD, 296 | SPARC_INS_FHSUBS, 297 | SPARC_INS_FITOD, 298 | SPARC_INS_FITOQ, 299 | SPARC_INS_FITOS, 300 | SPARC_INS_FLCMPD, 301 | SPARC_INS_FLCMPS, 302 | SPARC_INS_FLUSHW, 303 | SPARC_INS_FMEAN16, 304 | SPARC_INS_FMOVD, 305 | SPARC_INS_FMOVQ, 306 | SPARC_INS_FMOVRDGEZ, 307 | SPARC_INS_FMOVRQGEZ, 308 | SPARC_INS_FMOVRSGEZ, 309 | SPARC_INS_FMOVRDGZ, 310 | SPARC_INS_FMOVRQGZ, 311 | SPARC_INS_FMOVRSGZ, 312 | SPARC_INS_FMOVRDLEZ, 313 | SPARC_INS_FMOVRQLEZ, 314 | SPARC_INS_FMOVRSLEZ, 315 | SPARC_INS_FMOVRDLZ, 316 | SPARC_INS_FMOVRQLZ, 317 | SPARC_INS_FMOVRSLZ, 318 | SPARC_INS_FMOVRDNZ, 319 | SPARC_INS_FMOVRQNZ, 320 | SPARC_INS_FMOVRSNZ, 321 | SPARC_INS_FMOVRDZ, 322 | SPARC_INS_FMOVRQZ, 323 | SPARC_INS_FMOVRSZ, 324 | SPARC_INS_FMOVS, 325 | SPARC_INS_FMUL8SUX16, 326 | SPARC_INS_FMUL8ULX16, 327 | SPARC_INS_FMUL8X16, 328 | SPARC_INS_FMUL8X16AL, 329 | SPARC_INS_FMUL8X16AU, 330 | SPARC_INS_FMULD, 331 | SPARC_INS_FMULD8SUX16, 332 | SPARC_INS_FMULD8ULX16, 333 | SPARC_INS_FMULQ, 334 | SPARC_INS_FMULS, 335 | SPARC_INS_FNADDD, 336 | SPARC_INS_FNADDS, 337 | SPARC_INS_FNAND, 338 | SPARC_INS_FNANDS, 339 | SPARC_INS_FNEGD, 340 | SPARC_INS_FNEGQ, 341 | SPARC_INS_FNEGS, 342 | SPARC_INS_FNHADDD, 343 | SPARC_INS_FNHADDS, 344 | SPARC_INS_FNOR, 345 | SPARC_INS_FNORS, 346 | SPARC_INS_FNOT1, 347 | SPARC_INS_FNOT1S, 348 | SPARC_INS_FNOT2, 349 | SPARC_INS_FNOT2S, 350 | SPARC_INS_FONE, 351 | SPARC_INS_FONES, 352 | SPARC_INS_FOR, 353 | SPARC_INS_FORNOT1, 354 | SPARC_INS_FORNOT1S, 355 | SPARC_INS_FORNOT2, 356 | SPARC_INS_FORNOT2S, 357 | SPARC_INS_FORS, 358 | SPARC_INS_FPACK16, 359 | SPARC_INS_FPACK32, 360 | SPARC_INS_FPACKFIX, 361 | SPARC_INS_FPADD16, 362 | SPARC_INS_FPADD16S, 363 | SPARC_INS_FPADD32, 364 | SPARC_INS_FPADD32S, 365 | SPARC_INS_FPADD64, 366 | SPARC_INS_FPMERGE, 367 | SPARC_INS_FPSUB16, 368 | SPARC_INS_FPSUB16S, 369 | SPARC_INS_FPSUB32, 370 | SPARC_INS_FPSUB32S, 371 | SPARC_INS_FQTOD, 372 | SPARC_INS_FQTOI, 373 | SPARC_INS_FQTOS, 374 | SPARC_INS_FQTOX, 375 | SPARC_INS_FSLAS16, 376 | SPARC_INS_FSLAS32, 377 | SPARC_INS_FSLL16, 378 | SPARC_INS_FSLL32, 379 | SPARC_INS_FSMULD, 380 | SPARC_INS_FSQRTD, 381 | SPARC_INS_FSQRTQ, 382 | SPARC_INS_FSQRTS, 383 | SPARC_INS_FSRA16, 384 | SPARC_INS_FSRA32, 385 | SPARC_INS_FSRC1, 386 | SPARC_INS_FSRC1S, 387 | SPARC_INS_FSRC2, 388 | SPARC_INS_FSRC2S, 389 | SPARC_INS_FSRL16, 390 | SPARC_INS_FSRL32, 391 | SPARC_INS_FSTOD, 392 | SPARC_INS_FSTOI, 393 | SPARC_INS_FSTOQ, 394 | SPARC_INS_FSTOX, 395 | SPARC_INS_FSUBD, 396 | SPARC_INS_FSUBQ, 397 | SPARC_INS_FSUBS, 398 | SPARC_INS_FXNOR, 399 | SPARC_INS_FXNORS, 400 | SPARC_INS_FXOR, 401 | SPARC_INS_FXORS, 402 | SPARC_INS_FXTOD, 403 | SPARC_INS_FXTOQ, 404 | SPARC_INS_FXTOS, 405 | SPARC_INS_FZERO, 406 | SPARC_INS_FZEROS, 407 | SPARC_INS_JMPL, 408 | SPARC_INS_LDD, 409 | SPARC_INS_LD, 410 | SPARC_INS_LDQ, 411 | SPARC_INS_LDSB, 412 | SPARC_INS_LDSH, 413 | SPARC_INS_LDSW, 414 | SPARC_INS_LDUB, 415 | SPARC_INS_LDUH, 416 | SPARC_INS_LDX, 417 | SPARC_INS_LZCNT, 418 | SPARC_INS_MEMBAR, 419 | SPARC_INS_MOVDTOX, 420 | SPARC_INS_MOV, 421 | SPARC_INS_MOVRGEZ, 422 | SPARC_INS_MOVRGZ, 423 | SPARC_INS_MOVRLEZ, 424 | SPARC_INS_MOVRLZ, 425 | SPARC_INS_MOVRNZ, 426 | SPARC_INS_MOVRZ, 427 | SPARC_INS_MOVSTOSW, 428 | SPARC_INS_MOVSTOUW, 429 | SPARC_INS_MULX, 430 | SPARC_INS_NOP, 431 | SPARC_INS_ORCC, 432 | SPARC_INS_ORNCC, 433 | SPARC_INS_ORN, 434 | SPARC_INS_OR, 435 | SPARC_INS_PDIST, 436 | SPARC_INS_PDISTN, 437 | SPARC_INS_POPC, 438 | SPARC_INS_RD, 439 | SPARC_INS_RESTORE, 440 | SPARC_INS_RETT, 441 | SPARC_INS_SAVE, 442 | SPARC_INS_SDIVCC, 443 | SPARC_INS_SDIVX, 444 | SPARC_INS_SDIV, 445 | SPARC_INS_SETHI, 446 | SPARC_INS_SHUTDOWN, 447 | SPARC_INS_SIAM, 448 | SPARC_INS_SLLX, 449 | SPARC_INS_SLL, 450 | SPARC_INS_SMULCC, 451 | SPARC_INS_SMUL, 452 | SPARC_INS_SRAX, 453 | SPARC_INS_SRA, 454 | SPARC_INS_SRLX, 455 | SPARC_INS_SRL, 456 | SPARC_INS_STBAR, 457 | SPARC_INS_STB, 458 | SPARC_INS_STD, 459 | SPARC_INS_ST, 460 | SPARC_INS_STH, 461 | SPARC_INS_STQ, 462 | SPARC_INS_STX, 463 | SPARC_INS_SUBCC, 464 | SPARC_INS_SUBX, 465 | SPARC_INS_SUBXCC, 466 | SPARC_INS_SUB, 467 | SPARC_INS_SWAP, 468 | SPARC_INS_TADDCCTV, 469 | SPARC_INS_TADDCC, 470 | SPARC_INS_T, 471 | SPARC_INS_TSUBCCTV, 472 | SPARC_INS_TSUBCC, 473 | SPARC_INS_UDIVCC, 474 | SPARC_INS_UDIVX, 475 | SPARC_INS_UDIV, 476 | SPARC_INS_UMULCC, 477 | SPARC_INS_UMULXHI, 478 | SPARC_INS_UMUL, 479 | SPARC_INS_UNIMP, 480 | SPARC_INS_FCMPED, 481 | SPARC_INS_FCMPEQ, 482 | SPARC_INS_FCMPES, 483 | SPARC_INS_WR, 484 | SPARC_INS_XMULX, 485 | SPARC_INS_XMULXHI, 486 | SPARC_INS_XNORCC, 487 | SPARC_INS_XNOR, 488 | SPARC_INS_XORCC, 489 | SPARC_INS_XOR, 490 | 491 | // alias instructions 492 | SPARC_INS_RET, 493 | SPARC_INS_RETL, 494 | 495 | SPARC_INS_ENDING, // <-- mark the end of the list of instructions 496 | } sparc_insn; 497 | 498 | //> Group of SPARC instructions 499 | typedef enum sparc_insn_group { 500 | SPARC_GRP_INVALID = 0, // = CS_GRP_INVALID 501 | 502 | //> Generic groups 503 | // all jump instructions (conditional+direct+indirect jumps) 504 | SPARC_GRP_JUMP, // = CS_GRP_JUMP 505 | 506 | //> Architecture-specific groups 507 | SPARC_GRP_HARDQUAD = 128, 508 | SPARC_GRP_V9, 509 | SPARC_GRP_VIS, 510 | SPARC_GRP_VIS2, 511 | SPARC_GRP_VIS3, 512 | SPARC_GRP_32BIT, 513 | SPARC_GRP_64BIT, 514 | 515 | SPARC_GRP_ENDING, // <-- mark the end of the list of groups 516 | } sparc_insn_group; 517 | 518 | #ifdef __cplusplus 519 | } 520 | #endif 521 | 522 | #endif 523 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_devinfo.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_devinfo.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2018-2020 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_devinfo_h 9 | #define kern_devinfo_h 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * Obtain installed devices split into categories. 19 | * Should be used from onPatcherLoad and onwards. 20 | */ 21 | class DeviceInfo { 22 | /** 23 | * Updates reportedLayoutId 24 | */ 25 | void updateLayoutId(); 26 | 27 | /** 28 | * Updates reportedFramebufferId 29 | */ 30 | void updateFramebufferId(); 31 | 32 | /** 33 | * Obtains devices from PCI root 34 | * 35 | * @param pciRoot PCI root instance (commonly PCI0@0 device) 36 | */ 37 | void grabDevicesFromPciRoot(IORegistryEntry *pciRoot); 38 | 39 | /** 40 | * Await for PCI device publishing in IODeviceTree plane 41 | * 42 | * @param obj wait for (PCI) object publishing 43 | */ 44 | void awaitPublishing(IORegistryEntry *obj); 45 | 46 | public: 47 | /** 48 | * Obtains autodetected legacy framebuffer if applicable 49 | * 50 | * @return framebuffer or 0xFFFFFFFF 51 | */ 52 | static uint32_t getLegacyFramebufferId(); 53 | 54 | /** 55 | * Checks whether the framebuffer has connectors or not. 56 | * 57 | * @return true if the framebuffer has no connectors 58 | */ 59 | static bool isConnectorLessPlatformId(uint32_t id); 60 | 61 | /** 62 | * Common external GPU parameter list 63 | */ 64 | struct ExternalVideo { 65 | /** 66 | * Aka GFX0 device 67 | */ 68 | IORegistryEntry *video {nullptr}; 69 | 70 | /** 71 | * Aka HDAU device 72 | */ 73 | IORegistryEntry *audio {nullptr}; 74 | 75 | /** 76 | * External GPU vendor 77 | */ 78 | uint32_t vendor {0}; 79 | }; 80 | 81 | /** 82 | * Aka HDEF device 83 | */ 84 | IORegistryEntry *audioBuiltinAnalog {nullptr}; 85 | 86 | /** 87 | * Aka HDAU device for builtin GPU 88 | */ 89 | IORegistryEntry *audioBuiltinDigital {nullptr}; 90 | 91 | /** 92 | * Aka IGPU device 93 | */ 94 | IORegistryEntry *videoBuiltin {nullptr}; 95 | 96 | /** 97 | * Aka IMEI device 98 | */ 99 | IORegistryEntry *managementEngine {nullptr}; 100 | 101 | /** 102 | * Aka GFX0 devices (kept in sync with audioExternal) 103 | */ 104 | evector videoExternal; 105 | 106 | private: 107 | /** 108 | * This is the default reported layout-id passed to reportedLayoutId. 109 | * The reason for choosing 7 is its presence in 10.14 and the fact 110 | * Apple frameworks still communicate to the files present on disk. 111 | * For information purposes only! Use reportedLayoutId! 112 | */ 113 | static constexpr uint32_t DefaultReportedLayoutId = 7; 114 | 115 | /** 116 | * The boot-arg to override the reported layout-id to AppleHDA. 117 | * For user configuration only! Use reportedLayoutId! 118 | */ 119 | static constexpr const char *ReportedLayoutIdArg = "alcapplid"; 120 | 121 | /** 122 | * The property to override the reported layout-id to AppleHDA. 123 | * For user configuration only! Use reportedLayoutId! 124 | */ 125 | static constexpr const char *ReportedLayoutIdName = "apple-layout-id"; 126 | 127 | public: 128 | /** 129 | * Layout id to be reported by all audio devices (you must update it yourself). 130 | * This follows the standard convention initially found in AppleALC: 131 | * alcapplid=X boot-arg has highest priority and overrides any other value. 132 | * apple-layout-id HDEF prop has normal priority, you may use it if you need. 133 | * DefaultReportedLayoutId will be used if both of the above are not set. 134 | */ 135 | uint32_t reportedLayoutId {0}; 136 | 137 | private: 138 | /** 139 | * The boot-arg to override the reported AAPL,ig-platform-id to Intel drivers. 140 | * For user configuration only! Use reportedFramebufferId! 141 | */ 142 | static constexpr const char *ReportedFrameIdArg = "igfxframe"; 143 | 144 | /** 145 | * The boot-arg to override the reported AAPL,ig-platform-id to Intel drivers. 146 | * Sets VESA framebuffer id (0xFFFFFFFF). 147 | * For user configuration only! Use reportedFramebufferId! 148 | */ 149 | static constexpr const char *ReportedVesaIdArg = "-igfxvesa"; 150 | 151 | /** 152 | * The boot-arg to force-disable any external GPU if found. 153 | * For user configuration only! Use requestedExternalSwitchOff! 154 | */ 155 | static constexpr const char *RequestedExternalSwitchOffArg {"-wegnoegpu"}; 156 | 157 | /** 158 | * The boot-arg to force-disable any internal GPU if found. 159 | * For user configuration only! Use requestedInternalSwitchOff! 160 | */ 161 | static constexpr const char *RequestedInternalSwitchOffArg {"-wegnoigpu"}; 162 | 163 | /** 164 | * The boot-arg to force-disable any internal GPU if external GPU found. 165 | * For user configuration only! Use requestedGpuSwitch!! 166 | */ 167 | static constexpr const char *RequestedGpuSwitchArg {"-wegswitchgpu"}; 168 | 169 | /** 170 | * The property to set your platform id for Intel drivers (Ivy and newer). 171 | * For user configuration only! Use reportedFramebufferName! 172 | */ 173 | static constexpr const char *ReportedFrameIdName = "AAPL,ig-platform-id"; 174 | 175 | /** 176 | * The property to set your platform id for Intel drivers (Sandy). 177 | * For user configuration only! Use reportedFramebufferName! 178 | */ 179 | static constexpr const char *ReportedFrameIdLegacyName = "AAPL,snb-platform-id"; 180 | 181 | /** 182 | * The IGPU property to force-disable any external GPU if found. 183 | * For user configuration only! Use processSwitchOff()! 184 | */ 185 | static constexpr const char *RequestedExternalSwitchOffName {"disable-external-gpu"}; 186 | 187 | /** 188 | * The IGPU property to force-disable the IGPU if any external GPU is found. 189 | * For user configuration only! Use processSwitchOff()! 190 | */ 191 | static constexpr const char *RequestedGpuSwitchName {"switch-to-external-gpu"}; 192 | 193 | /** 194 | * The GPU property to force-disable any external or internal GPU. 195 | * For user configuration only! Use processSwitchOff()! 196 | */ 197 | static constexpr const char *RequestedGpuSwitchOffName {"disable-gpu"}; 198 | 199 | /** 200 | * The GPU property to force-disable any this external GPU with minimum kernel version (inclusive). 201 | * For user configuration only! Use processSwitchOff()! 202 | */ 203 | static constexpr const char *RequestedGpuSwitchOffMinKernelName {"disable-gpu-min"}; 204 | 205 | /** 206 | * The GPU property to force-disable any this external GPU with maximum kernel version (inclusive). 207 | * For user configuration only! Use processSwitchOff()! 208 | */ 209 | static constexpr const char *RequestedGpuSwitchOffMaxKernelName {"disable-gpu-max"}; 210 | 211 | 212 | /** 213 | * Known platform ids used by Intel GPU kexts 214 | * For user configuration only! 215 | */ 216 | static constexpr uint32_t DefaultAppleSkylakePlatformId {0x19120000}; 217 | static constexpr uint32_t DefaultAppleKabyLakePlatformId {0x59160000}; 218 | static constexpr uint32_t DefaultAppleCoffeeLakePlatformId {0x3EA50000}; 219 | static constexpr uint32_t DefaultAppleCannonLakePlatformId {0x5A520000}; 220 | static constexpr uint32_t DefaultAppleIceLakeRealPlatformId {0x8A520000}; 221 | static constexpr uint32_t DefaultAppleIceLakeSimulatorPlatformId {0xFF050000}; 222 | 223 | /** 224 | * Framebuffers without any ports used for hardware acceleration only 225 | * Note 1: Broadwell framebuffers all have connectors added. 226 | * Note 2: Coffee Lake framebuffers without connectors are only present in 10.14. 227 | * Note 3: prerelease Cannon Lake and Ice Lake framebuffers are without connectors. 228 | * For user configuration only! 229 | */ 230 | static constexpr uint32_t ConnectorLessSandyBridgePlatformId1 {0x00030030}; 231 | static constexpr uint32_t ConnectorLessSandyBridgePlatformId2 {0x00050000}; 232 | static constexpr uint32_t ConnectorLessIvyBridgePlatformId1 {0x01620006}; 233 | static constexpr uint32_t ConnectorLessIvyBridgePlatformId2 {0x01620007}; 234 | static constexpr uint32_t ConnectorLessHaswellPlatformId1 {0x04120004}; 235 | static constexpr uint32_t ConnectorLessHaswellPlatformId2 {0x0412000B}; 236 | static constexpr uint32_t ConnectorLessSkylakePlatformId1 {0x19020001}; 237 | static constexpr uint32_t ConnectorLessSkylakePlatformId2 {0x19170001}; 238 | static constexpr uint32_t ConnectorLessSkylakePlatformId3 {0x19120001}; 239 | static constexpr uint32_t ConnectorLessSkylakePlatformId4 {0x19320001}; 240 | static constexpr uint32_t ConnectorLessKabyLakePlatformId1 {0x59180002}; 241 | static constexpr uint32_t ConnectorLessKabyLakePlatformId2 {0x59120003}; 242 | static constexpr uint32_t ConnectorLessCoffeeLakePlatformId1 {0x3E920003}; 243 | static constexpr uint32_t ConnectorLessCoffeeLakePlatformId2 {0x3E910003}; 244 | static constexpr uint32_t ConnectorLessCoffeeLakePlatformId3 {0x3E980003}; 245 | static constexpr uint32_t ConnectorLessCoffeeLakePlatformId4 {0x9BC80003}; 246 | static constexpr uint32_t ConnectorLessCoffeeLakePlatformId5 {0x9BC50003}; 247 | static constexpr uint32_t ConnectorLessCoffeeLakePlatformId6 {0x9BC40003}; 248 | 249 | public: 250 | /** 251 | * Vesa framebuffer identifier 252 | */ 253 | static constexpr uint32_t DefaultVesaPlatformId {0xFFFFFFFF}; 254 | 255 | /** 256 | * Framebuffer id to be reported to IGPU. 257 | * This follows the standard convention initially found in IntelGraphicsFixup: 258 | * igfxframe=X boot-arg has highest priority and overrides any other value. 259 | * -igfxvesa forces 0xFFFFFFFF frame to get into VESA mode. 260 | * Manually specified AAPL,ig-platform-id or AAPL,snb-platform-id go next. 261 | * On Sandy Bridge processors a default AAPL,snb-platform-id will be tried afterwards. 262 | * On Skylake and Kaby Lake processors some default id will be tried afterwards. 263 | */ 264 | uint32_t reportedFramebufferId {0}; 265 | 266 | /** 267 | * Compatible platform id property name for this IGPU 268 | */ 269 | const char *reportedFramebufferName {nullptr}; 270 | 271 | /** 272 | * Set to true if the framebuffer has no connectors 273 | */ 274 | bool reportedFramebufferIsConnectorLess {false}; 275 | 276 | /** 277 | * Known variants of firmware vendors 278 | * Please note, that it may not be possible to always detect the right vendor 279 | */ 280 | enum class FirmwareVendor { 281 | Unknown, 282 | Apple, 283 | VMware, 284 | EDKII, 285 | Parallels, 286 | AMI, 287 | Insyde, 288 | Phoenix, 289 | HP 290 | }; 291 | 292 | /** 293 | * Firmware vendor manufacturer 294 | */ 295 | FirmwareVendor firmwareVendor {FirmwareVendor::Unknown}; 296 | 297 | /** 298 | * Requested external GPU switchoff 299 | */ 300 | bool requestedExternalSwitchOff {false}; 301 | 302 | /** 303 | * Requested internal GPU switchoff 304 | */ 305 | bool requestedInternalSwitchOff {false}; 306 | 307 | /** 308 | * Requested GPU switch 309 | */ 310 | bool requestedGpuSwitch {false}; 311 | /** 312 | * Allocate and initialise cached device list. 313 | * 314 | * @return device list or nullptr 315 | */ 316 | static DeviceInfo *createCached(); 317 | 318 | /** 319 | * Allocate and initialise the device list. 320 | * 321 | * @return device list or nullptr 322 | */ 323 | EXPORT static DeviceInfo *create(); 324 | 325 | /** 326 | * Release initialised device list. 327 | * 328 | * @param d device list 329 | */ 330 | EXPORT static void deleter(DeviceInfo *d NONNULL); 331 | 332 | /** 333 | * Perform device switch-off as prescribed by the properties injected. 334 | */ 335 | EXPORT void processSwitchOff(); 336 | }; 337 | 338 | /** 339 | * Simple device information available at early stage. 340 | */ 341 | class BaseDeviceInfo { 342 | /** 343 | * Updates firmwareVendor 344 | */ 345 | void updateFirmwareVendor(); 346 | 347 | /** 348 | * Updates model information 349 | */ 350 | void updateModelInfo(); 351 | public: 352 | /** 353 | * Board identifier board-id (VMware has "440BX Desktop Reference Platform", eek) 354 | */ 355 | char boardIdentifier[48] {}; 356 | 357 | /** 358 | * Model identifier 359 | */ 360 | char modelIdentifier[48] {}; 361 | 362 | /** 363 | * Computer model type. 364 | */ 365 | int modelType {WIOKit::ComputerModel::ComputerAny}; 366 | 367 | /** 368 | * Firmware vendor manufacturer 369 | */ 370 | DeviceInfo::FirmwareVendor firmwareVendor {DeviceInfo::FirmwareVendor::Unknown}; 371 | 372 | /** 373 | * Known variants of bootloader vendors 374 | * Please note, that it may not be possible to always detect the right vendor 375 | */ 376 | enum class BootloaderVendor { 377 | Unknown, 378 | Acidanthera, 379 | Clover 380 | }; 381 | 382 | /** 383 | * Bootloader vendor 384 | */ 385 | BootloaderVendor bootloaderVendor {BootloaderVendor::Unknown}; 386 | 387 | /** 388 | * CPU vendor 389 | */ 390 | CPUInfo::CpuVendor cpuVendor {CPUInfo::CpuVendor::Unknown}; 391 | 392 | /** 393 | * CPU generation 394 | */ 395 | CPUInfo::CpuGeneration cpuGeneration {CPUInfo::CpuGeneration::Unknown}; 396 | 397 | /** 398 | * CPU family 399 | */ 400 | uint32_t cpuFamily {}; 401 | 402 | /** 403 | * CPU model 404 | */ 405 | uint32_t cpuModel {}; 406 | 407 | /** 408 | * CPU stepping 409 | */ 410 | uint32_t cpuStepping {}; 411 | 412 | /** 413 | * CPU max level 414 | */ 415 | uint32_t cpuMaxLevel {}; 416 | 417 | /** 418 | * CPU max level (ext) 419 | */ 420 | uint32_t cpuMaxLevelExt {0x80000000}; 421 | 422 | /** 423 | * AVX 2.0 support 424 | */ 425 | bool cpuHasAvx2 {false}; 426 | 427 | /** 428 | * Obtain base device info. 429 | */ 430 | EXPORT static const BaseDeviceInfo &get(); 431 | 432 | /** 433 | * Initialize global base device info. 434 | */ 435 | static void init(); 436 | }; 437 | 438 | #endif /* kern_devinfo_h */ 439 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_api.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_api.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2016-2017 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_api_h 9 | #define kern_api_h 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifndef __ACIDANTHERA_MAC_SDK 22 | #error "This kext SDK is unsupported. Download from https://github.com/acidanthera/MacKernelSDK" 23 | #endif 24 | 25 | class LiluAPI { 26 | public: 27 | /** 28 | * Initialise lilu api 29 | */ 30 | void init(); 31 | 32 | /** 33 | * Deinitialise lilu api 34 | */ 35 | void deinit(); 36 | 37 | /** 38 | * Errors returned by functions 39 | */ 40 | enum class Error { 41 | NoError, 42 | LockError, 43 | MemoryError, 44 | UnsupportedFeature, 45 | IncompatibleOS, 46 | Disabled, 47 | TooLate, 48 | Offline 49 | }; 50 | 51 | /** 52 | * Minimal API version that guarantees forward ABI compatibility 53 | * Present due to lack of OSBundleCompatibleVersion at kext injection 54 | */ 55 | static constexpr size_t CompatibilityVersion {parseModuleVersion("1.2.0")}; 56 | 57 | /** 58 | * Obtains api access by holding a lock, which is required when accessing out of the main context 59 | * 60 | * @param version api compatibility version 61 | * @param check do not wait on the lock but return Error::LockError on failure 62 | * 63 | * @return Error::NoError on success 64 | */ 65 | EXPORT Error requestAccess(size_t version=CompatibilityVersion, bool check=false); 66 | 67 | /** 68 | * Releases api lock 69 | * 70 | * @return Error::NoError on success 71 | */ 72 | EXPORT Error releaseAccess(); 73 | 74 | /** 75 | * You are supposed declare that your plugins work in at least one of these modes 76 | * It is assumed that single user mode is equal to normal, because it is generally 77 | * used to continue the load of a complete OS, and by default Lilu itself ignores it. 78 | */ 79 | enum RunningMode : uint32_t { 80 | RunningNormal = 1, 81 | AllowNormal = RunningNormal, 82 | RunningInstallerRecovery = 2, 83 | AllowInstallerRecovery = RunningInstallerRecovery, 84 | RunningSafeMode = 4, 85 | AllowSafeMode = RunningSafeMode 86 | }; 87 | 88 | /** 89 | * Obtain current run mode similarly to requirements 90 | * 91 | * @return run mode mask (RunningMode) 92 | */ 93 | inline uint32_t getRunMode() { 94 | return currentRunMode; 95 | } 96 | 97 | /** 98 | * Decides whether you are eligible to continue 99 | * 100 | * @param product product name 101 | * @param version product version 102 | * @param runmode bitmask of allowed enviornments 103 | * @param disableArg pointer to disabling boot arguments array 104 | * @param disableArgNum number of disabling boot arguments 105 | * @param debugArg pointer to debug boot arguments array 106 | * @param debugArgNum number of debug boot arguments 107 | * @param betaArg pointer to beta boot arguments array 108 | * @param betaArgNum number of beta boot arguments 109 | * @param min minimal required kernel version 110 | * @param max maximum supported kernel version 111 | * @param printDebug returns debug printing status (based on debugArg) 112 | * 113 | * @return Error::NoError on success 114 | */ 115 | EXPORT Error shouldLoad(const char *product, size_t version, uint32_t runmode, const char **disableArg, size_t disableArgNum, const char **debugArg, size_t debugArgNum, const char **betaArg, size_t betaArgNum, KernelVersion min, KernelVersion max, bool &printDebug); 116 | 117 | /** 118 | * Kernel patcher loaded callback 119 | * 120 | * @param user user provided pointer at registering 121 | * @param patcher kernel patcher instance 122 | */ 123 | using t_patcherLoaded = void (*)(void *user, KernelPatcher &patcher); 124 | 125 | /** 126 | * Registers custom provided callbacks for later invocation on kernel patcher initialisation 127 | * 128 | * @param callback your callback function 129 | * @param user your pointer that will be passed to the callback function 130 | * 131 | * @return Error::NoError on success 132 | */ 133 | EXPORT Error onPatcherLoad(t_patcherLoaded callback, void *user=nullptr); 134 | 135 | /** 136 | * Registers custom provided callbacks for later invocation on kernel patcher initialisation 137 | * Enforced version, which panics on registration failure (assuming your code cannot continue otherwise) 138 | * 139 | * @param callback your callback function 140 | * @param user your pointer that will be passed to the callback function 141 | */ 142 | inline void onPatcherLoadForce(t_patcherLoaded callback, void *user=nullptr) { 143 | auto err = onPatcherLoad(callback, user); 144 | if (err != Error::NoError) 145 | PANIC("api", "onPatcherLoad failed with code %d", err); 146 | } 147 | 148 | /** 149 | * Kext loaded callback 150 | * Note that you will get notified of all the requested kexts for speed reasons 151 | * 152 | * @param user user provided pointer at registering 153 | * @param patcher kernel patcher instance 154 | * @param id loaded kinfo id 155 | * @param slide loaded slide 156 | * @param size loaded memory size 157 | */ 158 | using t_kextLoaded = void (*)(void *user, KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size); 159 | 160 | /** 161 | * Registers custom provided callbacks for later invocation on kext load 162 | * 163 | * @param infos your kext list (make sure to point to const memory) 164 | * @param num number of provided kext entries 165 | * @param callback your callback function (optional) 166 | * @param user your pointer that will be passed to the callback function (optional) 167 | * 168 | * @return Error::NoError on success 169 | */ 170 | EXPORT Error onKextLoad(KernelPatcher::KextInfo *infos, size_t num=1, t_kextLoaded callback=nullptr, void *user=nullptr); 171 | 172 | /** 173 | * Registers custom provided callbacks for later invocation on kext load 174 | * Enforced version, which panics on registration failure (assuming your code cannot continue otherwise) 175 | * 176 | * @param infos your kext list (make sure to point to const memory) 177 | * @param num number of provided kext entries 178 | * @param callback your callback function (optional) 179 | * @param user your pointer that will be passed to the callback function (optional) 180 | */ 181 | inline void onKextLoadForce(KernelPatcher::KextInfo *infos, size_t num=1, t_kextLoaded callback=nullptr, void *user=nullptr) { 182 | auto err = onKextLoad(infos, num, callback, user); 183 | if (err != Error::NoError) 184 | PANIC("api", "onKextLoad failed with code %d", err); 185 | } 186 | 187 | /** 188 | * Registers custom provided callbacks for later invocation on binary load 189 | * 190 | * @param infos your binary list (make sure to point to const memory) 191 | * @param num number of provided binary entries 192 | * @param callback your callback function (could be null) 193 | * @param user your pointer that will be passed to the callback function 194 | * @param mods optional mod list (make sure to point to const memory) 195 | * @param modnum number of provided mod entries 196 | * 197 | * @return Error::NoError on success 198 | */ 199 | EXPORT Error onProcLoad(UserPatcher::ProcInfo *infos, size_t num=1, UserPatcher::t_BinaryLoaded callback=nullptr, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0); 200 | 201 | /** 202 | * Registers custom provided callbacks for later invocation on binary load 203 | * Enforced version, which panics on registration failure (assuming your code cannot continue otherwise) 204 | * 205 | * @param infos your binary list (make sure to point to const memory) 206 | * @param num number of provided binary entries 207 | * @param callback your callback function (could be null) 208 | * @param user your pointer that will be passed to the callback function 209 | * @param mods optional mod list (make sure to point to const memory) 210 | * @param modnum number of provided mod entries 211 | */ 212 | inline void onProcLoadForce(UserPatcher::ProcInfo *infos, size_t num=1, UserPatcher::t_BinaryLoaded callback=nullptr, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0) { 213 | auto err = onProcLoad(infos, num, callback, user, mods, modnum); 214 | if (err != Error::NoError) 215 | PANIC("api", "onProcLoad failed with code %d", err); 216 | } 217 | 218 | /** 219 | * Kext loaded callback 220 | * Note that you will get notified of all the requested kexts for speed reasons 221 | * 222 | * @param user user provided pointer at registering 223 | * @param task task 224 | * @param entitlement loaded kinfo id 225 | * @param original original entitlement value 226 | */ 227 | using t_entitlementRequested = void (*)(void *user, task_t task, const char *entitlement, OSObject *&original); 228 | 229 | /** 230 | * Registers custom provided callbacks for later invocation on entitlement registration 231 | * 232 | * @param callback your callback function 233 | * @param user your pointer that will be passed to the callback function 234 | * 235 | * @return Error::NoError on success 236 | */ 237 | EXPORT Error onEntitlementRequest(t_entitlementRequested callback, void *user=nullptr); 238 | 239 | /** 240 | * Registers custom provided callbacks for later invocation on entitlement registration 241 | * Enforced version, which panics on registration failure (assuming your code cannot continue otherwise) 242 | * 243 | * @param callback your callback function 244 | * @param user your pointer that will be passed to the callback function 245 | */ 246 | inline void onEntitlementRequestForce(t_entitlementRequested callback, void *user=nullptr) { 247 | auto err = onEntitlementRequest(callback, user); 248 | if (err != Error::NoError) 249 | PANIC("api", "onEntitlementRequest failed with code %d", err); 250 | } 251 | 252 | /** 253 | * Complete plugin registration and perform regulatory actions 254 | */ 255 | void finaliseRequests(); 256 | 257 | /** 258 | * Processes all the registered patcher load callbacks 259 | * 260 | * @param patcher kernel patcher instance 261 | */ 262 | void processPatcherLoadCallbacks(KernelPatcher &patcher); 263 | 264 | /** 265 | * Processes all the registered kext load callbacks 266 | * 267 | * @param patcher kernel patcher instance 268 | * @param id loaded kinfo id 269 | * @param slide loaded slide 270 | * @param size loaded memory size 271 | * @param reloadable kinfo could be unloaded 272 | */ 273 | void processKextLoadCallbacks(KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size, bool reloadable); 274 | 275 | /** 276 | * Processes all the registered user patcher load callbacks 277 | * 278 | * @param patcher user patcher instance 279 | */ 280 | void processUserLoadCallbacks(UserPatcher &patcher); 281 | 282 | /** 283 | * Processes all the registered binary load callbacks 284 | * 285 | * @param patcher kernel patcher instance 286 | * @param map process image vm_map 287 | * @param path path to the binary absolute or relative 288 | * @param len path length excluding null terminator 289 | */ 290 | void processBinaryLoadCallbacks(UserPatcher &patcher, vm_map_t map, const char *path, size_t len); 291 | 292 | /** 293 | * Activates patchers 294 | * 295 | * @param kpatcher kernel patcher instance 296 | * @param upatcher user patcher instance 297 | */ 298 | void activate(KernelPatcher &kpatcher, UserPatcher &upatcher); 299 | 300 | private: 301 | 302 | /** 303 | * Api lock 304 | */ 305 | IOLock *access {nullptr}; 306 | 307 | /** 308 | * Defines current running modes 309 | */ 310 | uint32_t currentRunMode {}; 311 | 312 | /** 313 | * No longer accept any requests 314 | */ 315 | bool apiRequestsOver {false}; 316 | 317 | /** 318 | * Stores call function and user pointer 319 | */ 320 | template 321 | using stored_pair = ppair; 322 | 323 | /** 324 | * Stores multiple callbacks 325 | */ 326 | template 327 | using stored_vector = evector *, stored_pair::deleter>; 328 | 329 | /** 330 | * List of patcher callbacks 331 | */ 332 | stored_vector patcherLoadedCallbacks; 333 | 334 | /** 335 | * List of kext callbacks 336 | */ 337 | stored_vector kextLoadedCallbacks; 338 | 339 | /** 340 | * List of binary callbacks 341 | */ 342 | stored_vector binaryLoadedCallbacks; 343 | 344 | /** 345 | * List of entitlement callbacks 346 | */ 347 | stored_vector entitlementRequestedCallbacks; 348 | 349 | /** 350 | * List of processed kexts 351 | */ 352 | stored_vector storedKexts; 353 | 354 | /** 355 | * List of processed procs 356 | */ 357 | evector storedProcs; 358 | 359 | /** 360 | * List of processed binary mods 361 | */ 362 | evector storedBinaryMods; 363 | 364 | /** 365 | * Copy client entitlement type (see IOUserClient) 366 | */ 367 | using t_copyClientEntitlement = OSObject *(*)(task_t, const char *); 368 | 369 | /** 370 | * Hooked entitlement copying method 371 | */ 372 | static OSObject *copyClientEntitlement(task_t task, const char *entitlement); 373 | 374 | /** 375 | * Trampoline for original entitlement copying method 376 | */ 377 | t_copyClientEntitlement orgCopyClientEntitlement {nullptr}; 378 | }; 379 | 380 | EXPORT extern LiluAPI lilu; 381 | 382 | #endif /* kern_api_h */ 383 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/VirtualSMC.kext/Contents/Resources/VirtualSMCSDK/kern_vsmcapi.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_vsmcapi.hpp 3 | // VirtualSMC 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_vsmcapi_hpp 9 | #define kern_vsmcapi_hpp 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace VirtualSMCAPI { 17 | /** 18 | * SMC device service name. Please be aware that the same name is used for any (including physical) SMC device. 19 | */ 20 | static constexpr const char *ServiceName = "APP0001"; 21 | 22 | /** 23 | * Main communication platform function interface. 24 | * Takes plugin IOService and VirtualSMCPlugin as arguments. No modifications to struct contents are allowed once it is submitted. 25 | * Virtual key functions may be invoked asynchronously from inside IOSimpleLock context, so they should be designed 26 | * with the help of lock-free algorithms. 27 | */ 28 | static constexpr const char *SubmitPlugin = "VirtualSMCSubmitPlugin"; 29 | 30 | /** 31 | * A total maximum of allowed plugins for installation. 32 | */ 33 | static constexpr size_t PluginMax = 16; 34 | 35 | /** 36 | * Accepted plugin API (and ABI) compatibility 37 | */ 38 | static constexpr size_t Version = 1; 39 | 40 | /** 41 | * Sorted key storage containing pairs of keys and values. 42 | */ 43 | using KeyStorage = evector; 44 | 45 | /** 46 | * Main description structure submitted by a plugin. Must be unchanged and never deallocated after submission. 47 | */ 48 | struct Plugin { 49 | const char *product; // Product name (e.g. xStringify(PRODUCT_NAME)) 50 | size_t version; // Product version (e.g. parseModuleVersion(xStringify(MODULE_VERSION))) 51 | size_t apiver; // Product API compatibility (i.e. VirtualSMCAPIVersion) 52 | // Please note, that storage vectors MUST be sorted. Otherwise the behaviour is undefined. 53 | KeyStorage data, dataHidden; 54 | }; 55 | 56 | /** 57 | * Register plugin handler for plugin loading 58 | * 59 | * @param handler function to handle the notification 60 | * @param context function context 61 | * 62 | * @result notifier (must be released) or nullptr 63 | */ 64 | EXPORT IONotifier *registerHandler(IOServiceMatchingNotificationHandler handler, void *context); 65 | 66 | /** 67 | * Asynchronous event poster, which may be used for submitting plugin events. 68 | * Note, this may only be used after SubmitPlugin. 69 | * 70 | * @param code event code to post 71 | * @param data data to include in the interrupt 72 | * @param dataSize size of the supplied data 73 | * 74 | * @return true on success 75 | */ 76 | EXPORT bool postInterrupt(SMC_EVENT_CODE code, const void *data=nullptr, uint32_t dataSize=0); 77 | 78 | /** 79 | * Obtain emulated SMC device info to determine used keys and their format. 80 | * Note, this may only be used within SubmitPlugin or afterwards. 81 | * 82 | * @param info device info object to be copied to 83 | * 84 | * @return true on success 85 | */ 86 | EXPORT bool getDeviceInfo(SMCInfo &info); 87 | 88 | /** 89 | * Adds a key with given value to a key storage. 90 | * Does nothing if given value is nullptr. 91 | * 92 | * @param key an SMC key 93 | * @param data a key storage to add the key to 94 | * @param val an SMC value for the given key 95 | * 96 | * @return true on success 97 | */ 98 | EXPORT bool addKey(SMC_KEY key, KeyStorage &data, VirtualSMCValue *val); 99 | 100 | /** 101 | * Initializes the given value with the appropriate data. Creates new value if nullptr passed as thisValue. 102 | * 103 | * @param smcData a pointer to SMC_DATA to be used for the value. 104 | * @param smcDataSize a size of given SMC_DATA. Cannot be 0. 105 | * @param smcKeyType a key type to init value with. 106 | * @param thisValue a pointer to VirtualSMCValue. Must always be heap-based, don't use address take operator (&). If nullptr passed an instance of VirtualSMCValue will be created for you. Defaults to nullptr. 107 | * @param smcKeyAttrs a key attributes as SMC_KEY_ATTRIBUTES flags. Defaults to SMC_KEY_ATTRIBUTE_READ. 108 | * @param serializeLevel a serialize level needed. Defaults to SerializeLevel::None. 109 | * 110 | * @return thisValue either passed or created new on success, nullptr if something went wrong. 111 | */ 112 | EXPORT VirtualSMCValue *valueWithData(const SMC_DATA *smcData, SMC_DATA_SIZE smcDataSize, SMC_KEY_TYPE smcKeyType, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None); 113 | 114 | /** 115 | * Decode Apple SP signed fixed point fractional format 116 | * 117 | * @param type encoding type, e.g. SmcKeyTypeSp78 118 | * @param value value as it is read from SMC_DATA field 119 | * 120 | * @return floating point value 121 | */ 122 | EXPORT double decodeSp(uint32_t type, uint16_t value); 123 | 124 | /** 125 | * Encode Apple SP signed fixed point fractional format 126 | * 127 | * @param type encoding type, e.g. SmcKeyTypeSp78 128 | * @param value source value 129 | * 130 | * @return value as it is to be written to SMC_DATA field 131 | */ 132 | EXPORT uint16_t encodeSp(uint32_t type, double value); 133 | 134 | /** 135 | * Decode Apple FP unsigned fixed point fractional format 136 | * 137 | * @param type encoding type, e.g. SmcKeyTypeFp88 138 | * @param value value as it is read from SMC_DATA field 139 | * 140 | * @return floating point value 141 | */ 142 | EXPORT double decodeFp(uint32_t type, uint16_t value); 143 | 144 | /** 145 | * Encode Apple FP unsigned fixed point fractional format 146 | * 147 | * @param type encoding type, e.g. SmcKeyTypeFp88 148 | * @param value source value 149 | * 150 | * @return value as it is to be written to SMC_DATA field 151 | */ 152 | EXPORT uint16_t encodeFp(uint32_t type, double value); 153 | 154 | /** 155 | * Decode Apple FP signed integral number 156 | * 157 | * @param type encoding type, e.g. SmcKeyTypeSp78 158 | * @param value value as it is read from SMC_DATA field 159 | * 160 | * @return floating point value 161 | */ 162 | EXPORT int16_t decodeIntSp(uint32_t type, uint16_t value); 163 | 164 | /** 165 | * Encode Apple FP signed integral number 166 | * 167 | * @param type encoding type, e.g. SmcKeyTypeSp78 168 | * @param value source value 169 | * 170 | * @return value as it is to be written to SMC_DATA field 171 | */ 172 | EXPORT uint16_t encodeIntSp(uint32_t type, int16_t value); 173 | 174 | /** 175 | * Decode Apple FP unsigned integral number 176 | * 177 | * @param type encoding type, e.g. SmcKeyTypeFpe2 178 | * @param value value as it is read from SMC_DATA field 179 | * 180 | * @return floating point value 181 | */ 182 | EXPORT uint16_t decodeIntFp(uint32_t type, uint16_t value); 183 | 184 | /** 185 | * Encode Apple FP unsigned integral number 186 | * 187 | * @param type encoding type, e.g. SmcKeyTypeFpe2 188 | * @param value source value 189 | * 190 | * @return value as it is to be written to SMC_DATA field 191 | */ 192 | EXPORT uint16_t encodeIntFp(uint32_t type, uint16_t value); 193 | 194 | /** 195 | * Decode Apple float fractional format 196 | * 197 | * @param value value as it is read from SMC_DATA field 198 | * 199 | * @return floating point value 200 | */ 201 | inline float decodeFlt(uint32_t value) { 202 | union { uint32_t u32; float f; } v {value}; 203 | return v.f; 204 | } 205 | 206 | /** 207 | * Encode Apple float fractional format 208 | * 209 | * @param value source value 210 | * 211 | * @return value as it is to be written to SMC_DATA field 212 | */ 213 | inline uint32_t encodeFlt(float value) { 214 | union { float f; uint32_t u32; } v {value}; 215 | return v.u32; 216 | } 217 | 218 | /** 219 | * A convenient method for initializing flag type key value. 220 | * 221 | * @param flagValue a boolean true or false. 222 | * @see VirtualSMCAPI::valueWithData 223 | */ 224 | inline VirtualSMCValue *valueWithFlag(bool flagValue, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 225 | return valueWithData(reinterpret_cast(&flagValue), sizeof(bool), SmcKeyTypeFlag, thisValue, smcKeyAttrs, serializeLevel); 226 | } 227 | 228 | /** 229 | * A convenient method for initializing Uint8 type key value. 230 | * 231 | * @param uint8Value an integer of 0..255 range. 232 | * @see VirtualSMCAPI::valueWithData 233 | */ 234 | inline VirtualSMCValue *valueWithUint8(uint8_t uint8Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 235 | return valueWithData(reinterpret_cast(&uint8Value), sizeof(uint8_t), SmcKeyTypeUint8, thisValue, smcKeyAttrs, serializeLevel); 236 | } 237 | 238 | /** 239 | * A convenient method for initializing Sint8 type key value. 240 | * 241 | * @param sint8Value an integer of -128..127 range. 242 | * @see VirtualSMCAPI::valueWithData 243 | */ 244 | inline VirtualSMCValue *valueWithSint8(int8_t sint8Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 245 | return valueWithData(reinterpret_cast(&sint8Value), sizeof(uint8_t), SmcKeyTypeSint8, thisValue, smcKeyAttrs, serializeLevel); 246 | } 247 | 248 | /** 249 | * A convenient method for initializing Sint16 type key value. 250 | * 251 | * @param int16Value an integer of -32767..32768 range. 252 | * @see VirtualSMCAPI::valueWithData 253 | */ 254 | inline VirtualSMCValue *valueWithSint16(int16_t int16Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 255 | int16_t t = OSSwapHostToBigInt16(int16Value); 256 | return valueWithData(reinterpret_cast(&t), sizeof(int16_t), SmcKeyTypeSint16, thisValue, smcKeyAttrs, serializeLevel); 257 | } 258 | 259 | /** 260 | * A convenient method for initializing Uint16 type key value. 261 | * 262 | * @param uint16Value an integer of 0..65535 range. 263 | * @see VirtualSMCAPI::valueWithData 264 | */ 265 | inline VirtualSMCValue *valueWithUint16(uint16_t uint16Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 266 | uint16_t t = OSSwapHostToBigInt16(uint16Value); 267 | return valueWithData(reinterpret_cast(&t), sizeof(uint16_t), SmcKeyTypeUint16, thisValue, smcKeyAttrs, serializeLevel); 268 | } 269 | 270 | /** 271 | * A convenient method for initializing Sint32 type key value. 272 | * 273 | * @param int32Value an integer of –2147483648..2147483647 range. 274 | * @see VirtualSMCAPI::valueWithData 275 | */ 276 | inline VirtualSMCValue *valueWithSint32(int32_t int32Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 277 | int32_t t = OSSwapHostToBigInt32(int32Value); 278 | return valueWithData(reinterpret_cast(&t), sizeof(int32_t), SmcKeyTypeSint32, thisValue, smcKeyAttrs, serializeLevel); 279 | } 280 | 281 | /** 282 | * A convenient method for initializing uint32_t type key value. 283 | * 284 | * @param uint32Value an integer of 0..4294967295 range. 285 | * @see VirtualSMCAPI::valueWithData 286 | */ 287 | inline VirtualSMCValue *valueWithUint32(uint32_t uint32Value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 288 | uint32_t t = OSSwapHostToBigInt32(uint32Value); 289 | return valueWithData(reinterpret_cast(&t), sizeof(uint32_t), SmcKeyTypeUint32, thisValue, smcKeyAttrs, serializeLevel); 290 | } 291 | 292 | /** 293 | * A convenient method for initializing spXX key value 294 | * 295 | * @param value floating point value 296 | * @param type Apple sp type (see encodeSp) 297 | * @see VirtualSMCAPI::valueWithData 298 | */ 299 | inline VirtualSMCValue *valueWithSp(double value, SMC_KEY_TYPE spType, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 300 | auto e = encodeSp(spType, value); 301 | return valueWithData(reinterpret_cast(&e), sizeof(e), spType, thisValue, smcKeyAttrs, serializeLevel); 302 | } 303 | 304 | /** 305 | * A convenient method for initializing fpXX key value 306 | * 307 | * @param value floating point value 308 | * @param type Apple fp type (see encodeFp) 309 | * @see VirtualSMCAPI::valueWithData 310 | */ 311 | inline VirtualSMCValue *valueWithFp(double value, SMC_KEY_TYPE fpType, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 312 | auto e = encodeFp(fpType, value); 313 | return valueWithData(reinterpret_cast(&e), sizeof(e), fpType, thisValue, smcKeyAttrs, serializeLevel); 314 | } 315 | 316 | /** 317 | * A convenient method for initializing flt key value 318 | * 319 | * @param value floating point value 320 | * @see VirtualSMCAPI::valueWithData 321 | */ 322 | inline VirtualSMCValue *valueWithFlt(float value, VirtualSMCValue *thisValue = nullptr, SMC_KEY_ATTRIBUTES smcKeyAttrs = SMC_KEY_ATTRIBUTE_READ, SerializeLevel serializeLevel = SerializeLevel::None) { 323 | auto e = encodeFlt(value); 324 | return valueWithData(reinterpret_cast(&e), sizeof(e), SmcKeyTypeFloat, thisValue, smcKeyAttrs, serializeLevel); 325 | } 326 | } 327 | 328 | #endif /* kern_vsmcapi_hpp */ 329 | -------------------------------------------------------------------------------- /EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_cpu.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_cpu.hpp 3 | // Lilu 4 | // 5 | // Copyright © 2018 vit9696. All rights reserved. 6 | // 7 | 8 | #ifndef kern_cpu_h 9 | #define kern_cpu_h 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | /** 18 | * XNU CPU-related exports missing from headers 19 | */ 20 | extern "C" { 21 | int cpu_number(void); 22 | void mp_rendezvous_no_intrs(void (*action_func)(void *), void *arg); 23 | }; 24 | 25 | namespace CPUInfo { 26 | /** 27 | * Keep this in sync to XNU MAX_CPUS from osfmk/i386/mp.h 28 | */ 29 | static constexpr size_t MaxCpus {64}; 30 | 31 | /** 32 | * Contents of CPUID(1) eax register contents describing model version 33 | */ 34 | struct CpuVersion { 35 | uint32_t stepping : 4; 36 | uint32_t model : 4; 37 | uint32_t family : 4; 38 | uint32_t type : 2; 39 | uint32_t reserved1 : 2; 40 | uint32_t extendedModel : 4; 41 | uint32_t extendedFamily : 8; 42 | uint32_t reserved2 : 4; 43 | }; 44 | 45 | static_assert(sizeof(CpuVersion) == sizeof(uint32_t), "CpuVersion size mismatch!"); 46 | 47 | /** 48 | * Intel CPU models as returned by CPUID 49 | * The list is synchronised and updated with XNU source code (osfmk/i386/cpuid.h). 50 | * Names are altered to avoid conflicts just in case. 51 | * Last update: xnu-4903.221.2 52 | * Some details could be found on http://instlatx64.atw.hu and https://en.wikichip.org/wiki/64-bit_architecture#x86 53 | * Also: https://www.intel.com/content/dam/www/public/us/en/documents/sa00115-microcode-update-guidance.pdf 54 | */ 55 | enum CpuModel { 56 | CPU_MODEL_UNKNOWN = 0x00, 57 | CPU_MODEL_PENRYN = 0x17, 58 | CPU_MODEL_NEHALEM = 0x1A, 59 | CPU_MODEL_FIELDS = 0x1E, /* Lynnfield, Clarksfield */ 60 | CPU_MODEL_DALES = 0x1F, /* Havendale, Auburndale */ 61 | CPU_MODEL_NEHALEM_EX = 0x2E, 62 | CPU_MODEL_DALES_32NM = 0x25, /* Clarkdale, Arrandale */ 63 | CPU_MODEL_WESTMERE = 0x2C, /* Gulftown, Westmere-EP/-WS */ 64 | CPU_MODEL_WESTMERE_EX = 0x2F, 65 | CPU_MODEL_SANDYBRIDGE = 0x2A, 66 | CPU_MODEL_JAKETOWN = 0x2D, 67 | CPU_MODEL_IVYBRIDGE = 0x3A, 68 | CPU_MODEL_IVYBRIDGE_EP = 0x3E, 69 | CPU_MODEL_CRYSTALWELL = 0x46, 70 | CPU_MODEL_HASWELL = 0x3C, 71 | CPU_MODEL_HASWELL_EP = 0x3F, 72 | CPU_MODEL_HASWELL_ULT = 0x45, 73 | CPU_MODEL_BROADWELL = 0x3D, 74 | CPU_MODEL_BROADWELL_ULX = 0x3D, 75 | CPU_MODEL_BROADWELL_ULT = 0x3D, 76 | CPU_MODEL_BRYSTALWELL = 0x47, 77 | CPU_MODEL_SKYLAKE = 0x4E, 78 | CPU_MODEL_SKYLAKE_ULT = 0x4E, 79 | CPU_MODEL_SKYLAKE_ULX = 0x4E, 80 | CPU_MODEL_SKYLAKE_DT = 0x5E, 81 | CPU_MODEL_SKYLAKE_W = 0x55, 82 | CPU_MODEL_KABYLAKE = 0x8E, 83 | CPU_MODEL_KABYLAKE_ULT = 0x8E, 84 | CPU_MODEL_KABYLAKE_ULX = 0x8E, 85 | CPU_MODEL_KABYLAKE_DT = 0x9E, 86 | CPU_MODEL_CANNONLAKE = 0x66, 87 | CPU_MODEL_ICELAKE_Y = 0x7D, 88 | CPU_MODEL_ICELAKE_U = 0x7E, 89 | CPU_MODEL_ICELAKE_SP = 0x9F, /* Some variation of Ice Lake */ 90 | CPU_MODEL_COMETLAKE_S = 0xA5, /* desktop CometLake */ 91 | CPU_MODEL_COMETLAKE_Y = 0xA5, /* aka 10th generation Amber Lake Y */ 92 | CPU_MODEL_COMETLAKE_U = 0xA6, 93 | CPU_MODEL_ROCKETLAKE_S = 0xA7, /* desktop RocketLake */ 94 | CPU_MODEL_TIGERLAKE_U = 0x8C, 95 | CPU_MODEL_ALDERLAKE_S = 0x97, 96 | }; 97 | 98 | /** 99 | * Known CPU vendors 100 | */ 101 | enum class CpuVendor { 102 | Unknown, 103 | AMD, 104 | Intel 105 | /* Add more processors here if needed */ 106 | }; 107 | 108 | /** 109 | * Intel CPU generations (starting from 0) 110 | */ 111 | enum class CpuGeneration { 112 | Unknown, 113 | Penryn, 114 | Nehalem, 115 | Westmere, 116 | SandyBridge, 117 | IvyBridge, 118 | Haswell, 119 | Broadwell, 120 | Skylake, 121 | KabyLake, 122 | CoffeeLake, 123 | CannonLake, 124 | IceLake, 125 | CometLake, 126 | RocketLake, 127 | TigerLake, 128 | AlderLake, 129 | MaxGeneration 130 | }; 131 | 132 | /* Responses identification request with %eax 0 */ 133 | /* AMD: "AuthenticAMD" */ 134 | static constexpr uint32_t signature_AMD_ebx = 0x68747541; 135 | static constexpr uint32_t signature_AMD_edx = 0x69746e65; 136 | static constexpr uint32_t signature_AMD_ecx = 0x444d4163; 137 | /* CENTAUR: "CentaurHauls" */ 138 | static constexpr uint32_t signature_CENTAUR_ebx = 0x746e6543; 139 | static constexpr uint32_t signature_CENTAUR_edx = 0x48727561; 140 | static constexpr uint32_t signature_CENTAUR_ecx = 0x736c7561; 141 | /* CYRIX: "CyrixInstead" */ 142 | static constexpr uint32_t signature_CYRIX_ebx = 0x69727943; 143 | static constexpr uint32_t signature_CYRIX_edx = 0x736e4978; 144 | static constexpr uint32_t signature_CYRIX_ecx = 0x64616574; 145 | /* INTEL: "GenuineIntel" */ 146 | static constexpr uint32_t signature_INTEL_ebx = 0x756e6547; 147 | static constexpr uint32_t signature_INTEL_edx = 0x49656e69; 148 | static constexpr uint32_t signature_INTEL_ecx = 0x6c65746e; 149 | /* TM1: "TransmetaCPU" */ 150 | static constexpr uint32_t signature_TM1_ebx = 0x6e617254; 151 | static constexpr uint32_t signature_TM1_edx = 0x74656d73; 152 | static constexpr uint32_t signature_TM1_ecx = 0x55504361; 153 | /* TM2: "GenuineTMx86" */ 154 | static constexpr uint32_t signature_TM2_ebx = 0x756e6547; 155 | static constexpr uint32_t signature_TM2_edx = 0x54656e69; 156 | static constexpr uint32_t signature_TM2_ecx = 0x3638784d; 157 | /* NSC: "Geode by NSC" */ 158 | static constexpr uint32_t signature_NSC_ebx = 0x646f6547; 159 | static constexpr uint32_t signature_NSC_edx = 0x43534e20; 160 | static constexpr uint32_t signature_NSC_ecx = 0x79622065; 161 | /* NEXGEN: "NexGenDriven" */ 162 | static constexpr uint32_t signature_NEXGEN_ebx = 0x4778654e; 163 | static constexpr uint32_t signature_NEXGEN_edx = 0x72446e65; 164 | static constexpr uint32_t signature_NEXGEN_ecx = 0x6e657669; 165 | /* RISE: "RiseRiseRise" */ 166 | static constexpr uint32_t signature_RISE_ebx = 0x65736952; 167 | static constexpr uint32_t signature_RISE_edx = 0x65736952; 168 | static constexpr uint32_t signature_RISE_ecx = 0x65736952; 169 | /* SIS: "SiS SiS SiS " */ 170 | static constexpr uint32_t signature_SIS_ebx = 0x20536953; 171 | static constexpr uint32_t signature_SIS_edx = 0x20536953; 172 | static constexpr uint32_t signature_SIS_ecx = 0x20536953; 173 | /* UMC: "UMC UMC UMC " */ 174 | static constexpr uint32_t signature_UMC_ebx = 0x20434d55; 175 | static constexpr uint32_t signature_UMC_edx = 0x20434d55; 176 | static constexpr uint32_t signature_UMC_ecx = 0x20434d55; 177 | /* VIA: "VIA VIA VIA " */ 178 | static constexpr uint32_t signature_VIA_ebx = 0x20414956; 179 | static constexpr uint32_t signature_VIA_edx = 0x20414956; 180 | static constexpr uint32_t signature_VIA_ecx = 0x20414956; 181 | /* VORTEX: "Vortex86 SoC" */ 182 | static constexpr uint32_t signature_VORTEX_ebx = 0x74726f56; 183 | static constexpr uint32_t signature_VORTEX_edx = 0x36387865; 184 | static constexpr uint32_t signature_VORTEX_ecx = 0x436f5320; 185 | 186 | /* Features in %ecx for leaf 1 */ 187 | static constexpr uint32_t bit_SSE3 = 0x00000001; 188 | static constexpr uint32_t bit_PCLMULQDQ = 0x00000002; 189 | static constexpr uint32_t bit_DTES64 = 0x00000004; 190 | static constexpr uint32_t bit_MONITOR = 0x00000008; 191 | static constexpr uint32_t bit_DSCPL = 0x00000010; 192 | static constexpr uint32_t bit_VMX = 0x00000020; 193 | static constexpr uint32_t bit_SMX = 0x00000040; 194 | static constexpr uint32_t bit_EIST = 0x00000080; 195 | static constexpr uint32_t bit_TM2 = 0x00000100; 196 | static constexpr uint32_t bit_SSSE3 = 0x00000200; 197 | static constexpr uint32_t bit_CNXTID = 0x00000400; 198 | static constexpr uint32_t bit_FMA = 0x00001000; 199 | static constexpr uint32_t bit_CMPXCHG16B = 0x00002000; 200 | static constexpr uint32_t bit_xTPR = 0x00004000; 201 | static constexpr uint32_t bit_PDCM = 0x00008000; 202 | static constexpr uint32_t bit_PCID = 0x00020000; 203 | static constexpr uint32_t bit_DCA = 0x00040000; 204 | static constexpr uint32_t bit_SSE41 = 0x00080000; 205 | static constexpr uint32_t bit_SSE42 = 0x00100000; 206 | static constexpr uint32_t bit_x2APIC = 0x00200000; 207 | static constexpr uint32_t bit_MOVBE = 0x00400000; 208 | static constexpr uint32_t bit_POPCNT = 0x00800000; 209 | static constexpr uint32_t bit_TSCDeadline = 0x01000000; 210 | static constexpr uint32_t bit_AESNI = 0x02000000; 211 | static constexpr uint32_t bit_XSAVE = 0x04000000; 212 | static constexpr uint32_t bit_OSXSAVE = 0x08000000; 213 | static constexpr uint32_t bit_AVX = 0x10000000; 214 | static constexpr uint32_t bit_F16C = 0x20000000; 215 | static constexpr uint32_t bit_RDRND = 0x40000000; 216 | 217 | /* Features in %edx for leaf 1 */ 218 | static constexpr uint32_t bit_FPU = 0x00000001; 219 | static constexpr uint32_t bit_VME = 0x00000002; 220 | static constexpr uint32_t bit_DE = 0x00000004; 221 | static constexpr uint32_t bit_PSE = 0x00000008; 222 | static constexpr uint32_t bit_TSC = 0x00000010; 223 | static constexpr uint32_t bit_MSR = 0x00000020; 224 | static constexpr uint32_t bit_PAE = 0x00000040; 225 | static constexpr uint32_t bit_MCE = 0x00000080; 226 | static constexpr uint32_t bit_CX8 = 0x00000100; 227 | static constexpr uint32_t bit_APIC = 0x00000200; 228 | static constexpr uint32_t bit_SEP = 0x00000800; 229 | static constexpr uint32_t bit_MTRR = 0x00001000; 230 | static constexpr uint32_t bit_PGE = 0x00002000; 231 | static constexpr uint32_t bit_MCA = 0x00004000; 232 | static constexpr uint32_t bit_CMOV = 0x00008000; 233 | static constexpr uint32_t bit_PAT = 0x00010000; 234 | static constexpr uint32_t bit_PSE36 = 0x00020000; 235 | static constexpr uint32_t bit_PSN = 0x00040000; 236 | static constexpr uint32_t bit_CLFSH = 0x00080000; 237 | static constexpr uint32_t bit_DS = 0x00200000; 238 | static constexpr uint32_t bit_ACPI = 0x00400000; 239 | static constexpr uint32_t bit_MMX = 0x00800000; 240 | static constexpr uint32_t bit_FXSR = 0x01000000; 241 | static constexpr uint32_t bit_SSE = 0x02000000; 242 | static constexpr uint32_t bit_SSE2 = 0x04000000; 243 | static constexpr uint32_t bit_SS = 0x08000000; 244 | static constexpr uint32_t bit_HTT = 0x10000000; 245 | static constexpr uint32_t bit_TM = 0x20000000; 246 | static constexpr uint32_t bit_PBE = 0x80000000; 247 | 248 | /* Features in %ebx for leaf 7 sub-leaf 0 */ 249 | static constexpr uint32_t bit_FSGSBASE = 0x00000001; 250 | static constexpr uint32_t bit_SGX = 0x00000004; 251 | static constexpr uint32_t bit_BMI = 0x00000008; 252 | static constexpr uint32_t bit_HLE = 0x00000010; 253 | static constexpr uint32_t bit_AVX2 = 0x00000020; 254 | static constexpr uint32_t bit_SMEP = 0x00000080; 255 | static constexpr uint32_t bit_BMI2 = 0x00000100; 256 | static constexpr uint32_t bit_ENH_MOVSB = 0x00000200; 257 | static constexpr uint32_t bit_RTM = 0x00000800; 258 | static constexpr uint32_t bit_MPX = 0x00004000; 259 | static constexpr uint32_t bit_AVX512F = 0x00010000; 260 | static constexpr uint32_t bit_AVX512DQ = 0x00020000; 261 | static constexpr uint32_t bit_RDSEED = 0x00040000; 262 | static constexpr uint32_t bit_ADX = 0x00080000; 263 | static constexpr uint32_t bit_AVX512IFMA = 0x00200000; 264 | static constexpr uint32_t bit_CLFLUSHOPT = 0x00800000; 265 | static constexpr uint32_t bit_CLWB = 0x01000000; 266 | static constexpr uint32_t bit_AVX512PF = 0x04000000; 267 | static constexpr uint32_t bit_AVX51SER = 0x08000000; 268 | static constexpr uint32_t bit_AVX512CD = 0x10000000; 269 | static constexpr uint32_t bit_SHA = 0x20000000; 270 | static constexpr uint32_t bit_AVX512BW = 0x40000000; 271 | static constexpr uint32_t bit_AVX512VL = 0x80000000; 272 | 273 | /* Features in %ecx for leaf 7 sub-leaf 0 */ 274 | static constexpr uint32_t bit_PREFTCHWT1 = 0x00000001; 275 | static constexpr uint32_t bit_AVX512VBMI = 0x00000002; 276 | static constexpr uint32_t bit_PKU = 0x00000004; 277 | static constexpr uint32_t bit_OSPKE = 0x00000010; 278 | static constexpr uint32_t bit_AVX512VPOPCNTDQ = 0x00004000; 279 | static constexpr uint32_t bit_RDPID = 0x00400000; 280 | 281 | /* Features in %edx for leaf 7 sub-leaf 0 */ 282 | static constexpr uint32_t bit_AVX5124VNNIW = 0x00000004; 283 | static constexpr uint32_t bit_AVX5124FMAPS = 0x00000008; 284 | 285 | /* Features in %eax for leaf 13 sub-leaf 1 */ 286 | static constexpr uint32_t bit_XSAVEOPT = 0x00000001; 287 | static constexpr uint32_t bit_XSAVEC = 0x00000002; 288 | static constexpr uint32_t bit_XSAVES = 0x00000008; 289 | 290 | /* Features in %ecx for leaf = 0x80000001 */; 291 | static constexpr uint32_t bit_LAHF_LM = 0x00000001; 292 | static constexpr uint32_t bit_ABM = 0x00000020; 293 | static constexpr uint32_t bit_SSE4a = 0x00000040; 294 | static constexpr uint32_t bit_PRFCHW = 0x00000100; 295 | static constexpr uint32_t bit_XOP = 0x00000800; 296 | static constexpr uint32_t bit_LWP = 0x00008000; 297 | static constexpr uint32_t bit_FMA4 = 0x00010000; 298 | static constexpr uint32_t bit_TBM = 0x00200000; 299 | static constexpr uint32_t bit_MWAITX = 0x20000000; 300 | 301 | /* Features in %edx for leaf = 0x80000001 */; 302 | static constexpr uint32_t bit_MMXEXT = 0x00400000; 303 | static constexpr uint32_t bit_LM = 0x20000000; 304 | static constexpr uint32_t bit_3DNOWP = 0x40000000; 305 | static constexpr uint32_t bit_3DNOW = 0x80000000; 306 | 307 | /* Features in %ebx for leaf = 0x80000001 */; 308 | static constexpr uint32_t bit_CLZERO = 0x00000001; 309 | 310 | /** 311 | * Reads CPU information and other data. 312 | */ 313 | void init(); 314 | 315 | /** 316 | * Installed CPU information mapping 317 | */ 318 | struct CpuTopology { 319 | /** 320 | * Number of physical processors installed 321 | */ 322 | uint8_t packageCount {0}; 323 | 324 | /** 325 | * Number of physical cores per package 326 | */ 327 | uint8_t physicalCount[MaxCpus] {}; 328 | 329 | /** 330 | * Number of logical cores per package 331 | */ 332 | uint8_t logicalCount[MaxCpus] {}; 333 | 334 | /** 335 | * Total number of physical cores 336 | */ 337 | inline uint8_t totalPhysical() { 338 | uint8_t count = physicalCount[0]; 339 | for (uint8_t i = 1; i < packageCount; i++) 340 | count += physicalCount[i]; 341 | return count; 342 | } 343 | 344 | /** 345 | * Total number of logical cores 346 | */ 347 | inline uint8_t totalLogical() { 348 | uint8_t count = logicalCount[0]; 349 | for (uint8_t i = 1; i < packageCount; i++) 350 | count += logicalCount[i]; 351 | return count; 352 | } 353 | 354 | /** 355 | * Mapping of cpu_number() to CPU package from 0 to packageCount 356 | */ 357 | uint8_t numberToPackage[MaxCpus] {}; 358 | 359 | /** 360 | * Mapping of cpu_number() to physical core from 0 to physicalCount in package 361 | */ 362 | uint8_t numberToPhysical[MaxCpus] {}; 363 | 364 | /** 365 | * Mapping of cpu_number() to physical cores from 0 to totalPhysical. 366 | */ 367 | inline uint8_t numberToPhysicalUnique(uint8_t i) { 368 | uint8_t num = 0; 369 | uint8_t package = numberToPackage[i]; 370 | for (uint8_t i = 0; i < package; i++) 371 | num += physicalCount[i]; 372 | return num + numberToPhysical[i]; 373 | } 374 | 375 | /** 376 | * Mapping of cpu_number() to logical thread from 0 to logicalCount in package 377 | * Note, that the list is sorted, and the first physicalCount logical threads 378 | * correspond to their corresponding physical cores. 379 | */ 380 | uint8_t numberToLogical[MaxCpus] {}; 381 | }; 382 | 383 | /** 384 | * Get running CPU generation. 385 | * 386 | * @param ofamily a pointer to store CPU family in 387 | * @param omodel a pointer to store CPU model in 388 | * @param ostepping a pointer to store CPU stepping in 389 | * 390 | * @return detected Intel CPU generation 391 | */ 392 | EXPORT CpuGeneration getGeneration(uint32_t *ofamily=nullptr, uint32_t *omodel=nullptr, uint32_t *ostepping=nullptr) DEPRECATE("Use BaseDeviceInfo");; 393 | 394 | /** 395 | * Obtain CPU topology. 396 | * 397 | * @param topology parsed cpu topology, must be passed zeroed. 398 | * 399 | * @return true on success 400 | */ 401 | EXPORT bool getCpuTopology(CpuTopology &topology); 402 | 403 | /** 404 | * Obtain cpuid registers 405 | * 406 | * @param no cpuid number 407 | * @param count cpuid count 408 | * @param a eax output pointer (optional) 409 | * @param b ebx output pointer (optional) 410 | * @param c ecx output pointer (optional) 411 | * @param d edx output pointer (optional) 412 | * 413 | * @return true if supported 414 | */ 415 | EXPORT bool getCpuid(uint32_t no, uint32_t count, uint32_t *a, uint32_t *b=nullptr, uint32_t *c=nullptr, uint32_t *d=nullptr); 416 | } 417 | 418 | #endif /* kern_cpu_h */ 419 | --------------------------------------------------------------------------------