Skip to content

Commit

Permalink
Updates for macOS 14.4
Browse files Browse the repository at this point in the history
Fixes #27

Signed-off-by: Visual Ehrmanntraut <[email protected]>
  • Loading branch information
VisualEhrmanntraut committed Mar 13, 2024
1 parent 7ec1a66 commit bfff2a8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 24 deletions.
70 changes: 50 additions & 20 deletions NootRX/HWLibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ bool HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address_t sl
SolveRequestPlus solveRequest {"_CAILAsicCapsInitTable", orgCapsInitTable, kCAILAsicCapsInitTablePattern};
solveRequest.solve(patcher, id, slide, size);

if (getKernelVersion() > KernelVersion::Sonoma ||
(getKernelVersion() == KernelVersion::Sonoma && getKernelMinorVersion() >= 4)) {
bool sonoma144 = getKernelVersion() > KernelVersion::Sonoma ||
(getKernelVersion() == KernelVersion::Sonoma && getKernelMinorVersion() >= 4);
if (sonoma144) {
RouteRequestPlus request = {"_psp_cmd_km_submit", wrapPspCmdKmSubmit, this->orgPspCmdKmSubmit,
kPspCmdKmSubmitPattern14_4, kPspCmdKmSubmitMask14_4};
PANIC_COND(!request.route(patcher, id, slide, size), "HWLibs", "Failed to route psp_cmd_km_submit (14.4+)");
Expand All @@ -90,11 +91,19 @@ bool HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address_t sl
}

if (NootRXMain::callback->chipType == ChipType::Navi22) {
RouteRequestPlus request = {"_smu_11_0_7_send_message_with_parameter", wrapSmu1107SendMessageWithParameter,
this->orgSmu1107SendMessageWithParameter, kSmu1107SendMessageWithParameterPattern,
kSmu1107SendMessageWithParameterPatternMask};
PANIC_COND(!request.route(patcher, id, slide, size), "HWLibs",
"Failed to route smu_11_0_7_send_message_with_parameter");
if (sonoma144) {
RouteRequestPlus request = {"_smu_11_0_7_send_message_with_parameter",
wrapSmu1107SendMessageWithParameter, this->orgSmu1107SendMessageWithParameter,
kSmu1107SendMessageWithParameterPattern14_4, kSmu1107SendMessageWithParameterPatternMask14_4};
PANIC_COND(!request.route(patcher, id, slide, size), "HWLibs",
"Failed to route smu_11_0_7_send_message_with_parameter (14.4+)");
} else {
RouteRequestPlus request = {"_smu_11_0_7_send_message_with_parameter",
wrapSmu1107SendMessageWithParameter, this->orgSmu1107SendMessageWithParameter,
kSmu1107SendMessageWithParameterPattern, kSmu1107SendMessageWithParameterPatternMask};
PANIC_COND(!request.route(patcher, id, slide, size), "HWLibs",
"Failed to route smu_11_0_7_send_message_with_parameter");
}
}

PANIC_COND(MachInfo::setKernelWriting(true, KernelPatcher::kernelWriteLock) != KERN_SUCCESS, "HWLibs",
Expand Down Expand Up @@ -231,23 +240,44 @@ bool HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address_t sl
const LookupPatchPlus patches[] = {
{&kextRadeonX6810HWLibs, kGcSwInitOriginal, kGcSwInitOriginalMask, kGcSwInitPatched,
kGcSwInitPatchedMask, 1},
{&kextRadeonX6810HWLibs, kGcSetFwEntryInfoOriginal, kGcSetFwEntryInfoOriginalMask,
kGcSetFwEntryInfoPatched, kGcSetFwEntryInfoPatchedMask, 1},
{&kextRadeonX6810HWLibs, kPspSwInit1Original, kPspSwInit1OriginalMask, kPspSwInit1Patched,
kPspSwInit1PatchedMask, 1},
{&kextRadeonX6810HWLibs, kPspSwInit2Original, kPspSwInit2OriginalMask, kPspSwInit2Patched,
kPspSwInit2PatchedMask, 1},
{&kextRadeonX6810HWLibs, kPspSwInit3Original, kPspSwInit3OriginalMask, kPspSwInit3Patched,
kPspSwInit3PatchedMask, 1},
{&kextRadeonX6810HWLibs, kSmu1107CheckFwVersionOriginal, kSmu1107CheckFwVersionOriginalMask,
kSmu1107CheckFwVersionPatched, kSmu1107CheckFwVersionPatchedMask, 1},
};
PANIC_COND(!LookupPatchPlus::applyAll(patcher, patches, slide, size), "HWLibs",
"Failed to apply Navi 22 patches");
if (getKernelVersion() >= KernelVersion::Ventura) {
const LookupPatchPlus patch {&kextRadeonX6810HWLibs, kSdmaInitFunctionPointerOriginal,
kSdmaInitFunctionPointerOriginalMask, kSdmaInitFunctionPointerPatched, 1};
PANIC_COND(!patch.apply(patcher, slide, size), "HWLibs", "Failed to apply Navi 22 Ventura SDMA patch");
"Failed to apply Navi 22 patches (all vers)");
if (sonoma144) {
const LookupPatchPlus patches[] = {
{&kextRadeonX6810HWLibs, kGcSetFwEntryInfoOriginal14_4, kGcSetFwEntryInfoOriginalMask14_4,
kGcSetFwEntryInfoPatched14_4, kGcSetFwEntryInfoPatchedMask14_4, 1},
{&kextRadeonX6810HWLibs, kPspSwInit1Original14_4, kPspSwInit1OriginalMask14_4,
kPspSwInit1Patched14_4, kPspSwInit1PatchedMask14_4, 1},
{&kextRadeonX6810HWLibs, kPspSwInit2Original14_4, kPspSwInit2OriginalMask14_4,
kPspSwInit2Patched14_4, kPspSwInit2PatchedMask14_4, 1},
{&kextRadeonX6810HWLibs, kPspSwInit3Original14_4, kPspSwInit3Patched14_4, 1},
{&kextRadeonX6810HWLibs, kSdmaInitFunctionPointerOriginal14_4,
kSdmaInitFunctionPointerOriginalMask14_4, kSdmaInitFunctionPointerPatched14_4, 1},
};
PANIC_COND(!LookupPatchPlus::applyAll(patcher, patches, slide, size), "HWLibs",
"Failed to apply Navi 22 patches (>=14.4)");
} else {
const LookupPatchPlus patches[] = {
{&kextRadeonX6810HWLibs, kGcSetFwEntryInfoOriginal, kGcSetFwEntryInfoOriginalMask,
kGcSetFwEntryInfoPatched, kGcSetFwEntryInfoPatchedMask, 1},
{&kextRadeonX6810HWLibs, kPspSwInit1Original, kPspSwInit1OriginalMask, kPspSwInit1Patched,
kPspSwInit1PatchedMask, 1},
{&kextRadeonX6810HWLibs, kPspSwInit2Original, kPspSwInit2OriginalMask, kPspSwInit2Patched,
kPspSwInit2PatchedMask, 1},
{&kextRadeonX6810HWLibs, kPspSwInit3Original, kPspSwInit3OriginalMask, kPspSwInit3Patched,
kPspSwInit3PatchedMask, 1},
};
PANIC_COND(!LookupPatchPlus::applyAll(patcher, patches, slide, size), "HWLibs",
"Failed to apply Navi 22 patches (<14.4)");
if (getKernelVersion() >= KernelVersion::Ventura) {
const LookupPatchPlus patch {&kextRadeonX6810HWLibs, kSdmaInitFunctionPointerOriginal,
kSdmaInitFunctionPointerOriginalMask, kSdmaInitFunctionPointerPatched, 1};
PANIC_COND(!patch.apply(patcher, slide, size), "HWLibs",
"Failed to apply Navi 22 Ventura SDMA patch");
}
}
}
return true;
Expand Down
35 changes: 31 additions & 4 deletions NootRX/HWLibs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ static const UInt8 kSmu1107SendMessageWithParameterPattern[] = {0x55, 0x48, 0x89
static const UInt8 kSmu1107SendMessageWithParameterPatternMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF};
static const UInt8 kSmu1107SendMessageWithParameterPattern14_4[] = {0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56,
0x41, 0x54, 0x53, 0x89, 0xD3, 0x41, 0x89, 0xF6, 0x49, 0x89, 0xFF, 0x8B, 0x8F, 0x00, 0x00, 0x00, 0x00};
static const UInt8 kSmu1107SendMessageWithParameterPatternMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF};

