diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 69 |
1 files changed, 28 insertions, 41 deletions
@@ -6,17 +6,22 @@ #include "proc.h" #include "x86.h" -static void startothers(void); -static void mpmain(void) __attribute__((noreturn)); extern pde_t *kpgdir; extern char end[]; // first address after kernel loaded from ELF file +static void main(void) __attribute__((noreturn)); +static void startothers(void); + + // Bootstrap processor starts running C code here. // Allocate a real stack and switch to it, first // doing some setup required for memory allocator to work. int -main(void) +bpmain(uint64 mbmagic, uint64 mbaddr) { + if(mbmagic != 0x2badb002) + panic("multiboot header not found"); + kinit1(end, P2V(4*1024*1024)); // phys page allocator kvmalloc(); // kernel page table mpinit(); // detect other processors @@ -30,26 +35,19 @@ main(void) tvinit(); // trap vectors binit(); // buffer cache fileinit(); // file table - ideinit(); // disk + ideinit(); // disk + startothers(); // start other processors + kinit2(P2V(4*1024*1024), P2V(PHYSTOP)); // must come after startothers() userinit(); // first user process - mpmain(); // finish this processor's setup -} - -// Other CPUs jump here from entryother.S. -static void -mpenter(void) -{ - switchkvm(); - seginit(); - lapicinit(); - mpmain(); + main(); + return 0; } // Common CPU setup code. static void -mpmain(void) +main(void) { cprintf("cpu%d: starting %d\n", cpuid(), cpuid()); idtinit(); // load idt register @@ -57,7 +55,17 @@ mpmain(void) scheduler(); // start running processes } -pde_t entrypgdir[]; // For entry.S +// Other CPUs jump here from entryother.S. +void +apmain(void) +{ + switchkvm(); + seginit(); + lapicinit(); + main(); +} + +void apstart(void); // Start the non-boot (AP) processors. static void @@ -72,7 +80,7 @@ startothers(void) // The linker has placed the image of entryother.S in // _binary_entryother_start. code = P2V(0x7000); - memmove(code, _binary_entryother_start, (uint)_binary_entryother_size); + memmove(code, _binary_entryother_start, (uint64)_binary_entryother_size); for(c = cpus; c < cpus+ncpu; c++){ if(c == mycpu()) // We've started already. @@ -82,9 +90,8 @@ startothers(void) // pgdir to use. We cannot use kpgdir yet, because the AP processor // is running in low memory, so we use entrypgdir for the APs too. stack = kalloc(); - *(void**)(code-4) = stack + KSTACKSIZE; - *(void(**)(void))(code-8) = mpenter; - *(int**)(code-12) = (void *) V2P(entrypgdir); + *(uint32*)(code-4) = V2P(apstart); + *(uint64*)(code-12) = (uint64) (stack+KSTACKSIZE); lapicstartap(c->apicid, V2P(code)); @@ -94,23 +101,3 @@ startothers(void) } } -// The boot page table used in entry.S and entryother.S. -// Page directories (and page tables) must start on page boundaries, -// hence the __aligned__ attribute. -// PTE_PS in a page directory entry enables 4Mbyte pages. - -__attribute__((__aligned__(PGSIZE))) -pde_t entrypgdir[NPDENTRIES] = { - // Map VA's [0, 4MB) to PA's [0, 4MB) - [0] = (0) | PTE_P | PTE_W | PTE_PS, - // Map VA's [KERNBASE, KERNBASE+4MB) to PA's [0, 4MB) - [KERNBASE>>PDXSHIFT] = (0) | PTE_P | PTE_W | PTE_PS, -}; - -//PAGEBREAK! -// Blank page. -//PAGEBREAK! -// Blank page. -//PAGEBREAK! -// Blank page. - |