From 1ceaa8c52a0f3763c015c34260518a0c35ced702 Mon Sep 17 00:00:00 2001 From: Lioncache Date: Mon, 18 Dec 2023 16:34:10 -0500 Subject: [PATCH 1/3] Core/GeckoCode: Remove global system accessor We can use the CPUThreadGuard instance to retrieve the system instance instead. --- Source/Core/Core/GeckoCode.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 3baf683314..48e3423d15 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -17,6 +17,7 @@ #include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" +#include "Core/Core.h" #include "Core/PowerPC/MMU.h" #include "Core/PowerPC/PowerPC.h" #include "Core/System.h" @@ -206,10 +207,8 @@ static Installation InstallCodeHandlerLocked(const Core::CPUThreadGuard& guard) // Turn on codes PowerPC::MMU::HostWrite_U8(guard, 1, INSTALLER_BASE_ADDRESS + 7); - auto& system = Core::System::GetInstance(); - auto& ppc_state = system.GetPPCState(); - // Invalidate the icache and any asm codes + auto& ppc_state = guard.GetSystem().GetPPCState(); for (unsigned int j = 0; j < (INSTALLER_END_ADDRESS - INSTALLER_BASE_ADDRESS); j += 32) { ppc_state.iCache.Invalidate(INSTALLER_BASE_ADDRESS + j); @@ -258,8 +257,7 @@ void RunCodeHandler(const Core::CPUThreadGuard& guard) } } - auto& system = Core::System::GetInstance(); - auto& ppc_state = system.GetPPCState(); + auto& ppc_state = guard.GetSystem().GetPPCState(); // We always do this to avoid problems with the stack since we're branching in random locations. // Even with function call return hooks (PC == LR), hand coded assembler won't necessarily From bb866248cfee7b2d099953c60a089b4fbfb9b1a7 Mon Sep 17 00:00:00 2001 From: Lioncache Date: Mon, 18 Dec 2023 16:37:33 -0500 Subject: [PATCH 2/3] Core/GeckoCode: Avoid signed conversion in RunCodeHandler() i is being used alongside unsigned types, so it should be unsigned as well. --- Source/Core/Core/GeckoCode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 48e3423d15..7ba2988b4b 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -279,7 +279,7 @@ void RunCodeHandler(const Core::CPUThreadGuard& guard) PowerPC::MMU::HostWrite_U32(guard, LR(ppc_state), SP + 16); PowerPC::MMU::HostWrite_U32(guard, ppc_state.cr.Get(), SP + 20); // Registers FPR0->13 are volatile - for (int i = 0; i < 14; ++i) + for (u32 i = 0; i < 14; ++i) { PowerPC::MMU::HostWrite_U64(guard, ppc_state.ps[i].PS0AsU64(), SP + 24 + 2 * i * sizeof(u64)); PowerPC::MMU::HostWrite_U64(guard, ppc_state.ps[i].PS1AsU64(), From cea58759d9f8d56c7d28aedfae1b34164e3c2e4d Mon Sep 17 00:00:00 2001 From: Lioncache Date: Mon, 18 Dec 2023 16:39:02 -0500 Subject: [PATCH 3/3] Core/GeckoCode: unsigned int -> u32 Same thing for all intents and purposes, less to read. --- Source/Core/Core/GeckoCode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 7ba2988b4b..fca0ff081e 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -146,7 +146,7 @@ static Installation InstallCodeHandlerLocked(const Core::CPUThreadGuard& guard) PowerPC::MMU::HostWrite_U8(guard, data[i], INSTALLER_BASE_ADDRESS + i); // Patch the code handler to the current system type (Gamecube/Wii) - for (unsigned int h = 0; h < data.length(); h += 4) + for (u32 h = 0; h < data.length(); h += 4) { // Patch MMIO address if (PowerPC::MMU::HostRead_U32(guard, INSTALLER_BASE_ADDRESS + h) == @@ -209,7 +209,7 @@ static Installation InstallCodeHandlerLocked(const Core::CPUThreadGuard& guard) // Invalidate the icache and any asm codes auto& ppc_state = guard.GetSystem().GetPPCState(); - for (unsigned int j = 0; j < (INSTALLER_END_ADDRESS - INSTALLER_BASE_ADDRESS); j += 32) + for (u32 j = 0; j < (INSTALLER_END_ADDRESS - INSTALLER_BASE_ADDRESS); j += 32) { ppc_state.iCache.Invalidate(INSTALLER_BASE_ADDRESS + j); }