kvmmake() makes a complete kernel page table, matching Figure 3.3

This commit is contained in:
Frans Kaashoek 2020-10-14 20:03:14 -04:00
parent 21cfc97809
commit d4cecb269f
3 changed files with 47 additions and 27 deletions

View file

@ -21,6 +21,23 @@ static void freeproc(struct proc *p);
extern char trampoline[]; // trampoline.S
// Allocate a page for each process's kernel stack.
// Map it high in memory, followed by an invalid
// guard page.
void
proc_mapstacks(pagetable_t kpgtbl) {
struct proc *p;
for(p = proc; p < &proc[NPROC]; p++) {
char *pa = kalloc();
if(pa == 0)
panic("kalloc");
uint64 va = KSTACK((int) (p - proc));
kvmmap(kpgtbl, va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
}
}
// initialize the proc table at boot time.
void
procinit(void)
@ -30,18 +47,8 @@ procinit(void)
initlock(&pid_lock, "nextpid");
for(p = proc; p < &proc[NPROC]; p++) {
initlock(&p->lock, "proc");
// Allocate a page for the process's kernel stack.
// Map it high in memory, followed by an invalid
// guard page.
char *pa = kalloc();
if(pa == 0)
panic("kalloc");
uint64 va = KSTACK((int) (p - proc));
kvmmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
p->kstack = va;
p->kstack = KSTACK((int) (p - proc));
}
kvminithart();
}
// Must be called with interrupts disabled,