--- nono/debugger/debugger_m680x0.cpp 2026/04/29 17:05:16 1.1.1.9 +++ nono/debugger/debugger_m680x0.cpp 2026/04/29 17:05:32 1.1.1.11 @@ -11,7 +11,8 @@ #include "debugger_m680x0.h" #include "debugger_memory.h" #include "debugger.h" -#include "m68030disasm.h" +#include "exttostr.h" +#include "m680x0disasm.h" #include "m68030mmu.h" #include "mainbus.h" @@ -20,7 +21,7 @@ DebuggerMD_m680x0::DebuggerMD_m680x0(Deb : inherited(parent_, CPUArch::M680x0) { // この時点で Get*Device() は使える - cpu = GetMPU680x0Device(); + cpu = GetMPU680x0Device(parent->mpu); bus = GetMainbusDevice(); // 機種依存変数 @@ -37,21 +38,14 @@ DebuggerMD_m680x0::~DebuggerMD_m680x0() } // アドレス変換 -uint64 -DebuggerMD_m680x0::TranslateAddr(saddr_t laddr, bool lookup) const +busaddr +DebuggerMD_m680x0::TranslateAddr(busaddr laddr) const { - uint fc; - - fc = laddr.IsData() ? M68K::FC_DATA : M68K::FC_PROG; - if (laddr.IsSuper()) { - fc |= M68K::FC_SUPER; - } - - return cpu->TranslatePeek((uint32)laddr, fc, lookup); + return cpu->TranslatePeek(laddr); } -// op が 68030 の条件命令 Bcc, Scc, TRAPcc, DBcc なら true を返す。 -bool +// op が 680x0 の条件命令 Bcc, Scc, TRAPcc, DBcc なら true を返す。 +/*static*/ bool DebuggerMD_m680x0::IsOPcc(uint16 op) { uint16 cc; @@ -73,7 +67,7 @@ DebuggerMD_m680x0::IsOPcc(uint16 op) } // op が DBcc 命令なら true を返す。 -bool +/*static*/ bool DebuggerMD_m680x0::IsDBcc(uint16 op) { if ((op & 0xf0f8) == 0x50c8) { // DBcc @@ -82,9 +76,37 @@ DebuggerMD_m680x0::IsDBcc(uint16 op) return false; } +// ir[] が FBcc, FScc, FDBcc, FTRAPcc 命令なら condition のあるワード位置を +// 返す。これらの条件命令でなければ (FNOP も含む)、-1 を返す。 +/*static*/ int +DebuggerMD_m680x0::IsFXcc(const std::vector& ir) +{ + if ((ir[0] & 0xfe00) != 0xf200) { + return -1; + } + if (ir.size() < 2) { + return -1; + } + + // FNOP は除く。 + if (ir[0] == 0xf280 && ir[1] == 0) { + return -1; + } + + uint type = (ir[0] >> 6) & 7; + if (type == 1) { // FScc/FDBcc/FTRAPcc + return 1; + } else if (type == 2) { // FBcc.W + return 0; + } else if (type == 3) { // FBcc.L + return 0; + } + return -1; +} + // op の cccc 条件が現在の CCR で成立するなら true を返す。 bool -DebuggerMD_m680x0::IsCond(uint16 op) +DebuggerMD_m680x0::IsCond(uint16 op) const { bool N = cpu->reg.ccr.IsN(); bool Z = cpu->reg.ccr.IsZ(); @@ -133,7 +155,7 @@ DebuggerMD_m680x0::IsCond(uint16 op) // Bcc, Scc, TRAPcc 命令なら、条件が成立するかどうか。 // DBcc 命令ならブランチするかどうか。 const char * -DebuggerMD_m680x0::CondStr(const std::vector& ir) +DebuggerMD_m680x0::CondStr(const std::vector& ir) const { uint16 op = ir[0]; @@ -164,6 +186,22 @@ DebuggerMD_m680x0::CondStr(const std::ve } } + // FXcc + int n = IsFXcc(ir); + if (n >= 0) { + struct fpemu fe0; + struct fpframe fpf0; + memset(&fe0, 0, sizeof(fe0)); + fe0.fe_fpframe = &fpf0; + fe0.fe_fpsr = cpu->reg.fpframe.fpf_fpsr; + int result = test_cc(&fe0, ir[n]); + if (result < 0) { + return " (will take)"; + } else if (result == 0) { + return " (will not take)"; + } + } + // (ここで知ってる)条件命令ではない return ""; } @@ -193,6 +231,7 @@ DebuggerMD_m680x0::IsOpStepIn(DebuggerMe || (op & 0xf0f8) == 0x50f8 // TRAPcc || (op & 0xff00) == 0x6100 // BSR || (op & 0xfff8) == 0xf278 // FTRAPcc + || (op & 0xfe00) == 0xfe00 // DOS($FFxx), FPACK($FExx) ) { return true; } @@ -225,16 +264,37 @@ DebuggerMD_m680x0::GetRegAddr(const char } else if (strcmp(name, "sp") == 0) { addr = cpu->reg.A[7]; -#if 0 } else if (strcmp(name, "usp") == 0) { - addr = cpu->RegUSP; + if (cpu->reg.s == false) { + addr = cpu->reg.A[7]; + } else { + addr = cpu->reg.usp; + } } else if (strcmp(name, "isp") == 0) { - addr = cpu->RegISP; + if (cpu->reg.s && cpu->reg.m == false) { + addr = cpu->reg.A[7]; + } else { + addr = cpu->reg.isp; + } } else if (strcmp(name, "msp") == 0) { - addr = cpu->RegMSP; -#endif + if (cpu->reg.s && cpu->reg.m) { + addr = cpu->reg.A[7]; + } else { + addr = cpu->reg.msp; + } + + } else if (strcmp(name, "ssp") == 0) { + if (cpu->reg.s) { + addr = cpu->reg.A[7]; + } else { + if (cpu->reg.m) { + addr = cpu->reg.msp; + } else { + addr = cpu->reg.isp; + } + } } else if (strcmp(name, "pc") == 0) { addr = cpu->reg.pc; @@ -243,10 +303,29 @@ DebuggerMD_m680x0::GetRegAddr(const char addr = cpu->GetVBR(); } else if (strcmp(name, "srp") == 0) { - addr = cpu->GetSRPl(); + if (cpu->GetMPUType() == m680x0MPUType::M68030) { + auto cpu68030 = dynamic_cast(cpu); + addr = cpu68030->GetSRPl(); + } else { + auto cpu68040 = dynamic_cast(cpu); + addr = cpu68040->GetSRP(); + } } else if (strcmp(name, "crp") == 0) { - addr = cpu->GetCRPl(); + auto cpu68030 = dynamic_cast(cpu); + if (cpu68030) { + addr = cpu68030->GetCRPl(); + } else { + return (uint64)-1; + } + + } else if (strcmp(name, "urp") == 0) { + auto cpu68040 = dynamic_cast(cpu); + if (cpu68040) { + addr = cpu68040->GetURP(); + } else { + return (uint64)-1; + } } else { return (uint64)-1; @@ -336,7 +415,11 @@ DebuggerMD_m680x0::ShowRegister(FILE *co return true; } if (args[0] == "rm") { - ShowRegMMU(cons); + if (cpu->GetMPUType() == m680x0MPUType::M68030) { + ShowRegMMU30(cons); + } else { + ShowRegMMU40(cons); + } return true; } if (args[0] == "ro") { @@ -419,32 +502,14 @@ void DebuggerMD_m680x0::ShowRegFPU(FILE *cons) { /* -FP0:0000_12345678_12345678 (-0.1234567890123456789) FPCR:1234 -FP1: BS,SN,OP,OV,UF,DZ,I2,I1 -FP2: RP=xx RM=xx -FP3: FPSR:12345678 -FP4: N,Z,Inf,NAN Q=$xx -FP5: BS,SN,OP,OV,UF,DZ,I2,I1 -FP6: AXEC -FP7: FPIAR:12345678 +FP0:0000_12345678_12345678 = -0.1234567890123456789) +FPCR: 1234 BS,SN,OE,OF,UF,DZ,X2,X1 RP=.X RM=Minus +FPSR: 12345678 N Z Inf NAN Q=$xx BS,SN,OE,OF,UF,DZ,X2,X1 AV AO AU AZ AX +FPIAR:12345678 */ -#define PUT_FP(n) do { \ - uint32 *c_ = cpu->reg.fpframe.fpf_regs + (n) * 3; \ - uint32 *p_ = prev.fpframe.fpf_regs + (n) * 3; \ - bool d = (c_[0] ^ p_[0]) | (c_[1] ^ p_[1]) | (c_[2] ^ p_[2]); \ - fprintf(cons, "%sFP%d:%04xxxxx_%08x_%08x (%-20s)%s ", \ - BOLDIF(d), (n), c_[0] >> 16, c_[1], c_[2], "notyet", NORM); \ -} while (0) - uint32 fpcr, fpsr, fpiar; uint32 ppcr, ppsr, ppiar; - static const char * const rpstr[] = { - ".EXT", - ".SGL", - ".DBL", - ".???", - }; static const char * const rmstr[] = { "Near", "Zero", @@ -459,39 +524,39 @@ FP7: ppsr = prev.fpframe.fpf_fpsr; ppiar = prev.fpframe.fpf_fpiar; - PUT_FP(0); - fprintf(cons, "%sFPCR:%04x%s\n", BOLDIF(fpcr != ppcr), fpcr, NORM); + for (uint n = 0; n < 8; n++) { + uint32 *c_ = cpu->reg.fpframe.fpf_regs + (n) * 3; + uint32 *p_ = prev.fpframe.fpf_regs + (n) * 3; + bool d = (c_[0] ^ p_[0]) | (c_[1] ^ p_[1]) | (c_[2] ^ p_[2]); + fprintf(cons, "%sFP%u:%04x_%08x_%08x%s = %s\n", + BOLDIF(d), n, c_[0] >> 16, c_[1], c_[2], NORM, + ExtToStr(c_).c_str()); + } - PUT_FP(1); - fprintf(cons, " %s %s %s %s %s %s %s %s\n", + fprintf(cons, "%sFPCR: %04x%s%20s", + BOLDIF(fpcr != ppcr), fpcr, NORM, ""); + fprintf(cons, "%s %s %s %s %s %s %s %s ", (fpcr & 0x8000) ? "BS" : "--", (fpcr & 0x4000) ? "SN" : "--", - (fpcr & 0x2000) ? "OP" : "--", - (fpcr & 0x1000) ? "OV" : "--", + (fpcr & 0x2000) ? "OE" : "--", + (fpcr & 0x1000) ? "OF" : "--", (fpcr & 0x0800) ? "UF" : "--", (fpcr & 0x0400) ? "DZ" : "--", - (fpcr & 0x0200) ? "I2" : "--", - (fpcr & 0x0100) ? "I1" : "--"); - - PUT_FP(2); - fprintf(cons, " RP=%s RM=%s\n", - rpstr[(fpcr >> 6) & 3], + (fpcr & 0x0200) ? "X2" : "--", + (fpcr & 0x0100) ? "X1" : "--"); + fprintf(cons, "RP=.%c RM=%s\n", + "XSD?"[(fpcr >> 6) & 3], rmstr[(fpcr >> 4) & 3]); - PUT_FP(3); - fprintf(cons, "%sFPSR:%08x%s\n", BOLDIF(fpsr != ppsr), fpsr, NORM); - - PUT_FP(4); uint cc = fpsr >> 24; - fprintf(cons, " %c %c %s %s Q=$%02x\n", + fprintf(cons, "%sFPSR: %08x%s ", BOLDIF(fpsr != ppsr), fpsr, NORM); + fprintf(cons, "%c %c %s %s Q=$%02x ", (cc & 0x08) ? 'N' : '-', (cc & 0x04) ? 'Z' : '-', (cc & 0x02) ? "Inf" : "---", (cc & 0x01) ? "NAN" : "---", (fpsr >> 16) & 0xff); - - PUT_FP(5); - fprintf(cons, " %s %s %s %s %s %s %s %s\n", + fprintf(cons, "%s %s %s %s %s %s %s %s ", (fpsr & 0x8000) ? "BS" : "--", (fpsr & 0x4000) ? "SN" : "--", (fpsr & 0x2000) ? "OP" : "--", @@ -500,27 +565,25 @@ FP7: (fpsr & 0x0400) ? "DZ" : "--", (fpsr & 0x0200) ? "I2" : "--", (fpsr & 0x0100) ? "I1" : "--"); + fprintf(cons, "%s %s %s %s %s\n", + (fpsr & 0x80) ? "AV" : "--", + (fpsr & 0x40) ? "AO" : "--", + (fpsr & 0x20) ? "AU" : "--", + (fpsr & 0x10) ? "AZ" : "--", + (fpsr & 0x08) ? "AX" : "--"); - PUT_FP(6); - fprintf(cons, " %s %s %s %s %s\n", - (fpsr & 0x80) ? "IOP" : "---", - (fpsr & 0x40) ? "OVFL" : "----", - (fpsr & 0x20) ? "UNFL" : "----", - (fpsr & 0x10) ? "DZ" : "--", - (fpsr & 0x08) ? "INEX" : "----"); - - PUT_FP(7); fprintf(cons, "%sFPIAR:%08x%s\n", BOLDIF(fpiar != ppiar), fpiar, NORM); } -// MMU レジスタ表示 +// 68030 MMU レジスタ表示 void -DebuggerMD_m680x0::ShowRegMMU(FILE *cons) +DebuggerMD_m680x0::ShowRegMMU30(FILE *cons) { /* SRP:00001111_22223333 TT0:00001111 TC:00001111 (---) CRP:00001111_22223333 TT1:00001111 MMUSR: 0011 ( */ + auto cpu68030 = dynamic_cast(cpu); uint64 srp, osrp; uint64 crp, ocrp; uint32 tt0, ott0; @@ -531,12 +594,12 @@ CRP:00001111_22223333 TT1:00001111 MMUSR bool t; bool c; - srp = cpu->GetSRP(); - crp = cpu->GetCRP(); - tt0 = cpu->GetTT(0); - tt1 = cpu->GetTT(1); - tc = cpu->GetTC(); - sr = cpu->GetMMUSR(); + srp = cpu68030->GetSRP(); + crp = cpu68030->GetCRP(); + tt0 = cpu68030->GetTT(0); + tt1 = cpu68030->GetTT(1); + tc = cpu68030->GetTC(); + sr = cpu68030->GetMMUSR(); osrp = prev.srp.q; ocrp = prev.crp.q; @@ -583,6 +646,13 @@ CRP:00001111_22223333 TT1:00001111 MMUSR (sr & m68030MMUSR::N)); } +// 68040 MMU レジスタ表示 +void +DebuggerMD_m680x0::ShowRegMMU40(FILE *cons) +{ + fprintf(cons, "Not implemented\n"); +} + // ATC を表示 void DebuggerMD_m680x0::ShowRegATC() @@ -606,8 +676,8 @@ DebuggerMD_m680x0::ShowRegOther() s.Print(0, 1, EM(caar), "CAAR:%08x", cpu->reg.caar); s.Print(15, 0, EM(vbr), "VBR:%08x", cpu->reg.vbr); - s.Print(15, 1, EM(sfc), "SFC:%d", cpu->reg.sfc); - s.Print(22, 1, EM(dfc), "DFC:%d", cpu->reg.dfc); + s.Print(15, 1, EM(sfc), "SFC:%d", cpu->reg.GetSFC()); + s.Print(22, 1, EM(dfc), "DFC:%d", cpu->reg.GetDFC()); // スタック欄はモードによって表示を変える。 // ユーザ 割り込み マスタ