-
Notifications
You must be signed in to change notification settings - Fork 175
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
Added the flag to disable the illegal instruction exception for undefined CSRs #696
base: master
Are you sure you want to change the base?
Conversation
Uh, no? My copy of the privileged spec very clearly reads:
So it sounds like you have an implementation that's added a non-conforming custom extension (or whatever the current wording is for "tramples on encodings reserved for standard extensions") which defines every CSR encoding it doesn't implement as |
That was changed to this in recent specs (including the latest ratified one):
So I think we do need this flag. |
(or at least, it isn't wrong, and probably implementations will behave like this) |
Ok, but treating it as a NOP rather than a read-zero-write-ignore register is probably wrong and likely to cause issues. Also I know BBL and OpenSBI rely on detecting the number of PMP regions by the fact that unimplemented CSRs trap. So I'm not sure this is a good idea to be doing... |
(Ditto a few other CSRs; see csr_read_allowed and csr_write_allowed in OpenSBI) |
According to the unpriv spec decoding a reserved instruction is explictly 'UNSPECIFIED behaviour'. Should we really be doing anything other than raising an error that says you are now outside the bounds of what the spec says? (and therefore if you want explicit behaviour, you need to implement a custom extension that defines it). |
Ah yes I agree - I haven't actually read the code yet and assumed it was using read-only zero.
I think we should try and support common configurations. I have thought about having a mode where the model raises an error if it encounters any unspecified/reserved behaviour (technically spec compliant, if you take it to nasal dragons extremes), but I bet real software invokes UB all the time. Could be useful for testing software though. However... I don't know if this actually is a common configuration. @maria-rehman did you write this because you are working with a real implementation that doesn't trap? |
If the CSRs (Control and Status Registers) are not defined by the RISC-V ISA and are also not implemented, their behavior on access can vary, it’s implementation-dependent. Some systems may raise an illegal instruction exception, while others might not.
To handle this variability, I’ve added a new flag, disable_trap_undef_csr, to the Sail tool. When this flag is enabled, the tool will not generate an exception for undefined or unimplemented CSR accesses. However, if the flag is not set, the tool will generate an illegal instruction exception for such accesses.