aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShay Aviv <shay.aviv@gmail.com>2021-06-09 23:15:09 +0300
committerGitHub <noreply@github.com>2021-06-09 13:15:09 -0700
commit1908fc380c24ef0989063e8029eaa14913c187dd (patch)
treecb447cd78f78935bb6daa11456610706285ba4af
parent0e4b5cbc25e27ccb8e7a1bebf08111c0f5e9bebe (diff)
downloadspike-1908fc380c24ef0989063e8029eaa14913c187dd.zip
spike-1908fc380c24ef0989063e8029eaa14913c187dd.tar.gz
spike-1908fc380c24ef0989063e8029eaa14913c187dd.tar.bz2
Apply scounteren only if S-mode is supported (#726)
When U-mode is enabled but S-mode is disabled, `mcounteren` should control the availability of the hardware performance-monitoring counters in U-mode, and `scounteren` should be ignored. The current implementation (incorrectly) raises an illegal instruction trap when reading performance-monitoring counters in U-mode while S-mode is disabled, even if the counters are enabled in `mcounteren`.
-rw-r--r--riscv/processor.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/riscv/processor.cc b/riscv/processor.cc
index 9b6fe12..6225a92 100644
--- a/riscv/processor.cc
+++ b/riscv/processor.cc
@@ -1405,7 +1405,7 @@ reg_t processor_t::get_csr(int which, insn_t insn, bool write, bool peek)
uint32_t ctr_en = -1;
if (state.prv < PRV_M)
ctr_en &= state.mcounteren;
- if (state.prv < PRV_S)
+ if (supports_extension('S') && state.prv < PRV_S)
ctr_en &= state.scounteren;
bool ctr_ok = (ctr_en >> (which & 31)) & 1;
if (state.v)