diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 57 |
1 files changed, 39 insertions, 18 deletions
@@ -6,23 +6,42 @@ #include "x86.h" static void bootothers(void); -static void mpmain(void) __attribute__((noreturn)); +static void mpmain(void); +void jkstack(void) __attribute__((noreturn)); +void mainc(void); // Bootstrap processor starts running C code here. int main(void) { - mpinit(); // collect info about this machine + mpinit(); // collect info about this machine lapicinit(mpbcpu()); - ksegment(); + ksegment(); // set up segments picinit(); // interrupt controller ioapicinit(); // another interrupt controller consoleinit(); // I/O devices & their interrupts uartinit(); // serial port -cprintf("cpus %p cpu %p\n", cpus, cpu); - cprintf("\ncpu%d: starting xv6\n\n", cpu->id); + pminit(); // discover how much memory there is + jkstack(); // call mainc() on a properly-allocated stack +} + +void +jkstack(void) +{ + char *kstack = kalloc(PGSIZE); + if (!kstack) + panic("jkstack\n"); + char *top = kstack + PGSIZE; + asm volatile("movl %0,%%esp" : : "r" (top)); + asm volatile("call mainc"); + panic("jkstack"); +} - kinit(); // physical memory allocator +void +mainc(void) +{ + cprintf("\ncpu%d: starting xv6\n\n", cpu->id); + kvmalloc(); // initialze the kernel page table pinit(); // process table tvinit(); // trap vectors binit(); // buffer cache @@ -38,20 +57,21 @@ cprintf("cpus %p cpu %p\n", cpus, cpu); mpmain(); } -// Bootstrap processor gets here after setting up the hardware. -// Additional processors start here. +// Common CPU setup code. +// Bootstrap CPU comes here from mainc(). +// Other CPUs jump here from bootother.S. static void mpmain(void) { - if(cpunum() != mpbcpu()) + if(cpunum() != mpbcpu()) { + ksegment(); lapicinit(cpunum()); - ksegment(); - cprintf("cpu%d: mpmain\n", cpu->id); - idtinit(); + } + vminit(); // turn on paging + cprintf("cpu%d: starting\n", cpu->id); + idtinit(); // load idt register xchg(&cpu->booted, 1); - - cprintf("cpu%d: scheduling\n", cpu->id); - scheduler(); + scheduler(); // start running processes } static void @@ -62,8 +82,9 @@ bootothers(void) struct cpu *c; char *stack; - // Write bootstrap code to unused memory at 0x7000. - code = (uchar*)0x7000; + // Write bootstrap code to unused memory at 0x7000. The linker has + // placed the start of bootother.S there. + code = (uchar *) 0x7000; memmove(code, _binary_bootother_start, (uint)_binary_bootother_size); for(c = cpus; c < cpus+ncpu; c++){ @@ -76,7 +97,7 @@ bootothers(void) *(void**)(code-8) = mpmain; lapicstartap(c->id, (uint)code); - // Wait for cpu to get through bootstrap. + // Wait for cpu to finish mpmain() while(c->booted == 0) ; } |