Skip to content

Commit

Permalink
Add more fancier cpu state dump fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Spritetm committed Jun 28, 2024
1 parent 2d73b2e commit c7c85f8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRC = Musashi/m68kcpu.c Musashi/softfloat/softfloat.c Musashi/m68kops.c
SRC = Musashi/m68kcpu.c Musashi/softfloat/softfloat.c Musashi/m68kops.c Musashi/m68kdasm.c
SRC += main.c uart.c csr.c ramrom.c mapper.c scsi.c mbus.c rtc.c log.c
SRC += emu.c scsi_dev_hd.c rtcram.c

Expand Down
4 changes: 4 additions & 0 deletions Musashi/m68kconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@
#define M68K_USE_64_BIT OPT_ON


#define m68k_read_disassembler_16(A) m68k_read_memory_16(A)
#define m68k_read_disassembler_32(A) m68k_read_memory_32(A)


#endif /* M68K_COMPILE_FOR_MAME */

/* ======================================================================== */
Expand Down
37 changes: 37 additions & 0 deletions emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,38 @@ void dump_cpu_state() {
EMU_LOG_INFO("id %d CPU %d PC %08X SP %08X SR %08X D0 %08X\n", insn_id, cur_cpu, pc, sp, sr, d0);
}

void dump_cpu_state_all() {
int regs[]={
M68K_REG_PC, M68K_REG_SR, M68K_REG_SP, M68K_REG_USP,
M68K_REG_D0, M68K_REG_D1, M68K_REG_D2, M68K_REG_D3,
M68K_REG_D4, M68K_REG_D5, M68K_REG_D6, M68K_REG_D7,
M68K_REG_A0, M68K_REG_A1, M68K_REG_A2, M68K_REG_A3,
M68K_REG_A4, M68K_REG_A5, M68K_REG_A6, M68K_REG_A7,
};
char *regnames[]={
"PC", "SR", "SP", "USP",
"D0", "D1", "D2", "D3",
"D4", "D5", "D6", "D7",
"A0", "A1", "A2", "A3",
"A4", "A5", "A6", "A7"
};
EMU_LOG_INFO("CPU %d STATE DUMP:\n", cur_cpu);
for (int i=0; i<sizeof(regs)/sizeof(regs[0]); i++) {
EMU_LOG_INFO("%s\t%08X%s", regnames[i], m68k_get_reg(NULL, regs[i]), ((i&3)==3)?"\n":"\t");
}
int pc=m68k_get_reg(NULL, M68K_REG_PC);
int pos=pc-18;
char buf[1024];
//try to align to full insn
pos+=m68k_disassemble(buf, pos, M68K_CPU_TYPE_68010);
while (pos<pc+16) {
pos+=m68k_disassemble(buf, pos, M68K_CPU_TYPE_68010);
EMU_LOG_INFO("%06X %s%s\n", pos, buf, pos==pc?"\t\t<-- PC":"");
}
EMU_LOG_INFO("END DUMP\n");
}


void dump_callstack() {
EMU_LOG_INFO("Callstack (CPU %d): ", cur_cpu);
for (int i=callstack_ptr[cur_cpu]-1; i>=0; --i) {
Expand Down Expand Up @@ -210,6 +242,7 @@ static unsigned int read_memory_32(unsigned int address) {
#if PRINT_MEMREAD
EMU_LOG_INFO("read32 %s %x -> %x\n", m->name, address, m->read32(m->obj, address - m->offset));
#endif

if (!check_can_access(m, address)) return 0;
return m->read32(m->obj, address - m->offset);
}
Expand Down Expand Up @@ -702,6 +735,10 @@ void m68k_trace_cb(unsigned int pc) {
EMU_LOG_INFO("write\n");
dump_callstack();
}
if (0 && (pc==0x1FB74 || pc==0x1FB76 || pc==0x1FB78)) {
EMU_LOG_INFO("Ad 0 %x\n", read_memory_32(0));
dump_cpu_state_all();
}

//note: pc already is advanced to the next insn when this is called
//but ir is not
Expand Down
1 change: 1 addition & 0 deletions emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "mapper.h" //for access flags

void dump_cpu_state();
void dump_cpu_state_all();
void dump_callstack();

void emu_raise_int(uint8_t vector, uint8_t level, int cpu);
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int main(int argc, char **argv) {
}
int m=cfg.mem_size_bytes/(1024*1024);
if ((m & (m-1)) || m<1 || m>8) {
printf("Memory needs to be 1, 2, 4 or 8MiB (%d given)\n");
printf("Memory needs to be 1, 2, 4 or 8MiB (%d given)\n", m);
printf("Note 1 and 8 MB may not be supported by the OS\n");
error=1;
}
Expand Down

0 comments on commit c7c85f8

Please sign in to comment.