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 committed Nov 21, 2024
1 parent 8a2e0f5 commit ba05f95
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions model/riscv_sys_regs.sail
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit ba05f95

Please sign in to comment.