You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rCore_stu/ch3-coop/os/src/trap/trap.S

73 lines
4.0 KiB
ArmAsm

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# trap__alltraps, __restore
.altmacro
.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
#
sd x1, 1*8(sp) # x1 (x0, 便)
# sp(x2)
sd x3, 3*8(sp) # x3 (x4, 便)
# tp(x4)使
# x5~x31
.set n, 5 # n 5
.rept 27 # 27
SAVE_GP %n # x_n
.set n, n+1 # n 1
.endr #
# 使 t0/t1/t2
csrr t0, sstatus # sstatus
csrr t1, sepc # sepc
sd t0, 32*8(sp) # sstatus
sd t1, 33*8(sp) # sepc
# sscratch
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
__restore: # __restore
# case1:
# case2: U
mv sp, a0 # a0 sp sp KERNEL_STACK_SIZE,
# sstatus/sepc
ld t0, 32*8(sp) # sstatus
ld t1, 33*8(sp) # sepc
ld t2, 2*8(sp) #
csrw sstatus, t0 # sstatus
csrw sepc, t1 # sepc
csrw sscratch, t2 # sscratch
# sp sscratch
# sp/tp
# x0
ld x1, 1*8(sp) # x1
# x2
ld x3, 3*8(sp) # x3
#
.set n, 5 # n 5
.rept 27 # 27
LOAD_GP %n # x_n
.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()
sret # , sstatus(/) sepc(/ pc)