diff options
| -rw-r--r-- | target/riscv/op_helper.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 83d7023d07..be62690d52 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -319,6 +319,11 @@ target_ulong helper_sret(CPURISCVState *env) const target_ulong src_priv = env->priv; const bool src_virt = env->virt_enabled; + if ((env->virt_enabled && env->priv < PRV_S) || + (env->virt_enabled && get_field(env->hstatus, HSTATUS_VTSR))) { + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); + } + if (!(env->priv >= PRV_S)) { riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } @@ -334,10 +339,6 @@ target_ulong helper_sret(CPURISCVState *env) riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } - if (env->virt_enabled && get_field(env->hstatus, HSTATUS_VTSR)) { - riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); - } - mstatus = env->mstatus; prev_priv = get_field(mstatus, MSTATUS_SPP); mstatus = set_field(mstatus, MSTATUS_SIE, |
