fix(csr, exception): divide the excep raised from csrrw into 2 stages #739
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this, we assumed that all possible exceptions during CSR read and write operations should be handled according to their priority.
Therefore, we used
has_vi
to record whether a virtual instruction exception exists and ensured that all illegal instruction exceptions take precedence over virtual instruction exceptions.However, with the implementation of certain extensions like Smcsrind and Smstateen, we encounter scenarios where virtual instruction exceptions must take precedence over illegal instruction exceptions triggered.
For instance, when mstateen0.csrind is set to 1 and hstateen0.csrind is 0, a virtual instruction exception should be raised if VS mode attempts to access sireg. However, if the vsiselect value is reserved in this situation, an illegal instruction exception will be raised instead. If these checks are treated as being at the same priority level, an illegal instruction exception would ultimately be raised.
In reality, a virtual instruction exception should take precedence because when the extension is disabled, we should not even evaluate the value of vsiselect.
We should first check whether the CSR exists, is read-only, has proper permissions, and is enabled/disabled before proceeding to check indirect CSR accesses.