target/riscv: Fix mstatus related problems
v2 cover target/riscv: Fix mstatus related problems
This patchset tries to fix some problems in the fields of mstatus, such as make MPV only work when MPP != PRM.
The port is available here:
https://github.com/plctlab/plct-qemu/tree/plct-mpv-upstream-v2
v2:
* Drop patch 3 (remove check on mode M for MPRV)
* rebase on apply-to-riscv.next
Weiwei Li (3):
target/riscv: Make MPV only work when MPP != PRV_M target/riscv: Support MSTATUS.MPV/GVA only when RVH is enabled target/riscv: Remove redundant assignment to SXL
target/riscv/cpu_helper.c | 3 ++- target/riscv/csr.c | 14 ++++---------- target/riscv/op_helper.c | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 target/riscv: Make MPV only work when MPP != PRV_M
Upon MRET or explicit memory access with MPRV=1, MPV should be ignored when MPP=PRV_M.
--- target/riscv/cpu_helper.c | 3 ++- target/riscv/op_helper.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
target/riscv/cpu_helper.c +2 -1
@@ -46,7 +46,8 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)if (mode ==PRV_M &&get_field (status,MSTATUS_MPRV )) { mode =get_field (env->mstatus,MSTATUS_MPP ); - virt =get_field (env->mstatus,MSTATUS_MPV ); + virt =get_field (env->mstatus,MSTATUS_MPV ) && + (mode !=PRV_M );if (virt) { status = env->vsstatus; }
target/riscv/op_helper.c +2 -1
@@ -335,7 +335,8 @@ target_ulong helper_mret(CPURISCVState *env)riscv_raise_exception (env,RISCV_EXCP_INST_ACCESS_FAULT ,GETPC ()); } -target_ulong prev_virt =get_field (env->mstatus,MSTATUS_MPV ); +target_ulong prev_virt =get_field (env->mstatus,MSTATUS_MPV ) && + (prev_priv !=PRV_M ); mstatus =set_field (mstatus,MSTATUS_MIE ,get_field (mstatus,MSTATUS_MPIE )); mstatus =set_field (mstatus,MSTATUS_MPIE ,1 );
Signature · 1 line
2.25.1
PATCH v2 2/3 target/riscv: Support MSTATUS.MPV/GVA only when RVH is enabled
In reply to Weiwei LiMPV and GVA bits are added by hypervisor extension to mstatus and mstatush (if MXLEN=32).
--- target/riscv/csr.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
target/riscv/csr.c +4 -6
@@ -1311,11 +1311,9 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, }if (xl !=MXL_RV32 || env->debugger) { -/* -* RV32: MPV and GVA are not in mstatus. The current plan is to -* add them to mstatush. For now, we just don't support it. -*/ - mask |=MSTATUS_MPV |MSTATUS_GVA ; +if (riscv_has_ext (env,RVH )) { + mask |=MSTATUS_MPV |MSTATUS_GVA ; + }if ((val &MSTATUS64_UXL ) !=0 ) { mask |=MSTATUS64_UXL ; }
@@ -1351,7 +1349,7 @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno, target_ulong val) {uint64_t valh = (uint64_t )val <<32 ; -uint64_t mask =MSTATUS_MPV |MSTATUS_GVA ; +uint64_t mask =riscv_has_ext (env,RVH ) ?MSTATUS_MPV |MSTATUS_GVA :0 ; env->mstatus = (env->mstatus & ~mask) | (valh & mask);
Signature · 1 line
2.25.1
PATCH v2 3/3 target/riscv: Remove redundant assignment to SXL
In reply to Weiwei LiSXL is initialized as env->misa_mxl which is also the mxl value. So we can just remain it unchanged to keep it read-only.
--- target/riscv/csr.c | 4 ---- 1 file changed, 4 deletions(-)
target/riscv/csr.c +0 -4
@@ -1321,10 +1321,6 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, mstatus = (mstatus & ~mask) | (val & mask); -if (xl >MXL_RV32 ) { -/* SXL field is for now read only */ - mstatus =set_field (mstatus,MSTATUS64_SXL , xl); - } env->mstatus = mstatus;/*
Signature · 1 line
2.25.1
Alistair Francis
AppliedQuoted 6 lines · Weiwei Li
This patchset tries to fix some problems in the fields of mstatus, such as make MPV only work when MPP != PRM.
The port is available here:
https://github.com/plctlab/plct-qemu/tree/plct-mpv-upstream-v2
Quoted 8 lines
v2:
* Drop patch 3 (remove check on mode M for MPRV)
* rebase on apply-to-riscv.nextWeiwei Li (3):
target/riscv: Make MPV only work when MPP !=PRV_Mtarget/riscv: Support MSTATUS.MPV/GVA only when RVH is enabled target/riscv: Remove redundant assignment to SXL
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 10 lines
target/riscv/cpu_helper.c | 3 ++- target/riscv/csr.c | 14 ++++---------- target/riscv/op_helper.c | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-)--
2.25.1