From e03422fe9ae3ef9fc7ecbfa19723af9cd6095a63 Mon Sep 17 00:00:00 2001 From: Tyler Smith <74526874+tylertms@users.noreply.github.com> Date: Mon, 19 Oct 2026 02:13:17 +0000 Subject: [PATCH] fix(runtime): let the DART's clear-side registers read back as SPTM orders its writes --- crates/stela-runtime/src/platform/apple/dart.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/stela-runtime/src/platform/apple/dart.rs b/crates/stela-runtime/src/platform/apple/dart.rs index e5e60076b1..d3c7d52453 100644 --- a/crates/stela-runtime/src/platform/apple/dart.rs +++ b/crates/stela-runtime/src/platform/apple/dart.rs @@ -538,7 +538,11 @@ impl MmioDevice for Dart { ERROR_MASK => self.error_mask, ERROR_ADDRESS_LOW => self.error_address as u32, ERROR_ADDRESS_HIGH => (self.error_address >> 32) as u32, - PROTECT => self.protect, + // UNPROTECT and DISABLE_STREAMS are clear-side views of the + // protection and enable state. SPTM reads each register back + // after writing it to order the write (file 0xcd75c), ignoring + // the value; inferred: the view reads the state it clears. + PROTECT | UNPROTECT => self.protect, PROTECT_LOCK => self.locked, // The boot stage leaves protected-write reporting disabled and // there is no pending protected-write violation. @@ -551,7 +555,9 @@ impl MmioDevice for Dart { _ => { if let Some(word) = bitmap_word(offset, ERROR_STREAMS) { self.error_streams[word] - } else if let Some(word) = bitmap_word(offset, ENABLE_STREAMS) { + } else if let Some(word) = bitmap_word(offset, ENABLE_STREAMS) + .or_else(|| bitmap_word(offset, DISABLE_STREAMS)) + { self.enabled[word] } else if let Some(word) = bitmap_word(offset, STREAM_INTERRUPTS) { self.stream_interrupts[word] @@ -745,6 +751,13 @@ mod tests { assert_eq!(d.read(STREAM_INTERRUPTS + 4, Width::Word, &mut a), Ok(5)); // The counters themselves are absent. assert!(d.read(0x760, Width::Word, &mut a).is_err()); + // Power-down disables each stream and reads the word back. + d.write(ENABLE_STREAMS + 4, Width::Word, 0x3, &mut a) + .unwrap(); + d.write(DISABLE_STREAMS + 4, Width::Word, 0x1, &mut a) + .unwrap(); + assert_eq!(d.read(DISABLE_STREAMS + 4, Width::Word, &mut a), Ok(2)); + assert_eq!(d.read(UNPROTECT, Width::Word, &mut a), Ok(0)); d.set_power(false, false, &mut a); d.set_power(true, false, &mut a); assert_eq!(d.read(STREAM_INTERRUPTS + 4, Width::Word, &mut a), Ok(0));