From 2532b87826610ec007059996f265b2bb41752438 Mon Sep 17 00:00:00 2001 From: George Wright Date: Wed, 24 Jun 2026 18:49:22 -0700 Subject: [PATCH] logging: add a centralised logging macro --- CMakeLists.txt | 1 + WindCore/arm710.cpp | 4 ++++ WindCore/logger.cpp | 20 ++++++++++++++++++++ WindCore/logger.h | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 WindCore/logger.cpp create mode 100644 WindCore/logger.h diff --git a/CMakeLists.txt b/CMakeLists.txt index be00226..cae2a76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(WIND_CORE_SOURCES WindCore/emubase.cpp WindCore/decoder.c WindCore/decoder-arm.c + WindCore/logger.cpp WindCore/osaris/clps7111.cpp WindCore/osaris/clps7600.cpp WindCore/series5mx/etna.cpp diff --git a/WindCore/arm710.cpp b/WindCore/arm710.cpp index 4cbe1e1..c568470 100644 --- a/WindCore/arm710.cpp +++ b/WindCore/arm710.cpp @@ -1,5 +1,6 @@ #include "arm710.h" #include "common.h" +#include "logger.h" // this will need changing if this code ever compiles on big-endian procs inline uint32_t read32LE(uint8_t* p) { return *((uint32_t*)p); } @@ -73,6 +74,9 @@ void ARM710::reset() { } uint32_t ARM710::tick() { + uint32_t pc = getGPR(15) - 0x8; + setPC(pc); + // pop an instruction off the end of the pipeline bool haveInsn = false; uint32_t insn; diff --git a/WindCore/logger.cpp b/WindCore/logger.cpp new file mode 100644 index 0000000..94328f2 --- /dev/null +++ b/WindCore/logger.cpp @@ -0,0 +1,20 @@ +#include "logger.h" + +static uint64_t sEventNumber = 0; + +uint64_t getNextEventNumber() { + return sEventNumber++; +} + +uint64_t getEventNumber() { + return sEventNumber; +} + +static uint32_t sCurrentPC = 0; + +void setPC(uint32_t pc) { + sCurrentPC = pc; +} +uint32_t getPC() { + return sCurrentPC; +} diff --git a/WindCore/logger.h b/WindCore/logger.h new file mode 100644 index 0000000..829543d --- /dev/null +++ b/WindCore/logger.h @@ -0,0 +1,39 @@ +#ifndef LOGGER_H +#define LOGGER_H + +#include +#include + +uint64_t getNextEventNumber(); +uint64_t getEventNumber(); + +void setPC(uint32_t); +uint32_t getPC(); + +#define LOGGING_ENABLE 0 + +#if LOGGING_ENABLE +#define LOG_REG_W(name, addr, value) \ + printf("%llu: (%08x) [W] %s [%08x] <= %08x\n", getNextEventNumber(), \ + getPC(), name, addr, value) + +#define LOG_REG_R(name, addr, value) \ + printf("%llu: (%08x) [R] %s [%08x] => %08x\n", getNextEventNumber(), \ + getPC(), name, addr, value) + +#define LOG(...) printf(__VA_ARGS__) +#else +#define LOG_REG_W(name, addr, value) \ + do { \ + { \ + } \ + } while (0) +#define LOG_REG_R(name, addr, value) \ + do { \ + { \ + } \ + } while (0) +#define LOG(...) +#endif + +#endif // LOGGER_H -- 2.45.2