2 #include "../port/lib.h"
16 memset(edata, 0, (ulong)end-(ulong)edata);
48 memset(m, 0, sizeof(Mach));
49 m->cputype = getpvr()>>16;
52 * For polled uart output at boot, need
53 * a default delay constant. 100000 should
54 * be enough for a while. Cpuidentify will
55 * calculate the real value later.
57 m->loopconst = 100000;
60 puthid0(gethid0() | BIT(16) | BIT(17));
71 id = "unknown PowerPC";
77 print("cpu0: %s\n", id);
88 { "ether0", "type=2114x" },
96 for(i = 0; i < nelem(plan9ini); i++)
97 if(cistrcmp(name, plan9ini[i].name) == 0)
98 return plan9ini[i].val;
105 // char **p, *q, name[KNAMELEN];
107 char buf[2*KNAMELEN];
114 * These are o.k. because rootinit is null.
115 * Then early kproc's will have a root and dot.
117 up->slash = namec("#/", Atodir, 0, 0);
118 pathclose(up->slash->path);
119 up->slash->path = newpath("/");
120 up->dot = cclone(up->slash);
125 snprint(buf, sizeof(buf), "power %s mtx", conffile);
126 ksetenv("terminal", buf, 0);
127 ksetenv("cputype", "power", 0);
129 ksetenv("service", "cpu", 0);
131 ksetenv("service", "terminal", 0);
134 for(p = confenv; *p; p++) {
135 q = strchr(p[0], '=');
141 memmove(name, p[0], n);
144 ksetenv(name, q+1, 0);
145 ksetenv(name, q+1, 1);
150 kproc("alarm", alarmkproc, 0);
151 kproc("mmusweep", mmusweep, 0);
152 touser((void*)(USTKTOP-8));
165 p->egrp = smalloc(sizeof(Egrp));
167 p->fgrp = dupfgrp(nil);
172 kstrdup(&p->text, "*init*");
173 kstrdup(&p->user, eve);
180 * N.B. The -12 for the stack pointer is important.
181 * 4 bytes for gotolabel's return PC
183 p->sched.pc = (ulong)init0;
184 p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);
189 s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
191 pg = newpage(1, 0, USTKTOP-BY2PG);
197 s = newseg(SG_TEXT, UTZERO, 1);
200 pg = newpage(1, 0, UTZERO);
201 memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
203 k = kmap(s->map[0]->pages[0]);
204 memmove((ulong*)VA(k), initcode, sizeof initcode);
212 reboot(void*, void*, ulong)
224 active.ispanic = ispanic;
225 else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
227 once = active.machs & (1<<m->machno);
228 active.machs &= ~(1<<m->machno);
233 print("cpu%d: exiting\n", m->machno);
235 for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
237 if(active.machs == 0 && consactive() == 0)
241 if(active.ispanic && m->machno == 0){
244 else if(conf.monitor)
254 * set up floating point for a new process
268 * Save the mach dependent part of the process state.
273 if(p->fpstate == FPactive){
274 if(p->state != Moribund)
276 p->fpstate = FPinactive;
286 extern ulong memsize; /* passed in from ROM monitor */
288 if(p = getconf("*kernelpercent"))
289 userpcnt = 100 - strtol(p, 0, 0);
293 pa = PGROUND(PADDR(end));
295 conf.mem[0].npage = memsize/BY2PG;
296 conf.mem[0].base = pa;
297 conf.npage = conf.mem[0].npage;
300 conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
303 if(conf.nproc > 2000)
306 conf.nswap = conf.nproc*80;
308 conf.copymode = 0; /* copy on write */
313 kpages = conf.npage - (conf.npage*userpcnt)/100;
316 * Hack for the big boys. Only good while physmem < 4GB.
317 * Give the kernel a max. of 16MB + enough to allocate the
319 * This is an overestimate as conf.upages < conf.npages.
320 * The patch of nimage is a band-aid, scanning the whole
321 * page list in imagereclaim just takes too long.
323 if(kpages > (16*MB + conf.npage*sizeof(Page))/BY2PG){
324 kpages = (16*MB + conf.npage*sizeof(Page))/BY2PG;
326 kpages += (conf.nproc*KSTACK)/BY2PG;
330 if(conf.npage*BY2PG < 16*MB)
335 kpages = conf.npage - (conf.npage*userpcnt)/100;
338 * Make sure terminals with low memory get at least
339 * 4MB on the first Image chunk allocation.
341 if(conf.npage*BY2PG < 16*MB)
342 imagmem->minarena = 4*1024*1024;
344 conf.upages = conf.npage - kpages;
345 conf.ialloc = (kpages/2)*BY2PG;
348 * Guess how much is taken by the large permanent
349 * datastructures. Mntcache and Mntrpc are not accounted for
353 kpages -= conf.upages*sizeof(Page)
354 + conf.nproc*sizeof(Proc)
355 + conf.nimage*sizeof(Image)
357 + conf.nswppo*sizeof(Page);
358 mainmem->maxsize = kpages;
361 * give terminals lots of image memory, too; the dynamic
362 * allocation will balance the load properly, hopefully.
363 * be careful with 32-bit overflow.
365 imagmem->maxsize = kpages;
368 // conf.monitor = 1; /* BUG */
372 getcfields(char* lp, char** fields, int n, char* sep)
376 for(i = 0; lp && *lp && i < n; i++){
377 while(*lp && strchr(sep, *lp) != 0)
382 while(*lp && strchr(sep, *lp) == 0){
383 if(*lp == '\\' && *(lp+1) == '\n')
393 isaconfig(char *class, int ctlrno, ISAConf *isa)
396 char cc[KNAMELEN], *p;
398 sprint(cc, "%s%d", class, ctlrno);
403 isa->nopt = tokenize(p, isa->opt, NISAOPT);
404 for(i = 0; i < isa->nopt; i++){
406 if(cistrncmp(p, "type=", 5) == 0)
408 else if(cistrncmp(p, "port=", 5) == 0)
409 isa->port = strtoul(p+5, &p, 0);
410 else if(cistrncmp(p, "irq=", 4) == 0)
411 isa->irq = strtoul(p+4, &p, 0);
412 else if(cistrncmp(p, "dma=", 4) == 0)
413 isa->dma = strtoul(p+4, &p, 0);
414 else if(cistrncmp(p, "mem=", 4) == 0)
415 isa->mem = strtoul(p+4, &p, 0);
416 else if(cistrncmp(p, "size=", 5) == 0)
417 isa->size = strtoul(p+5, &p, 0);
418 else if(cistrncmp(p, "freq=", 5) == 0)
419 isa->freq = strtoul(p+5, &p, 0);
425 cistrcmp(char *a, char *b)
433 if(ac >= 'A' && ac <= 'Z')
434 ac = 'a' + (ac - 'A');
435 if(bc >= 'A' && bc <= 'Z')
436 bc = 'a' + (bc - 'A');
447 cistrncmp(char *a, char *b, int n)
456 if(ac >= 'A' && ac <= 'Z')
457 ac = 'a' + (ac - 'A');
458 if(bc >= 'A' && bc <= 'Z')
459 bc = 'a' + (bc - 'A');