From 49711b79d5e4b60031dfdcd55e1785fb2f646f07 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 9 Feb 2013 20:07:42 -0500 Subject: [PATCH] use cpu's instruction logging facilities --- bin/loader.cpp | 76 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/bin/loader.cpp b/bin/loader.cpp index 781681c..300f340 100644 --- a/bin/loader.cpp +++ b/bin/loader.cpp @@ -304,6 +304,45 @@ void InitializeMPW(int argc, char **argv) WriteLong(Memory, 0x0a06, 0xffffffff); } + +void InstructionLogger() +{ + + static char strings[4][256]; + for (unsigned j = 0; j < 4; ++j) strings[j][0] = 0; + + uint32_t pc = cpuGetPC(); + //uint16_t opcode = ReadWord(Memory, pc); + + #if 0 + if ((opcode & 0xf000) == 0xa000) + { + fprintf(stderr, "tool %04x\n", opcode); + } + #endif + + #if 0 + fprintf(stderr, "D0 D1 D2 D3 D4 D5 D6 D7 A0 A1 A2 A3 A4 A5 A6 A7\n"); + fprintf(stderr, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", + cpuGetDReg(0), cpuGetDReg(1), cpuGetDReg(2), cpuGetDReg(3), + cpuGetDReg(4), cpuGetDReg(5), cpuGetDReg(6), cpuGetDReg(7), + cpuGetAReg(0), cpuGetAReg(1), cpuGetAReg(2), cpuGetAReg(3), + cpuGetAReg(4), cpuGetAReg(5), cpuGetAReg(6), cpuGetAReg(7) + ); + #endif + // todo - check for Axxx, recognize as a toolcall. + // move this to the cpuLogging facility? + cpuDisOpcode(pc, strings[0], strings[1], strings[2], strings[3]); + + // address, data, instruction, operand + fprintf(stderr, "%s %-10s %-40s ; %s\n", strings[0], strings[2], strings[3], strings[1]); + + // todo -- trace registers (only print changed registers?) + + + +} + void help() { @@ -470,41 +509,18 @@ int main(int argc, char **argv) cpuSetALineExceptionFunc(ToolBox::dispatch); memorySetMemory(Memory, MemorySize); + memorySetGlobalLog(0x10000); + MM::Init(Memory, MemorySize, HighWater); - for (unsigned i = 0; i < 10000; ++i) + if (Flags.traceCPU) { - if (Flags.traceCPU) - { - static char strings[4][256]; - for (unsigned j = 0; j < 4; ++j) strings[j][0] = 0; + cpuSetInstructionLoggingFunc(InstructionLogger); + } - uint32_t pc = cpuGetPC(); - uint16_t opcode = ReadWord(Memory, pc); + for (unsigned i = 0; i < 9200; ++i) + { - if ((opcode & 0xf000) == 0xa000) - { - fprintf(stderr, "tool %04x\n", opcode); - } - - #if 0 - fprintf(stderr, "D0 D1 D2 D3 D4 D5 D6 D7 A0 A1 A2 A3 A4 A5 A6 A7\n"); - fprintf(stderr, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", - cpuGetDReg(0), cpuGetDReg(1), cpuGetDReg(2), cpuGetDReg(3), - cpuGetDReg(4), cpuGetDReg(5), cpuGetDReg(6), cpuGetDReg(7), - cpuGetAReg(0), cpuGetAReg(1), cpuGetAReg(2), cpuGetAReg(3), - cpuGetAReg(4), cpuGetAReg(5), cpuGetAReg(6), cpuGetAReg(7) - ); - #endif - // todo - check for Axxx, recognize as a toolcall. - // move this to the cpuLogging facility? - cpuDisOpcode(pc, strings[0], strings[1], strings[2], strings[3]); - - // address, data, instruction, operand - fprintf(stderr, "%s %-10s %-40s ; %s\n", strings[0], strings[2], strings[3], strings[1]); - - // todo -- trace registers (only print changed registers?) - } cpuExecuteInstruction(); }