-
Notifications
You must be signed in to change notification settings - Fork 340
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: only update mstatus.*ie bits with set_maskisr steponly #1222
Open
sobuch
wants to merge
1
commit into
riscv-collab:riscv
Choose a base branch
from
sobuch:fix_maskisr_change_unrelated_mstatus_bits
base: riscv
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'm confused by the current implementation of
riscv_interrupts_restore()
.Looking at the name I would expect it only touches certain bits of
mstatus
, but it is actually equivalent toriscv_reg_set(target, GDB_REGNO_MSTATUS, current_mstatus)
.My suggestion is to either:
mstatus
and the masking-out of irrelevant bits intoriscv_interrupts_restore()
.riscv_interrupts_restore()
withriscv_reg_set()
.I slightly prefer the first option since there is the
riscv_interrupts_disable()
function.This will introduce a change in behavior since there is a use of
riscv_interrupts_disable/restore
inriscv_run_algorithm()
, and if an algorithm clobbersmstatus
current code restores it fully, but I don't think it is the intended behavior.Note: if you decide to touch
riscv_interrupts_disable/restore()
, please make themstatic
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I didnt want to affect the code in
riscv_run_algorithm
, both to keep this minimal and because I dont have a deep enough understanding of it.Could you please elaborate on what you think the behavior should be, when restoring registers after algorithm run? Why would we not want to restore
mstatus
fully?I am quite curious about this, in the espressif fork we use a different implementation, and actually save/restore a lot more registers (all writable registers as far as I understand).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am leaning on the second option. As together with that, we could log a warning if any of the interrupt enable bits have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to what @en-sc says above, I would prefer to:
riscv_interrupt_restore()
.riscv_interrupt_restore()
, display a warning, as @MarekVCodasip prefers it.riscv_interrupt_restore()
to update only the IRQ bits, and keep the others intact.I am not concerned about
riscv_run_algorithm()
since sensible algorithms (like CRC calculation) will only clobber DPC and general-purpose registers. Restoration of DPC and GPRs is already handled insideriscv_run_algorithm()
as of now. It is IMO unlikely that someone would come up with an algorithm that would modify mstatus. And if that happened, the mstatus save & restore would need to be added intoriscv_run_algorithm()
.