Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify handling of mstatush #639

Open
Timmmm opened this issue Dec 10, 2024 · 1 comment
Open

Simplify handling of mstatush #639

Timmmm opened this issue Dec 10, 2024 · 1 comment
Labels
refactor Code clean up

Comments

@Timmmm
Copy link
Collaborator

Timmmm commented Dec 10, 2024

mstatush is not really handled correctly at the moment. The Mstatus type is:


bitfield Mstatus : xlenbits = {
  SD   : xlen - 1,

  // The MBE and SBE fields are in mstatus in RV64 and absent in RV32.
  // On RV32, they are in mstatush, which doesn't exist in RV64.  For now,
  // they are handled in an ad-hoc way.
  // MBE  : 37
  // SBE  : 36

  // The SXL and UXL fields don't exist on RV32, so they are modelled
  // via explicit getters and setters; see below.
  // SXL  : 35 .. 34,
  // UXL  : 33 .. 32,

  TSR  : 22,
...
  SIE  : 1,
}

register mstatus : Mstatus

There is an mstatush register:

bitfield Mstatush : bits(32) = {
  MBE  : 5,
  SBE  : 4
}
register mstatush : Mstatush

But it is never modified and we ignore writes to mstatush (because the model doesn't support big endian.

This is quite awkward. For other 64-bit registers, e.g. menvcfg the h version is just a view into the top 32 bits of the 64-bit value (search for Upper 32 bits of in the priv spec and you see a load of these). That is easy to handle because we just have a single bitfield Menvcfg : bits(64) and then read/write the relevant parts in the CSR access functions.

However mstatus is very annoyingly not quite like that because the SD bit is always at xlen - 1. It is in a different position on RV32 and RV64.

The best solution I can think of is this:

bitfield Mstatus : bits(64) = {
  SD_64   : 63, // SD bit for RV64.

  MBE  : 37
  SBE  : 36

  SXL  : 35 .. 34,
  UXL  : 33 .. 32,

  SD_32 : 31, // SD bit for RV32.

  TSR  : 22,
...
  SIE  : 1,
}

And then you have to do something like:

let sd = mstatus[if xlen == 32 then SD_32 else SD_64];

We can put that in a function.

I think that is better than the current situation, and it would remove the need to have getters/setters for MBE/SBE/SXL/UXL.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Dec 10, 2024

For reference, here are the latest fields for the registers.

It is only SD that moves, and SXL/UXL don't exist for RV32. The other fields are the same for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code clean up
Projects
None yet
Development

No branches or pull requests

1 participant