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

ch4
zhangxinyu 2 years ago
parent 8f8b06e3bf
commit 021722883d

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