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

SailBugfix: Modifies only mie in write Sie when the interrupt is dele… #383

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

francois141
Copy link
Collaborator

…gated

Before modifying each specific interrupt enable bit (e.g., SEIE, STIE, or SSIE), the code checks whether the corresponding bit in Mideleg is set. Mideleg determines whether a specific interrupt is delegated to the supervisor level, so this ensures that only interrupts managed by the supervisor are updated.

@francois141 francois141 requested a review from CharlyCst January 15, 2025 15:45
@CharlyCst CharlyCst force-pushed the sailbugfix-write-sie branch from 3ac2a9a to 5dd6663 Compare January 27, 2025 13:14
@CharlyCst
Copy link
Owner

I see what you want to do here, shouldn't it simply be:

// Only delegated interrupts can be enabled through `sie`
let mideleg = self.get(Csr::Mideleg);
self.csr.mie = (self.csr.mie & !mideleg) | (mideleg & value);

where all delegated interrupts can be modified?

@francois141
Copy link
Collaborator Author

francois141 commented Jan 27, 2025

The two formulations are not equivalent. In the case mideleg is set to 0 you don't want to change the value of the bit. Therefore we need three if statements ^^

You can't beat kani ^^

@CharlyCst
Copy link
Owner

Well yes indeed, and the proposed code snipped does not change any value when mideleg is 0 as it evaluates to (self.csr.mie & u64::MAX) | (0x0 & value) = self.csr.mie, isn't that what is expected?

The reason I am asking is because the version in the PR is missing the LCOFIE bit, which is not it the Sail model but is present on the hardware, so we would need at least a 4th if to support it.

@francois141
Copy link
Collaborator Author

The problem is that if only one of the interrupt is delegated, with the previous implementation we can clear the entire mask which is wrong. Regarding lcofie, let me fix that

@francois141
Copy link
Collaborator Author

@CharlyCst Ready for review! I did the change

@CharlyCst
Copy link
Owner

Yes, I agree the previous implementation was wrong, but is:

// Only delegated interrupts can be enabled through `sie`
let mideleg = self.get(Csr::Mideleg);
self.csr.mie = (self.csr.mie & !mideleg) | (mideleg & value);

Correct? That was my question ^^

@francois141
Copy link
Collaborator Author

This also looks correct, let me test with kani

@francois141
Copy link
Collaborator Author

Works, pushed

…gated

Before modifying each specific interrupt enable bit (e.g., SEIE, STIE, or SSIE), the code checks whether the corresponding bit in Mideleg is set. Mideleg determines whether a specific interrupt is delegated to the supervisor level, so this ensures that only interrupts managed by the supervisor are updated.
@CharlyCst CharlyCst force-pushed the sailbugfix-write-sie branch from 46440cb to ea2d4a2 Compare January 28, 2025 12:13
@CharlyCst CharlyCst merged commit 95cbbe0 into main Jan 28, 2025
1 check passed
@CharlyCst CharlyCst deleted the sailbugfix-write-sie branch January 28, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants