|
|
@ -15,18 +15,18 @@
|
|
|
|
# the kernel stack pointer. If we came from the kernel, sscratch
|
|
|
|
# the kernel stack pointer. If we came from the kernel, sscratch
|
|
|
|
# will contain 0, and we should continue on the current stack.
|
|
|
|
# will contain 0, and we should continue on the current stack.
|
|
|
|
csrrw sp, (xscratch), sp
|
|
|
|
csrrw sp, (xscratch), sp
|
|
|
|
bnez sp, _save_context
|
|
|
|
bnez sp, trap_from_user
|
|
|
|
_restore_kernel_sp:
|
|
|
|
trap_from_kernel:
|
|
|
|
csrr sp, (xscratch)
|
|
|
|
csrr sp, (xscratch)
|
|
|
|
|
|
|
|
STORE gp, 0
|
|
|
|
# sscratch = previous-sp, sp = kernel-sp
|
|
|
|
# sscratch = previous-sp, sp = kernel-sp
|
|
|
|
_save_context:
|
|
|
|
trap_from_user:
|
|
|
|
# provide room for trap frame
|
|
|
|
# provide room for trap frame
|
|
|
|
addi sp, sp, -36 * XLENB
|
|
|
|
addi sp, sp, -36 * XLENB
|
|
|
|
# save x registers except x2 (sp)
|
|
|
|
# save x registers except x2 (sp)
|
|
|
|
STORE x1, 1
|
|
|
|
STORE x1, 1
|
|
|
|
STORE x3, 3
|
|
|
|
STORE x3, 3
|
|
|
|
# tp(x4) = hartid. DON'T change.
|
|
|
|
STORE x4, 4
|
|
|
|
# STORE x4, 4
|
|
|
|
|
|
|
|
STORE x5, 5
|
|
|
|
STORE x5, 5
|
|
|
|
STORE x6, 6
|
|
|
|
STORE x6, 6
|
|
|
|
STORE x7, 7
|
|
|
|
STORE x7, 7
|
|
|
@ -55,6 +55,9 @@ _save_context:
|
|
|
|
STORE x30, 30
|
|
|
|
STORE x30, 30
|
|
|
|
STORE x31, 31
|
|
|
|
STORE x31, 31
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# load hartid to gp from sp[36]
|
|
|
|
|
|
|
|
LOAD gp, 36
|
|
|
|
|
|
|
|
|
|
|
|
# get sp, sstatus, sepc, stval, scause
|
|
|
|
# get sp, sstatus, sepc, stval, scause
|
|
|
|
# set sscratch = 0
|
|
|
|
# set sscratch = 0
|
|
|
|
csrrw s0, (xscratch), x0
|
|
|
|
csrrw s0, (xscratch), x0
|
|
|
@ -74,11 +77,12 @@ _save_context:
|
|
|
|
LOAD s1, 32 # s1 = sstatus
|
|
|
|
LOAD s1, 32 # s1 = sstatus
|
|
|
|
LOAD s2, 33 # s2 = sepc
|
|
|
|
LOAD s2, 33 # s2 = sepc
|
|
|
|
TEST_BACK_TO_KERNEL
|
|
|
|
TEST_BACK_TO_KERNEL
|
|
|
|
bnez s0, _restore_context # s0 = back to kernel?
|
|
|
|
bnez s0, _to_kernel # s0 = back to kernel?
|
|
|
|
_save_kernel_sp:
|
|
|
|
_to_user:
|
|
|
|
addi s0, sp, 36*XLENB
|
|
|
|
addi s0, sp, 36*XLENB
|
|
|
|
csrw (xscratch), s0 # sscratch = kernel-sp
|
|
|
|
csrw (xscratch), s0 # sscratch = kernel-sp
|
|
|
|
_restore_context:
|
|
|
|
STORE gp, 36 # store hartid from gp to sp[36]
|
|
|
|
|
|
|
|
_to_kernel:
|
|
|
|
# restore sstatus, sepc
|
|
|
|
# restore sstatus, sepc
|
|
|
|
csrw (xstatus), s1
|
|
|
|
csrw (xstatus), s1
|
|
|
|
csrw (xepc), s2
|
|
|
|
csrw (xepc), s2
|
|
|
@ -86,7 +90,7 @@ _restore_context:
|
|
|
|
# restore x registers except x2 (sp)
|
|
|
|
# restore x registers except x2 (sp)
|
|
|
|
LOAD x1, 1
|
|
|
|
LOAD x1, 1
|
|
|
|
LOAD x3, 3
|
|
|
|
LOAD x3, 3
|
|
|
|
# LOAD x4, 4
|
|
|
|
LOAD x4, 4
|
|
|
|
LOAD x5, 5
|
|
|
|
LOAD x5, 5
|
|
|
|
LOAD x6, 6
|
|
|
|
LOAD x6, 6
|
|
|
|
LOAD x7, 7
|
|
|
|
LOAD x7, 7
|
|
|
@ -119,13 +123,13 @@ _restore_context:
|
|
|
|
.endm
|
|
|
|
.endm
|
|
|
|
|
|
|
|
|
|
|
|
.section .text
|
|
|
|
.section .text
|
|
|
|
.globl __alltraps
|
|
|
|
.globl trap_entry
|
|
|
|
__alltraps:
|
|
|
|
trap_entry:
|
|
|
|
SAVE_ALL
|
|
|
|
SAVE_ALL
|
|
|
|
mv a0, sp
|
|
|
|
mv a0, sp
|
|
|
|
jal rust_trap
|
|
|
|
jal rust_trap
|
|
|
|
.globl __trapret
|
|
|
|
.globl trap_return
|
|
|
|
__trapret:
|
|
|
|
trap_return:
|
|
|
|
RESTORE_ALL
|
|
|
|
RESTORE_ALL
|
|
|
|
# return from supervisor call
|
|
|
|
# return from supervisor call
|
|
|
|
XRET
|
|
|
|
XRET
|
|
|
|