Skip to content

Commit

Permalink
SailBugfix: mcounteren is read-only except for IR, TMP, and CY fields
Browse files Browse the repository at this point in the history
This commit makes all bits in the mcounteren register read-only, except for the aforementioned IR, TMP, and CY fields, which remain writable.
  • Loading branch information
francois141 authored and CharlyCst committed Dec 3, 2024
1 parent df20efb commit b2edd40
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/virt/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ impl HwRegisterContextSetter<Csr> for VirtContext {
self.csr.mcountinhibit |= (value & 0b101) as u32;
}
Csr::Mhpmevent(_event_idx) => (), // Read-only 0
Csr::Mcounteren => self.csr.mcounteren = (value & 0b111) as u32, // Only show IR, TM and CY (for cycle, time and instret counters)
Csr::Mcounteren => {
// Only show IR, TM and CY (for cycle, time and instret counters)
self.csr.mcounteren = (self.csr.mcounteren & !0b111) | (value & 0b111) as u32
}
Csr::Menvcfg => {
let mut mask: usize = usize::MAX;
if !mctx.hw.extensions.has_sstc_extension {
Expand Down

0 comments on commit b2edd40

Please sign in to comment.