aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeiwei Li <liweiwei@iscas.ac.cn>2022-07-17 10:00:23 +0800
committerWeiwei Li <liweiwei@iscas.ac.cn>2022-07-17 10:00:23 +0800
commit89a79b673208a61f7ff16be628955109a742c1ac (patch)
tree01e4b34cc8b3e96231ea8e180917486aac33a73f
parentf82e54124345f348abaa80ec82d67528a9a8f774 (diff)
downloadspike-89a79b673208a61f7ff16be628955109a742c1ac.zip
spike-89a79b673208a61f7ff16be628955109a742c1ac.tar.gz
spike-89a79b673208a61f7ff16be628955109a742c1ac.tar.bz2
Fix the initial value and write mask for mstatus
- MPRV is read-only 0 if U-mode is not supported - If U-mode is not supported, UBE is read-only 0 - If S-mode is not supported, SBE is read-only 0
-rw-r--r--riscv/csrs.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/riscv/csrs.cc b/riscv/csrs.cc
index c27410c..57778c3 100644
--- a/riscv/csrs.cc
+++ b/riscv/csrs.cc
@@ -474,7 +474,8 @@ bool mstatus_csr_t::unlogged_write(const reg_t val) noexcept {
const bool has_gva = has_mpv;
const reg_t mask = sstatus_write_mask
- | MSTATUS_MIE | MSTATUS_MPIE | MSTATUS_MPRV
+ | MSTATUS_MIE | MSTATUS_MPIE
+ | (proc->extension_enabled('U') ? MSTATUS_MPRV : 0)
| MSTATUS_MPP | MSTATUS_TW
| (proc->extension_enabled('S') ? MSTATUS_TSR : 0)
| (has_page ? MSTATUS_TVM : 0)
@@ -490,10 +491,13 @@ bool mstatus_csr_t::unlogged_write(const reg_t val) noexcept {
}
reg_t mstatus_csr_t::compute_mstatus_initial_value() const noexcept {
+ const reg_t big_endian_bits = (proc->extension_enabled_const('U') ? MSTATUS_UBE : 0)
+ | (proc->extension_enabled_const('S') ? MSTATUS_SBE : 0)
+ | MSTATUS_MBE;
return 0
| (proc->extension_enabled_const('U') && (proc->get_const_xlen() != 32) ? set_field((reg_t)0, MSTATUS_UXL, xlen_to_uxl(proc->get_const_xlen())) : 0)
| (proc->extension_enabled_const('S') && (proc->get_const_xlen() != 32) ? set_field((reg_t)0, MSTATUS_SXL, xlen_to_uxl(proc->get_const_xlen())) : 0)
- | (proc->get_mmu()->is_target_big_endian() ? MSTATUS_UBE | MSTATUS_SBE | MSTATUS_MBE : 0)
+ | (proc->get_mmu()->is_target_big_endian() ? big_endian_bits : 0)
| 0; // initial value for mstatus
}