00001 #include "types.h"
00002 #include "defs.h"
00003 #include "param.h"
00004 #include "mmu.h"
00005 #include "proc.h"
00006 #include "x86.h"
00007
00008 static void bootothers(void);
00009 static void mpmain(void) __attribute__((noreturn));
00010
00011
00012 int
00013 main(void)
00014 {
00015 mpinit();
00016 lapicinit(mpbcpu());
00017 ksegment();
00018 picinit();
00019 ioapicinit();
00020 consoleinit();
00021 uartinit();
00022 cprintf("cpus %p cpu %p\n", cpus, cpu);
00023 cprintf("\ncpu%d: starting xv6\n\n", cpu->id);
00024
00025 kinit();
00026 pinit();
00027 tvinit();
00028 binit();
00029 fileinit();
00030 iinit();
00031 ideinit();
00032 if(!ismp)
00033 timerinit();
00034 userinit();
00035 bootothers();
00036
00037
00038 mpmain();
00039 }
00040
00041
00042
00043 static void
00044 mpmain(void)
00045 {
00046 if(cpunum() != mpbcpu())
00047 lapicinit(cpunum());
00048 ksegment();
00049 cprintf("cpu%d: mpmain\n", cpu->id);
00050 idtinit();
00051 xchg(&cpu->booted, 1);
00052
00053 cprintf("cpu%d: scheduling\n", cpu->id);
00054 scheduler();
00055 }
00056
00057 static void
00058 bootothers(void)
00059 {
00060 extern uchar _binary_bootother_start[], _binary_bootother_size[];
00061 uchar *code;
00062 struct cpu *c;
00063 char *stack;
00064
00065
00066 code = (uchar*)0x7000;
00067 memmove(code, _binary_bootother_start, (uint)_binary_bootother_size);
00068
00069 for(c = cpus; c < cpus+ncpu; c++){
00070 if(c == cpus+cpunum())
00071 continue;
00072
00073
00074 stack = kalloc(KSTACKSIZE);
00075 *(void**)(code-4) = stack + KSTACKSIZE;
00076 *(void**)(code-8) = mpmain;
00077 lapicstartap(c->id, (uint)code);
00078
00079
00080 while(c->booted == 0)
00081 ;
00082 }
00083 }
00084