summaryrefslogtreecommitdiff
path: root/kernel/trampoline.S
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trampoline.S')
-rw-r--r--kernel/trampoline.S37
1 files changed, 19 insertions, 18 deletions
diff --git a/kernel/trampoline.S b/kernel/trampoline.S
index fabaaf9..2ce4886 100644
--- a/kernel/trampoline.S
+++ b/kernel/trampoline.S
@@ -8,6 +8,10 @@
# kernel.ld causes this to be aligned
# to a page boundary.
#
+
+#include "riscv.h"
+#include "memlayout.h"
+
.section trampsec
.globl trampoline
trampoline:
@@ -20,14 +24,16 @@ uservec:
# in supervisor mode, but with a
# user page table.
#
- # sscratch points to where the process's p->trapframe is
- # mapped into user space, at TRAPFRAME.
- #
-
- # swap a0 and sscratch
- # so that a0 is TRAPFRAME
- csrrw a0, sscratch, a0
+ # save user a0 in sscratch so
+ # a0 can be used to get at TRAPFRAME.
+ csrw sscratch, a0
+
+ # each process has a separate p->trapframe memory area,
+ # but it's mapped to the same virtual address
+ # (TRAPFRAME) in every process.
+ li a0, TRAPFRAME
+
# save the user registers in TRAPFRAME
sd ra, 40(a0)
sd sp, 48(a0)
@@ -86,20 +92,15 @@ uservec:
.globl userret
userret:
- # userret(TRAPFRAME, pagetable)
+ # userret(pagetable)
# switch from kernel to user.
- # usertrapret() calls here.
- # a0: TRAPFRAME, in user page table.
- # a1: user page table, for satp.
+ # a0: user page table, for satp.
# switch to the user page table.
- csrw satp, a1
+ csrw satp, a0
sfence.vma zero, zero
- # put the saved user a0 in sscratch, so we
- # can swap it with our a0 (TRAPFRAME) in the last step.
- ld t0, 112(a0)
- csrw sscratch, t0
+ li a0, TRAPFRAME
# restore all but a0 from TRAPFRAME
ld ra, 40(a0)
@@ -133,8 +134,8 @@ userret:
ld t5, 272(a0)
ld t6, 280(a0)
- # restore user a0, and save TRAPFRAME in sscratch
- csrrw a0, sscratch, a0
+ # restore user a0
+ ld a0, 112(a0)
# return to user mode and user pc.
# usertrapret() set up sstatus and sepc.