From dbd8d9d474ed12aa618e888415fff345f4d7bca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Costa?= Date: Sat, 30 Nov 2024 23:09:20 +0100 Subject: [PATCH] SailBugfix: scounteren is read-only except for IR, TMP, and CY fields This commit makes all bits in the mcounteren register read-only, except for the aforementioned IR, TMP, and CY fields, which remain writable. --- src/virt/csr.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/virt/csr.rs b/src/virt/csr.rs index 4d9c65a2..34823049 100644 --- a/src/virt/csr.rs +++ b/src/virt/csr.rs @@ -520,7 +520,10 @@ impl HwRegisterContextSetter for VirtContext { } } } - Csr::Scounteren => (), // Read-only 0 + Csr::Scounteren => { + // Only show IR, TM and CY (for cycle, time and instret counters) + self.csr.scounteren = (self.csr.scounteren & !0b111) | (value & 0b111) as u32 + } Csr::Senvcfg => self.csr.senvcfg = value, Csr::Sscratch => self.csr.sscratch = value, Csr::Sepc => {