Skip to content

Commit d2e92f1

Browse files
clementlegeralistair23
authored andcommitted
target/riscv: Add Smdbltrp CSRs handling
Add `ext_smdbltrp`in RISCVCPUConfig and implement MSTATUS.MDT behavior. Also set MDT to 1 at reset according to the specification. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20250110125441.3208676-7-cleger@rivosinc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
1 parent b0edcbe commit d2e92f1

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

target/riscv/cpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
10641064
env->mstatus_hs = set_field(env->mstatus_hs,
10651065
MSTATUS64_UXL, env->misa_mxl);
10661066
}
1067+
if (riscv_cpu_cfg(env)->ext_smdbltrp) {
1068+
env->mstatus = set_field(env->mstatus, MSTATUS_MDT, 1);
1069+
}
10671070
}
10681071
env->mcause = 0;
10691072
env->miclaim = MIP_SGEIP;

target/riscv/cpu_bits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@
559559
#define MSTATUS_MPELP 0x020000000000 /* zicfilp */
560560
#define MSTATUS_GVA 0x4000000000ULL
561561
#define MSTATUS_MPV 0x8000000000ULL
562+
#define MSTATUS_MDT 0x40000000000ULL /* Smdbltrp extension */
562563

563564
#define MSTATUS64_UXL 0x0000000300000000ULL
564565
#define MSTATUS64_SXL 0x0000000C00000000ULL

target/riscv/cpu_cfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct RISCVCPUConfig {
8484
bool ext_smcsrind;
8585
bool ext_sscsrind;
8686
bool ext_ssdbltrp;
87+
bool ext_smdbltrp;
8788
bool ext_svadu;
8889
bool ext_svinval;
8990
bool ext_svnapot;

target/riscv/csr.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,13 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
19541954
}
19551955
}
19561956

1957+
if (riscv_cpu_cfg(env)->ext_smdbltrp) {
1958+
mask |= MSTATUS_MDT;
1959+
if ((val & MSTATUS_MDT) != 0) {
1960+
val &= ~MSTATUS_MIE;
1961+
}
1962+
}
1963+
19571964
if (xl != MXL_RV32 || env->debugger) {
19581965
if (riscv_has_ext(env, RVH)) {
19591966
mask |= MSTATUS_MPV | MSTATUS_GVA;
@@ -1996,6 +2003,12 @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno,
19962003
uint64_t valh = (uint64_t)val << 32;
19972004
uint64_t mask = riscv_has_ext(env, RVH) ? MSTATUS_MPV | MSTATUS_GVA : 0;
19982005

2006+
if (riscv_cpu_cfg(env)->ext_smdbltrp) {
2007+
mask |= MSTATUS_MDT;
2008+
if ((valh & MSTATUS_MDT) != 0) {
2009+
mask |= MSTATUS_MIE;
2010+
}
2011+
}
19992012
env->mstatus = (env->mstatus & ~mask) | (valh & mask);
20002013

20012014
return RISCV_EXCP_NONE;

0 commit comments

Comments
 (0)