trampin -> uservec

trampout -> userret
This commit is contained in:
Robert Morris 2019-07-26 04:53:46 -04:00
parent 4e62de64cd
commit ea95a6654c
6 changed files with 18 additions and 17 deletions

View file

@ -12,7 +12,7 @@ SECTIONS
{
*(.text)
. = ALIGN(0x1000);
*(trampoline)
*(trampsec)
}
. = ALIGN(0x1000);

View file

@ -18,7 +18,7 @@ struct spinlock pid_lock;
extern void forkret(void);
static void wakeup1(struct proc *chan);
extern char trampout[]; // trampoline.S
extern char trampoline[]; // trampoline.S
void
procinit(void)
@ -159,7 +159,7 @@ proc_pagetable(struct proc *p)
// only the supervisor uses it, on the way
// to/from user space, so not PTE_U.
mappages(pagetable, TRAMPOLINE, PGSIZE,
(uint64)trampout, PTE_R | PTE_X);
(uint64)trampoline, PTE_R | PTE_X);
// map the trapframe just below TRAMPOLINE, for trampoline.S.
mappages(pagetable, TRAPFRAME, PGSIZE,

View file

@ -32,10 +32,10 @@ extern struct cpu cpus[NCPU];
// sits in a page by itself just under the trampoline page in the
// user page table. not specially mapped in the kernel page table.
// the sscratch register points here.
// trampin in trampoline.S saves user registers in the trapframe,
// uservec in trampoline.S saves user registers in the trapframe,
// then initializes registers from the trapframe's
// kernel_sp, kernel_hartid, kernel_satp, and jumps to kernel_trap.
// usertrapret() and trampout in trampoline.S set up
// usertrapret() and userret in trampoline.S set up
// the trapframe's kernel_*, restore user registers from the
// trapframe, switch to the user page table, and enter user space.
// the trapframe includes callee-saved user registers like s0-s11 because the

View file

@ -5,14 +5,15 @@
# in user and kernel space so that it continues
# to work when it switches page tables.
#
# kernel.ld causes trampout to be aligned
# kernel.ld causes userret to be aligned
# to a page boundary.
#
.globl usertrap
.section trampoline
.globl trampout
trampout:
# trampout(trapframe, pagetable)
.section trampsec
.globl trampoline
trampoline:
.globl userret
userret:
# userret(trapframe, pagetable)
# switch from kernel to user.
# usertrapret() calls here.
# a0: p->tf in user page table
@ -67,8 +68,8 @@ trampout:
sret
.align 4
.globl trampin
trampin:
.globl uservec
uservec:
#
# trap.c set stvec to point here, so
# user interrupts and exceptions start here,

View file

@ -9,7 +9,7 @@
struct spinlock tickslock;
uint ticks;
extern char trampout[], trampin[];
extern char trampoline[], uservec[];
// in kernelvec.S, calls kerneltrap().
void kernelvec();
@ -96,7 +96,7 @@ usertrapret(void)
intr_off();
// send interrupts and exceptions to trampoline.S
w_stvec(TRAMPOLINE + (trampin - trampout));
w_stvec(TRAMPOLINE + (uservec - trampoline));
// set up values that trampoline.S will need when
// the process next re-enters the kernel.

View file

@ -13,7 +13,7 @@ pagetable_t kernel_pagetable;
extern char etext[]; // kernel.ld sets this to end of kernel code.
extern char trampout[]; // trampoline.S
extern char trampoline[]; // trampoline.S
/*
* create a direct-map page table for the kernel and
@ -46,7 +46,7 @@ kvminit()
// map the trampoline for trap entry/exit to
// the highest virtual address in the kernel.
kvmmap(TRAMPOLINE, (uint64)trampout, PGSIZE, PTE_R | PTE_X);
kvmmap(TRAMPOLINE, (uint64)trampoline, PGSIZE, PTE_R | PTE_X);
}
// Switch h/w page table register to the kernel's page table,