Skip to content

Commit

Permalink
Fix mstatus legalisation of SD bit
Browse files Browse the repository at this point in the history
Unfortunately ded340f subtly broke the mstatus legalisation. It needs to calculate FS/XS bits before it calculates SD as it's the OR of the others.
  • Loading branch information
Timmmm authored Nov 21, 2024
1 parent 8a2e0f5 commit 7e30e2d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions model/riscv_sys_regs.sail
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,22 @@ 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
/* Legalize MPP */
MPP = if have_privLevel(m[MPP]) then m[MPP] else privLevel_to_bits(lowest_supported_privLevel()),
/* 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));
Expand Down

0 comments on commit 7e30e2d

Please sign in to comment.