From acd4765317564a657b91a93891c5adf220d76976 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 16 Feb 2013 18:32:37 -0500 Subject: [PATCH] mpw trace flag --- bin/loader.cpp | 20 +++++++++++++++++++- mpw/mpw.cpp | 5 ++++- mpw/mpw.h | 3 +++ mpw/mpw_access.cpp | 8 +++++--- mpw/mpw_close.cpp | 4 +++- mpw/mpw_internal.h | 8 ++++++++ mpw/mpw_ioctl.cpp | 23 ++++++++++++++--------- 7 files changed, 56 insertions(+), 15 deletions(-) diff --git a/bin/loader.cpp b/bin/loader.cpp index dc46185..2af8a49 100644 --- a/bin/loader.cpp +++ b/bin/loader.cpp @@ -24,11 +24,14 @@ struct { uint32_t ram; uint32_t stack; uint32_t machine; + bool traceCPU; bool traceMacsbug; bool traceGlobals; + bool traceToolBox; + bool traceMPW; -} Flags = { 16 * 1024 * 1024, 8 * 1024, 68030, false, false, false }; +} Flags = { 16 * 1024 * 1024, 8 * 1024, 68030, false, false, false, false, false}; uint8_t *Memory; @@ -598,6 +601,8 @@ int main(int argc, char **argv) kTraceCPU = 1, kTraceMacsBug, kTraceGlobals, + kTraceToolBox, + kTraceMPW, }; static struct option LongOpts[] = { @@ -607,6 +612,8 @@ int main(int argc, char **argv) { "trace-cpu", no_argument, NULL, kTraceCPU }, { "trace-macsbug", no_argument, NULL, kTraceMacsBug }, { "trace-globals", no_argument, NULL, kTraceGlobals }, + { "trace-toolbox", no_argument, NULL, kTraceToolBox }, + { "trace-mpw", no_argument, NULL, kTraceMPW }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } @@ -629,6 +636,14 @@ int main(int argc, char **argv) Flags.traceGlobals = true; break; + case kTraceToolBox: + Flags.traceToolBox = true; + break; + + case kTraceMPW: + Flags.traceMPW = true; + break; + case 'm': if (!parse_number(optarg, &Flags.machine)) exit(EX_CONFIG); @@ -682,6 +697,9 @@ int main(int argc, char **argv) InitializeMPW(argc, argv); + MPW::Init(); + + MPW::Trace = Flags.traceMPW; if (!Flags.stack) { diff --git a/mpw/mpw.cpp b/mpw/mpw.cpp index ef0c625..fea72b3 100644 --- a/mpw/mpw.cpp +++ b/mpw/mpw.cpp @@ -29,6 +29,8 @@ namespace MPW { using namespace Internal; + bool Trace = false; + int errno_to_errno(int xerrno) { switch (xerrno) @@ -90,7 +92,8 @@ namespace MPW void ftrap_quit(uint16_t trap) { - fprintf(stderr, "%04x Quit()\n", trap); + Log("%04x Quit()\n", trap); + //fprintf(stderr, "%04x Quit()\n", trap); cpuSetStop(true); } diff --git a/mpw/mpw.h b/mpw/mpw.h index ef12b02..d575fc3 100644 --- a/mpw/mpw.h +++ b/mpw/mpw.h @@ -5,6 +5,9 @@ namespace MPW { + extern bool Trace; + + struct MPWFile { diff --git a/mpw/mpw_access.cpp b/mpw/mpw_access.cpp index 715e4e9..1b1d828 100644 --- a/mpw/mpw_access.cpp +++ b/mpw/mpw_access.cpp @@ -65,7 +65,8 @@ namespace MPW sname = ToolBox::ReadCString(name); - fprintf(stderr, " open(%s, %04x)\n", sname.c_str(), f.flags); + //fprintf(stderr, " open(%s, %04x)\n", sname.c_str(), f.flags); + Log(" open(%s, %04x)\n", sname.c_str(), f.flags); // TODO -- can you create a resource file like this? @@ -128,8 +129,9 @@ namespace MPW uint32_t op = memoryReadLong(sp + 8); uint32_t parm = memoryReadLong(sp + 12); - fprintf(stderr, "%04x Access(%08x, %04x, %08x)\n", trap, name, op, parm); - + //fprintf(stderr, "%04x Access(%08x, %04x, %08x)\n", trap, name, op, parm); + Log("%04x Access(%08x, %04x, %08x)\n", trap, name, op, parm); + switch (op) { case kF_OPEN: diff --git a/mpw/mpw_close.cpp b/mpw/mpw_close.cpp index 2b54dbc..a7d303d 100644 --- a/mpw/mpw_close.cpp +++ b/mpw/mpw_close.cpp @@ -40,7 +40,8 @@ namespace MPW f.buffer = memoryReadLong(parm + 16); - fprintf(stderr, "%04x Close(%08x)\n", trap, parm); + //fprintf(stderr, "%04x Close(%08x)\n", trap, parm); + Log("%04x Close(%08x)\n", trap, parm); if (!parm) { @@ -60,6 +61,7 @@ namespace MPW { if (--FDTable[fd] == 0) { + Log(" close(%02x)\n", fd); ::close(fd); f.error = 0; d0 = 0; diff --git a/mpw/mpw_internal.h b/mpw/mpw_internal.h index d7438dd..9f3f752 100644 --- a/mpw/mpw_internal.h +++ b/mpw/mpw_internal.h @@ -2,9 +2,17 @@ #define __MPW_INTERNAL_H__ #include +#include namespace MPW { + + template + inline void Log(const char *format, Args... args) + { + if (Trace) fprintf(stderr, format, args...); + } + namespace Internal { // for dup counts, etc. diff --git a/mpw/mpw_ioctl.cpp b/mpw/mpw_ioctl.cpp index f3ac698..a71145e 100644 --- a/mpw/mpw_ioctl.cpp +++ b/mpw/mpw_ioctl.cpp @@ -44,7 +44,8 @@ namespace MPW int fd = f.cookie; - fprintf(stderr, " dup(%02x)\n", fd); + //fprintf(stderr, " dup(%02x)\n", fd); + Log(" dup(%02x)\n", fd); if (fd < 0 || fd >= FDTable.size() || !FDTable[fd]) { @@ -78,8 +79,8 @@ namespace MPW int fd = f.cookie; - fprintf(stderr, " bufsize(%02x)\n", fd); - + //fprintf(stderr, " bufsize(%02x)\n", fd); + Log(" bufsize(%02x)\n", fd); memoryWriteWord(f.error, parm + 2); return kEINVAL; @@ -110,7 +111,8 @@ namespace MPW int fd = f.cookie; - fprintf(stderr, " interactive(%02x)\n", fd); + //fprintf(stderr, " interactive(%02x)\n", fd); + Log(" interactive(%02x)\n", fd); //d0 = kEINVAL; @@ -150,7 +152,8 @@ namespace MPW int fd = f.cookie; - fprintf(stderr, " fname(%02x)\n", fd); + //fprintf(stderr, " fname(%02x)\n", fd); + Log(" fname(%02x)\n", fd); memoryWriteWord(f.error, parm + 2); return kEINVAL; @@ -174,7 +177,8 @@ namespace MPW int fd = f.cookie; - fprintf(stderr, " refnum(%02x)\n", fd); + //fprintf(stderr, " refnum(%02x)\n", fd); + Log(" refnum(%02x)\n", fd); if (fd < 0 || fd >= FDTable.size() || !FDTable[fd]) { @@ -238,7 +242,8 @@ namespace MPW return kEINVAL; } - fprintf(stderr, " lseek(%02x, %08x, %02x)\n", fd, offset, nativeWhence); + //fprintf(stderr, " lseek(%02x, %08x, %02x)\n", fd, offset, nativeWhence); + Log(" lseek(%02x, %08x, %02x)\n", fd, offset, nativeWhence); if (::isatty(fd)) { @@ -264,7 +269,6 @@ namespace MPW { d0 = 0; f.error = 0; - fprintf(stderr, "-> %lld\n", rv); } memoryWriteLong(rv, arg + 4); @@ -285,7 +289,8 @@ namespace MPW uint32_t cmd = memoryReadLong(sp + 8); uint32_t arg = memoryReadLong(sp + 12); - fprintf(stderr, "%04x IOCtl(%08x, %08x, %08x)\n", trap, fd, cmd, arg); + //fprintf(stderr, "%04x IOCtl(%08x, %08x, %08x)\n", trap, fd, cmd, arg); + Log("%04x IOCtl(%08x, %08x, %08x)\n", trap, fd, cmd, arg); switch (cmd) {