From 18f8ae37ab1091f104114489a4a8371d94b9475c Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 28 Mar 2023 20:39:02 +0200 Subject: [PATCH] PowerPC/Expression: Pass System to EvaluateCondition(). --- Source/Core/Core/PowerPC/BreakPoints.cpp | 7 ++++--- Source/Core/Core/PowerPC/BreakPoints.h | 4 ++-- Source/Core/Core/PowerPC/Expression.cpp | 23 ++++++++++++----------- Source/Core/Core/PowerPC/Expression.h | 11 ++++++----- Source/Core/Core/PowerPC/MMU.cpp | 3 ++- Source/Core/Core/PowerPC/PowerPC.cpp | 2 +- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Source/Core/Core/PowerPC/BreakPoints.cpp b/Source/Core/Core/PowerPC/BreakPoints.cpp index fd30da2b91..473871e74f 100644 --- a/Source/Core/Core/PowerPC/BreakPoints.cpp +++ b/Source/Core/Core/PowerPC/BreakPoints.cpp @@ -16,6 +16,7 @@ #include "Core/PowerPC/Expression.h" #include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/MMU.h" +#include "Core/PowerPC/PowerPC.h" #include "Core/System.h" bool BreakPoints::IsAddressBreakPoint(u32 address) const @@ -352,14 +353,14 @@ bool MemChecks::OverlapsMemcheck(u32 address, u32 length) const }); } -bool TMemCheck::Action(Common::DebugInterface* debug_interface, u64 value, u32 addr, bool write, - size_t size, u32 pc) +bool TMemCheck::Action(Core::System& system, Common::DebugInterface* debug_interface, u64 value, + u32 addr, bool write, size_t size, u32 pc) { if (!is_enabled) return false; if (((write && is_break_on_write) || (!write && is_break_on_read)) && - EvaluateCondition(this->condition)) + EvaluateCondition(system, this->condition)) { if (log_on_hit) { diff --git a/Source/Core/Core/PowerPC/BreakPoints.h b/Source/Core/Core/PowerPC/BreakPoints.h index 0be6981ebe..111e1bb365 100644 --- a/Source/Core/Core/PowerPC/BreakPoints.h +++ b/Source/Core/Core/PowerPC/BreakPoints.h @@ -45,8 +45,8 @@ struct TMemCheck std::optional condition; // returns whether to break - bool Action(Common::DebugInterface* debug_interface, u64 value, u32 addr, bool write, size_t size, - u32 pc); + bool Action(Core::System& system, Common::DebugInterface* debug_interface, u64 value, u32 addr, + bool write, size_t size, u32 pc); }; // Code breakpoints. diff --git a/Source/Core/Core/PowerPC/Expression.cpp b/Source/Core/Core/PowerPC/Expression.cpp index bd089e3a01..2fe2d8c036 100644 --- a/Source/Core/Core/PowerPC/Expression.cpp +++ b/Source/Core/Core/PowerPC/Expression.cpp @@ -267,21 +267,22 @@ std::optional Expression::TryParse(std::string_view text) return Expression{text, std::move(ex), std::move(vars)}; } -double Expression::Evaluate() const +double Expression::Evaluate(Core::System& system) const { - SynchronizeBindings(SynchronizeDirection::From); + SynchronizeBindings(system, SynchronizeDirection::From); double result = expr_eval(m_expr.get()); - SynchronizeBindings(SynchronizeDirection::To); + SynchronizeBindings(system, SynchronizeDirection::To); Reporting(result); return result; } -void Expression::SynchronizeBindings(SynchronizeDirection dir) const +void Expression::SynchronizeBindings(Core::System& system, SynchronizeDirection dir) const { + auto& ppc_state = system.GetPPCState(); auto bind = m_binds.begin(); for (auto* v = m_vars->head; v != nullptr; v = v->next, ++bind) { @@ -293,25 +294,25 @@ void Expression::SynchronizeBindings(SynchronizeDirection dir) const break; case VarBindingType::GPR: if (dir == SynchronizeDirection::From) - v->value = static_cast(PowerPC::ppcState.gpr[bind->index]); + v->value = static_cast(ppc_state.gpr[bind->index]); else - PowerPC::ppcState.gpr[bind->index] = static_cast(static_cast(v->value)); + ppc_state.gpr[bind->index] = static_cast(static_cast(v->value)); break; case VarBindingType::FPR: if (dir == SynchronizeDirection::From) - v->value = PowerPC::ppcState.ps[bind->index].PS0AsDouble(); + v->value = ppc_state.ps[bind->index].PS0AsDouble(); else - PowerPC::ppcState.ps[bind->index].SetPS0(v->value); + ppc_state.ps[bind->index].SetPS0(v->value); break; case VarBindingType::SPR: if (dir == SynchronizeDirection::From) - v->value = static_cast(PowerPC::ppcState.spr[bind->index]); + v->value = static_cast(ppc_state.spr[bind->index]); else - PowerPC::ppcState.spr[bind->index] = static_cast(static_cast(v->value)); + ppc_state.spr[bind->index] = static_cast(static_cast(v->value)); break; case VarBindingType::PCtr: if (dir == SynchronizeDirection::From) - v->value = static_cast(PowerPC::ppcState.pc); + v->value = static_cast(ppc_state.pc); break; } } diff --git a/Source/Core/Core/PowerPC/Expression.h b/Source/Core/Core/PowerPC/Expression.h index 2c96e04f44..d9799caa82 100644 --- a/Source/Core/Core/PowerPC/Expression.h +++ b/Source/Core/Core/PowerPC/Expression.h @@ -15,7 +15,8 @@ struct expr_var_list; namespace Core { class CPUThreadGuard; -} +class System; +} // namespace Core struct ExprDeleter { @@ -36,7 +37,7 @@ class Expression public: static std::optional TryParse(std::string_view text); - double Evaluate() const; + double Evaluate(Core::System& system) const; std::string GetText() const; @@ -64,7 +65,7 @@ private: Expression(std::string_view text, ExprPointer ex, ExprVarListPointer vars); - void SynchronizeBindings(SynchronizeDirection dir) const; + void SynchronizeBindings(Core::System& system, SynchronizeDirection dir) const; void Reporting(const double result) const; std::string m_text; @@ -73,7 +74,7 @@ private: std::vector m_binds; }; -inline bool EvaluateCondition(const std::optional& condition) +inline bool EvaluateCondition(Core::System& system, const std::optional& condition) { - return !condition || condition->Evaluate() != 0.0; + return !condition || condition->Evaluate(system) != 0.0; } diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 92786beec6..bfbc25c655 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -545,7 +545,8 @@ void MMU::Memcheck(u32 address, u64 var, bool write, size_t size) mc->num_hits++; - const bool pause = mc->Action(&debug_interface, var, address, write, size, m_ppc_state.pc); + const bool pause = + mc->Action(m_system, &debug_interface, var, address, write, size, m_ppc_state.pc); if (!pause) return; diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index fef24a482a..6f18fad090 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -645,7 +645,7 @@ void CheckBreakPoints() { const TBreakPoint* bp = PowerPC::breakpoints.GetBreakpoint(PowerPC::ppcState.pc); - if (!bp || !bp->is_enabled || !EvaluateCondition(bp->condition)) + if (!bp || !bp->is_enabled || !EvaluateCondition(Core::System::GetInstance(), bp->condition)) return; if (bp->break_on_hit)