//------ Patches ------//

//! Replace call in `_gc_sw_init` to `_gc_get_hw_version` with constant (0x0A0304).
static const UInt8 kGcSwInitOriginal[] = {0x0C, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x41, 0x89, 0xC7};
static const UInt8 kGcSwInitOriginalMask[] = {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF};
static const UInt8 kGcSwInitPatched[] = {0x00, 0xB8, 0x04, 0x03, 0x0A, 0x00, 0x00, 0x00, 0x00};
static const UInt8 kGcSwInitPatchedMask[] = {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};
static const UInt8 kGcSwInitOriginal[] = {0x7B, 0x0C, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x41, 0x89, 0xC7};
static const UInt8 kGcSwInitOriginalMask[] = {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF};
static const UInt8 kGcSwInitPatched[] = {0x00, 0x00, 0xB8, 0x04, 0x03, 0x0A, 0x00, 0x00, 0x00, 0x00};
static const UInt8 kGcSwInitPatchedMask[] = {0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};

//! Replace call in `_gc_set_fw_entry_info` to `_gc_get_hw_version` with constant (0x0A0304).
static const UInt8 kGcSetFwEntryInfoOriginal[] = {0xE8, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x41, 0x89, 0x00, 0x10,
Expand All @@ -77,24 +81,42 @@ static const UInt8 kGcSetFwEntryInfoPatched[] = {0xB8, 0x04, 0x03, 0x0A, 0x00, 0
0x00, 0x00, 0x00, 0x00};
static const UInt8 kGcSetFwEntryInfoPatchedMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00};
static const UInt8 kGcSetFwEntryInfoOriginal14_4[] = {0xE8, 0x00, 0x00, 0x00, 0x00, 0x45, 0x31, 0xFF, 0x45, 0x89, 0x7E,
0x10};
static const UInt8 kGcSetFwEntryInfoOriginalMask14_4[] = {0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF};
static const UInt8 kGcSetFwEntryInfoPatched14_4[] = {0xB8, 0x04, 0x03, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00};
static const UInt8 kGcSetFwEntryInfoPatchedMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00};

