simplify kernel mapping calls

This commit is contained in:
Robert Morris 2019-07-23 12:17:17 -04:00
parent 55bc96d419
commit 54178ad94d
8 changed files with 53 additions and 45 deletions

View file

@ -28,12 +28,18 @@ procinit(void)
initlock(&pid_lock, "nextpid");
for(p = proc; p < &proc[NPROC]; p++) {
initlock(&p->lock, "proc");
// Allocate a page for the kernel stack.
uint64 kstack = KSTACK((int) (p - proc));
if((p->kstack = mapkstack(kstack)) == 0) {
panic("procinit");
}
// 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));
kmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
p->kstack = va;
}
kvminithart();
}
// Must be called with interrupts disabled,
@ -113,7 +119,7 @@ found:
// which returns to user space.
memset(&p->context, 0, sizeof p->context);
p->context.ra = (uint64)forkret;
p->context.sp = (uint64)p->kstack + PGSIZE;
p->context.sp = p->kstack + PGSIZE;
return p;
}