Read memory-mapped registers through the registers, not the backing store

C5xCore::data() answers from m_data, which for an address below 0x60 is a
cell that no memory-mapped register keeps up to date. DM_READ16 routes those
through cpuregs_r; the inspection accessor never did. So every harness that
reached for a register got zero however the firmware had set it, and said so
confidently:

  PMST  reads 0000, is 00b0   - iptr 0, MP/MC 0, OVLY, RAM and AVIS all set
  CBSR1 reads 0000, is 0bc0   - the datapump's output buffer
  CBER1 reads 0000, is 0bdf
  CBCR  reads 0000, is 00ef   - circular buffer 1, AR7, enabled, 32 words
  TDXR  reads 0000            - whatever INTR 17's handler has been writing

Reading those four was what led to "the firmware never sets up a circular
buffer" and "TDXR never changes". Both were the accessor, not the firmware.

register_value() answers from the register and has no side effects, which is
the difference that matters for an inspection path: cpuregs_r pops the codec
queue on DRR and clears the ready flag on TRCV. data() keeps its meaning, so
nothing that already treats low addresses as scratch changes behaviour.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Cryan209andClaude Opus 5 committed 2026-09-16 21:46:40 +12:00
1 parent f01e9d82c6
commit cf84decd47
4 files changed
+62

No files matched your search

+12
View File
@@ -261,6 +261,8 @@ class NativeC5x:
lib.courier_c5x_get_io.restype = ctypes.c_uint16
lib.courier_c5x_get_program.argtypes = [ctypes.c_void_p, ctypes.c_uint16]
lib.courier_c5x_get_program.restype = ctypes.c_uint16
lib.courier_c5x_get_register.argtypes = [ctypes.c_void_p, ctypes.c_uint16]
lib.courier_c5x_get_register.restype = ctypes.c_uint16
lib.courier_c5x_get_data.argtypes = [ctypes.c_void_p, ctypes.c_uint16]
lib.courier_c5x_set_data_trace_filter.argtypes = [ctypes.c_void_p, ctypes.c_uint, ctypes.c_int]
lib.courier_c5x_set_data_trace_filter.restype = None
@@ -525,6 +527,16 @@ class NativeC5x:
def set_data(self, address: int, value: int) -> None:
self.library.courier_c5x_set_data(self.handle, address, value)
def register(self, offset: int) -> int:
"""A memory-mapped register, read without disturbing it.
`data()` answers from the raw backing store, which for an address below
0x60 is a cell no register keeps up to date: PMST, CBCR and TDXR all
read zero through it however the firmware has set them. Reading them
needs this instead.
"""
return int(self.library.courier_c5x_get_register(self.handle, offset))
def interrupt(self, irq: int) -> None:
self.library.courier_c5x_interrupt(self.handle, irq)
+5
View File
@@ -259,6 +259,11 @@ uint16_t courier_c5x_get_data(void *handle, uint16_t address)
return handle ? static_cast<C5xCore *>(handle)->data(address) : 0xffff;
}
uint16_t courier_c5x_get_register(void *handle, uint16_t offset)
{
return handle ? static_cast<C5xCore *>(handle)->register_value(offset) : 0xffff;
}
void courier_c5x_set_data(void *handle, uint16_t address, uint16_t value)
{
if (handle) static_cast<C5xCore *>(handle)->set_data(address, value);
+38
View File
@@ -527,6 +527,44 @@ void C5xCore::set_data(uint16_t address, uint16_t value)
else m_data[address] = value;
}
uint16_t C5xCore::register_value(uint16_t offset) const
{
switch (offset) {
case 0x04: return m_imr;
case 0x06: return m_ifr;
case 0x07: return uint16_t((m_pmst.iptr << 11) | (m_pmst.avis << 7) |
(m_pmst.ovly << 5) | (m_pmst.ram << 4) | (m_pmst.mpmc << 3) |
(m_pmst.ndx << 2) | (m_pmst.trm << 1) | m_pmst.braf);
case 0x09: return uint16_t(m_brcr);
case 0x0c: return m_treg0;
case 0x0d: return m_treg1;
case 0x0e: return m_treg2;
case 0x0f: return m_dbmr;
case 0x10: case 0x11: case 0x12: case 0x13:
case 0x14: case 0x15: case 0x16: case 0x17: return m_ar[offset - 0x10];
case 0x18: return m_indx; case 0x19: return m_arcr;
case 0x1a: return m_cbsr1; case 0x1b: return m_cber1;
case 0x1c: return m_cbsr2; case 0x1d: return m_cber2;
case 0x1e: return m_cbcr; case 0x1f: return m_bmar;
// DRR and TRCV read their held word without consuming it.
case 0x20: return m_serial.drr;
case 0x21: return m_serial.dxr;
case 0x22: return m_serial.spc;
case 0x24: return m_timer.tim; case 0x25: return m_timer.prd;
case 0x26: return uint16_t(((m_timer.psc & 0xf) << 6) | (m_timer.tddr & 0xf));
case 0x28: return m_pdwsr;
case 0x29: return m_iowsr;
case 0x2a: return m_cwsr;
case 0x30: return m_tdm.trcv;
case 0x31: return m_tdm.tdxr;
case 0x32: return m_tdm.tspc;
case 0x33: return m_tdm.tcsr;
case 0x34: return m_tdm.trta;
case 0x35: return m_tdm.trad;
default: return m_data[offset];
}
}
C5xCore::MemoryMap C5xCore::memory_map() const
{
m_map.mpmc_pin = m_mpmc_pin;
+7
View File
@@ -250,6 +250,13 @@ public:
uint16_t io_output(uint16_t port) const;
uint16_t program(uint16_t address) const;
uint16_t data(uint16_t address) const;
// Inspection only. data() returns the raw backing store, so for an address
// below 0x60 it answers with a cell no memory-mapped register keeps up to
// date - a harness reading PMST, CBCR or TDXR through it sees zero however
// the firmware has set them. This reads the register itself, and unlike
// cpuregs_r it has no side effects: DRR does not pop the codec queue and
// TRCV does not clear its ready flag.
uint16_t register_value(uint16_t offset) const;
void set_data(uint16_t address, uint16_t value);
void interrupt(unsigned irq);
void nmi();