//! `_psp_sw_init`: Force `pIn->pspVerMinor == 0x5` path.
static const UInt8 kPspSwInit1Original[] = {0x8B, 0x43, 0x10, 0x83, 0xF8, 0x05, 0x74, 0x00, 0x85, 0xC0};
static const UInt8 kPspSwInit1OriginalMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF};
static const UInt8 kPspSwInit1Patched[] = {0x66, 0x90, 0x66, 0x90, 0x66, 0x90, 0xEB, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit1PatchedMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit1Original14_4[] = {0x41, 0x8B, 0x46, 0x0C, 0x83, 0xF8, 0x05, 0x74, 0x00, 0x85, 0xC0};
static const UInt8 kPspSwInit1OriginalMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF};
static const UInt8 kPspSwInit1Patched14_4[] = {0x66, 0x90, 0x66, 0x90, 0x66, 0x90, 0x90, 0xEB, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit1PatchedMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};

//! `_psp_sw_init`: Force `pIn->pspVerPatch == 0x0` path.
static const UInt8 kPspSwInit2Original[] = {0x83, 0x7B, 0x14, 0x00, 0x74, 0x00, 0x41};
static const UInt8 kPspSwInit2OriginalMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF};
static const UInt8 kPspSwInit2Patched[] = {0x66, 0x90, 0x66, 0x90, 0xEB, 0x00, 0x00};
static const UInt8 kPspSwInit2PatchedMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00};
static const UInt8 kPspSwInit2Original14_4[] = {0x41, 0x83, 0x7E, 0x10, 0x00, 0x74, 0x00, 0xC7, 0x83};
static const UInt8 kPspSwInit2OriginalMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF};
static const UInt8 kPspSwInit2Patched14_4[] = {0x66, 0x90, 0x66, 0x90, 0x90, 0xEB, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit2PatchedMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};

//! `_psp_sw_init`: Set field `0x7???` to `0xE`.
static const UInt8 kPspSwInit3Original[] = {0x41, 0xC7, 0x84, 0x24, 0x00, 0x70, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit3OriginalMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static const UInt8 kPspSwInit3Patched[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit3PatchedMask[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00};
static const UInt8 kPspSwInit3Original14_4[] = {0xC7, 0x83, 0x94, 0x7D, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xE9};
static const UInt8 kPspSwInit3Patched14_4[] = {0xC7, 0x83, 0x94, 0x7D, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0xE9};

//! Skip check for firmware version in `_smu_11_0_7_check_fw_version`.
static const UInt8 kSmu1107CheckFwVersionOriginal[] = {0x83, 0xFE, 0x40, 0x75, 0x00, 0xEB, 0x00};
Expand All @@ -106,3 +128,8 @@ static const UInt8 kSmu1107CheckFwVersionPatchedMask[] = {0xFF, 0xFF, 0xFF, 0xFF
static const UInt8 kSdmaInitFunctionPointerOriginal[] = {0x00, 0x00, 0x00, 0x41, 0x83, 0xFE, 0x04, 0x75, 0x00};
static const UInt8 kSdmaInitFunctionPointerOriginalMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
static const UInt8 kSdmaInitFunctionPointerPatched[] = {0x00, 0x00, 0x00, 0x66, 0x90, 0x66, 0x90, 0x66, 0x90};
static const UInt8 kSdmaInitFunctionPointerOriginal14_4[] = {0xB8, 0x02, 0x00, 0x00, 0x00, 0x83, 0xF9, 0x04, 0x75,
0x00};
static const UInt8 kSdmaInitFunctionPointerOriginalMask14_4[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00};
static const UInt8 kSdmaInitFunctionPointerPatched14_4[] = {0xB8, 0x02, 0x00, 0x00, 0x00, 0x66, 0x90, 0x66, 0x90, 0x90};

0 comments on commit bfff2a8

Please sign in to comment.