-
Notifications
You must be signed in to change notification settings - Fork 77
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
fix 10-SystemCall trap bug #15
Open
ccckmit
wants to merge
1
commit into
master
Choose a base branch
from
trapBugFixed
base: master
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ | |
sw t3, 108(\base) | ||
sw t4, 112(\base) | ||
sw t5, 116(\base) | ||
sw t6, 120(\base) | ||
.endm | ||
|
||
.macro reg_load base | ||
|
@@ -142,12 +143,12 @@ trap_vector: | |
# save context(registers). | ||
csrrw t6, mscratch, t6 # swap t6 and mscratch | ||
reg_save t6 | ||
csrw mscratch, t6 | ||
|
||
# save mepc to context of current task | ||
csrr a0, mepc | ||
sw a0, 124(t6) | ||
sw a0, 128(t6) | ||
|
||
csrrw t6, mscratch, t6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感覺這行與 line 162 的 |
||
# call the C trap handler in trap.c | ||
csrr a0, mepc | ||
csrr a1, mcause | ||
|
@@ -158,28 +159,9 @@ trap_vector: | |
csrw mepc, a0 | ||
|
||
# load context(registers). | ||
csrr t6, mscratch | ||
csrrw t6, mscratch, t6 | ||
reg_load t6 | ||
mret | ||
|
||
# void switch_to(struct context *next); | ||
# a0: pointer to the context of the next task | ||
.globl switch_to | ||
.align 4 | ||
switch_to: | ||
# switch mscratch to point to the context of the next task | ||
csrw mscratch, a0 | ||
# set mepc to the pc of the next task | ||
lw a1, 124(a0) | ||
csrw mepc, a1 | ||
|
||
# Restore all GP registers | ||
# Use t6 to point to the context of the new task | ||
mv t6, a0 | ||
reg_load t6 | ||
|
||
# Do actual context switching. | ||
# Notice this will enable global interrupt | ||
csrrw t6, mscratch, t6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. t 開頭的暫存器都是提供暫存用的,trap_vector 結束時不換回來也沒關係。 |
||
mret | ||
|
||
.end |
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
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
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.
124(t6)
應該沒有使用到,為何要用128(t6)
呢