]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/squidboy.c
ether82563: fix multicast for i210
[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         machinit();
16         mmuinit();
17         cpuidentify();
18         cpuidprint();
19         syncclock();
20         active.machs[m->machno] = 1;
21         apic->online = 1;
22         lapicinit(apic);
23         lapiconline();
24         timersinit();
25         fpoff();
26         schedinit();
27 }
28
29 void
30 mpstartap(Apic* apic)
31 {
32         ulong *apbootp, *pdb, *pte;
33         Mach *mach, *mach0;
34         int i, machno;
35         uchar *p;
36
37         mach0 = MACHP(0);
38
39         /*
40          * Initialise the AP page-tables and Mach structure. The page-tables
41          * are the same as for the bootstrap processor with the exception of
42          * the PTE for the Mach structure.
43          * Xspanalloc will panic if an allocation can't be made.
44          */
45         p = xspanalloc(4*BY2PG, BY2PG, 0);
46         pdb = (ulong*)p;
47         memmove(pdb, mach0->pdb, BY2PG);
48         p += BY2PG;
49
50         if((pte = mmuwalk(pdb, MACHADDR, 1, 0)) == nil)
51                 return;
52         memmove(p, KADDR(PPN(*pte)), BY2PG);
53         *pte = PADDR(p)|PTEWRITE|PTEVALID;
54         if(mach0->havepge)
55                 *pte |= PTEGLOBAL;
56         p += BY2PG;
57
58         mach = (Mach*)p;
59         if((pte = mmuwalk(pdb, MACHADDR, 2, 0)) == nil)
60                 return;
61         *pte = PADDR(mach)|PTEWRITE|PTEVALID;
62         if(mach0->havepge)
63                 *pte |= PTEGLOBAL;
64         p += BY2PG;
65
66         machno = apic->machno;
67         MACHP(machno) = mach;
68         mach->machno = machno;
69         mach->pdb = pdb;
70         mach->gdt = (Segdesc*)p;        /* filled by mmuinit */
71
72         /*
73          * Tell the AP where its kernel vector and pdb are.
74          * The offsets are known in the AP bootstrap code.
75          */
76         apbootp = (ulong*)(APBOOTSTRAP+0x08);
77         *apbootp++ = (ulong)squidboy;   /* assembler jumps here eventually */
78         *apbootp++ = PADDR(pdb);
79         *apbootp = (ulong)apic;
80
81         /*
82          * Universal Startup Algorithm.
83          */
84         p = KADDR(0x467);               /* warm-reset vector */
85         *p++ = PADDR(APBOOTSTRAP);
86         *p++ = PADDR(APBOOTSTRAP)>>8;
87         i = (PADDR(APBOOTSTRAP) & ~0xFFFF)/16;
88         /* code assumes i==0 */
89         if(i != 0)
90                 print("mp: bad APBOOTSTRAP\n");
91         *p++ = i;
92         *p = i>>8;
93         coherence();
94
95         nvramwrite(0x0F, 0x0A);         /* shutdown code: warm reset upon init ipi */
96         lapicstartap(apic, PADDR(APBOOTSTRAP));
97         for(i = 0; i < 100000; i++){
98                 if(arch->fastclock == tscticks)
99                         cycles(&m->tscticks);   /* for ap's syncclock(); */
100                 if(apic->online)
101                         break;
102                 delay(1);
103         }
104         nvramwrite(0x0F, 0x00);
105 }