Skip to content

Commit c015893

Browse files
committed
CPU: Add COP0 register names to disassembly
1 parent d7b2f2d commit c015893

File tree

3 files changed

+77
-11
lines changed

3 files changed

+77
-11
lines changed

src/core/cpu_disasm.cpp

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ static constexpr const std::array<const char*, 64> s_gte_register_names = {
203203
"trz", "llm_0", "llm_1", "llm_2", "llm_3", "llm_4", "rbk", "gbk", "bbk", "lcm_0", "lcm_1", "lcm_2", "lcm_3",
204204
"lcm_4", "rfc", "gfc", "bfc", "ofx", "ofy", "h", "dqa", "dqb", "zsf3", "zsf4", "flag"}};
205205

206+
static constexpr const std::array<const char*, 32> s_cop0_register_names = {
207+
{"$0", "$1", "$2", "BPC", "$4", "BDA", "TAR", "DCIC", "BadA", "BDAM", "$10",
208+
"BPCM", "SR", "CAUSE", "EPC", "PRID", "$16", "$17", "$18", "$19", "$20", "$21",
209+
"$22", "$23", "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31"}};
210+
206211
static constexpr const std::array<GTEInstructionTable, 64> s_gte_instructions = {{
207212
{"UNKNOWN", false, false, false}, // 0x00
208213
{"rtps", true, true, false}, // 0x01
@@ -352,24 +357,28 @@ void CPU::FormatInstruction(SmallStringBase* dest, const Instruction inst, u32 p
352357
}
353358
else if (std::strncmp(str, "coprdc", 6) == 0)
354359
{
355-
if (inst.IsCop2Instruction())
360+
if (inst.cop.cop_n == 2)
356361
dest->append(GetGTERegisterName(static_cast<u8>(inst.r.rd.GetValue()) + 32));
357362
else
358363
dest->append_format("{}", ZeroExtend32(static_cast<u8>(inst.r.rd.GetValue())));
359364
str += 6;
360365
}
361366
else if (std::strncmp(str, "coprd", 5) == 0)
362367
{
363-
if (inst.IsCop2Instruction())
368+
if (inst.cop.cop_n == 2)
364369
dest->append(GetGTERegisterName(static_cast<u8>(inst.r.rd.GetValue())));
370+
else if (inst.cop.cop_n == 0)
371+
dest->append(GetCop0RegisterName(static_cast<u8>(inst.r.rd.GetValue())));
365372
else
366373
dest->append_format("{}", ZeroExtend32(static_cast<u8>(inst.r.rd.GetValue())));
367374
str += 5;
368375
}
369376
else if (std::strncmp(str, "coprt", 5) == 0)
370377
{
371-
if (inst.IsCop2Instruction())
378+
if (inst.cop.cop_n == 2)
372379
dest->append(GetGTERegisterName(static_cast<u8>(inst.r.rt.GetValue())));
380+
else if (inst.cop.cop_n == 0)
381+
dest->append(GetCop0RegisterName(static_cast<u8>(inst.r.rt.GetValue())));
373382
else
374383
dest->append_format("{}", ZeroExtend32(static_cast<u8>(inst.r.rt.GetValue())));
375384
str += 5;
@@ -480,28 +489,84 @@ void CPU::FormatComment(SmallStringBase* dest, const Instruction inst, u32 pc, c
480489
}
481490
else if (std::strncmp(str, "coprdc", 6) == 0)
482491
{
483-
if (inst.IsCop2Instruction())
492+
if (inst.cop.cop_n == 2)
484493
{
485494
dest->append_format("{}{}=0x{:08x}", dest->empty() ? "" : ", ",
486495
GetGTERegisterName(static_cast<u8>(inst.r.rd.GetValue()) + 32),
487496
g_state.gte_regs.cr32[static_cast<u8>(inst.r.rd.GetValue())]);
488497
}
498+
489499
str += 6;
490500
}
491501
else if (std::strncmp(str, "coprd", 5) == 0)
492502
{
493-
if (inst.IsCop2Instruction())
503+
if (inst.cop.cop_n == 2)
494504
{
495505
dest->append_format("{}{}=0x{:08x}", dest->empty() ? "" : ", ",
496506
GetGTERegisterName(static_cast<u8>(inst.r.rd.GetValue())),
497507
g_state.gte_regs.dr32[static_cast<u8>(inst.r.rd.GetValue())]);
498508
}
509+
else if (inst.cop.cop_n == 0)
510+
{
511+
dest->append_format("{}{}", dest->empty() ? "" : ", ",
512+
GetCop0RegisterName(static_cast<u8>(inst.r.rd.GetValue())));
513+
514+
u32 value = 0;
515+
switch (static_cast<Cop0Reg>(inst.r.rd.GetValue()))
516+
{
517+
case Cop0Reg::BPC:
518+
value = g_state.cop0_regs.BPC;
519+
break;
520+
521+
case Cop0Reg::BPCM:
522+
value = g_state.cop0_regs.BPCM;
523+
break;
524+
525+
case Cop0Reg::BDA:
526+
value = g_state.cop0_regs.BDA;
527+
break;
528+
529+
case Cop0Reg::BDAM:
530+
value = g_state.cop0_regs.BDAM;
531+
break;
532+
533+
case Cop0Reg::DCIC:
534+
value = g_state.cop0_regs.dcic.bits;
535+
break;
536+
537+
case Cop0Reg::JUMPDEST:
538+
value = g_state.cop0_regs.TAR;
539+
break;
540+
541+
case Cop0Reg::BadVaddr:
542+
value = g_state.cop0_regs.BadVaddr;
543+
break;
544+
545+
case Cop0Reg::SR:
546+
value = g_state.cop0_regs.sr.bits;
547+
break;
548+
549+
case Cop0Reg::CAUSE:
550+
value = g_state.cop0_regs.cause.bits;
551+
break;
552+
553+
case Cop0Reg::EPC:
554+
value = g_state.cop0_regs.EPC;
555+
break;
556+
557+
case Cop0Reg::PRID:
558+
value = g_state.cop0_regs.PRID;
559+
break;
560+
}
561+
562+
dest->append_format("=0x{:08x}", value);
563+
}
499564

500565
str += 5;
501566
}
502567
else if (std::strncmp(str, "coprt", 5) == 0)
503568
{
504-
if (inst.IsCop2Instruction())
569+
if (inst.cop.cop_n == 2)
505570
{
506571
dest->append_format("{}{}=0x{:08x}", dest->empty() ? "" : ", ",
507572
GetGTERegisterName(static_cast<u8>(inst.r.rt.GetValue())),
@@ -702,3 +767,8 @@ const char* CPU::GetGTERegisterName(u32 index)
702767
{
703768
return (index < s_gte_register_names.size()) ? s_gte_register_names[index] : "";
704769
}
770+
771+
const char* CPU::GetCop0RegisterName(u32 index)
772+
{
773+
return (index < s_cop0_register_names.size()) ? s_cop0_register_names[index] : "";
774+
}

src/core/cpu_disasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ void DisassembleInstruction(SmallStringBase* dest, u32 pc, u32 bits);
1212
void DisassembleInstructionComment(SmallStringBase* dest, u32 pc, u32 bits);
1313

1414
const char* GetGTERegisterName(u32 index);
15+
const char* GetCop0RegisterName(u32 index);
1516

1617
} // namespace CPU

src/core/cpu_types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ union Instruction
214214
ALWAYS_INLINE Cop0Instruction Cop0Op() const { return static_cast<Cop0Instruction>(bits & UINT32_C(0x3F)); }
215215
ALWAYS_INLINE u32 Cop2Index() const { return ((bits >> 11) & 0x1F) | ((bits >> 17) & 0x20); }
216216
} cop;
217-
218-
bool IsCop2Instruction() const
219-
{
220-
return (op == InstructionOp::cop2 || op == InstructionOp::lwc2 || op == InstructionOp::swc2);
221-
}
222217
};
223218

224219
// Instruction helpers.

0 commit comments

Comments
 (0)