Skip to content

Commit f2efb6e

Browse files
clementlegeralistair23
authored andcommitted
target/riscv: Implement Smdbltrp sret, mret and mnret behavior
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> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20250110125441.3208676-8-cleger@rivosinc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
1 parent d2e92f1 commit f2efb6e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

target/riscv/op_helper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ target_ulong helper_sret(CPURISCVState *env)
306306
}
307307
mstatus = set_field(mstatus, MSTATUS_SDT, 0);
308308
}
309+
if (riscv_cpu_cfg(env)->ext_smdbltrp && env->priv >= PRV_M) {
310+
mstatus = set_field(mstatus, MSTATUS_MDT, 0);
311+
}
309312
if (env->priv_ver >= PRIV_VERSION_1_12_0) {
310313
mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
311314
}
@@ -391,6 +394,9 @@ target_ulong helper_mret(CPURISCVState *env)
391394
if (riscv_cpu_cfg(env)->ext_ssdbltrp) {
392395
mstatus = ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt);
393396
}
397+
if (riscv_cpu_cfg(env)->ext_smdbltrp) {
398+
mstatus = set_field(mstatus, MSTATUS_MDT, 0);
399+
}
394400
if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) {
395401
mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
396402
}
@@ -436,6 +442,12 @@ target_ulong helper_mnret(CPURISCVState *env)
436442
env->mstatus = ssdbltrp_mxret(env, env->mstatus, prev_priv, prev_virt);
437443
}
438444

445+
if (riscv_cpu_cfg(env)->ext_smdbltrp) {
446+
if (prev_priv < PRV_M) {
447+
env->mstatus = set_field(env->mstatus, MSTATUS_MDT, 0);
448+
}
449+
}
450+
439451
if (riscv_has_ext(env, RVH) && prev_virt) {
440452
riscv_cpu_swap_hypervisor_regs(env);
441453
}

0 commit comments

Comments
 (0)