diff --git a/rpcs3/Emu/CPU/CPUDisAsm.h b/rpcs3/Emu/CPU/CPUDisAsm.h index c960902d16..38cffdb770 100644 --- a/rpcs3/Emu/CPU/CPUDisAsm.h +++ b/rpcs3/Emu/CPU/CPUDisAsm.h @@ -16,6 +16,7 @@ class CPUDisAsm { protected: const CPUDisAsmMode m_mode; + const std::add_pointer_t m_offset; virtual void Write(const std::string& value) { @@ -24,20 +25,20 @@ protected: case CPUDisAsm_DumpMode: { last_opcode = fmt::format("\t%08x:\t%02x %02x %02x %02x\t%s\n", dump_pc, - offset[dump_pc], - offset[dump_pc + 1], - offset[dump_pc + 2], - offset[dump_pc + 3], value); + m_offset[dump_pc], + m_offset[dump_pc + 1], + m_offset[dump_pc + 2], + m_offset[dump_pc + 3], value); break; } case CPUDisAsm_InterpreterMode: { last_opcode = fmt::format("[%08x] %02x %02x %02x %02x: %s", dump_pc, - offset[dump_pc], - offset[dump_pc + 1], - offset[dump_pc + 2], - offset[dump_pc + 3], value); + m_offset[dump_pc], + m_offset[dump_pc + 1], + m_offset[dump_pc + 2], + m_offset[dump_pc + 3], value); break; } @@ -58,12 +59,11 @@ protected: public: std::string last_opcode; u32 dump_pc; - const u8* offset; protected: - CPUDisAsm(CPUDisAsmMode mode) + CPUDisAsm(CPUDisAsmMode mode, const u8* offset) : m_mode(mode) - , offset(0) + , m_offset(offset) { } diff --git a/rpcs3/Emu/Cell/PPCDisAsm.h b/rpcs3/Emu/Cell/PPCDisAsm.h index b5ae5a5f2f..3347ee3a11 100644 --- a/rpcs3/Emu/Cell/PPCDisAsm.h +++ b/rpcs3/Emu/Cell/PPCDisAsm.h @@ -5,7 +5,7 @@ class PPCDisAsm : public CPUDisAsm { protected: - PPCDisAsm(CPUDisAsmMode mode) : CPUDisAsm(mode) + PPCDisAsm(CPUDisAsmMode mode, const u8* offset) : CPUDisAsm(mode, offset) { } diff --git a/rpcs3/Emu/Cell/PPUDisAsm.cpp b/rpcs3/Emu/Cell/PPUDisAsm.cpp index 2b82fa73ef..aab2444c02 100644 --- a/rpcs3/Emu/Cell/PPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/PPUDisAsm.cpp @@ -6,7 +6,8 @@ const ppu_decoder s_ppu_disasm; u32 PPUDisAsm::disasm(u32 pc) { - const u32 op = *reinterpret_cast*>(offset + pc); + dump_pc = pc; + const u32 op = *reinterpret_cast*>(m_offset + pc); (this->*(s_ppu_disasm.decode(op)))({ op }); return 4; } diff --git a/rpcs3/Emu/Cell/PPUDisAsm.h b/rpcs3/Emu/Cell/PPUDisAsm.h index f9b25c439c..61570a2fbe 100644 --- a/rpcs3/Emu/Cell/PPUDisAsm.h +++ b/rpcs3/Emu/Cell/PPUDisAsm.h @@ -6,7 +6,7 @@ class PPUDisAsm final : public PPCDisAsm { public: - PPUDisAsm(CPUDisAsmMode mode) : PPCDisAsm(mode) + PPUDisAsm(CPUDisAsmMode mode, const u8* offset) : PPCDisAsm(mode, offset) { } diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 9b472040ab..4ce1408dd0 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -499,9 +499,7 @@ std::string ppu_thread::dump_regs() const } else { - PPUDisAsm dis_asm(CPUDisAsm_NormalMode); - dis_asm.offset = vm::g_sudo_addr; - dis_asm.dump_pc = reg; + PPUDisAsm dis_asm(CPUDisAsm_NormalMode, vm::g_sudo_addr); dis_asm.disasm(reg); fmt::append(ret, " -> %s", dis_asm.last_opcode); } diff --git a/rpcs3/Emu/Cell/SPUDisAsm.cpp b/rpcs3/Emu/Cell/SPUDisAsm.cpp index 81a9532674..c7a0d3013c 100644 --- a/rpcs3/Emu/Cell/SPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/SPUDisAsm.cpp @@ -11,7 +11,8 @@ const spu_decoder s_spu_iflag; u32 SPUDisAsm::disasm(u32 pc) { - const u32 op = *reinterpret_cast*>(offset + pc); + dump_pc = pc; + const u32 op = *reinterpret_cast*>(m_offset + pc); (this->*(s_spu_disasm.decode(op)))({ op }); return 4; } @@ -33,7 +34,7 @@ std::pair SPUDisAsm::try_get_const_value(u32 reg, u32 pc) const for (s32 i = pc - 4; i >= 0; i -= 4) { - const u32 opcode = *reinterpret_cast*>(offset + i); + const u32 opcode = *reinterpret_cast*>(m_offset + i); const spu_opcode_t op0{ opcode }; const auto type = s_spu_itype.decode(opcode); diff --git a/rpcs3/Emu/Cell/SPUDisAsm.h b/rpcs3/Emu/Cell/SPUDisAsm.h index 5047bd7dbf..9ec1ff22fd 100644 --- a/rpcs3/Emu/Cell/SPUDisAsm.h +++ b/rpcs3/Emu/Cell/SPUDisAsm.h @@ -71,7 +71,7 @@ static constexpr const char* spu_ch_name[128] = class SPUDisAsm final : public PPCDisAsm { public: - SPUDisAsm(CPUDisAsmMode mode) : PPCDisAsm(mode) + SPUDisAsm(CPUDisAsmMode mode, const u8* offset) : PPCDisAsm(mode, offset) { } diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index cfac074b06..0dcf9b565e 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -3146,8 +3146,7 @@ spu_program spu_recompiler_base::analyse(const be_t* ls, u32 entry_point) void spu_recompiler_base::dump(const spu_program& result, std::string& out) { - SPUDisAsm dis_asm(CPUDisAsm_DumpMode); - dis_asm.offset = reinterpret_cast(result.data.data()) - result.lower_bound; + SPUDisAsm dis_asm(CPUDisAsm_DumpMode, reinterpret_cast(result.data.data()) - result.lower_bound); std::string hash; { @@ -3166,7 +3165,6 @@ void spu_recompiler_base::dump(const spu_program& result, std::string& out) { for (u32 pos = bb.first, end = bb.first + bb.second.size * 4; pos < end; pos += 4) { - dis_asm.dump_pc = pos; dis_asm.disasm(pos); fmt::append(out, ">%s\n", dis_asm.last_opcode); } diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index cd15901925..c252e16013 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1288,9 +1288,7 @@ std::string spu_thread::dump_regs() const if (i3 >= 0x80 && is_exec_code(i3)) { - SPUDisAsm dis_asm(CPUDisAsm_NormalMode); - dis_asm.offset = ls; - dis_asm.dump_pc = i3; + SPUDisAsm dis_asm(CPUDisAsm_NormalMode, ls); dis_asm.disasm(i3); fmt::append(ret, " -> %s", dis_asm.last_opcode); } diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 6ef89cf19a..139dd909ea 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1807,8 +1807,7 @@ void Emulator::Resume() // Print and reset debug data collected if (m_state == system_state::paused && g_cfg.core.ppu_debug) { - PPUDisAsm dis_asm(CPUDisAsm_DumpMode); - dis_asm.offset = vm::g_sudo_addr; + PPUDisAsm dis_asm(CPUDisAsm_DumpMode, vm::g_sudo_addr); std::string dump; @@ -1818,7 +1817,6 @@ void Emulator::Resume() { if (auto& data = *reinterpret_cast*>(vm::g_stat_addr + i)) { - dis_asm.dump_pc = i; dis_asm.disasm(i); fmt::append(dump, "\n\t'%08X' %s", data, dis_asm.last_opcode); data = 0; diff --git a/rpcs3/rpcs3qt/breakpoint_list.cpp b/rpcs3/rpcs3qt/breakpoint_list.cpp index a73dd46b96..12e6acfb0e 100644 --- a/rpcs3/rpcs3qt/breakpoint_list.cpp +++ b/rpcs3/rpcs3qt/breakpoint_list.cpp @@ -63,10 +63,8 @@ void breakpoint_list::AddBreakpoint(u32 pc) m_breakpoint_handler->AddBreakpoint(pc); const auto cpu = this->cpu.lock(); - const auto cpu_offset = cpu->id_type() == 2 ? static_cast(*cpu).ls : vm::g_sudo_addr; - m_disasm->offset = cpu_offset; - m_disasm->disasm(m_disasm->dump_pc = pc); + m_disasm->disasm(pc); QString breakpointItemText = qstr(m_disasm->last_opcode); diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index 7ab9da67ee..b00bc5f557 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -467,7 +467,7 @@ void debugger_frame::OnSelectUnit() if (cpu0.get() == idm::check>(cpu0->id)) { cpu = cpu0; - m_disasm = std::make_unique(CPUDisAsm_InterpreterMode); + m_disasm = std::make_unique(CPUDisAsm_InterpreterMode, vm::g_sudo_addr); } } else if (cpu0->id_type() == 2) @@ -475,7 +475,7 @@ void debugger_frame::OnSelectUnit() if (cpu0.get() == idm::check>(cpu0->id)) { cpu = cpu0; - m_disasm = std::make_unique(CPUDisAsm_InterpreterMode); + m_disasm = std::make_unique(CPUDisAsm_InterpreterMode, static_cast(cpu0.get())->ls); } } } diff --git a/rpcs3/rpcs3qt/debugger_list.cpp b/rpcs3/rpcs3qt/debugger_list.cpp index db7b360000..cf0759f757 100644 --- a/rpcs3/rpcs3qt/debugger_list.cpp +++ b/rpcs3/rpcs3qt/debugger_list.cpp @@ -68,7 +68,7 @@ void debugger_list::ShowAddress(u32 addr, bool force) const auto default_foreground = palette().color(foregroundRole()); const auto default_background = palette().color(backgroundRole()); - if (!cpu) + if (!cpu || !m_disasm) { for (uint i = 0; i < m_item_count; ++i) { @@ -80,10 +80,8 @@ void debugger_list::ShowAddress(u32 addr, bool force) else { const bool is_spu = cpu->id_type() != 1; - const auto cpu_offset = cpu->id_type() != 1 ? static_cast(*cpu).ls : vm::g_sudo_addr; const u32 address_limits = (is_spu ? 0x3fffc : ~3); m_pc &= address_limits; - m_disasm->offset = cpu_offset; u32 pc = m_pc; for (uint i = 0, count = 4; idisasm(m_disasm->dump_pc = pc); + count = m_disasm->disasm(pc); item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(m_disasm->last_opcode)); }