]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/teg2/main.c
devarch: restrict i/o port access to 64K, disallow msr 32-bit wrap arround (thanks...
[plan9front.git] / sys / src / 9 / teg2 / main.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
8 #include "init.h"
9 #include <pool.h>
10
11 #include "arm.h"
12 #include "reboot.h"
13
14 /*
15  * Where configuration info is left for the loaded programme.
16  * This will turn into a structure as more is done by the boot loader
17  * (e.g. why parse the .ini file twice?).
18  * There are 3584 bytes available at CONFADDR.
19  */
20 #define BOOTARGS        ((char*)CONFADDR)
21 #define BOOTARGSLEN     (16*KiB)                /* limit in devenv.c */
22 #define MAXCONF         64
23 #define MAXCONFLINE     160
24
25 enum {
26         Minmem  = 256*MB,                       /* conservative default */
27 };
28
29 #define isascii(c) ((uchar)(c) > 0 && (uchar)(c) < 0177)
30
31 extern char bdata[], edata[], end[], etext[];
32
33 uintptr kseg0 = KZERO;
34 Mach* machaddr[MAXMACH];
35 uchar *l2pages;
36
37 Memcache cachel[8];             /* arm arch v7 supports 1-7 */
38 /*
39  * these are used by the cache.v7.s routines.
40  */
41 Lowmemcache *cacheconf;
42
43 /*
44  * Option arguments from the command line.
45  * oargv[0] is the boot file.
46  * Optionsinit() is called from multiboot()
47  * or some other machine-dependent place
48  * to set it all up.
49  */
50 static int oargc;
51 static char* oargv[20];
52 static char oargb[128];
53 static int oargblen;
54 static char oenv[4096];
55
56 static uintptr sp;              /* XXX - must go - user stack of init proc */
57
58 int vflag;
59 int normalprint;
60 char debug[256];
61
62 static Lock testlock;
63
64 /* store plan9.ini contents here at least until we stash them in #ec */
65 static char confname[MAXCONF][KNAMELEN];
66 static char confval[MAXCONF][MAXCONFLINE];
67 static int nconf;
68
69 static int
70 findconf(char *name)
71 {
72         int i;
73
74         for(i = 0; i < nconf; i++)
75                 if(cistrcmp(confname[i], name) == 0)
76                         return i;
77         return -1;
78 }
79
80 char*
81 getconf(char *name)
82 {
83         int i;
84
85         i = findconf(name);
86         if(i >= 0)
87                 return confval[i];
88         return nil;
89 }
90
91 void
92 addconf(char *name, char *val)
93 {
94         int i;
95
96         i = findconf(name);
97         if(i < 0){
98                 if(val == nil || nconf >= MAXCONF)
99                         return;
100                 i = nconf++;
101                 strecpy(confname[i], confname[i]+sizeof(confname[i]), name);
102         }
103 //      confval[i] = val;
104         strecpy(confval[i], confval[i]+sizeof(confval[i]), val);
105 }
106
107 static void
108 writeconf(void)
109 {
110         char *p, *q;
111         int n;
112
113         p = getconfenv();
114
115         if(waserror()) {
116                 free(p);
117                 nexterror();
118         }
119
120         /* convert to name=value\n format */
121         for(q=p; *q; q++) {
122                 q += strlen(q);
123                 *q = '=';
124                 q += strlen(q);
125                 *q = '\n';
126         }
127         n = q - p + 1;
128         if(n >= BOOTARGSLEN)
129                 error("kernel configuration too large");
130         memmove(BOOTARGS, p, n);
131         memset(BOOTARGS + n, '\n', BOOTARGSLEN - n);
132         poperror();
133         free(p);
134 }
135
136 /*
137  * assumes that we have loaded our /cfg/pxe/mac file at CONFADDR
138  * (usually 0x1000) with tftp in u-boot.  no longer uses malloc, so
139  * can be called early.
140  */
141 static void
142 plan9iniinit(void)
143 {
144         char *k, *v, *next;
145
146         k = (char *)CONFADDR;
147         if(!isascii(*k))
148                 return;
149
150         for(; k && *k != '\0'; k = next) {
151                 if (!isascii(*k))               /* sanity check */
152                         break;
153                 next = strchr(k, '\n');
154                 if (next)
155                         *next++ = '\0';
156
157                 if (*k == '\0' || *k == '\n' || *k == '#')
158                         continue;
159                 v = strchr(k, '=');
160                 if(v == nil)
161                         continue;               /* mal-formed line */
162                 *v++ = '\0';
163
164                 addconf(k, v);
165         }
166 }
167
168 static void
169 optionsinit(char* s)
170 {
171         char *o;
172
173         strcpy(oenv, "");
174         o = strecpy(oargb, oargb+sizeof(oargb), s)+1;
175         if(getenv("bootargs", o, o - oargb) != nil)
176                 *(o-1) = ' ';
177
178         oargblen = strlen(oargb);
179         oargc = tokenize(oargb, oargv, nelem(oargv)-1);
180         oargv[oargc] = nil;
181 }
182
183 char*
184 getenv(char* name, char* buf, int n)
185 {
186         char *e, *p, *q;
187
188         p = oenv;
189         while(*p != 0){
190                 if((e = strchr(p, '=')) == nil)
191                         break;
192                 for(q = name; p < e; p++){
193                         if(*p != *q)
194                                 break;
195                         q++;
196                 }
197                 if(p == e && *q == 0){
198                         strecpy(buf, buf+n, e+1);
199                         return buf;
200                 }
201                 p += strlen(p)+1;
202         }
203
204         return nil;
205 }
206
207 /* enable scheduling of this cpu */
208 void
209 machon(uint cpu)
210 {
211         lock(&active);
212         if (active.machs[cpu] == 0) {   /* currently off? */
213                 active.machs[cpu] = 1;
214                 conf.nmach++;
215         }
216         unlock(&active);
217 }
218
219 /* disable scheduling of this cpu */
220 void
221 machoff(uint cpu)
222 {
223         lock(&active);
224         if (active.machs[cpu]) {                /* currently on? */
225                 active.machs[cpu] = 0;
226                 conf.nmach--;
227         }
228         unlock(&active);
229 }
230
231 void
232 machinit(void)
233 {
234         Mach *m0;
235
236         if (m == 0) {
237                 serialputc('?');
238                 serialputc('m');
239                 serialputc('0');
240         }
241         if(machaddr[m->machno] != m) {
242                 serialputc('?');
243                 serialputc('m');
244                 serialputc('m');
245         }
246
247         if (canlock(&testlock)) {
248                 serialputc('?');
249                 serialputc('l');
250                 panic("cpu%d: locks don't work", m->machno);
251         }
252
253         m->ticks = 1;
254         m->perf.period = 1;
255         m0 = MACHP(0);
256         if (m->machno != 0) {
257                 /* synchronise with cpu 0 */
258                 m->ticks = m0->ticks;
259                 m->fastclock = m0->fastclock;
260                 m->cpuhz = m0->cpuhz;
261                 m->delayloop = m0->delayloop;
262         }
263         if (m->machno != 0 &&
264             (m->fastclock == 0 || m->cpuhz == 0 || m->delayloop == 0))
265                 panic("buggered cpu 0 Mach");
266
267         machon(m->machno);
268         fpoff();
269 }
270
271 /* l.s has already zeroed Mach, which now contains our stack. */
272 void
273 mach0init(void)
274 {
275         if (m == 0) {
276                 serialputc('?');
277                 serialputc('m');
278         }
279         conf.nmach = 0;
280
281         m->machno = 0;
282         machaddr[0] = m;
283
284         lock(&testlock);                /* hold this forever */
285         machinit();
286
287         active.exiting = 0;
288         l1cache->wbse(&active, sizeof active);
289         up = nil;
290 }
291
292 /*
293  *  count CPU's, set up their mach structures and l1 ptes.
294  *  we're running on cpu 0 and our data structures were
295  *  statically allocated.
296  */
297 void
298 launchinit(void)
299 {
300         int mach;
301         Mach *mm;
302         PTE *l1;
303
304         for(mach = 1; mach < MAXMACH; mach++){
305                 machaddr[mach] = mm = mallocalign(MACHSIZE, MACHSIZE, 0, 0);
306                 l1 = mallocalign(L1SIZE, L1SIZE, 0, 0);
307                 if(mm == nil || l1 == nil)
308                         panic("launchinit");
309                 memset(mm, 0, MACHSIZE);
310                 mm->machno = mach;
311
312                 memmove(l1, (void *)L1, L1SIZE);  /* clone cpu0's l1 table */
313                 l1cache->wbse(l1, L1SIZE);
314
315                 mm->mmul1 = l1;
316                 l1cache->wbse(mm, MACHSIZE);
317         }
318         l1cache->wbse(machaddr, sizeof machaddr);
319         conf.nmach = 1;
320 }
321
322 void
323 dump(void *vaddr, int words)
324 {
325         ulong *addr;
326
327         addr = vaddr;
328         while (words-- > 0)
329                 iprint("%.8lux%c", *addr++, words % 8 == 0? '\n': ' ');
330 }
331
332 static void
333 cacheinit(void)
334 {
335         allcacheinfo(cachel);
336         cacheconf = (Lowmemcache *)CACHECONF;
337         cacheconf->l1waysh = cachel[1].waysh;
338         cacheconf->l1setsh = cachel[1].setsh;
339         /* on the tegra 2, l2 is unarchitected */
340         cacheconf->l2waysh = cachel[2].waysh;
341         cacheconf->l2setsh = cachel[2].setsh;
342
343         l2pl310init();
344         allcacheson();
345         allcache->wb();
346 }
347
348 void
349 l2pageinit(void)
350 {
351         l2pages = KADDR(PHYSDRAM + DRAMSIZE - RESRVDHIMEM);
352 }
353
354 /*
355  * at entry, l.s has set m for cpu0 and printed "Plan 9 from Be"
356  * but has not zeroed bss.
357  */
358 void
359 main(void)
360 {
361         int cpu;
362         static ulong vfy = 0xcafebabe;
363
364         up = nil;
365         if (vfy != 0xcafebabe) {
366                 serialputc('?');
367                 serialputc('d');
368                 panic("data segment misaligned");
369         }
370
371         memset(edata, 0, end - edata);
372
373         /*
374          * we can't lock until smpon has run, but we're supposed to wait
375          * until l1 & l2 are on.  too bad.  l1 is on, l2 will soon be.
376          */
377         smpon();
378         iprint("ll Labs ");
379         cacheinit();
380
381         /*
382          * data segment is aligned, bss is zeroed, caches' characteristics
383          * are known.  begin initialisation.
384          */
385         mach0init();
386         l2pageinit();
387         mmuinit();
388
389         optionsinit("/boot/boot boot");
390         quotefmtinstall();
391
392         /* want plan9.ini to be able to affect memory sizing in confinit */
393         plan9iniinit();         /* before we step on plan9.ini in low memory */
394
395         /* l2 looks for *l2off= in plan9.ini */
396         l2cache->on();          /* l2->on requires locks to work, thus smpon */
397         l2cache->info(&cachel[2]);
398         allcache->on();
399
400         cortexa9cachecfg();
401
402         trapinit();             /* so confinit can probe memory to size it */
403         confinit();             /* figures out amount of memory */
404         /* xinit prints (if it can), so finish up the banner here. */
405         delay(100);
406         navailcpus = getncpus();
407         iprint("(mp arm; %d cpus)\n\n", navailcpus);
408         delay(100);
409
410         for (cpu = 1; cpu < navailcpus; cpu++)
411                 stopcpu(cpu);
412
413         xinit();
414         irqtooearly = 0;        /* now that xinit and trapinit have run */
415
416         mainmem->flags |= POOL_ANTAGONISM /* | POOL_PARANOIA */ ;
417
418         /*
419          * Printinit will cause the first malloc call.
420          * (printinit->qopen->malloc) unless any of the
421          * above (like clockinit) do an irqenable, which
422          * will call malloc.
423          * If the system dies here it's probably due
424          * to malloc(->xalloc) not being initialised
425          * correctly, or the data segment is misaligned
426          * (it's amazing how far you can get with
427          * things like that completely broken).
428          *
429          * (Should be) boilerplate from here on.
430          */
431
432         archreset();                    /* cfg clock signals, print cache cfg */
433         clockinit();                    /* start clocks */
434         timersinit();
435
436         delay(50);                      /* let uart catch up */
437         printinit();
438
439         cpuidprint();
440         chkmissing();
441
442         procinit0();
443         initseg();
444
445 //      dmainit();
446         links();
447         conf.monitor = 1;
448 //      screeninit();
449
450         iprint("pcireset...");
451         pcireset();                     /* this tends to hang after a reboot */
452         iprint("ok\n");
453
454         chandevreset();                 /* most devices are discovered here */
455 //      i8250console();                 /* too early; see init0 */
456
457         pageinit();                     /* prints "1020M memory: â‹¯ */
458         userinit();
459
460         /*
461          * starting a cpu will eventually result in it calling schedinit,
462          * so everything necessary to run user processes should be set up
463          * before starting secondary cpus.
464          */
465         launchinit();
466         /* SMP & FW are already on when we get here; u-boot set them? */
467         for (cpu = 1; cpu < navailcpus; cpu++)
468                 if (startcpu(cpu) < 0)
469                         panic("cpu%d didn't start", cpu);
470         l1diag();
471
472         schedinit();
473         panic("cpu%d: schedinit returned", m->machno);
474 }
475
476 /*
477  *  exit kernel either on a panic or user request
478  */
479 void
480 exit(int)
481 {
482         cpushutdown();
483         splhi();
484         if (m->machno == 0)
485                 archreboot();
486         else {
487                 intrcpushutdown();
488                 stopcpu(m->machno);
489                 for (;;)
490                         idlehands();
491         }
492 }
493
494 int
495 isaconfig(char *class, int ctlrno, ISAConf *isa)
496 {
497         char cc[32], *p, *x;
498         int i;
499
500         snprint(cc, sizeof cc, "%s%d", class, ctlrno);
501         p = getconf(cc);
502         if(p == nil)
503                 return 0;
504
505         x = nil;
506         kstrdup(&x, p);
507         p = x;
508
509         isa->type = "";
510         isa->nopt = tokenize(p, isa->opt, NISAOPT);
511         for(i = 0; i < isa->nopt; i++){
512                 p = isa->opt[i];
513                 if(cistrncmp(p, "type=", 5) == 0)
514                         isa->type = p + 5;
515                 else if(cistrncmp(p, "port=", 5) == 0)
516                         isa->port = strtoul(p+5, &p, 0);
517                 else if(cistrncmp(p, "irq=", 4) == 0)
518                         isa->irq = strtoul(p+4, &p, 0);
519                 else if(cistrncmp(p, "dma=", 4) == 0)
520                         isa->dma = strtoul(p+4, &p, 0);
521                 else if(cistrncmp(p, "mem=", 4) == 0)
522                         isa->mem = strtoul(p+4, &p, 0);
523                 else if(cistrncmp(p, "size=", 5) == 0)
524                         isa->size = strtoul(p+5, &p, 0);
525                 else if(cistrncmp(p, "freq=", 5) == 0)
526                         isa->freq = strtoul(p+5, &p, 0);
527         }
528         return 1;
529 }
530
531 /*
532  * the new kernel is already loaded at address `code'
533  * of size `size' and entry point `entry'.
534  */
535 void
536 reboot(void *entry, void *code, ulong size)
537 {
538         void (*f)(ulong, ulong, ulong);
539
540         writeconf();
541
542         /*
543          * the boot processor is cpu0.  execute this function on it
544          * so that the new kernel has the same cpu0.
545          */
546         if (m->machno != 0) {
547                 procwired(up, 0);
548                 sched();
549         }
550         cpushutdown();
551
552         /*
553          * should be the only processor running now
554          */
555         pcireset();
556
557         /* turn off buffered serial console */
558         serialoq = nil;
559         kprintoq = nil;
560         screenputs = nil;
561
562         /* shutdown devices */
563         chandevshutdown();
564
565         /* call off the dog */
566         clockshutdown();
567
568         splhi();
569         intrshutdown();
570
571         /* setup reboot trampoline function */
572         f = (void*)REBOOTADDR;
573         memmove(f, rebootcode, sizeof(rebootcode));
574         cachedwb();
575         l2cache->wbinv();
576         l2cache->off();
577         cacheuwbinv();
578
579         /* off we go - never to return */
580         (*f)(PADDR(entry), PADDR(code), size);
581 }
582
583 /*
584  *  starting place for first process
585  */
586 void
587 init0(void)
588 {
589         int i;
590         char buf[2*KNAMELEN];
591
592         up->nerrlab = 0;
593         coherence();
594         spllo();
595
596         /*
597          * These are o.k. because rootinit is null.
598          * Then early kproc's will have a root and dot.
599          */
600         up->slash = namec("#/", Atodir, 0, 0);
601         pathclose(up->slash->path);
602         up->slash->path = newpath("/");
603         up->dot = cclone(up->slash);
604
605         chandevinit();
606         i8250console();         /* might be redundant, but harmless */
607         if(serialoq == nil)
608                 panic("init0: nil serialoq");
609         normalprint = 1;
610
611         if(!waserror()){
612                 snprint(buf, sizeof(buf), "%s %s", "ARM", conffile);
613                 ksetenv("terminal", buf, 0);
614                 ksetenv("cputype", "arm", 0);
615                 if(cpuserver)
616                         ksetenv("service", "cpu", 0);
617                 else
618                         ksetenv("service", "terminal", 0);
619
620                 /* convert plan9.ini variables to #e and #ec */
621                 for(i = 0; i < nconf; i++) {
622                         ksetenv(confname[i], confval[i], 0);
623                         ksetenv(confname[i], confval[i], 1);
624                 }
625                 poperror();
626         }
627         kproc("alarm", alarmkproc, 0);
628
629         touser(sp);
630 }
631
632 static void
633 bootargs(uintptr base)
634 {
635         int i;
636         ulong ssize;
637         char **av, *p;
638
639         /*
640          * Push the boot args onto the stack.
641          * The initial value of the user stack must be such
642          * that the total used is larger than the maximum size
643          * of the argument list checked in syscall.
644          */
645         i = oargblen+1;
646         p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
647         memmove(p, oargb, i);
648
649         /*
650          * Now push argc and the argv pointers.
651          * This isn't strictly correct as the code jumped to by
652          * touser in init9.s calls startboot (port/initcode.c) which
653          * expects arguments
654          *      startboot(char *argv0, char **argv)
655          * not the usual (int argc, char* argv[]), but argv0 is
656          * unused so it doesn't matter (at the moment...).
657          */
658         av = (char**)(p - (oargc+2)*sizeof(char*));
659         ssize = base + BY2PG - PTR2UINT(av);
660         *av++ = (char*)oargc;
661         for(i = 0; i < oargc; i++)
662                 *av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
663         *av = nil;
664
665         /*
666          * Leave space for the return PC of the
667          * caller of initcode.
668          */
669         sp = USTKTOP - ssize - sizeof(void*);
670 }
671
672 /*
673  *  create the first process
674  */
675 void
676 userinit(void)
677 {
678         Proc *p;
679         Segment *s;
680         KMap *k;
681         Page *pg;
682
683         /* no processes yet */
684         up = nil;
685
686         p = newproc();
687         p->pgrp = newpgrp();
688         p->egrp = smalloc(sizeof(Egrp));
689         p->egrp->ref = 1;
690         p->fgrp = dupfgrp(nil);
691         p->rgrp = newrgrp();
692         p->procmode = 0640;
693
694         kstrdup(&eve, "");
695         kstrdup(&p->text, "*init*");
696         kstrdup(&p->user, eve);
697
698         /*
699          * Kernel Stack
700          */
701         p->sched.pc = PTR2UINT(init0);
702         p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
703         p->sched.sp = STACKALIGN(p->sched.sp);
704
705         /*
706          * User Stack
707          *
708          * Technically, newpage can't be called here because it
709          * should only be called when in a user context as it may
710          * try to sleep if there are no pages available, but that
711          * shouldn't be the case here.
712          */
713         s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
714         s->flushme++;
715         p->seg[SSEG] = s;
716         pg = newpage(1, 0, USTKTOP-BY2PG);
717         segpage(s, pg);
718         k = kmap(pg);
719         bootargs(VA(k));
720         kunmap(k);
721
722         /*
723          * Text
724          */
725         s = newseg(SG_TEXT, UTZERO, 1);
726         p->seg[TSEG] = s;
727         pg = newpage(1, 0, UTZERO);
728         pg->txtflush = ~0;
729         segpage(s, pg);
730         k = kmap(s->map[0]->pages[0]);
731         memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
732         kunmap(k);
733
734         ready(p);
735 }
736
737 Conf conf;                      /* XXX - must go - gag */
738
739 Confmem tsmem[nelem(conf.mem)] = {
740         /*
741          * Memory available to Plan 9:
742          */
743         { .base = PHYSDRAM, .limit = PHYSDRAM + Minmem, },
744 };
745 ulong memsize = DRAMSIZE;
746
747 static int
748 gotmem(uintptr sz)
749 {
750         uintptr addr;
751
752         /* back off a little from the end */
753         addr = (uintptr)KADDR(PHYSDRAM + sz - BY2WD);
754         if (probeaddr(addr) >= 0) {     /* didn't trap? memory present */
755                 memsize = sz;
756                 return 0;
757         }
758         return -1;
759 }
760
761 void
762 confinit(void)
763 {
764         int i;
765         ulong kpages;
766         uintptr pa;
767         char *p;
768
769         if(p = getconf("service")){
770                 if(strcmp(p, "cpu") == 0)
771                         cpuserver = 1;
772                 else if(strcmp(p,"terminal") == 0)
773                         cpuserver = 0;
774         }
775
776         /*
777          * Copy the physical memory configuration to Conf.mem.
778          */
779         if(nelem(tsmem) > nelem(conf.mem)){
780                 iprint("memory configuration botch\n");
781                 exit(1);
782         }
783         if(0 && (p = getconf("*maxmem")) != nil) {
784                 memsize = strtoul(p, 0, 0) - PHYSDRAM;
785                 if (memsize < 16*MB)            /* sanity */
786                         memsize = 16*MB;
787         }
788
789         /*
790          * see if all that memory exists; if not, find out how much does.
791          * trapinit must have been called first.
792          */
793         if (gotmem(memsize - RESRVDHIMEM) < 0)
794                 panic("can't find 1GB of memory");
795
796         tsmem[0].limit = PHYSDRAM + memsize;
797         memmove(conf.mem, tsmem, sizeof(tsmem));
798
799         conf.npage = 0;
800         pa = PADDR(PGROUND(PTR2UINT(end)));
801
802         /*
803          *  we assume that the kernel is at the beginning of one of the
804          *  contiguous chunks of memory and fits therein.
805          */
806         for(i=0; i<nelem(conf.mem); i++){
807                 /* take kernel out of allocatable space */
808                 if(pa > conf.mem[i].base && pa < conf.mem[i].limit)
809                         conf.mem[i].base = pa;
810
811                 conf.mem[i].npage = (conf.mem[i].limit - conf.mem[i].base)/BY2PG;
812                 conf.npage += conf.mem[i].npage;
813         }
814
815         conf.upages = (conf.npage*80)/100;
816         conf.ialloc = ((conf.npage-conf.upages)/2)*BY2PG;
817
818         /* set up other configuration parameters */
819         conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
820         if(cpuserver)
821                 conf.nproc *= 3;
822         if(conf.nproc > 2000)
823                 conf.nproc = 2000;
824         conf.nswap = conf.npage*3;
825         conf.nswppo = 4096;
826         conf.nimage = 200;
827
828         /*
829          * it's simpler on mp systems to take page-faults early,
830          * on reference, rather than later, on write, which might
831          * require tlb shootdowns.
832          */
833         conf.copymode = 1;              /* copy on reference */
834
835         /*
836          * Guess how much is taken by the large permanent
837          * datastructures. Mntcache and Mntrpc are not accounted for.
838          */
839         kpages = conf.npage - conf.upages;
840         kpages *= BY2PG;
841         kpages -= conf.upages*sizeof(Page)
842                 + conf.nproc*sizeof(Proc)
843                 + conf.nimage*sizeof(Image)
844                 + conf.nswap
845                 + conf.nswppo*sizeof(Page*);
846         mainmem->maxsize = kpages;
847         if(!cpuserver)
848                 /*
849                  * give terminals lots of image memory, too; the dynamic
850                  * allocation will balance the load properly, hopefully.
851                  * be careful with 32-bit overflow.
852                  */
853                 imagmem->maxsize = kpages;
854 }
855
856 void
857 advertwfi(void)                 /* advertise my wfi status */
858 {
859         ilock(&active);
860         active.wfi |= 1 << m->machno;
861         iunlock(&active);
862 }
863
864 void
865 unadvertwfi(void)               /* do not advertise my wfi status */
866 {
867         ilock(&active);
868         active.wfi &= ~(1 << m->machno);
869         iunlock(&active);
870 }
871
872 void
873 idlehands(void)
874 {
875 #ifdef use_ipi
876         int advertised;
877
878         /* don't go into wfi until my local timer is ticking */
879         if (m->ticks <= 1)
880                 return;
881
882         advertised = 0;
883         m->inidlehands++;
884         /* avoid recursion via ilock, advertise iff this cpu is initialised */
885         if (m->inidlehands == 1 && m->syscall > 0) {
886                 advertwfi();
887                 advertised = 1;
888         }
889
890         wfi();
891
892         if (advertised)
893                 unadvertwfi();
894         m->inidlehands--;
895 #endif
896 }
897
898 void
899 wakewfi(void)
900 {
901 #ifdef use_ipi
902         uint cpu;
903
904         /*
905          * find any cpu other than me currently in wfi.
906          * need not be exact.
907          */
908         cpu = BI2BY*BY2WD - 1 - clz(active.wfi & ~(1 << m->machno));
909         if (cpu < MAXMACH)
910                 intrcpu(cpu);
911 #endif
912 }
913
914 void
915 setupwatchpts(Proc *, Watchpt *, int n)
916 {
917         if(n > 0)
918                 error("no watchpoints");
919 }