xv6-65oo2/kernel/kernelvec.S

125 lines
2.9 KiB
ArmAsm
Raw Permalink Normal View History

2022-08-09 18:17:46 +00:00
#
2019-06-06 09:19:35 +00:00
# interrupts and exceptions while in supervisor
# mode come here.
#
2022-08-09 18:17:46 +00:00
# the current stack is a kernel stack.
# push all registers, call kerneltrap().
# when kerneltrap() returns, restore registers, return.
2019-06-06 09:19:35 +00:00
#
.globl kerneltrap
.globl kernelvec
.align 4
kernelvec:
2022-08-09 18:17:46 +00:00
# make room to save registers.
2019-06-06 09:19:35 +00:00
addi sp, sp, -256
2022-08-09 18:17:46 +00:00
# save the registers.
2019-06-06 09:19:35 +00:00
sd ra, 0(sp)
sd sp, 8(sp)
sd gp, 16(sp)
sd tp, 24(sp)
sd t0, 32(sp)
sd t1, 40(sp)
sd t2, 48(sp)
sd s0, 56(sp)
sd s1, 64(sp)
sd a0, 72(sp)
sd a1, 80(sp)
sd a2, 88(sp)
sd a3, 96(sp)
sd a4, 104(sp)
sd a5, 112(sp)
sd a6, 120(sp)
sd a7, 128(sp)
sd s2, 136(sp)
sd s3, 144(sp)
sd s4, 152(sp)
sd s5, 160(sp)
sd s6, 168(sp)
sd s7, 176(sp)
sd s8, 184(sp)
sd s9, 192(sp)
sd s10, 200(sp)
sd s11, 208(sp)
sd t3, 216(sp)
sd t4, 224(sp)
sd t5, 232(sp)
sd t6, 240(sp)
2022-08-09 18:17:46 +00:00
# call the C trap handler in trap.c
2019-06-06 09:19:35 +00:00
call kerneltrap
2022-08-09 18:17:46 +00:00
# restore registers.
2019-06-06 09:19:35 +00:00
ld ra, 0(sp)
ld sp, 8(sp)
ld gp, 16(sp)
2022-08-09 18:17:46 +00:00
# not tp (contains hartid), in case we moved CPUs
2019-06-06 09:19:35 +00:00
ld t0, 32(sp)
ld t1, 40(sp)
ld t2, 48(sp)
ld s0, 56(sp)
ld s1, 64(sp)
ld a0, 72(sp)
ld a1, 80(sp)
ld a2, 88(sp)
ld a3, 96(sp)
ld a4, 104(sp)
ld a5, 112(sp)
ld a6, 120(sp)
ld a7, 128(sp)
ld s2, 136(sp)
ld s3, 144(sp)
ld s4, 152(sp)
ld s5, 160(sp)
ld s6, 168(sp)
ld s7, 176(sp)
ld s8, 184(sp)
ld s9, 192(sp)
ld s10, 200(sp)
ld s11, 208(sp)
ld t3, 216(sp)
ld t4, 224(sp)
ld t5, 232(sp)
ld t6, 240(sp)
addi sp, sp, 256
2022-08-09 18:17:46 +00:00
# return to whatever we were doing in the kernel.
2019-06-06 09:19:35 +00:00
sret
#
# machine-mode timer interrupt.
#
2019-07-26 14:17:02 +00:00
.globl timervec
2019-06-06 09:19:35 +00:00
.align 4
2019-07-26 14:17:02 +00:00
timervec:
2019-07-25 09:35:03 +00:00
# start.c has set up the memory that mscratch points to:
# scratch[0,8,16] : register save area.
# scratch[24] : address of CLINT's MTIMECMP register.
# scratch[32] : desired interval between interrupts.
2019-07-25 09:35:03 +00:00
2019-06-06 09:19:35 +00:00
csrrw a0, mscratch, a0
sd a1, 0(a0)
sd a2, 8(a0)
sd a3, 16(a0)
2019-07-26 15:09:54 +00:00
# schedule the next timer interrupt
# by adding interval to mtimecmp.
ld a1, 24(a0) # CLINT_MTIMECMP(hart)
ld a2, 32(a0) # interval
2019-06-06 09:19:35 +00:00
ld a3, 0(a1)
add a3, a3, a2
sd a3, 0(a1)
2022-08-09 18:17:46 +00:00
# arrange for a supervisor software interrupt
# after this handler returns.
li a1, 2
2019-06-06 09:19:35 +00:00
csrw sip, a1
ld a3, 16(a0)
ld a2, 8(a0)
ld a1, 0(a0)
csrrw a0, mscratch, a0
mret