From a998c18ad861924ac2dcb4a0496fc9d2e6ac35d2 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Mon, 8 Mar 2021 14:56:06 -0500 Subject: [PATCH] target/riscv: Add a virtualised MMU Mode Add a new MMU mode that includes the current virt mode. Backports c445593d30037d0c82241e8ec23eb845bca476e9 --- qemu/target/riscv/cpu-param.h | 12 +++++++++++- qemu/target/riscv/cpu.h | 4 +++- qemu/target/riscv/cpu_helper.c | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/qemu/target/riscv/cpu-param.h b/qemu/target/riscv/cpu-param.h index 664fc1d3..ccd714b9 100644 --- a/qemu/target/riscv/cpu-param.h +++ b/qemu/target/riscv/cpu-param.h @@ -18,6 +18,16 @@ # define TARGET_VIRT_ADDR_SPACE_BITS 32 /* sv32 */ #endif #define TARGET_PAGE_BITS 12 /* 4 KiB Pages */ -#define NB_MMU_MODES 4 + +/* + * The current MMU Modes are: + * - U mode 0b000 + * - S mode 0b001 + * - M mode 0b011 + * - U mode HLV/HLVX/HSV 0b100 + * - S mode HLV/HLVX/HSV 0b101 + * - M mode HLV/HLVX/HSV 0b111 + */ +#define NB_MMU_MODES 8 #endif diff --git a/qemu/target/riscv/cpu.h b/qemu/target/riscv/cpu.h index 135b80de..7f86d438 100644 --- a/qemu/target/riscv/cpu.h +++ b/qemu/target/riscv/cpu.h @@ -365,7 +365,9 @@ void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env, target_ulong riscv_cpu_get_fflags(CPURISCVState *env); void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); -#define TB_FLAGS_MMU_MASK 3 +#define TB_FLAGS_MMU_MASK 7 +#define TB_FLAGS_PRIV_MMU_MASK 3 +#define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2) #define TB_FLAGS_MSTATUS_FS MSTATUS_FS typedef CPURISCVState CPUArchState; diff --git a/qemu/target/riscv/cpu_helper.c b/qemu/target/riscv/cpu_helper.c index 9c1654a1..68055fe9 100644 --- a/qemu/target/riscv/cpu_helper.c +++ b/qemu/target/riscv/cpu_helper.c @@ -317,7 +317,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, * (riscv_cpu_do_interrupt) is correct */ MemTxResult res; MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; - int mode = mmu_idx; + int mode = mmu_idx & TB_FLAGS_PRIV_MMU_MASK; bool use_background = false; /*