Keep interrupts disabled during startup.

This commit is contained in:
rsc 2006-07-16 15:50:13 +00:00
parent ef2bd07ae4
commit b74f4b57ae
3 changed files with 32 additions and 19 deletions

43
main.c
View file

@ -11,36 +11,30 @@
#include "spinlock.h" #include "spinlock.h"
extern char edata[], end[]; extern char edata[], end[];
extern int acpu;
extern uint8_t _binary_user1_start[], _binary_user1_size[]; extern uint8_t _binary_user1_start[], _binary_user1_size[];
extern uint8_t _binary_usertests_start[], _binary_usertests_size[]; extern uint8_t _binary_usertests_start[], _binary_usertests_size[];
extern uint8_t _binary_userfs_start[], _binary_userfs_size[]; extern uint8_t _binary_userfs_start[], _binary_userfs_size[];
extern int use_console_lock; extern int use_console_lock;
struct spinlock sillylock; // hold this to keep interrupts disabled // CPU 0 starts running C code here.
int int
main() main()
{ {
int i;
struct proc *p; struct proc *p;
if (acpu) {
cprintf("an application processor\n");
idtinit(); // CPU's idt
lapic_init(cpu());
lapic_timerinit();
lapic_enableintr();
scheduler();
}
acpu = 1;
// clear BSS // clear BSS
memset(edata, 0, end - edata); memset(edata, 0, end - edata);
// Make sure interrupts stay disabled on all processors
// until each signals it is ready, by pretending to hold
// an extra lock.
for(i=0; i<NCPU; i++)
cpus[i].nlock++;
mp_init(); // collect info about this machine mp_init(); // collect info about this machine
acquire(&sillylock);
use_console_lock = 1; use_console_lock = 1;
lapic_init(mp_bcpu()); lapic_init(mp_bcpu());
@ -78,7 +72,8 @@ main()
// init disk device // init disk device
//ide_init(); //ide_init();
// become interruptable // Enable interrupts on this processor.
cpus[cpu()].nlock--;
sti(); sti();
p = copyproc(&proc[0]); p = copyproc(&proc[0]);
@ -87,13 +82,29 @@ main()
//load_icode(p, _binary_userfs_start, (unsigned) _binary_userfs_size); //load_icode(p, _binary_userfs_start, (unsigned) _binary_userfs_size);
p->state = RUNNABLE; p->state = RUNNABLE;
cprintf("loaded userfs\n"); cprintf("loaded userfs\n");
release(&sillylock);
scheduler(); scheduler();
return 0; return 0;
} }
// Additional processors start here.
int
mpmain(void)
{
cprintf("an application processor\n");
idtinit(); // CPU's idt
lapic_init(cpu());
lapic_timerinit();
lapic_enableintr();
// Enable interrupts on this processor.
cpus[cpu()].nlock--;
sti();
scheduler();
}
void void
load_icode(struct proc *p, uint8_t *binary, unsigned size) load_icode(struct proc *p, uint8_t *binary, unsigned size)
{ {

4
mp.c
View file

@ -191,6 +191,8 @@ mp_bcpu(void)
return bcpu-cpus; return bcpu-cpus;
} }
extern void mpmain(void);
void void
mp_startthem() mp_startthem()
{ {
@ -205,7 +207,7 @@ mp_startthem()
if (c == cpu()) continue; if (c == cpu()) continue;
cprintf ("starting processor %d\n", c); cprintf ("starting processor %d\n", c);
*(unsigned *)(APBOOTCODE-4) = (unsigned) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp *(unsigned *)(APBOOTCODE-4) = (unsigned) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp
*(unsigned *)(APBOOTCODE-8) = (unsigned)&main; // tell it where to jump to *(unsigned *)(APBOOTCODE-8) = (unsigned)mpmain; // tell it where to jump to
lapic_startap(cpus[c].apicid, (uint32_t) APBOOTCODE); lapic_startap(cpus[c].apicid, (uint32_t) APBOOTCODE);
} }
} }

View file

@ -10,7 +10,7 @@
// because cprintf uses them itself. // because cprintf uses them itself.
#define cprintf dont_use_cprintf #define cprintf dont_use_cprintf
extern int bootstrap; extern int use_console_lock;
int int
getcallerpc(void *v) getcallerpc(void *v)
@ -34,7 +34,7 @@ release(struct spinlock * lock)
{ {
cpuid(0, 0, 0, 0, 0); // memory barrier cpuid(0, 0, 0, 0, 0); // memory barrier
lock->locked = 0; lock->locked = 0;
if(--cpus[cpu()].nlock == 0 && !bootstrap) if(--cpus[cpu()].nlock == 0)
sti(); sti();
} }