aboutsummaryrefslogtreecommitdiff
path: root/target/riscv
diff options
context:
space:
mode:
authorAlistair Francis <alistair.francis@wdc.com>2020-01-31 17:01:56 -0800
committerPalmer Dabbelt <palmerdabbelt@google.com>2020-02-27 13:45:30 -0800
commit0a42f4c4408824dc7cb9ff60c9bdce6dcc0d24a5 (patch)
treedb795a9ed7bc6f8cee2bf8c3ac16abffa4ded30e /target/riscv
parentc7b1bbc80fc2af17395d3986c346fd2307e57829 (diff)
downloadqemu-0a42f4c4408824dc7cb9ff60c9bdce6dcc0d24a5.zip
qemu-0a42f4c4408824dc7cb9ff60c9bdce6dcc0d24a5.tar.gz
qemu-0a42f4c4408824dc7cb9ff60c9bdce6dcc0d24a5.tar.bz2
target/riscv: Fix CSR perm checking for HS mode
Update the CSR permission checking to work correctly when we are in HS-mode. Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Diffstat (limited to 'target/riscv')
-rw-r--r--target/riscv/csr.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index ca27359..c63b2f9 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -801,12 +801,22 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
/* check privileges and return -1 if check fails */
#if !defined(CONFIG_USER_ONLY)
- int csr_priv = get_field(csrno, 0x300);
+ int effective_priv = env->priv;
int read_only = get_field(csrno, 0xC00) == 3;
- if ((!env->debugger) && (env->priv < csr_priv)) {
- return -1;
+
+ if (riscv_has_ext(env, RVH) &&
+ env->priv == PRV_S &&
+ !riscv_cpu_virt_enabled(env)) {
+ /*
+ * We are in S mode without virtualisation, therefore we are in HS Mode.
+ * Add 1 to the effective privledge level to allow us to access the
+ * Hypervisor CSRs.
+ */
+ effective_priv++;
}
- if (write_mask && read_only) {
+
+ if ((write_mask && read_only) ||
+ (!env->debugger && (effective_priv < get_field(csrno, 0x300)))) {
return -1;
}
#endif