Trampoline assembly documentation

This commit is contained in:
Imbus 2024-08-07 14:25:27 +02:00
parent 530d8c0fe4
commit 80a3465ebd

View file

@ -31,13 +31,16 @@ uservec:
# save user a0 in sscratch so # save user a0 in sscratch so
# a0 can be used to get at TRAPFRAME. # a0 can be used to get at TRAPFRAME.
csrw sscratch, a0 # CSRW = Control and Status Register Write
csrw sscratch, a0 # Save the userspace a0 in sscratch
# each process has a separate p->trapframe memory area, # each process has a separate p->trapframe memory area,
# but it's mapped to the same virtual address # but it's mapped to the same virtual address
# (TRAPFRAME) in every process's user page table. # (TRAPFRAME) in every process's user page table.
li a0, TRAPFRAME li a0, TRAPFRAME
# INFO: To see the layout of TRAPFRAME, see: proc.h
# save the user registers in TRAPFRAME # save the user registers in TRAPFRAME
sd ra, 40(a0) sd ra, 40(a0)
sd sp, 48(a0) sd sp, 48(a0)
@ -48,6 +51,7 @@ uservec:
sd t2, 88(a0) sd t2, 88(a0)
sd s0, 96(a0) sd s0, 96(a0)
sd s1, 104(a0) sd s1, 104(a0)
// Note that we dont save a0
sd a1, 120(a0) sd a1, 120(a0)
sd a2, 128(a0) sd a2, 128(a0)
sd a3, 136(a0) sd a3, 136(a0)
@ -71,8 +75,9 @@ uservec:
sd t6, 280(a0) sd t6, 280(a0)
# save the user a0 in p->trapframe->a0 # save the user a0 in p->trapframe->a0
csrr t0, sscratch # CSRR = Control and Status Register Read
sd t0, 112(a0) csrr t0, sscratch # Get the userspace a0 from where we stored it before
sd t0, 112(a0) # Store userspace a0 in p->trapframe->a0
# initialize kernel stack pointer, from p->trapframe->kernel_sp # initialize kernel stack pointer, from p->trapframe->kernel_sp
ld sp, 8(a0) ld sp, 8(a0)
@ -83,7 +88,6 @@ uservec:
# load the address of usertrap(), from p->trapframe->kernel_trap # load the address of usertrap(), from p->trapframe->kernel_trap
ld t0, 16(a0) ld t0, 16(a0)
# fetch the kernel page table address, from p->trapframe->kernel_satp. # fetch the kernel page table address, from p->trapframe->kernel_satp.
ld t1, 0(a0) ld t1, 0(a0)
@ -94,7 +98,7 @@ uservec:
# install the kernel page table. # install the kernel page table.
csrw satp, t1 csrw satp, t1
# flush now-stale user entries from the TLB. # flush now-stale user entries from the TLB (Translation Lookaside Buffer)
sfence.vma zero, zero sfence.vma zero, zero
# jump to usertrap(), which does not return # jump to usertrap(), which does not return