From 74e1577a2c91d5c5925b8cb170dc1ad41c02b3a0 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 4 Jan 2023 02:52:40 +0100 Subject: [PATCH] HW/ProcessorInterface: Refactor to class, move to Core::System. --- Source/Core/Core/HW/AudioInterface.cpp | 7 +- Source/Core/Core/HW/DSP.cpp | 5 +- Source/Core/Core/HW/DVD/DVDInterface.cpp | 2 +- Source/Core/Core/HW/EXI/EXI.cpp | 5 +- Source/Core/Core/HW/GPFifo.cpp | 11 +-- Source/Core/Core/HW/HW.cpp | 4 +- Source/Core/Core/HW/Memmap.cpp | 2 +- Source/Core/Core/HW/ProcessorInterface.cpp | 82 ++++++++----------- Source/Core/Core/HW/ProcessorInterface.h | 68 ++++++++++----- Source/Core/Core/HW/SI/SI.cpp | 5 +- .../Core/Core/HW/SI/SI_DeviceGCController.cpp | 5 +- Source/Core/Core/HW/VideoInterface.cpp | 7 +- Source/Core/Core/HW/WII_IPC.cpp | 4 +- Source/Core/Core/Movie.cpp | 5 +- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 3 +- .../PowerPC/Jit64/Jit_SystemRegisters.cpp | 3 +- Source/Core/Core/PowerPC/JitArm64/Jit.cpp | 7 +- Source/Core/Core/PowerPC/MMU.cpp | 45 +++++----- Source/Core/Core/System.cpp | 7 ++ Source/Core/Core/System.h | 5 ++ Source/Core/DolphinNoGUI/Platform.cpp | 10 +-- .../DolphinQt/Debugger/RegisterWidget.cpp | 13 ++- Source/Core/DolphinQt/MainWindow.cpp | 4 +- Source/Core/UICommon/UICommon.cpp | 4 +- Source/Core/VideoCommon/CommandProcessor.cpp | 24 +++--- Source/Core/VideoCommon/PixelEngine.cpp | 7 +- 26 files changed, 200 insertions(+), 144 deletions(-) diff --git a/Source/Core/Core/HW/AudioInterface.cpp b/Source/Core/Core/HW/AudioInterface.cpp index af2b116117..f3951f7301 100644 --- a/Source/Core/Core/HW/AudioInterface.cpp +++ b/Source/Core/Core/HW/AudioInterface.cpp @@ -155,9 +155,10 @@ namespace { void UpdateInterrupts() { - auto& state = Core::System::GetInstance().GetAudioInterfaceState().GetData(); - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_AI, - state.control.AIINT & state.control.AIINTMSK); + auto& system = Core::System::GetInstance(); + auto& state = system.GetAudioInterfaceState().GetData(); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_AI, + state.control.AIINT & state.control.AIINTMSK); } void GenerateAudioInterrupt() diff --git a/Source/Core/Core/HW/DSP.cpp b/Source/Core/Core/HW/DSP.cpp index aedc600c9f..c9578d1f39 100644 --- a/Source/Core/Core/HW/DSP.cpp +++ b/Source/Core/Core/HW/DSP.cpp @@ -465,7 +465,8 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) // UpdateInterrupts static void UpdateInterrupts() { - auto& state = Core::System::GetInstance().GetDSPState().GetData(); + auto& system = Core::System::GetInstance(); + auto& state = system.GetDSPState().GetData(); // For each interrupt bit in DSP_CONTROL, the interrupt enablemask is the bit directly // to the left of it. By doing: @@ -474,7 +475,7 @@ static void UpdateInterrupts() bool ints_set = (((state.dsp_control.Hex >> 1) & state.dsp_control.Hex & (INT_DSP | INT_ARAM | INT_AID)) != 0); - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_DSP, ints_set); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_DSP, ints_set); } static void GenerateDSPInterrupt(Core::System& system, u64 DSPIntType, s64 cyclesLate) diff --git a/Source/Core/Core/HW/DVD/DVDInterface.cpp b/Source/Core/Core/HW/DVD/DVDInterface.cpp index 94051a66be..d3277914c1 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVD/DVDInterface.cpp @@ -737,7 +737,7 @@ static void UpdateInterrupts() (state.DISR.BRKINT & state.DISR.BRKINTMASK) != 0 || (state.DICVR.CVRINT & state.DICVR.CVRINTMASK) != 0; - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_DI, set_mask); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_DI, set_mask); // Required for Summoner: A Goddess Reborn system.GetCoreTiming().ForceExceptionCheck(50); diff --git a/Source/Core/Core/HW/EXI/EXI.cpp b/Source/Core/Core/HW/EXI/EXI.cpp index 126872634e..b697f7f878 100644 --- a/Source/Core/Core/HW/EXI/EXI.cpp +++ b/Source/Core/Core/HW/EXI/EXI.cpp @@ -263,14 +263,15 @@ void UpdateInterrupts() // Channel 0 Device 0 generates interrupt on channel 0 // Channel 0 Device 2 generates interrupt on channel 2 // Channel 1 Device 0 generates interrupt on channel 1 - auto& state = Core::System::GetInstance().GetExpansionInterfaceState().GetData(); + auto& system = Core::System::GetInstance(); + auto& state = system.GetExpansionInterfaceState().GetData(); state.channels[2]->SetEXIINT(state.channels[0]->GetDevice(4)->IsInterruptSet()); bool causeInt = false; for (auto& channel : state.channels) causeInt |= channel->IsCausingInterrupt(); - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_EXI, causeInt); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_EXI, causeInt); } static void UpdateInterruptsCallback(Core::System& system, u64 userdata, s64 cycles_late) diff --git a/Source/Core/Core/HW/GPFifo.cpp b/Source/Core/Core/HW/GPFifo.cpp index de0d1773a4..564295ecf3 100644 --- a/Source/Core/Core/HW/GPFifo.cpp +++ b/Source/Core/Core/HW/GPFifo.cpp @@ -85,10 +85,11 @@ void UpdateGatherPipe() { auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); + auto& processor_interface = system.GetProcessorInterface(); size_t pipe_count = GetGatherPipeCount(); size_t processed; - u8* cur_mem = memory.GetPointer(ProcessorInterface::Fifo_CPUWritePointer); + u8* cur_mem = memory.GetPointer(processor_interface.Fifo_CPUWritePointer); for (processed = 0; pipe_count >= GATHER_PIPE_SIZE; processed += GATHER_PIPE_SIZE) { // copy the GatherPipe @@ -96,15 +97,15 @@ void UpdateGatherPipe() pipe_count -= GATHER_PIPE_SIZE; // increase the CPUWritePointer - if (ProcessorInterface::Fifo_CPUWritePointer == ProcessorInterface::Fifo_CPUEnd) + if (processor_interface.Fifo_CPUWritePointer == processor_interface.Fifo_CPUEnd) { - ProcessorInterface::Fifo_CPUWritePointer = ProcessorInterface::Fifo_CPUBase; - cur_mem = memory.GetPointer(ProcessorInterface::Fifo_CPUWritePointer); + processor_interface.Fifo_CPUWritePointer = processor_interface.Fifo_CPUBase; + cur_mem = memory.GetPointer(processor_interface.Fifo_CPUWritePointer); } else { cur_mem += GATHER_PIPE_SIZE; - ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE; + processor_interface.Fifo_CPUWritePointer += GATHER_PIPE_SIZE; } system.GetCommandProcessor().GatherPipeBursted(system); diff --git a/Source/Core/Core/HW/HW.cpp b/Source/Core/Core/HW/HW.cpp index 901e7c3507..759e6fd632 100644 --- a/Source/Core/Core/HW/HW.cpp +++ b/Source/Core/Core/HW/HW.cpp @@ -43,7 +43,7 @@ void Init(const Sram* override_sram) AudioInterface::Init(); VideoInterface::Init(); SerialInterface::Init(); - ProcessorInterface::Init(); + system.GetProcessorInterface().Init(); ExpansionInterface::Init(override_sram); // Needs to be initialized before Memory HSP::Init(); system.GetMemory().Init(); // Needs to be initialized before AddressSpace @@ -97,7 +97,7 @@ void DoState(PointerWrap& p) p.DoMarker("VideoInterface"); SerialInterface::DoState(p); p.DoMarker("SerialInterface"); - ProcessorInterface::DoState(p); + system.GetProcessorInterface().DoState(p); p.DoMarker("ProcessorInterface"); DSP::DoState(p); p.DoMarker("DSP"); diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index acacfa85e0..9edd303db3 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -52,7 +52,7 @@ void MemoryManager::InitMMIO(bool is_wii) system.GetCommandProcessor().RegisterMMIO(system, m_mmio_mapping.get(), 0x0C000000); system.GetPixelEngine().RegisterMMIO(m_mmio_mapping.get(), 0x0C001000); VideoInterface::RegisterMMIO(m_mmio_mapping.get(), 0x0C002000); - ProcessorInterface::RegisterMMIO(m_mmio_mapping.get(), 0x0C003000); + system.GetProcessorInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C003000); MemoryInterface::RegisterMMIO(m_mmio_mapping.get(), 0x0C004000); DSP::RegisterMMIO(m_mmio_mapping.get(), 0x0C005000); DVDInterface::RegisterMMIO(m_mmio_mapping.get(), 0x0C006000, false); diff --git a/Source/Core/Core/HW/ProcessorInterface.cpp b/Source/Core/Core/HW/ProcessorInterface.cpp index f55d5ab8b8..165487a0a5 100644 --- a/Source/Core/Core/HW/ProcessorInterface.cpp +++ b/Source/Core/Core/HW/ProcessorInterface.cpp @@ -27,30 +27,7 @@ constexpr u32 FLIPPER_REV_A = 0x046500B0; constexpr u32 FLIPPER_REV_B = 0x146500B1; constexpr u32 FLIPPER_REV_C = 0x246500B1; -// STATE_TO_SAVE -u32 m_InterruptCause; -u32 m_InterruptMask; -// addresses for CPU fifo accesses -u32 Fifo_CPUBase; -u32 Fifo_CPUEnd; -u32 Fifo_CPUWritePointer; - -static u32 m_ResetCode; - -// ID and callback for scheduling reset button presses/releases -static CoreTiming::EventType* toggleResetButton; -static void ToggleResetButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate); - -static CoreTiming::EventType* iosNotifyResetButton; -static void IOSNotifyResetButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate); - -static CoreTiming::EventType* iosNotifyPowerButton; -static void IOSNotifyPowerButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate); - -// Let the PPC know that an external exception is set/cleared -void UpdateException(); - -void DoState(PointerWrap& p) +void ProcessorInterfaceManager::DoState(PointerWrap& p) { p.Do(m_InterruptMask); p.Do(m_InterruptCause); @@ -60,7 +37,7 @@ void DoState(PointerWrap& p) p.Do(m_ResetCode); } -void Init() +void ProcessorInterfaceManager::Init() { m_InterruptMask = 0; m_InterruptCause = 0; @@ -81,18 +58,20 @@ void Init() core_timing.RegisterEvent("IOSNotifyPowerButton", IOSNotifyPowerButtonCallback); } -void RegisterMMIO(MMIO::Mapping* mmio, u32 base) +void ProcessorInterfaceManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) { mmio->Register(base | PI_INTERRUPT_CAUSE, MMIO::DirectRead(&m_InterruptCause), - MMIO::ComplexWrite([](Core::System&, u32, u32 val) { - m_InterruptCause &= ~val; - UpdateException(); + MMIO::ComplexWrite([](Core::System& system, u32, u32 val) { + auto& processor_interface = system.GetProcessorInterface(); + processor_interface.m_InterruptCause &= ~val; + processor_interface.UpdateException(); })); mmio->Register(base | PI_INTERRUPT_MASK, MMIO::DirectRead(&m_InterruptMask), - MMIO::ComplexWrite([](Core::System&, u32, u32 val) { - m_InterruptMask = val; - UpdateException(); + MMIO::ComplexWrite([](Core::System& system, u32, u32 val) { + auto& processor_interface = system.GetProcessorInterface(); + processor_interface.m_InterruptMask = val; + processor_interface.UpdateException(); })); mmio->Register(base | PI_FIFO_BASE, MMIO::DirectRead(&Fifo_CPUBase), @@ -127,14 +106,18 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) } })); - mmio->Register(base | PI_RESET_CODE, MMIO::ComplexRead([](Core::System&, u32) { - DEBUG_LOG_FMT(PROCESSORINTERFACE, "Read PI_RESET_CODE: {:08x}", m_ResetCode); - return m_ResetCode; + mmio->Register(base | PI_RESET_CODE, MMIO::ComplexRead([](Core::System& system, u32) { + auto& processor_interface = system.GetProcessorInterface(); + DEBUG_LOG_FMT(PROCESSORINTERFACE, "Read PI_RESET_CODE: {:08x}", + processor_interface.m_ResetCode); + return processor_interface.m_ResetCode; }), - MMIO::ComplexWrite([](Core::System&, u32, u32 val) { - m_ResetCode = val; - INFO_LOG_FMT(PROCESSORINTERFACE, "Wrote PI_RESET_CODE: {:08x}", m_ResetCode); - if (!SConfig::GetInstance().bWii && ~m_ResetCode & 0x4) + MMIO::ComplexWrite([](Core::System& system, u32, u32 val) { + auto& processor_interface = system.GetProcessorInterface(); + processor_interface.m_ResetCode = val; + INFO_LOG_FMT(PROCESSORINTERFACE, "Wrote PI_RESET_CODE: {:08x}", + processor_interface.m_ResetCode); + if (!SConfig::GetInstance().bWii && ~processor_interface.m_ResetCode & 0x4) { DVDInterface::ResetDrive(true); } @@ -153,7 +136,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) } } -void UpdateException() +void ProcessorInterfaceManager::UpdateException() { if ((m_InterruptCause & m_InterruptMask) != 0) PowerPC::ppcState.Exceptions |= EXCEPTION_EXTERNAL_INT; @@ -202,7 +185,7 @@ static const char* Debug_GetInterruptName(u32 cause_mask) } } -void SetInterrupt(u32 cause_mask, bool set) +void ProcessorInterfaceManager::SetInterrupt(u32 cause_mask, bool set) { DEBUG_ASSERT_MSG(POWERPC, Core::IsCPUThread(), "SetInterrupt from wrong thread"); @@ -227,17 +210,19 @@ void SetInterrupt(u32 cause_mask, bool set) UpdateException(); } -static void SetResetButton(bool set) +void ProcessorInterfaceManager::SetResetButton(bool set) { SetInterrupt(INT_CAUSE_RST_BUTTON, !set); } -static void ToggleResetButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate) +void ProcessorInterfaceManager::ToggleResetButtonCallback(Core::System& system, u64 userdata, + s64 cyclesLate) { - SetResetButton(!!userdata); + system.GetProcessorInterface().SetResetButton(!!userdata); } -static void IOSNotifyResetButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate) +void ProcessorInterfaceManager::IOSNotifyResetButtonCallback(Core::System& system, u64 userdata, + s64 cyclesLate) { const auto ios = IOS::HLE::GetIOS(); if (!ios) @@ -248,7 +233,8 @@ static void IOSNotifyResetButtonCallback(Core::System& system, u64 userdata, s64 std::static_pointer_cast(stm)->ResetButton(); } -static void IOSNotifyPowerButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate) +void ProcessorInterfaceManager::IOSNotifyPowerButtonCallback(Core::System& system, u64 userdata, + s64 cyclesLate) { const auto ios = IOS::HLE::GetIOS(); if (!ios) @@ -259,7 +245,7 @@ static void IOSNotifyPowerButtonCallback(Core::System& system, u64 userdata, s64 std::static_pointer_cast(stm)->PowerButton(); } -void ResetButton_Tap() +void ProcessorInterfaceManager::ResetButton_Tap() { if (!Core::IsRunning()) return; @@ -272,7 +258,7 @@ void ResetButton_Tap() CoreTiming::FromThread::ANY); } -void PowerButton_Tap() +void ProcessorInterfaceManager::PowerButton_Tap() { if (!Core::IsRunning()) return; diff --git a/Source/Core/Core/HW/ProcessorInterface.h b/Source/Core/Core/HW/ProcessorInterface.h index 0403b6d0a3..8655b80cc5 100644 --- a/Source/Core/Core/HW/ProcessorInterface.h +++ b/Source/Core/Core/HW/ProcessorInterface.h @@ -7,6 +7,14 @@ class PointerWrap; +namespace Core +{ +class System; +} +namespace CoreTiming +{ +struct EventType; +} namespace MMIO { class Mapping; @@ -52,30 +60,46 @@ enum PI_FLIPPER_UNK = 0x30 // BS1 writes 0x0245248A to it - prolly some bootstrap thing }; -extern u32 m_InterruptCause; -extern u32 m_InterruptMask; -extern u32 Fifo_CPUBase; -extern u32 Fifo_CPUEnd; -extern u32 Fifo_CPUWritePointer; - -void Init(); -void DoState(PointerWrap& p); - -void RegisterMMIO(MMIO::Mapping* mmio, u32 base); - -inline u32 GetMask() +class ProcessorInterfaceManager { - return m_InterruptMask; -} -inline u32 GetCause() -{ - return m_InterruptCause; -} +public: + void Init(); + void DoState(PointerWrap& p); -void SetInterrupt(u32 cause_mask, bool set = true); + void RegisterMMIO(MMIO::Mapping* mmio, u32 base); -// Thread-safe func which sets and clears reset button state automagically -void ResetButton_Tap(); -void PowerButton_Tap(); + u32 GetMask() const { return m_InterruptMask; } + u32 GetCause() const { return m_InterruptCause; } + void SetInterrupt(u32 cause_mask, bool set = true); + + // Thread-safe func which sets and clears reset button state automagically + void ResetButton_Tap(); + void PowerButton_Tap(); + + u32 m_InterruptCause = 0; + u32 m_InterruptMask = 0; + + // addresses for CPU fifo accesses + u32 Fifo_CPUBase = 0; + u32 Fifo_CPUEnd = 0; + u32 Fifo_CPUWritePointer = 0; + +private: + // Let the PPC know that an external exception is set/cleared + void UpdateException(); + + void SetResetButton(bool set); + + // ID and callback for scheduling reset button presses/releases + static void ToggleResetButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate); + static void IOSNotifyResetButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate); + static void IOSNotifyPowerButtonCallback(Core::System& system, u64 userdata, s64 cyclesLate); + + CoreTiming::EventType* toggleResetButton = nullptr; + CoreTiming::EventType* iosNotifyResetButton = nullptr; + CoreTiming::EventType* iosNotifyPowerButton = nullptr; + + u32 m_ResetCode = 0; +}; } // namespace ProcessorInterface diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp index c6766e96e9..caf40ed58d 100644 --- a/Source/Core/Core/HW/SI/SI.cpp +++ b/Source/Core/Core/HW/SI/SI.cpp @@ -253,7 +253,8 @@ static void ChangeDeviceCallback(Core::System& system, u64 user_data, s64 cycles static void UpdateInterrupts() { // check if we have to update the RDSTINT flag - auto& state = Core::System::GetInstance().GetSerialInterfaceState().GetData(); + auto& system = Core::System::GetInstance(); + auto& state = system.GetSerialInterfaceState().GetData(); if (state.status_reg.RDST0 || state.status_reg.RDST1 || state.status_reg.RDST2 || state.status_reg.RDST3) { @@ -268,7 +269,7 @@ static void UpdateInterrupts() const bool generate_interrupt = (state.com_csr.RDSTINT & state.com_csr.RDSTINTMSK) != 0 || (state.com_csr.TCINT & state.com_csr.TCINTMSK) != 0; - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_SI, generate_interrupt); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_SI, generate_interrupt); } static void GenerateSIInterrupt(SIInterruptType type) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp index 9f0941bd16..6abea36c8e 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp @@ -269,13 +269,14 @@ CSIDevice_GCController::HandleButtonCombos(const GCPadStatus& pad_status) if (m_last_button_combo != COMBO_NONE) { - const u64 current_time = Core::System::GetInstance().GetCoreTiming().GetTicks(); + auto& system = Core::System::GetInstance(); + const u64 current_time = system.GetCoreTiming().GetTicks(); if (u32(current_time - m_timer_button_combo_start) > SystemTimers::GetTicksPerSecond() * 3) { if (m_last_button_combo == COMBO_RESET) { INFO_LOG_FMT(SERIALINTERFACE, "PAD - COMBO_RESET"); - ProcessorInterface::ResetButton_Tap(); + system.GetProcessorInterface().ResetButton_Tap(); } else if (m_last_button_combo == COMBO_ORIGIN) { diff --git a/Source/Core/Core/HW/VideoInterface.cpp b/Source/Core/Core/HW/VideoInterface.cpp index a743bd0cae..f40f475c4d 100644 --- a/Source/Core/Core/HW/VideoInterface.cpp +++ b/Source/Core/Core/HW/VideoInterface.cpp @@ -424,17 +424,18 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) void UpdateInterrupts() { - auto& state = Core::System::GetInstance().GetVideoInterfaceState().GetData(); + auto& system = Core::System::GetInstance(); + auto& state = system.GetVideoInterfaceState().GetData(); if ((state.interrupt_register[0].IR_INT && state.interrupt_register[0].IR_MASK) || (state.interrupt_register[1].IR_INT && state.interrupt_register[1].IR_MASK) || (state.interrupt_register[2].IR_INT && state.interrupt_register[2].IR_MASK) || (state.interrupt_register[3].IR_INT && state.interrupt_register[3].IR_MASK)) { - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_VI, true); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_VI, true); } else { - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_VI, false); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_VI, false); } } diff --git a/Source/Core/Core/HW/WII_IPC.cpp b/Source/Core/Core/HW/WII_IPC.cpp index 3ebff20a69..baeb0aa15b 100644 --- a/Source/Core/Core/HW/WII_IPC.cpp +++ b/Source/Core/Core/HW/WII_IPC.cpp @@ -298,8 +298,8 @@ static void UpdateInterrupts(Core::System& system, u64 userdata, s64 cyclesLate) } // Generate interrupt on PI if any of the devices behind starlet have an interrupt and mask is set - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_WII_IPC, - !!(ppc_irq_flags & ppc_irq_masks)); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_WII_IPC, + !!(ppc_irq_flags & ppc_irq_masks)); } void ClearX1() diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 0e16010df2..ba52fb6f54 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1273,7 +1273,10 @@ void PlayController(GCPadStatus* PadStatus, int controllerID) } if (s_padState.reset) - ProcessorInterface::ResetButton_Tap(); + { + auto& system = Core::System::GetInstance(); + system.GetProcessorInterface().ResetButton_Tap(); + } SetInputDisplayString(s_padState, controllerID); CheckInputEnd(); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 3bd14acba6..1caaac3b52 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -1044,7 +1044,8 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) SetJumpTarget(extException); TEST(32, PPCSTATE(msr), Imm32(0x0008000)); FixupBranch noExtIntEnable = J_CC(CC_Z, true); - MOV(64, R(RSCRATCH), ImmPtr(&ProcessorInterface::m_InterruptCause)); + auto& system = Core::System::GetInstance(); + MOV(64, R(RSCRATCH), ImmPtr(&system.GetProcessorInterface().m_InterruptCause)); TEST(32, MatR(RSCRATCH), Imm32(ProcessorInterface::INT_CAUSE_CP | ProcessorInterface::INT_CAUSE_PE_TOKEN | ProcessorInterface::INT_CAUSE_PE_FINISH)); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp index 3629e2deec..cd19603601 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp @@ -452,7 +452,8 @@ void Jit64::mtmsr(UGeckoInstruction inst) FixupBranch noExceptionsPending = J_CC(CC_Z, true); // Check if a CP interrupt is waiting and keep the GPU emulation in sync (issue 4336) - MOV(64, R(RSCRATCH), ImmPtr(&ProcessorInterface::m_InterruptCause)); + auto& system = Core::System::GetInstance(); + MOV(64, R(RSCRATCH), ImmPtr(&system.GetProcessorInterface().m_InterruptCause)); TEST(32, MatR(RSCRATCH), Imm32(ProcessorInterface::INT_CAUSE_CP)); FixupBranch cpInt = J_CC(CC_NZ); diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index e34a5583a6..036c63af74 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -979,8 +979,9 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) SetJumpTarget(exception); LDR(IndexType::Unsigned, ARM64Reg::W30, PPC_REG, PPCSTATE_OFF(msr)); TBZ(ARM64Reg::W30, 15, done_here); // MSR.EE + auto& system = Core::System::GetInstance(); LDR(IndexType::Unsigned, ARM64Reg::W30, ARM64Reg::X30, - MOVPage2R(ARM64Reg::X30, &ProcessorInterface::m_InterruptCause)); + MOVPage2R(ARM64Reg::X30, &system.GetProcessorInterface().m_InterruptCause)); constexpr u32 cause_mask = ProcessorInterface::INT_CAUSE_CP | ProcessorInterface::INT_CAUSE_PE_TOKEN | ProcessorInterface::INT_CAUSE_PE_FINISH; @@ -1015,7 +1016,9 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) SetJumpTarget(exception); LDR(IndexType::Unsigned, WA, PPC_REG, PPCSTATE_OFF(msr)); TBZ(WA, 15, done_here); // MSR.EE - LDR(IndexType::Unsigned, WA, XA, MOVPage2R(XA, &ProcessorInterface::m_InterruptCause)); + auto& system = Core::System::GetInstance(); + LDR(IndexType::Unsigned, WA, XA, + MOVPage2R(XA, &system.GetProcessorInterface().m_InterruptCause)); constexpr u32 cause_mask = ProcessorInterface::INT_CAUSE_CP | ProcessorInterface::INT_CAUSE_PE_TOKEN | ProcessorInterface::INT_CAUSE_PE_FINISH; diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 307b6bfcbf..150b6673ec 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -255,8 +255,8 @@ static T ReadFromHardware(Memory::MemoryManager& memory, u32 em_address) } template -static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const u32 data, - const u32 size) +static void WriteToHardware(Core::System& system, Memory::MemoryManager& memory, u32 em_address, + const u32 data, const u32 size) { DEBUG_ASSERT(size <= 4); @@ -269,9 +269,10 @@ static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const // Note that "word" means 32-bit, so paired singles or doubles might still be 32-bit aligned! const u32 first_half_size = em_address_end_page - em_address; const u32 second_half_size = size - first_half_size; - WriteToHardware(memory, em_address, + WriteToHardware(system, memory, em_address, std::rotr(data, second_half_size * 8), first_half_size); - WriteToHardware(memory, em_address_end_page, data, second_half_size); + WriteToHardware(system, memory, em_address_end_page, data, + second_half_size); return; } @@ -376,7 +377,7 @@ static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const // TODO: This interrupt is supposed to have associated cause and address registers // TODO: This should trigger the hwtest's interrupt handling, but it does not seem to // (https://github.com/dolphin-emu/hwtests/pull/42) - ProcessorInterface::SetInterrupt(ProcessorInterface::INT_CAUSE_PI); + system.GetProcessorInterface().SetInterrupt(ProcessorInterface::INT_CAUSE_PI); const u32 rotated_data = std::rotr(data, ((em_address & 0x3) + size) * 8); @@ -384,8 +385,8 @@ static void WriteToHardware(Memory::MemoryManager& memory, u32 em_address, const const u32 end_addr = Common::AlignUp(em_address + size, 8); for (u32 addr = start_addr; addr != end_addr; addr += 8) { - WriteToHardware(memory, addr, rotated_data, 4); - WriteToHardware(memory, addr + 4, rotated_data, 4); + WriteToHardware(system, memory, addr, rotated_data, 4); + WriteToHardware(system, memory, addr + 4, rotated_data, 4); } return; @@ -688,7 +689,7 @@ void Write_U8(const u32 var, const u32 address) Memcheck(address, var, true, 1); auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, var, 1); + WriteToHardware(system, memory, address, var, 1); } void Write_U16(const u32 var, const u32 address) @@ -696,7 +697,7 @@ void Write_U16(const u32 var, const u32 address) Memcheck(address, var, true, 2); auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, var, 2); + WriteToHardware(system, memory, address, var, 2); } void Write_U16_Swap(const u32 var, const u32 address) { @@ -708,7 +709,7 @@ void Write_U32(const u32 var, const u32 address) Memcheck(address, var, true, 4); auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, var, 4); + WriteToHardware(system, memory, address, var, 4); } void Write_U32_Swap(const u32 var, const u32 address) { @@ -720,8 +721,9 @@ void Write_U64(const u64 var, const u32 address) Memcheck(address, var, true, 8); auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, static_cast(var >> 32), 4); - WriteToHardware(memory, address + sizeof(u32), static_cast(var), 4); + WriteToHardware(system, memory, address, static_cast(var >> 32), 4); + WriteToHardware(system, memory, address + sizeof(u32), + static_cast(var), 4); } void Write_U64_Swap(const u64 var, const u32 address) { @@ -781,30 +783,31 @@ void HostWrite_U8(const u32 var, const u32 address) { auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, var, 1); + WriteToHardware(system, memory, address, var, 1); } void HostWrite_U16(const u32 var, const u32 address) { auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, var, 2); + WriteToHardware(system, memory, address, var, 2); } void HostWrite_U32(const u32 var, const u32 address) { auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, var, 4); + WriteToHardware(system, memory, address, var, 4); } void HostWrite_U64(const u64 var, const u32 address) { auto& system = Core::System::GetInstance(); auto& memory = system.GetMemory(); - WriteToHardware(memory, address, static_cast(var >> 32), 4); - WriteToHardware(memory, address + sizeof(u32), static_cast(var), + WriteToHardware(system, memory, address, static_cast(var >> 32), 4); + WriteToHardware(system, memory, address + sizeof(u32), + static_cast(var), 4); } void HostWrite_F32(const float var, const u32 address) @@ -833,15 +836,15 @@ static std::optional HostTryWriteUX(const u32 var, const u32 addres switch (space) { case RequestedAddressSpace::Effective: - WriteToHardware(memory, address, var, size); + WriteToHardware(system, memory, address, var, size); return WriteResult(!!MSR.DR); case RequestedAddressSpace::Physical: - WriteToHardware(memory, address, var, size); + WriteToHardware(system, memory, address, var, size); return WriteResult(false); case RequestedAddressSpace::Virtual: if (!MSR.DR) return std::nullopt; - WriteToHardware(memory, address, var, size); + WriteToHardware(system, memory, address, var, size); return WriteResult(true); } @@ -1130,7 +1133,7 @@ void ClearCacheLine(u32 address) // TODO: This isn't precisely correct for non-RAM regions, but the difference // is unlikely to matter. for (u32 i = 0; i < 32; i += 4) - WriteToHardware(memory, address + i, 0, 4); + WriteToHardware(system, memory, address + i, 0, 4); } u32 IsOptimizableMMIOAccess(u32 address, u32 access_size) diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index ba47b9e9c2..a52996667a 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -15,6 +15,7 @@ #include "Core/HW/EXI/EXI.h" #include "Core/HW/Memmap.h" #include "Core/HW/MemoryInterface.h" +#include "Core/HW/ProcessorInterface.h" #include "Core/HW/SI/SI.h" #include "Core/HW/Sram.h" #include "Core/HW/VideoInterface.h" @@ -46,6 +47,7 @@ struct System::Impl MemoryInterface::MemoryInterfaceState m_memory_interface_state; PixelEngine::PixelEngineManager m_pixel_engine; PixelShaderManager m_pixel_shader_manager; + ProcessorInterface::ProcessorInterfaceManager m_processor_interface; SerialInterface::SerialInterfaceState m_serial_interface_state; Sram m_sram; VertexShaderManager m_vertex_shader_manager; @@ -160,6 +162,11 @@ PixelShaderManager& System::GetPixelShaderManager() const return m_impl->m_pixel_shader_manager; } +ProcessorInterface::ProcessorInterfaceManager& System::GetProcessorInterface() const +{ + return m_impl->m_processor_interface; +} + SerialInterface::SerialInterfaceState& System::GetSerialInterfaceState() const { return m_impl->m_serial_interface_state; diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h index fe8b9ca36e..0d6a9dbd92 100644 --- a/Source/Core/Core/System.h +++ b/Source/Core/Core/System.h @@ -55,6 +55,10 @@ namespace PixelEngine { class PixelEngineManager; }; +namespace ProcessorInterface +{ +class ProcessorInterfaceManager; +} namespace SerialInterface { class SerialInterfaceState; @@ -111,6 +115,7 @@ public: MemoryInterface::MemoryInterfaceState& GetMemoryInterfaceState() const; PixelEngine::PixelEngineManager& GetPixelEngine() const; PixelShaderManager& GetPixelShaderManager() const; + ProcessorInterface::ProcessorInterfaceManager& GetProcessorInterface() const; SerialInterface::SerialInterfaceState& GetSerialInterfaceState() const; Sram& GetSRAM() const; VertexShaderManager& GetVertexShaderManager() const; diff --git a/Source/Core/DolphinNoGUI/Platform.cpp b/Source/Core/DolphinNoGUI/Platform.cpp index d2caa71da8..52321da95c 100644 --- a/Source/Core/DolphinNoGUI/Platform.cpp +++ b/Source/Core/DolphinNoGUI/Platform.cpp @@ -2,14 +2,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "DolphinNoGUI/Platform.h" +#include "Core/HW/ProcessorInterface.h" #include "Core/IOS/IOS.h" #include "Core/IOS/STM/STM.h" #include "Core/State.h" - -namespace ProcessorInterface -{ -void PowerButton_Tap(); -} +#include "Core/System.h" Platform::~Platform() = default; @@ -31,7 +28,8 @@ void Platform::UpdateRunningFlag() if (!m_tried_graceful_shutdown.IsSet() && stm && std::static_pointer_cast(stm)->HasHookInstalled()) { - ProcessorInterface::PowerButton_Tap(); + auto& system = Core::System::GetInstance(); + system.GetProcessorInterface().PowerButton_Tap(); m_tried_graceful_shutdown.Set(); } else diff --git a/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp b/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp index c671499119..7dad7bf3c1 100644 --- a/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/RegisterWidget.cpp @@ -16,6 +16,7 @@ #include "Core/Core.h" #include "Core/HW/ProcessorInterface.h" #include "Core/PowerPC/PowerPC.h" +#include "Core/System.h" #include "DolphinQt/Host.h" #include "DolphinQt/Settings.h" @@ -448,12 +449,20 @@ void RegisterWidget::PopulateTable() // Int Mask AddRegister( - 27, 5, RegisterType::int_mask, "Int Mask", [] { return ProcessorInterface::GetMask(); }, + 27, 5, RegisterType::int_mask, "Int Mask", + [] { + auto& system = Core::System::GetInstance(); + return system.GetProcessorInterface().GetMask(); + }, nullptr); // Int Cause AddRegister( - 28, 5, RegisterType::int_cause, "Int Cause", [] { return ProcessorInterface::GetCause(); }, + 28, 5, RegisterType::int_cause, "Int Cause", + [] { + auto& system = Core::System::GetInstance(); + return system.GetProcessorInterface().GetCause(); + }, nullptr); // DSISR diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 7e530ba237..5c13da946c 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -61,6 +61,7 @@ #include "Core/NetPlayProto.h" #include "Core/NetPlayServer.h" #include "Core/State.h" +#include "Core/System.h" #include "Core/WiiUtils.h" #include "DiscIO/DirectoryBlob.h" @@ -942,7 +943,8 @@ void MainWindow::Reset() { if (Movie::IsRecordingInput()) Movie::SetReset(true); - ProcessorInterface::ResetButton_Tap(); + auto& system = Core::System::GetInstance(); + system.GetProcessorInterface().ResetButton_Tap(); } void MainWindow::FrameAdvance() diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 8e4bbbfdc5..349b21d52e 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -37,6 +37,7 @@ #include "Core/HotkeyManager.h" #include "Core/IOS/IOS.h" #include "Core/IOS/STM/STM.h" +#include "Core/System.h" #include "Core/WiiRoot.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" @@ -433,7 +434,8 @@ bool TriggerSTMPowerEvent() return false; Core::DisplayMessage("Shutting down", 30000); - ProcessorInterface::PowerButton_Tap(); + auto& system = Core::System::GetInstance(); + system.GetProcessorInterface().PowerButton_Tap(); return true; } diff --git a/Source/Core/VideoCommon/CommandProcessor.cpp b/Source/Core/VideoCommon/CommandProcessor.cpp index 529c82db04..b6bb1bb20d 100644 --- a/Source/Core/VideoCommon/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/CommandProcessor.cpp @@ -363,6 +363,8 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system) SetCPStatusFromCPU(system); + auto& processor_interface = system.GetProcessorInterface(); + // if we aren't linked, we don't care about gather pipe data if (!m_cp_ctrl_reg.GPLinkEnable) { @@ -370,8 +372,8 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system) { // In multibuffer mode is not allowed write in the same FIFO attached to the GPU. // Fix Pokemon XD in DC mode. - if ((ProcessorInterface::Fifo_CPUEnd == fifo.CPEnd.load(std::memory_order_relaxed)) && - (ProcessorInterface::Fifo_CPUBase == fifo.CPBase.load(std::memory_order_relaxed)) && + if ((processor_interface.Fifo_CPUEnd == fifo.CPEnd.load(std::memory_order_relaxed)) && + (processor_interface.Fifo_CPUBase == fifo.CPBase.load(std::memory_order_relaxed)) && fifo.CPReadWriteDistance.load(std::memory_order_relaxed) > 0) { system.GetFifo().FlushGpu(system); @@ -394,9 +396,9 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system) if (m_cp_ctrl_reg.GPReadEnable && m_cp_ctrl_reg.GPLinkEnable) { - ProcessorInterface::Fifo_CPUWritePointer = fifo.CPWritePointer.load(std::memory_order_relaxed); - ProcessorInterface::Fifo_CPUBase = fifo.CPBase.load(std::memory_order_relaxed); - ProcessorInterface::Fifo_CPUEnd = fifo.CPEnd.load(std::memory_order_relaxed); + processor_interface.Fifo_CPUWritePointer = fifo.CPWritePointer.load(std::memory_order_relaxed); + processor_interface.Fifo_CPUBase = fifo.CPBase.load(std::memory_order_relaxed); + processor_interface.Fifo_CPUEnd = fifo.CPEnd.load(std::memory_order_relaxed); } // If the game is running close to overflowing, make the exception checking more frequent. @@ -416,13 +418,13 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system) // check if we are in sync ASSERT_MSG(COMMANDPROCESSOR, fifo.CPWritePointer.load(std::memory_order_relaxed) == - ProcessorInterface::Fifo_CPUWritePointer, + processor_interface.Fifo_CPUWritePointer, "FIFOs linked but out of sync"); ASSERT_MSG(COMMANDPROCESSOR, - fifo.CPBase.load(std::memory_order_relaxed) == ProcessorInterface::Fifo_CPUBase, + fifo.CPBase.load(std::memory_order_relaxed) == processor_interface.Fifo_CPUBase, "FIFOs linked but out of sync"); ASSERT_MSG(COMMANDPROCESSOR, - fifo.CPEnd.load(std::memory_order_relaxed) == ProcessorInterface::Fifo_CPUEnd, + fifo.CPEnd.load(std::memory_order_relaxed) == processor_interface.Fifo_CPUEnd, "FIFOs linked but out of sync"); } @@ -432,13 +434,13 @@ void CommandProcessorManager::UpdateInterrupts(Core::System& system, u64 userdat { m_interrupt_set.Set(); DEBUG_LOG_FMT(COMMANDPROCESSOR, "Interrupt set"); - ProcessorInterface::SetInterrupt(INT_CAUSE_CP, true); + system.GetProcessorInterface().SetInterrupt(INT_CAUSE_CP, true); } else { m_interrupt_set.Clear(); DEBUG_LOG_FMT(COMMANDPROCESSOR, "Interrupt cleared"); - ProcessorInterface::SetInterrupt(INT_CAUSE_CP, false); + system.GetProcessorInterface().SetInterrupt(INT_CAUSE_CP, false); } system.GetCoreTiming().ForceExceptionCheck(0); m_interrupt_waiting.Clear(); @@ -563,7 +565,7 @@ void CommandProcessorManager::SetCPStatusFromCPU(Core::System& system) { m_interrupt_set.Set(interrupt); DEBUG_LOG_FMT(COMMANDPROCESSOR, "Interrupt set"); - ProcessorInterface::SetInterrupt(INT_CAUSE_CP, interrupt); + system.GetProcessorInterface().SetInterrupt(INT_CAUSE_CP, interrupt); } } else diff --git a/Source/Core/VideoCommon/PixelEngine.cpp b/Source/Core/VideoCommon/PixelEngine.cpp index 6cc9c05c02..82464339e4 100644 --- a/Source/Core/VideoCommon/PixelEngine.cpp +++ b/Source/Core/VideoCommon/PixelEngine.cpp @@ -157,12 +157,15 @@ void PixelEngineManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) void PixelEngineManager::UpdateInterrupts() { + auto& system = Core::System::GetInstance(); + auto& processor_interface = system.GetProcessorInterface(); + // check if there is a token-interrupt - ProcessorInterface::SetInterrupt(INT_CAUSE_PE_TOKEN, + processor_interface.SetInterrupt(INT_CAUSE_PE_TOKEN, m_signal_token_interrupt && m_control.pe_token_enable); // check if there is a finish-interrupt - ProcessorInterface::SetInterrupt(INT_CAUSE_PE_FINISH, + processor_interface.SetInterrupt(INT_CAUSE_PE_FINISH, m_signal_finish_interrupt && m_control.pe_finish_enable); }