]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/squidboy.c
kernel: change active.machs from bitmap to char array to support up to 64 cpus on...
[plan9front.git] / sys / src / 9 / pc / squidboy.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "io.h"
7 #include "ureg.h"
8
9 #include "mp.h"
10
11 static void
12 squidboy(Apic* apic)
13 {
14 //      iprint("Hello Squidboy\n");
15
16         machinit();
17         mmuinit();
18
19         cpuidentify();
20         cpuidprint();
21
22         apic->online = 1;
23         coherence();
24
25         lapicinit(apic);
26         lapiconline();
27         syncclock();
28         timersinit();
29
30         fpoff();
31
32         lock(&active);
33         active.machs[m->machno] = 1;
34         unlock(&active);
35
36         while(!active.thunderbirdsarego)
37                 microdelay(100);
38
39         schedinit();
40 }
41
42 void
43 mpstartap(Apic* apic)
44 {
45         ulong *apbootp, *pdb, *pte;
46         Mach *mach, *mach0;
47         int i, machno;
48         uchar *p;
49
50         mach0 = MACHP(0);
51
52         /*
53          * Initialise the AP page-tables and Mach structure. The page-tables
54          * are the same as for the bootstrap processor with the exception of
55          * the PTE for the Mach structure.
56          * Xspanalloc will panic if an allocation can't be made.
57          */
58         p = xspanalloc(4*BY2PG, BY2PG, 0);
59         pdb = (ulong*)p;
60         memmove(pdb, mach0->pdb, BY2PG);
61         p += BY2PG;
62
63         if((pte = mmuwalk(pdb, MACHADDR, 1, 0)) == nil)
64                 return;
65         memmove(p, KADDR(PPN(*pte)), BY2PG);
66         *pte = PADDR(p)|PTEWRITE|PTEVALID;
67         if(mach0->havepge)
68                 *pte |= PTEGLOBAL;
69         p += BY2PG;
70
71         mach = (Mach*)p;
72         if((pte = mmuwalk(pdb, MACHADDR, 2, 0)) == nil)
73                 return;
74         *pte = PADDR(mach)|PTEWRITE|PTEVALID;
75         if(mach0->havepge)
76                 *pte |= PTEGLOBAL;
77         p += BY2PG;
78
79         machno = apic->machno;
80         MACHP(machno) = mach;
81         mach->machno = machno;
82         mach->pdb = pdb;
83         mach->gdt = (Segdesc*)p;        /* filled by mmuinit */
84
85         /*
86          * Tell the AP where its kernel vector and pdb are.
87          * The offsets are known in the AP bootstrap code.
88          */
89         apbootp = (ulong*)(APBOOTSTRAP+0x08);
90         *apbootp++ = (ulong)squidboy;   /* assembler jumps here eventually */
91         *apbootp++ = PADDR(pdb);
92         *apbootp = (ulong)apic;
93
94         /*
95          * Universal Startup Algorithm.
96          */
97         p = KADDR(0x467);               /* warm-reset vector */
98         *p++ = PADDR(APBOOTSTRAP);
99         *p++ = PADDR(APBOOTSTRAP)>>8;
100         i = (PADDR(APBOOTSTRAP) & ~0xFFFF)/16;
101         /* code assumes i==0 */
102         if(i != 0)
103                 print("mp: bad APBOOTSTRAP\n");
104         *p++ = i;
105         *p = i>>8;
106         coherence();
107
108         nvramwrite(0x0F, 0x0A);         /* shutdown code: warm reset upon init ipi */
109         lapicstartap(apic, PADDR(APBOOTSTRAP));
110         for(i = 0; i < 1000; i++){
111                 if(apic->online)
112                         break;
113                 delay(10);
114         }
115         nvramwrite(0x0F, 0x00);
116 }