Cleanup disasm classes a bit

This commit is contained in:
Eladash 2020-12-16 08:53:59 +02:00 committed by Ivan
parent e449111c33
commit ef884642e4
13 changed files with 28 additions and 38 deletions

View file

@ -16,6 +16,7 @@ class CPUDisAsm
{ {
protected: protected:
const CPUDisAsmMode m_mode; const CPUDisAsmMode m_mode;
const std::add_pointer_t<const u8> m_offset;
virtual void Write(const std::string& value) virtual void Write(const std::string& value)
{ {
@ -24,20 +25,20 @@ protected:
case CPUDisAsm_DumpMode: case CPUDisAsm_DumpMode:
{ {
last_opcode = fmt::format("\t%08x:\t%02x %02x %02x %02x\t%s\n", dump_pc, last_opcode = fmt::format("\t%08x:\t%02x %02x %02x %02x\t%s\n", dump_pc,
offset[dump_pc], m_offset[dump_pc],
offset[dump_pc + 1], m_offset[dump_pc + 1],
offset[dump_pc + 2], m_offset[dump_pc + 2],
offset[dump_pc + 3], value); m_offset[dump_pc + 3], value);
break; break;
} }
case CPUDisAsm_InterpreterMode: case CPUDisAsm_InterpreterMode:
{ {
last_opcode = fmt::format("[%08x] %02x %02x %02x %02x: %s", dump_pc, last_opcode = fmt::format("[%08x] %02x %02x %02x %02x: %s", dump_pc,
offset[dump_pc], m_offset[dump_pc],
offset[dump_pc + 1], m_offset[dump_pc + 1],
offset[dump_pc + 2], m_offset[dump_pc + 2],
offset[dump_pc + 3], value); m_offset[dump_pc + 3], value);
break; break;
} }
@ -58,12 +59,11 @@ protected:
public: public:
std::string last_opcode; std::string last_opcode;
u32 dump_pc; u32 dump_pc;
const u8* offset;
protected: protected:
CPUDisAsm(CPUDisAsmMode mode) CPUDisAsm(CPUDisAsmMode mode, const u8* offset)
: m_mode(mode) : m_mode(mode)
, offset(0) , m_offset(offset)
{ {
} }

View file

@ -5,7 +5,7 @@
class PPCDisAsm : public CPUDisAsm class PPCDisAsm : public CPUDisAsm
{ {
protected: protected:
PPCDisAsm(CPUDisAsmMode mode) : CPUDisAsm(mode) PPCDisAsm(CPUDisAsmMode mode, const u8* offset) : CPUDisAsm(mode, offset)
{ {
} }

View file

@ -6,7 +6,8 @@ const ppu_decoder<PPUDisAsm> s_ppu_disasm;
u32 PPUDisAsm::disasm(u32 pc) u32 PPUDisAsm::disasm(u32 pc)
{ {
const u32 op = *reinterpret_cast<const be_t<u32>*>(offset + pc); dump_pc = pc;
const u32 op = *reinterpret_cast<const be_t<u32>*>(m_offset + pc);
(this->*(s_ppu_disasm.decode(op)))({ op }); (this->*(s_ppu_disasm.decode(op)))({ op });
return 4; return 4;
} }

View file

@ -6,7 +6,7 @@
class PPUDisAsm final : public PPCDisAsm class PPUDisAsm final : public PPCDisAsm
{ {
public: public:
PPUDisAsm(CPUDisAsmMode mode) : PPCDisAsm(mode) PPUDisAsm(CPUDisAsmMode mode, const u8* offset) : PPCDisAsm(mode, offset)
{ {
} }

View file

@ -499,9 +499,7 @@ std::string ppu_thread::dump_regs() const
} }
else else
{ {
PPUDisAsm dis_asm(CPUDisAsm_NormalMode); PPUDisAsm dis_asm(CPUDisAsm_NormalMode, vm::g_sudo_addr);
dis_asm.offset = vm::g_sudo_addr;
dis_asm.dump_pc = reg;
dis_asm.disasm(reg); dis_asm.disasm(reg);
fmt::append(ret, " -> %s", dis_asm.last_opcode); fmt::append(ret, " -> %s", dis_asm.last_opcode);
} }

View file

@ -11,7 +11,8 @@ const spu_decoder<spu_iflag> s_spu_iflag;
u32 SPUDisAsm::disasm(u32 pc) u32 SPUDisAsm::disasm(u32 pc)
{ {
const u32 op = *reinterpret_cast<const be_t<u32>*>(offset + pc); dump_pc = pc;
const u32 op = *reinterpret_cast<const be_t<u32>*>(m_offset + pc);
(this->*(s_spu_disasm.decode(op)))({ op }); (this->*(s_spu_disasm.decode(op)))({ op });
return 4; return 4;
} }
@ -33,7 +34,7 @@ std::pair<bool, v128> SPUDisAsm::try_get_const_value(u32 reg, u32 pc) const
for (s32 i = pc - 4; i >= 0; i -= 4) for (s32 i = pc - 4; i >= 0; i -= 4)
{ {
const u32 opcode = *reinterpret_cast<const be_t<u32>*>(offset + i); const u32 opcode = *reinterpret_cast<const be_t<u32>*>(m_offset + i);
const spu_opcode_t op0{ opcode }; const spu_opcode_t op0{ opcode };
const auto type = s_spu_itype.decode(opcode); const auto type = s_spu_itype.decode(opcode);

View file

@ -71,7 +71,7 @@ static constexpr const char* spu_ch_name[128] =
class SPUDisAsm final : public PPCDisAsm class SPUDisAsm final : public PPCDisAsm
{ {
public: public:
SPUDisAsm(CPUDisAsmMode mode) : PPCDisAsm(mode) SPUDisAsm(CPUDisAsmMode mode, const u8* offset) : PPCDisAsm(mode, offset)
{ {
} }

View file

@ -3146,8 +3146,7 @@ spu_program spu_recompiler_base::analyse(const be_t<u32>* ls, u32 entry_point)
void spu_recompiler_base::dump(const spu_program& result, std::string& out) void spu_recompiler_base::dump(const spu_program& result, std::string& out)
{ {
SPUDisAsm dis_asm(CPUDisAsm_DumpMode); SPUDisAsm dis_asm(CPUDisAsm_DumpMode, reinterpret_cast<const u8*>(result.data.data()) - result.lower_bound);
dis_asm.offset = reinterpret_cast<const u8*>(result.data.data()) - result.lower_bound;
std::string hash; 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) 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); dis_asm.disasm(pos);
fmt::append(out, ">%s\n", dis_asm.last_opcode); fmt::append(out, ">%s\n", dis_asm.last_opcode);
} }

View file

@ -1288,9 +1288,7 @@ std::string spu_thread::dump_regs() const
if (i3 >= 0x80 && is_exec_code(i3)) if (i3 >= 0x80 && is_exec_code(i3))
{ {
SPUDisAsm dis_asm(CPUDisAsm_NormalMode); SPUDisAsm dis_asm(CPUDisAsm_NormalMode, ls);
dis_asm.offset = ls;
dis_asm.dump_pc = i3;
dis_asm.disasm(i3); dis_asm.disasm(i3);
fmt::append(ret, " -> %s", dis_asm.last_opcode); fmt::append(ret, " -> %s", dis_asm.last_opcode);
} }

View file

@ -1807,8 +1807,7 @@ void Emulator::Resume()
// Print and reset debug data collected // Print and reset debug data collected
if (m_state == system_state::paused && g_cfg.core.ppu_debug) if (m_state == system_state::paused && g_cfg.core.ppu_debug)
{ {
PPUDisAsm dis_asm(CPUDisAsm_DumpMode); PPUDisAsm dis_asm(CPUDisAsm_DumpMode, vm::g_sudo_addr);
dis_asm.offset = vm::g_sudo_addr;
std::string dump; std::string dump;
@ -1818,7 +1817,6 @@ void Emulator::Resume()
{ {
if (auto& data = *reinterpret_cast<be_t<u32>*>(vm::g_stat_addr + i)) if (auto& data = *reinterpret_cast<be_t<u32>*>(vm::g_stat_addr + i))
{ {
dis_asm.dump_pc = i;
dis_asm.disasm(i); dis_asm.disasm(i);
fmt::append(dump, "\n\t'%08X' %s", data, dis_asm.last_opcode); fmt::append(dump, "\n\t'%08X' %s", data, dis_asm.last_opcode);
data = 0; data = 0;

View file

@ -63,10 +63,8 @@ void breakpoint_list::AddBreakpoint(u32 pc)
m_breakpoint_handler->AddBreakpoint(pc); m_breakpoint_handler->AddBreakpoint(pc);
const auto cpu = this->cpu.lock(); const auto cpu = this->cpu.lock();
const auto cpu_offset = cpu->id_type() == 2 ? static_cast<spu_thread&>(*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); QString breakpointItemText = qstr(m_disasm->last_opcode);

View file

@ -467,7 +467,7 @@ void debugger_frame::OnSelectUnit()
if (cpu0.get() == idm::check<named_thread<ppu_thread>>(cpu0->id)) if (cpu0.get() == idm::check<named_thread<ppu_thread>>(cpu0->id))
{ {
cpu = cpu0; cpu = cpu0;
m_disasm = std::make_unique<PPUDisAsm>(CPUDisAsm_InterpreterMode); m_disasm = std::make_unique<PPUDisAsm>(CPUDisAsm_InterpreterMode, vm::g_sudo_addr);
} }
} }
else if (cpu0->id_type() == 2) else if (cpu0->id_type() == 2)
@ -475,7 +475,7 @@ void debugger_frame::OnSelectUnit()
if (cpu0.get() == idm::check<named_thread<spu_thread>>(cpu0->id)) if (cpu0.get() == idm::check<named_thread<spu_thread>>(cpu0->id))
{ {
cpu = cpu0; cpu = cpu0;
m_disasm = std::make_unique<SPUDisAsm>(CPUDisAsm_InterpreterMode); m_disasm = std::make_unique<SPUDisAsm>(CPUDisAsm_InterpreterMode, static_cast<const spu_thread*>(cpu0.get())->ls);
} }
} }
} }

View file

@ -68,7 +68,7 @@ void debugger_list::ShowAddress(u32 addr, bool force)
const auto default_foreground = palette().color(foregroundRole()); const auto default_foreground = palette().color(foregroundRole());
const auto default_background = palette().color(backgroundRole()); const auto default_background = palette().color(backgroundRole());
if (!cpu) if (!cpu || !m_disasm)
{ {
for (uint i = 0; i < m_item_count; ++i) for (uint i = 0; i < m_item_count; ++i)
{ {
@ -80,10 +80,8 @@ void debugger_list::ShowAddress(u32 addr, bool force)
else else
{ {
const bool is_spu = cpu->id_type() != 1; const bool is_spu = cpu->id_type() != 1;
const auto cpu_offset = cpu->id_type() != 1 ? static_cast<spu_thread&>(*cpu).ls : vm::g_sudo_addr;
const u32 address_limits = (is_spu ? 0x3fffc : ~3); const u32 address_limits = (is_spu ? 0x3fffc : ~3);
m_pc &= address_limits; m_pc &= address_limits;
m_disasm->offset = cpu_offset;
u32 pc = m_pc; u32 pc = m_pc;
for (uint i = 0, count = 4; i<m_item_count; ++i, pc = (pc + count) & address_limits) for (uint i = 0, count = 4; i<m_item_count; ++i, pc = (pc + count) & address_limits)
@ -123,7 +121,7 @@ void debugger_list::ShowAddress(u32 addr, bool force)
continue; continue;
} }
count = m_disasm->disasm(m_disasm->dump_pc = pc); count = m_disasm->disasm(pc);
item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(m_disasm->last_opcode)); item(i)->setText((IsBreakpoint(pc) ? ">> " : " ") + qstr(m_disasm->last_opcode));
} }