Browse Source

Reuse sstatus bitmask for mstatus bits

To reduce repetition in code.

This has one functional effect that I can see: before this change, on
a config that supports floating point but not S-mode or Vector,
writing misa.F=0 would freeze the FS bits in mstatus. I assume this
was an accident and never the intended behavior, though I can't find
anything in the privileged spec about this.

Now the FS bits will always be writable regardless of misa.F, if the
bits exist at all. (Because we now call extension_enabled('F') only
once, at reset, instead of every mstatus write.)
pull/796/head
Scott Johnson 5 years ago
committed by Andrew Waterman
parent
commit
ca0850358e
  1. 14
      riscv/csrs.cc
  2. 2
      riscv/csrs.h

14
riscv/csrs.cc

@ -412,19 +412,13 @@ bool mstatus_csr_t::unlogged_write(const reg_t val) noexcept {
))
proc->get_mmu()->flush_tlb();
bool has_fs = proc->extension_enabled('S') || proc->extension_enabled('F')
|| proc->extension_enabled_const('V');
bool has_vs = proc->extension_enabled_const('V');
bool has_mpv = proc->extension_enabled('S') && proc->extension_enabled('H');
bool has_gva = has_mpv;
reg_t mask = MSTATUS_MIE | MSTATUS_MPIE | MSTATUS_MPRV | MSTATUS_MPP
| (proc->extension_enabled('S') ? (MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_SPP) : 0)
| MSTATUS_TW | MSTATUS_TSR
| (has_page ? (MSTATUS_MXR | MSTATUS_SUM | MSTATUS_TVM) : 0)
| (has_fs ? MSTATUS_FS : 0)
| (has_vs ? MSTATUS_VS : 0)
| (proc->any_custom_extensions() ? MSTATUS_XS : 0)
reg_t mask = sstatus_write_mask
| MSTATUS_MIE | MSTATUS_MPIE | MSTATUS_MPRV
| MSTATUS_MPP | MSTATUS_TW | MSTATUS_TSR
| (has_page ? MSTATUS_TVM : 0)
| (has_gva ? MSTATUS_GVA : 0)
| (has_mpv ? MSTATUS_MPV : 0);

2
riscv/csrs.h

@ -220,7 +220,7 @@ typedef std::shared_ptr<vsstatus_csr_t> vsstatus_csr_t_p;
// state.sstatus. When complete, all references to sstatus that
// need to be virtualized will be through this object.
// 3. [done] Convert mstatus into a csr_t subclass.
// 4. Refactor common code into base class.
// 4. [done] Refactor common code into base class.
// 5. [done] Convert sstatus to a virtualized_csr_t, with a
// nonvirtual_sstatus of type sstatus_proxy_csr_t, and
// simultaneously remove the swapping of mstatus & vsstatus from

Loading…
Cancel
Save