Skip to content

Commit 2d8e825

Browse files
clementlegeralistair23
authored andcommitted
target/riscv: Add Smdbltrp ISA extension enable switch
Add the switch to enable the Smdbltrp ISA extension and disable it for the max cpu. Indeed, OpenSBI when Smdbltrp is present, M-mode double trap is enabled by default and MSTATUS.MDT needs to be cleared to avoid taking a double trap. OpenSBI does not currently support it so disable it for the max cpu to avoid breaking regression tests. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Message-ID: <20250116131539.2475785-1-cleger@rivosinc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
1 parent 00af7d5 commit 2d8e825

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

target/riscv/cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
194194
ISA_EXT_DATA_ENTRY(smcdeleg, PRIV_VERSION_1_13_0, ext_smcdeleg),
195195
ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf),
196196
ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind),
197+
ISA_EXT_DATA_ENTRY(smdbltrp, PRIV_VERSION_1_13_0, ext_smdbltrp),
197198
ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp),
198199
ISA_EXT_DATA_ENTRY(smrnmi, PRIV_VERSION_1_12_0, ext_smrnmi),
199200
ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm),
@@ -1626,6 +1627,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
16261627
MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false),
16271628

16281629
MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false),
1630+
MULTI_EXT_CFG_BOOL("smdbltrp", ext_smdbltrp, false),
16291631
MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false),
16301632
MULTI_EXT_CFG_BOOL("smrnmi", ext_smrnmi, false),
16311633
MULTI_EXT_CFG_BOOL("smmpm", ext_smmpm, false),

target/riscv/tcg/tcg-cpu.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,16 @@ static void riscv_init_max_cpu_extensions(Object *obj)
14391439
isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smrnmi), false);
14401440
qemu_log("Smrnmi is disabled in the 'max' type CPU\n");
14411441
}
1442+
1443+
/*
1444+
* ext_smdbltrp requires the firmware to clear MSTATUS.MDT on startup to
1445+
* avoid generating a double trap. OpenSBI does not currently support it,
1446+
* disable it for now.
1447+
*/
1448+
if (cpu->cfg.ext_smdbltrp) {
1449+
isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smdbltrp), false);
1450+
qemu_log("Smdbltrp is disabled in the 'max' type CPU\n");
1451+
}
14421452
}
14431453

14441454
static bool riscv_cpu_has_max_extensions(Object *cpu_obj)

0 commit comments

Comments
 (0)