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

target/riscv: dont set mcause and mstatus as cachable #1217

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

sobuch
Copy link
Contributor

@sobuch sobuch commented Jan 27, 2025

With CLIC extension (smclic), mcause and mstatus CSRs share mirrored fields for mpp and mpie. Therefore, neither can be assumed cacheable.

CLIC spec available - https://github.com/riscv/riscv-fast-interrupt

Implemented e.g. in esp32c5 or Codasip's L110

With CLIC extension (smclic), mcause and mstatus CSRs
share mirrored fields for mpp and mpie. Therefore, neither
can be assumed cachable.

Signed-off-by: Samuel Obuch <[email protected]>
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

@sobuch The change looks all right to me, thanks.

I just wanted to check I understand the situation right -

Is this the case you are trying to fix: If the debugger writes to either mstatus or mcause register, that could cause the cached value of the other register to become invalid (bogus) due to the mirrored (shared) fields between the two registers. Marking both the registers as non-cacheable avoids this. Is that correct understanding?

@en-sc It looks like an equivalent fix should be applied to your PR #1187.

@sobuch
Copy link
Contributor Author

sobuch commented Jan 29, 2025

@JanMatCodasip yes, for example after the sequence bellow, mcause is actually 0x0, but the value is not re-read when assumed cacheable:

> reg mstatus
mstatus (/32): 0x00001800
> reg mcause
mcause (/32): 0x30000000
> reg mstatus 0
mstatus (/32): 0x00000000
> reg mcause
mcause (/32): 0x30000000

@sobuch
Copy link
Contributor Author

sobuch commented Jan 29, 2025

FYI just occurred to me that since mstatus also shares fields with the other *status registers, this patch solves similar issue for targets implementing S, H, or N extensions.

Copy link
Collaborator

@en-sc en-sc left a comment

Choose a reason for hiding this comment

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

LGTM

However, I believe there needs to be a better solution. Filed #1219

@en-sc en-sc merged commit 8f59570 into riscv-collab:riscv Jan 31, 2025
4 checks passed
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.

3 participants