From da20bda729e9bfe6d9f4330cbde7cd0315bcd2ee Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 27 Oct 2013 13:15:12 -0700 Subject: [PATCH] Make memchecks ignore cached/uncached memory. You usually want both. --- Core/Debugger/Breakpoints.cpp | 33 +++++++++++++++++++++++++++++++-- Core/Debugger/Breakpoints.h | 4 ++++ Core/MIPS/x86/Jit.cpp | 6 ++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index cf0ce4b284..48826a095c 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -248,6 +248,12 @@ void CBreakPoints::ClearAllMemChecks() } } +static inline u32 NotCached(u32 val) +{ + // Remove the cached part of the address. + return val & ~0x40000000; +} + MemCheck *CBreakPoints::GetMemCheck(u32 address, int size) { std::vector::iterator iter; @@ -256,12 +262,12 @@ MemCheck *CBreakPoints::GetMemCheck(u32 address, int size) MemCheck &check = *iter; if (check.end != 0) { - if (address + size > check.start && address < check.end) + if (NotCached(address + size) > NotCached(check.start) && NotCached(address) < NotCached(check.end)) return ✓ } else { - if (check.start == address) + if (NotCached(check.start) == NotCached(address)) return ✓ } } @@ -270,6 +276,13 @@ MemCheck *CBreakPoints::GetMemCheck(u32 address, int size) return 0; } +void CBreakPoints::ExecMemCheck(u32 address, bool write, int size, u32 pc) +{ + auto check = GetMemCheck(address, size); + if (check) + check->Action(address, write, size, pc); +} + void CBreakPoints::SetSkipFirst(u32 pc) { breakSkipFirstAt_ = pc; @@ -283,6 +296,22 @@ u32 CBreakPoints::CheckSkipFirst() return 0; } +const std::vector CBreakPoints::GetMemCheckRanges() +{ + std::vector ranges = memChecks_; + for (auto it = memChecks_.begin(), end = memChecks_.end(); it != end; ++it) + { + MemCheck check = *it; + // Toggle the cached part of the address. + check.start ^= 0x40000000; + if (check.end != 0) + check.end ^= 0x40000000; + ranges.push_back(check); + } + + return ranges; +} + const std::vector CBreakPoints::GetMemChecks() { return memChecks_; diff --git a/Core/Debugger/Breakpoints.h b/Core/Debugger/Breakpoints.h index fc9e9f63bc..d76a6724c3 100644 --- a/Core/Debugger/Breakpoints.h +++ b/Core/Debugger/Breakpoints.h @@ -123,10 +123,14 @@ public: static void ClearAllMemChecks(); static MemCheck *GetMemCheck(u32 address, int size); + static void ExecMemCheck(u32 address, bool write, int size, u32 pc); static void SetSkipFirst(u32 pc); static u32 CheckSkipFirst(); + // Includes uncached addresses. + static const std::vector GetMemCheckRanges(); + static const std::vector GetMemChecks(); static const std::vector GetBreakpoints(); diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 459710f521..1669cdd4a0 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -790,9 +790,7 @@ void JitMemCheck(u32 addr, int size, int isWrite) if (coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME) return; - MemCheck *check = CBreakPoints::GetMemCheck(addr, size); - if (check) - check->Action(addr, isWrite == 1, size, currentMIPS->pc); + CBreakPoints::ExecMemCheck(addr, isWrite == 1, size, currentMIPS->pc); } void Jit::JitSafeMem::MemCheckImm(ReadType type) @@ -817,7 +815,7 @@ void Jit::JitSafeMem::MemCheckImm(ReadType type) void Jit::JitSafeMem::MemCheckAsm(ReadType type) { - const auto memchecks = CBreakPoints::GetMemChecks(); + const auto memchecks = CBreakPoints::GetMemCheckRanges(); bool possible = false; for (auto it = memchecks.begin(), end = memchecks.end(); it != end; ++it) {