From 2cf6b32d4dbc915f5d3b2d7b0e382c0ad20299be Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Thu, 5 Aug 2010 14:15:03 -0400 Subject: move jkstack to main.c replace jstack with asm()s --- main.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 78cd334..8be66e3 100644 --- a/main.c +++ b/main.c @@ -7,7 +7,8 @@ static void bootothers(void); static void mpmain(void); -void jkstack(void) __attribute__((noreturn)); +void jkstack(void) __attribute__((noreturn)); +void mainc(void); // Bootstrap processor starts running C code here. int @@ -21,13 +22,24 @@ main(void) consoleinit(); // I/O devices & their interrupts uartinit(); // serial port pminit(); // physical memory for kernel - jkstack(); // Jump to mainc on a proper-allocated kernel stack + jkstack(); // Jump to 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"); } void mainc(void) { - cprintf("cpus %p cpu %p\n", cpus, cpu); cprintf("\ncpu%d: starting xv6\n\n", cpu->id); kvmalloc(); // allocate the kernel page table pinit(); // process table @@ -52,14 +64,12 @@ mpmain(void) { if(cpunum() != mpbcpu()) { ksegment(); - cprintf("other cpu\n"); lapicinit(cpunum()); } vminit(); // Run with paging on each processor - cprintf("cpu%d: mpmain\n", cpu->id); + cprintf("cpu%d: starting\n", cpu->id); idtinit(); xchg(&cpu->booted, 1); - cprintf("cpu%d: scheduling\n", cpu->id); scheduler(); } -- cgit v1.2.3 From 1afc9d3fcaa7c5992659bb8b69f639b746dda2bc Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Thu, 5 Aug 2010 21:16:55 -0400 Subject: add some comments find out the hard way why user and kernel must have separate segment descriptors --- main.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 8be66e3..a6088cb 100644 --- a/main.c +++ b/main.c @@ -16,13 +16,13 @@ main(void) { 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 - pminit(); // physical memory for kernel - jkstack(); // Jump to mainc on a properly-allocated stack + pminit(); // discover how much memory there is + jkstack(); // call mainc() on a properly-allocated stack } void @@ -41,7 +41,7 @@ void mainc(void) { cprintf("\ncpu%d: starting xv6\n\n", cpu->id); - kvmalloc(); // allocate the kernel page table + kvmalloc(); // initialze the kernel page table pinit(); // process table tvinit(); // trap vectors binit(); // buffer cache @@ -57,8 +57,9 @@ mainc(void) 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) { @@ -66,11 +67,11 @@ mpmain(void) ksegment(); lapicinit(cpunum()); } - vminit(); // Run with paging on each processor + vminit(); // turn on paging cprintf("cpu%d: starting\n", cpu->id); - idtinit(); + idtinit(); // load idt register xchg(&cpu->booted, 1); - scheduler(); + scheduler(); // start running processes } static void @@ -85,6 +86,7 @@ bootothers(void) // 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++){ if(c == cpus+cpunum()) // We've started already. continue; @@ -95,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) ; } -- cgit v1.2.3