Message ID | 20241017145226.365825-8-cleger@rivosinc.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | target/riscv: Add support for Smdbltrp and Ssdbltrp extensions | expand |
On Fri, Oct 18, 2024 at 12:54 AM Clément Léger <cleger@rivosinc.com> wrote: > > When the Ssdbltrp extension is enabled, SSTATUS.MDT field is cleared > when executing sret if executed in M-mode. When executing mret/mnret, > SSTATUS.MDT is cleared. > > Signed-off-by: Clément Léger <cleger@rivosinc.com> > --- > target/riscv/op_helper.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c > index dabc74de39..64c5792af8 100644 > --- a/target/riscv/op_helper.c > +++ b/target/riscv/op_helper.c > @@ -299,6 +299,9 @@ target_ulong helper_sret(CPURISCVState *env) > } > mstatus = set_field(mstatus, MSTATUS_SDT, 0); > } > + if (riscv_cpu_cfg(env)->ext_smdbltrp && env->priv >= PRV_M) { > + mstatus = set_field(mstatus, MSTATUS_MDT, 0); > + } > if (env->priv_ver >= PRIV_VERSION_1_12_0) { > mstatus = set_field(mstatus, MSTATUS_MPRV, 0); > } > @@ -375,6 +378,9 @@ target_ulong helper_mret(CPURISCVState *env) > if (riscv_cpu_cfg(env)->ext_ssdbltrp) { > mstatus = ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt); > } > + if (riscv_cpu_cfg(env)->ext_smdbltrp) { > + mstatus = set_field(mstatus, MSTATUS_MDT, 0); > + } > if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) { > mstatus = set_field(mstatus, MSTATUS_MPRV, 0); > } > @@ -412,6 +418,12 @@ target_ulong helper_mnret(CPURISCVState *env) > env->mstatus = ssdbltrp_mxret(env, env->mstatus, prev_priv, prev_virt); > } > > + if (riscv_cpu_cfg(env)->ext_smdbltrp) { > + if (prev_priv < PRV_M) { > + env->mstatus = set_field(env->mstatus, MSTATUS_MDT, false); 0 instead of false, otherwise Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Alistair > + } > + } > + > if (riscv_has_ext(env, RVH) && prev_virt) { > riscv_cpu_swap_hypervisor_regs(env); > } > -- > 2.45.2 > >
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index dabc74de39..64c5792af8 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -299,6 +299,9 @@ target_ulong helper_sret(CPURISCVState *env) } mstatus = set_field(mstatus, MSTATUS_SDT, 0); } + if (riscv_cpu_cfg(env)->ext_smdbltrp && env->priv >= PRV_M) { + mstatus = set_field(mstatus, MSTATUS_MDT, 0); + } if (env->priv_ver >= PRIV_VERSION_1_12_0) { mstatus = set_field(mstatus, MSTATUS_MPRV, 0); } @@ -375,6 +378,9 @@ target_ulong helper_mret(CPURISCVState *env) if (riscv_cpu_cfg(env)->ext_ssdbltrp) { mstatus = ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt); } + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + mstatus = set_field(mstatus, MSTATUS_MDT, 0); + } if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) { mstatus = set_field(mstatus, MSTATUS_MPRV, 0); } @@ -412,6 +418,12 @@ target_ulong helper_mnret(CPURISCVState *env) env->mstatus = ssdbltrp_mxret(env, env->mstatus, prev_priv, prev_virt); } + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + if (prev_priv < PRV_M) { + env->mstatus = set_field(env->mstatus, MSTATUS_MDT, false); + } + } + if (riscv_has_ext(env, RVH) && prev_virt) { riscv_cpu_swap_hypervisor_regs(env); }
When the Ssdbltrp extension is enabled, SSTATUS.MDT field is cleared when executing sret if executed in M-mode. When executing mret/mnret, SSTATUS.MDT is cleared. Signed-off-by: Clément Léger <cleger@rivosinc.com> --- target/riscv/op_helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)