From 6b379e4707d693bb383f51647f66ec5471d26979 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Mon, 22 Jul 2019 14:54:40 -0400 Subject: [PATCH] -MD and TRAPFRAME --- Makefile | 4 ++-- kernel/memlayout.h | 13 ++++++++++++- kernel/proc.c | 6 +++--- kernel/proc.h | 6 ------ kernel/trampoline.S | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 03befd7..f98f03a 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,8 @@ LD = $(TOOLPREFIX)ld OBJCOPY = $(TOOLPREFIX)objcopy OBJDUMP = $(TOOLPREFIX)objdump -# CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -O CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb +CFLAGS += -MD CFLAGS += -mcmodel=medany CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax CFLAGS += -I. @@ -133,7 +133,7 @@ UPROGS=\ fs.img: mkfs/mkfs README $(UPROGS) mkfs/mkfs fs.img README $(UPROGS) --include *.d +-include kernel/*.d user/*.d clean: rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ diff --git a/kernel/memlayout.h b/kernel/memlayout.h index ef5c1e1..c15e398 100644 --- a/kernel/memlayout.h +++ b/kernel/memlayout.h @@ -53,4 +53,15 @@ // map the trampoline page to the highest address, // in both user and kernel space. #define TRAMPOLINE (MAXVA - PGSIZE) -#define KSTACK(p) (TRAMPOLINE - (p+1)* 2*PGSIZE) +#define KSTACK(p) (TRAMPOLINE - ((p)+1)* 2*PGSIZE) + +// User memory layout. +// Address zero first: +// text +// original data and bss +// fixed-size stack +// expandable heap +// ... +// TRAPFRAME (p->tf, used by the trampoline) +// TRAMPOLINE (the same page as in the kernel) +#define TRAPFRAME (TRAMPOLINE - PGSIZE) diff --git a/kernel/proc.c b/kernel/proc.c index b9babed..d10c952 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -156,8 +156,8 @@ proc_pagetable(struct proc *p) mappages(pagetable, TRAMPOLINE, PGSIZE, (uint64)trampout, PTE_R | PTE_X); - // map the trapframe, for trampoline.S. - mappages(pagetable, (TRAMPOLINE - PGSIZE), PGSIZE, + // map the trapframe just below TRAMPOLINE, for trampoline.S. + mappages(pagetable, TRAPFRAME, PGSIZE, (uint64)(p->tf), PTE_R | PTE_W); return pagetable; @@ -169,7 +169,7 @@ void proc_freepagetable(pagetable_t pagetable, uint64 sz) { unmappages(pagetable, TRAMPOLINE, PGSIZE, 0); - unmappages(pagetable, TRAMPOLINE-PGSIZE, PGSIZE, 0); + unmappages(pagetable, TRAPFRAME, PGSIZE, 0); if(sz > 0) uvmfree(pagetable, sz); } diff --git a/kernel/proc.h b/kernel/proc.h index 1524c74..8f94d30 100644 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -105,9 +105,3 @@ struct proc { struct inode *cwd; // Current directory char name[16]; // Process name (debugging) }; - -// Process memory is laid out contiguously, low addresses first: -// text -// original data and bss -// fixed-size stack -// expandable heap diff --git a/kernel/trampoline.S b/kernel/trampoline.S index 471a29c..1924de2 100644 --- a/kernel/trampoline.S +++ b/kernel/trampoline.S @@ -75,7 +75,7 @@ trampin: # user page table. # # sscratch points to where the process's p->tf is - # mapped into user space (TRAMPOLINE - 4096). + # mapped into user space, at TRAPFRAME. # # swap a0 and sscratch