diff options
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 34 |
1 files changed, 16 insertions, 18 deletions
@@ -6,6 +6,7 @@ #include "x86.h" #include "proc.h" #include "spinlock.h" +#include "msr.h" struct { struct spinlock lock; @@ -16,7 +17,7 @@ static struct proc *initproc; int nextpid = 1; extern void forkret(void); -extern void trapret(void); +extern void sysexit(void); static void wakeup1(void *chan); @@ -104,13 +105,13 @@ found: // Set up new context to start executing at forkret, // which returns to trapret. - sp -= 4; - *(uint*)sp = (uint)trapret; + sp -= sizeof(uint64); + *(uint64*)sp = (uint64)sysexit; sp -= sizeof *p->context; p->context = (struct context*)sp; memset(p->context, 0, sizeof *p->context); - p->context->eip = (uint)forkret; + p->context->eip = (uint64)forkret; return p; } @@ -128,16 +129,12 @@ userinit(void) initproc = p; if((p->pgdir = setupkvm()) == 0) panic("userinit: out of memory?"); - inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size); + inituvm(p->pgdir, _binary_initcode_start, (uint64)_binary_initcode_size); p->sz = PGSIZE; memset(p->tf, 0, sizeof(*p->tf)); - p->tf->cs = (SEG_UCODE << 3) | DPL_USER; - p->tf->ds = (SEG_UDATA << 3) | DPL_USER; - p->tf->es = p->tf->ds; - p->tf->ss = p->tf->ds; - p->tf->eflags = FL_IF; - p->tf->esp = PGSIZE; - p->tf->eip = 0; // beginning of initcode.S + p->tf->r11 = FL_IF; + p->tf->rsp = PGSIZE; + p->tf->rcx = 0; // beginning of initcode.S safestrcpy(p->name, "initcode", sizeof(p->name)); p->cwd = namei("/"); @@ -201,7 +198,7 @@ fork(void) *np->tf = *curproc->tf; // Clear %eax so that fork returns 0 in the child. - np->tf->eax = 0; + np->tf->rax = 0; for(i = 0; i < NOFILE; i++) if(curproc->ofile[i]) @@ -289,8 +286,8 @@ wait(void) pid = p->pid; kfree(p->kstack); p->kstack = 0; - freevm(p->pgdir); - p->pid = 0; + freevm(p->pgdir, p->sz); + p->pid = 0; p->parent = 0; p->name[0] = 0; p->killed = 0; @@ -339,6 +336,7 @@ scheduler(void) // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. + c->proc = p; switchuvm(p); p->state = RUNNING; @@ -408,7 +406,7 @@ forkret(void) iinit(ROOTDEV); initlog(ROOTDEV); } - + // Return to "caller", actually trapret (see allocproc). } @@ -514,7 +512,7 @@ procdump(void) int i; struct proc *p; char *state; - uint pc[10]; + uint64 pc[10]; for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state == UNUSED) @@ -525,7 +523,7 @@ procdump(void) state = "???"; cprintf("%d %s %s", p->pid, state, p->name); if(p->state == SLEEPING){ - getcallerpcs((uint*)p->context->ebp+2, pc); + getcallerpcs((uint64*)p->context->ebp+2, pc); for(i=0; i<10 && pc[i] != 0; i++) cprintf(" %p", pc[i]); } |