From ba05f954f7e5f33dc74995aac425200328d2bb89 Mon Sep 17 00:00:00 2001 From: Tim Hutt Date: Thu, 21 Nov 2024 13:49:56 +0000 Subject: [PATCH] Fix mstatus legalisation of SD bit Unfortunately ded340f268e3ca46ac35e0d7ec11bec3c318c9ea subtly broke the mstatus legalisation. It needs to calculate FS/XS bits before it calculates SD as it's the OR of the others. --- model/riscv_sys_regs.sail | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/model/riscv_sys_regs.sail b/model/riscv_sys_regs.sail index 1d9ecb6c2..678e6dfb9 100644 --- a/model/riscv_sys_regs.sail +++ b/model/riscv_sys_regs.sail @@ -254,19 +254,23 @@ function legalize_mstatus(o : Mstatus, v : xlenbits) -> Mstatus = { * but only if Zfinx isn't enabled. * FIXME: This should be made a platform parameter. */ - let dirty = extStatus_of_bits(m[FS]) == Dirty | extStatus_of_bits(m[XS]) == Dirty | - extStatus_of_bits(m[VS]) == Dirty; - - /* Legalize MPP */ let m = [m with - MPP = if have_privLevel(m[MPP]) then m[MPP] else privLevel_to_bits(lowest_supported_privLevel()), + /* Legalize xPP */ + MPP = legalize_mpp(m[MPP]), + SPP = legalize_spp(m[SPP]), /* We don't have any extension context yet. */ XS = extStatus_to_bits(Off), - SD = bool_to_bits(dirty), FS = if sys_enable_zfinx() then extStatus_to_bits(Off) else m[FS], MPRV = if extensionEnabled(Ext_U) then m[MPRV] else 0b0, ]; + // Set dirty bit to OR of other status bits. + let m = [m with + SD = bool_to_bits(extStatus_of_bits(m[FS]) == Dirty | + extStatus_of_bits(m[XS]) == Dirty | + extStatus_of_bits(m[VS]) == Dirty), + ]; + /* We don't support dynamic changes to SXL and UXL. */ let m = set_mstatus_SXL(m, get_mstatus_SXL(o)); let m = set_mstatus_UXL(m, get_mstatus_UXL(o));