Skip to content

Commit

Permalink
Don't raise virtual instruction exceptions writes to read-only registers
Browse files Browse the repository at this point in the history
This is a bug in the spec that will be changed in the next few days.
  • Loading branch information
aswaterman committed May 20, 2021
1 parent ce170a7 commit 4630011
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions riscv/processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1745,14 +1745,13 @@ reg_t processor_t::get_csr(int which, insn_t insn, bool write, bool peek)
return res;

unsigned csr_priv = get_field(which, 0x300);
bool csr_read_only = get_field(which, 0xC00) == 3;
unsigned priv = state.prv == PRV_S && !state.v ? PRV_HS : state.prv;

if ((csr_priv == PRV_S && !supports_extension('S')) ||
(csr_priv == PRV_HS && !supports_extension('H')))
goto throw_illegal;

if ((write && csr_read_only) || priv < csr_priv) {
if (priv < csr_priv) {
if (state.v && csr_priv <= PRV_HS)
goto throw_virtual;
goto throw_illegal;
Expand Down

0 comments on commit 4630011

Please sign in to comment.