diff options
author | rsc <rsc> | 2007-09-27 20:29:50 +0000 |
---|---|---|
committer | rsc <rsc> | 2007-09-27 20:29:50 +0000 |
commit | ce2e7515552adca3a60e349de2931112736d17bf (patch) | |
tree | 4398d7aee836b939db83afa1f0c9f8e6bb1afb1f /proc.c | |
parent | aefc13f8ba13475fa721d6da837db5e368ee1b0a (diff) | |
download | xv6-labs-ce2e7515552adca3a60e349de2931112736d17bf.tar.gz xv6-labs-ce2e7515552adca3a60e349de2931112736d17bf.tar.bz2 xv6-labs-ce2e7515552adca3a60e349de2931112736d17bf.zip |
test: store curproc at top of stack
I don't actually think this is worthwhile, but I figured
I would check it in before reverting it, so that it can
be in the revision history.
Pros:
* curproc doesn't need to turn on/off interrupts
* scheduler doesn't have to edit curproc anymore
Cons:
* it's ugly
* all the stack computation is more complicated.
* it doesn't actually simplify anything but curproc,
and even curproc is harder to follow.
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -75,7 +75,7 @@ setupsegs(struct proc *p) c = &cpus[cpu()]; c->ts.ss0 = SEG_PROCSTACK << 3; if(p) - c->ts.esp0 = (uint)(p->kstack + KSTACKSIZE); + c->ts.esp0 = (uint)(p->kstack + KSTACKTOP); else c->ts.esp0 = 0xffffffff; @@ -118,7 +118,8 @@ copyproc(struct proc *p) np->state = UNUSED; return 0; } - np->tf = (struct trapframe*)(np->kstack + KSTACKSIZE) - 1; + *(void**)(np->kstack + KSTACKTOP) = np; + np->tf = (struct trapframe*)(np->kstack + KSTACKTOP) - 1; if(p){ // Copy process state from p. np->parent = p; @@ -187,12 +188,10 @@ userinit(void) struct proc* curproc(void) { - struct proc *p; + uint esp; - pushcli(); - p = cpus[cpu()].curproc; - popcli(); - return p; + asm volatile("movl %%esp, %0" : "=a" (esp)); + return *(struct proc**)((esp & ~(KSTACKSIZE-1)) + KSTACKTOP); } //PAGEBREAK: 42 @@ -223,14 +222,12 @@ scheduler(void) // Switch to chosen process. It is the process's job // to release proc_table_lock and then reacquire it // before jumping back to us. - c->curproc = p; setupsegs(p); p->state = RUNNING; swtch(&c->context, &p->context); // Process is done running for now. // It should have changed its p->state before coming back. - c->curproc = 0; setupsegs(0); } @@ -239,7 +236,7 @@ scheduler(void) } // Enter scheduler. Must already hold proc_table_lock -// and have changed curproc[cpu()]->state. +// and have changed cp->state. void sched(void) { |