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

Add Sstc extension #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Sstc extension #570

wants to merge 1 commit into from

Conversation

Timmmm
Copy link
Collaborator

@Timmmm Timmmm commented Oct 2, 2024

This adds the stimecmp[h] CSRs. It is enabled by default.

The code is slightly unfortunately structured to handle CSRs that don't fit the standard permission checks. I added a TODO to improve it.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Oct 2, 2024

This is a rebase of #395 by @ved-rivos. The model structure has changed a bit so it required fairly extensive changes. I also added a command line flag.

model/riscv_sys_regs.sail Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Oct 2, 2024

Test Results

396 tests  ±0   396 ✅ ±0   0s ⏱️ ±0s
  4 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 81287b2. ± Comparison against base commit a78ab63.

♻️ This comment has been updated with latest results.

@Alasdair
Copy link
Collaborator

Alasdair commented Oct 2, 2024

Yes, I think having a is_csr_accessible function might be a good idea

@Timmmm
Copy link
Collaborator Author

Timmmm commented Oct 10, 2024

☝️ rebased and fixed a missing & xlen == 32 on the stimecmph CSR that was found in testing.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Oct 29, 2024

@billmcspadden-riscv any idea who we could get to review this from a spec correctness point of view?

@Timmmm
Copy link
Collaborator Author

Timmmm commented Nov 27, 2024

Rebased to handle the CSR rejigging. I had to move some code around to make the dependencies work. I also removed the platform_wfi() speed hack since it would no longer be correct with Sstc. I doubt it make much difference to speed in practice.

We've been using this code for a while now with no issues found. It seems like @jscheid-ventana was the original author of the spec - if you could take a look that would be great!

Otherwise I think we should just merge this.

function clause is_CSR_defined(0x14D) = extensionEnabled(Ext_S) & extensionEnabled(Ext_Sstc)
function clause is_CSR_defined(0x15D) = extensionEnabled(Ext_S) & extensionEnabled(Ext_Sstc) & xlen == 32

function clause read_CSR(0x14D) = stimecmp[sizeof(xlen) - 1 .. 0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we have this commit, I think this can just be xlen - 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot - updated.

function check_Stimecmp(csr : csreg, p : Privilege) -> bool = {
// Check if it is not stimecmp.
if csr != 0x14D & csr != 0x15D
then return true;
Copy link
Collaborator

@Alasdair Alasdair Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think this would look better with the then on the preceding line like:

  if csr != 0x14D & csr != 0x15D then {
    return true
  };

or maybe with the whole if as a single line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never know how to format these - where's that autoformatter? :-D

I changed it to a single line.

@Alasdair
Copy link
Collaborator

I left some minor comments, but overall I also think this can just be merged.

@@ -61,8 +70,12 @@ function check_seed_CSR (csr : csreg, p : Privilege, isWrite : bool) -> bool = {
function check_CSR(csr : csreg, p : Privilege, isWrite : bool) -> bool =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but wouldn't this be cleaner as a scattered function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one shouldn't be a scattered function because check_CSR_access() is always the same, but the other functions should be moved into is_CSR_defined(), something like this:

function check_CSR(csr : csreg, p : Privilege, isWrite : bool) -> bool =
   check_CSR_access(csrAccess(csr), csrPriv(csr), p, isWrite) & is_CSR_defined(csr, p, isWrite)

Or we could potentially leave isWrite just for the seed CSR. It's the only one that needs it and unfortunately it is actually specified that way:

Attempts to access the seed CSR using a read-only CSR-access instruction (CSRRS/CSRRC with rs1=x0 or CSRRSI/CSRRCI with uimm=0) raise an illegal instruction exception

I'll make a PR to clean this up after this one.

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with @Alasdair's comment addressed

This adds the stimecmp[h] CSRs. It is enabled by default.

The code is slightly unfortunately structured to handle CSRs that don't fit the standard permission checks. I added a TODO to improve it.

Co-authored-by: Tim Hutt <timothy.hutt@codasip.com>
@Timmmm Timmmm added the will be merged Scheduled to be merged in a few days if nobody objects label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
will be merged Scheduled to be merged in a few days if nobody objects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants