From 1c833ddc3c6c58c18187ae87fb43c62e1c517dc8 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 20 Jul 2022 17:44:49 -0700 Subject: [PATCH] Create constant for GPFifo physical address --- Source/Core/Core/HW/GPFifo.h | 4 ++++ Source/Core/Core/HW/MMIO.h | 3 ++- .../Core/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp | 3 ++- Source/Core/Core/PowerPC/MMU.cpp | 5 +++-- Source/UnitTests/Core/MMIOTest.cpp | 5 +++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/HW/GPFifo.h b/Source/Core/Core/HW/GPFifo.h index 2925e82c05..b29b1b9fde 100644 --- a/Source/Core/Core/HW/GPFifo.h +++ b/Source/Core/Core/HW/GPFifo.h @@ -9,6 +9,10 @@ class PointerWrap; namespace GPFifo { +// This address is configurable in the WPAR SPR, but all games put it at this address +// (and presumably the hardware backing this system uses this address). +constexpr u32 GATHER_PIPE_PHYSICAL_ADDRESS = 0x0C008000; + constexpr u32 GATHER_PIPE_SIZE = 32; constexpr u32 GATHER_PIPE_EXTRA_SIZE = GATHER_PIPE_SIZE * 16; diff --git a/Source/Core/Core/HW/MMIO.h b/Source/Core/Core/HW/MMIO.h index d1be58bcfe..92c35bc5f3 100644 --- a/Source/Core/Core/HW/MMIO.h +++ b/Source/Core/Core/HW/MMIO.h @@ -13,6 +13,7 @@ #include "Common/BitUtils.h" #include "Common/CommonTypes.h" #include "Core/ConfigManager.h" +#include "Core/HW/GPFifo.h" #include "Core/HW/MMIOHandlers.h" namespace MMIO @@ -43,7 +44,7 @@ const u32 NUM_MMIOS = NUM_BLOCKS * BLOCK_SIZE; // interface. inline bool IsMMIOAddress(u32 address) { - if (address == 0x0C008000) + if (address == GPFifo::GATHER_PIPE_PHYSICAL_ADDRESS) return false; // WG Pipe if ((address & 0xFFFF0000) == 0x0C000000) return true; // GameCube MMIOs diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp index 04b305ce37..b7da980db3 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_SystemRegisters.cpp @@ -341,7 +341,8 @@ void Interpreter::mtspr(UGeckoInstruction inst) break; case SPR_WPAR: - ASSERT_MSG(POWERPC, rGPR[inst.RD] == 0x0C008000, "Gather pipe @ {:08x}", PC); + ASSERT_MSG(POWERPC, rSPR(SPR_WPAR) == GPFifo::GATHER_PIPE_PHYSICAL_ADDRESS, + "Gather pipe changed to unexpected address {:08x} @ PC {:08x}", rSPR(SPR_WPAR), PC); GPFifo::ResetGatherPipe(); break; diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 6c0867deb6..0ff7ccd88e 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -285,7 +285,8 @@ static void WriteToHardware(u32 em_address, const u32 data, const u32 size) // Check for a gather pipe write. // Note that we must mask the address to correctly emulate certain games; // Pac-Man World 3 in particular is affected by this. - if (flag == XCheckTLBFlag::Write && (em_address & 0xFFFFF000) == 0x0C008000) + if (flag == XCheckTLBFlag::Write && + (em_address & 0xFFFFF000) == GPFifo::GATHER_PIPE_PHYSICAL_ADDRESS) { switch (size) { @@ -1086,7 +1087,7 @@ bool IsOptimizableGatherPipeWrite(u32 address) return false; // Check whether the translated address equals the address in WPAR. - return address == 0x0C008000; + return address == GPFifo::GATHER_PIPE_PHYSICAL_ADDRESS; } TranslateResult JitCache_TranslateAddress(u32 address) diff --git a/Source/UnitTests/Core/MMIOTest.cpp b/Source/UnitTests/Core/MMIOTest.cpp index 480ba7f7b4..e10ee4e0ce 100644 --- a/Source/UnitTests/Core/MMIOTest.cpp +++ b/Source/UnitTests/Core/MMIOTest.cpp @@ -8,6 +8,7 @@ #include "Common/CommonTypes.h" #include "Common/Config/Config.h" #include "Common/FileUtil.h" +#include "Core/HW/GPFifo.h" #include "Core/HW/MMIO.h" #include "UICommon/UICommon.h" @@ -40,7 +41,7 @@ TEST(IsMMIOAddress, SpecialAddresses) SConfig::GetInstance().bWii = true; // WG Pipe address, should not be handled by MMIO. - EXPECT_FALSE(MMIO::IsMMIOAddress(0x0C008000)); + EXPECT_FALSE(MMIO::IsMMIOAddress(GPFifo::GATHER_PIPE_PHYSICAL_ADDRESS)); // Locked L1 cache allocation. EXPECT_FALSE(MMIO::IsMMIOAddress(0xE0000000)); @@ -52,7 +53,7 @@ TEST(IsMMIOAddress, SpecialAddresses) // addresses. EXPECT_FALSE(MMIO::IsMMIOAddress(0xCC0000E0)); - // And lets check some valid addresses too + // And let's check some valid addresses too EXPECT_TRUE(MMIO::IsMMIOAddress(0x0C0000E0)); // GameCube MMIOs EXPECT_TRUE(MMIO::IsMMIOAddress(0x0D00008C)); // Wii MMIOs EXPECT_TRUE(MMIO::IsMMIOAddress(0x0D800F10)); // Mirror of Wii MMIOs