修改了 陷入处理的 trap.S 汇编, 使其可以切换地址空间

ch4
zhangxinyu 2 years ago
parent 8f8b06e3bf
commit 021722883d

@ -4,19 +4,22 @@
.macro SAVE_GP n .macro SAVE_GP n
sd x\n, \n*8(sp) # x_n sd x\n, \n*8(sp) # x_n
.endm .endm
.macro LOAD_GP n .macro LOAD_GP n
ld x\n, \n*8(sp) # x_n ld x\n, \n*8(sp) # x_n
.endm .endm
.section .text # .text .section .text # .text
.globl __alltraps # __alltraps .globl __alltraps # __alltraps
.globl __restore # __restore .globl __restore # __restore
.align 2 # 2^2 = 4 .align 2 # 2^2 = 4
__alltraps: # __alltraps __alltraps: # __alltraps
csrrw sp, sscratch, sp # sp sscratch # sp sscratch
# sp sscratch # sscratch , trap context
# TrapContext # sp, sscratch, sptrap context
addi sp, sp, -34*8 # 34*8 csrrw sp, sscratch, sp
# #
sd x1, 1*8(sp) # x1 (x0, 便) sd x1, 1*8(sp) # x1 (x0, 便)
# sp(x2) # sp(x2)
@ -25,36 +28,57 @@ __alltraps: # __alltraps 符号的实现
# x5~x31 # x5~x31
.set n, 5 # n 5 .set n, 5 # n 5
.rept 27 # 27 .rept 27 # 27
SAVE_GP %n # x_n SAVE_GP %n # x_n trap context
.set n, n+1 # n 1 .set n, n+1 # n 1
.endr # .endr #
# 使 t0/t1/t2
# 使 t0/t1/t2 trap context
# CSR
csrr t0, sstatus # sstatus csrr t0, sstatus # sstatus
csrr t1, sepc # sepc csrr t1, sepc # sepc
sd t0, 32*8(sp) # sstatus sd t0, 32*8(sp) # sstatus trap context
sd t1, 33*8(sp) # sepc sd t1, 33*8(sp) # sepc trap context
# sscratch
# sscratch trap context
csrr t2, sscratch # sscratch csrr t2, sscratch # sscratch
sd t2, 2*8(sp) # trap context sd t2, 2*8(sp) # trap context
# trap_handler(cx: &mut TrapContext)
mv a0, sp # TrapContext a0 # ,
call trap_handler # trap_handler # , ,
# , KERNEL_SPACE.exclusive_access().token(), trap context
ld t0, 34*8(sp)
# jmp trap trap_handler as usize(as usize , , jmp)
ld t1, 36*8(sp)
# , sp trap context, trap context
ld sp, 35*8(sp)
#
csrw satp, t0
sfence.vma
# 使call, , , , callcall,
jr t1
__restore: # __restore __restore: # __restore
# case1: # trap_return , trap_cx_ptr(TRAP_CONTEXT), user_satp
# case2: U
#
csrw satp, a1
sfence.vma
# , switch # sscratch , trap context
# mv sp, a0 # a0 sp sp KERNEL_STACK_SIZE, csrw sscratch, a0
# trap context copysp,
mv sp, a0
# sstatus/sepc # sstatus/sepc
ld t0, 32*8(sp) # sstatus ld t0, 32*8(sp) # trap context sstatus
ld t1, 33*8(sp) # sepc ld t1, 33*8(sp) # trap context sepc
ld t2, 2*8(sp) #
csrw sstatus, t0 # sstatus csrw sstatus, t0 # sstatus
csrw sepc, t1 # sepc csrw sepc, t1 # sepc
csrw sscratch, t2 # sscratch
# sp sscratch
# sp/tp # sp/tp
# x0 # x0
@ -68,8 +92,6 @@ __restore: # __restore 符号的实现
.set n, n+1 # n 1 .set n, n+1 # n 1
.endr # .endr #
# sp sscratch , TrapContext, , # , trap context
addi sp, sp, 34*8 # sizeof<TrapContext> ld sp, 2*8(sp)
csrrw sp, sscratch, sp # sp sscratch , sscratch, sp USER_STACK()
sret # , sstatus(/) sepc(/ pc) sret # , sstatus(/) sepc(/ pc)
Loading…
Cancel
Save