From 9fc9f755e1f9ec56a452b334f6112028e0ec0329 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 9 Aug 2022 11:44:02 -0400 Subject: adopt github PR98 (No need to store TRAPFRAME in sscratch register) --- kernel/trampoline.S | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'kernel/trampoline.S') 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. -- cgit v1.2.3