2 #include "../port/lib.h"
16 memset(edata, 0, (ulong)end-(ulong)edata);
49 memset(m, 0, sizeof(Mach));
50 m->cputype = getpvr()>>16;
53 * For polled uart output at boot, need
54 * a default delay constant. 100000 should
55 * be enough for a while. Cpuidentify will
56 * calculate the real value later.
58 m->loopconst = 100000;
61 puthid0(gethid0() | BIT(16) | BIT(17));
72 id = "unknown PowerPC";
78 print("cpu0: %s\n", id);
89 { "ether0", "type=2114x" },
97 for(i = 0; i < nelem(plan9ini); i++)
98 if(cistrcmp(name, plan9ini[i].name) == 0)
99 return plan9ini[i].val;
106 // char **p, *q, name[KNAMELEN];
108 char buf[2*KNAMELEN];
115 * These are o.k. because rootinit is null.
116 * Then early kproc's will have a root and dot.
118 up->slash = namec("#/", Atodir, 0, 0);
119 pathclose(up->slash->path);
120 up->slash->path = newpath("/");
121 up->dot = cclone(up->slash);
126 snprint(buf, sizeof(buf), "power %s mtx", conffile);
127 ksetenv("terminal", buf, 0);
128 ksetenv("cputype", "power", 0);
130 ksetenv("service", "cpu", 0);
132 ksetenv("service", "terminal", 0);
135 for(p = confenv; *p; p++) {
136 q = strchr(p[0], '=');
142 memmove(name, p[0], n);
145 ksetenv(name, q+1, 0);
146 ksetenv(name, q+1, 1);
151 kproc("alarm", alarmkproc, 0);
152 kproc("mmusweep", mmusweep, 0);
153 touser((void*)(USTKTOP-8));
166 p->egrp = smalloc(sizeof(Egrp));
168 p->fgrp = dupfgrp(nil);
173 kstrdup(&p->text, "*init*");
174 kstrdup(&p->user, eve);
181 * N.B. The -12 for the stack pointer is important.
182 * 4 bytes for gotolabel's return PC
184 p->sched.pc = (ulong)init0;
185 p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);
190 s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
192 pg = newpage(1, 0, USTKTOP-BY2PG);
198 s = newseg(SG_TEXT, UTZERO, 1);
201 pg = newpage(1, 0, UTZERO);
202 memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
204 k = kmap(s->map[0]->pages[0]);
205 memmove((ulong*)VA(k), initcode, sizeof initcode);
213 reboot(void*, void*, ulong)
225 active.ispanic = ispanic;
226 else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
228 once = active.machs & (1<<m->machno);
229 active.machs &= ~(1<<m->machno);
234 print("cpu%d: exiting\n", m->machno);
236 for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
238 if(active.machs == 0 && consactive() == 0)
242 if(active.ispanic && m->machno == 0){
245 else if(conf.monitor)
255 * set up floating point for a new process
264 * Save the mach dependent part of the process state.
269 if(p->fpstate == FPactive){
270 if(p->state != Moribund)
272 p->fpstate = FPinactive;
282 extern ulong memsize; /* passed in from ROM monitor */
284 if(p = getconf("*kernelpercent"))
285 userpcnt = 100 - strtol(p, 0, 0);
289 pa = PGROUND(PADDR(end));
291 conf.mem[0].npage = memsize/BY2PG;
292 conf.mem[0].base = pa;
293 conf.npage = conf.mem[0].npage;
296 conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
299 if(conf.nproc > 2000)
302 conf.nswap = conf.nproc*80;
304 conf.copymode = 0; /* copy on write */
309 kpages = conf.npage - (conf.npage*userpcnt)/100;
312 * Hack for the big boys. Only good while physmem < 4GB.
313 * Give the kernel a max. of 16MB + enough to allocate the
315 * This is an overestimate as conf.upages < conf.npages.
316 * The patch of nimage is a band-aid, scanning the whole
317 * page list in imagereclaim just takes too long.
319 if(kpages > (16*MB + conf.npage*sizeof(Page))/BY2PG){
320 kpages = (16*MB + conf.npage*sizeof(Page))/BY2PG;
322 kpages += (conf.nproc*KSTACK)/BY2PG;
326 if(conf.npage*BY2PG < 16*MB)
331 kpages = conf.npage - (conf.npage*userpcnt)/100;
334 * Make sure terminals with low memory get at least
335 * 4MB on the first Image chunk allocation.
337 if(conf.npage*BY2PG < 16*MB)
338 imagmem->minarena = 4*1024*1024;
340 conf.upages = conf.npage - kpages;
341 conf.ialloc = (kpages/2)*BY2PG;
344 * Guess how much is taken by the large permanent
345 * datastructures. Mntcache and Mntrpc are not accounted for
349 kpages -= conf.upages*sizeof(Page)
350 + conf.nproc*sizeof(Proc)
351 + conf.nimage*sizeof(Image)
353 + conf.nswppo*sizeof(Page);
354 mainmem->maxsize = kpages;
357 * give terminals lots of image memory, too; the dynamic
358 * allocation will balance the load properly, hopefully.
359 * be careful with 32-bit overflow.
361 imagmem->maxsize = kpages;
364 // conf.monitor = 1; /* BUG */
368 getcfields(char* lp, char** fields, int n, char* sep)
372 for(i = 0; lp && *lp && i < n; i++){
373 while(*lp && strchr(sep, *lp) != 0)
378 while(*lp && strchr(sep, *lp) == 0){
379 if(*lp == '\\' && *(lp+1) == '\n')
389 isaconfig(char *class, int ctlrno, ISAConf *isa)
392 char cc[KNAMELEN], *p;
394 sprint(cc, "%s%d", class, ctlrno);
399 isa->nopt = tokenize(p, isa->opt, NISAOPT);
400 for(i = 0; i < isa->nopt; i++){
402 if(cistrncmp(p, "type=", 5) == 0)
404 else if(cistrncmp(p, "port=", 5) == 0)
405 isa->port = strtoul(p+5, &p, 0);
406 else if(cistrncmp(p, "irq=", 4) == 0)
407 isa->irq = strtoul(p+4, &p, 0);
408 else if(cistrncmp(p, "dma=", 4) == 0)
409 isa->dma = strtoul(p+4, &p, 0);
410 else if(cistrncmp(p, "mem=", 4) == 0)
411 isa->mem = strtoul(p+4, &p, 0);
412 else if(cistrncmp(p, "size=", 5) == 0)
413 isa->size = strtoul(p+5, &p, 0);
414 else if(cistrncmp(p, "freq=", 5) == 0)
415 isa->freq = strtoul(p+5, &p, 0);
421 cistrcmp(char *a, char *b)
429 if(ac >= 'A' && ac <= 'Z')
430 ac = 'a' + (ac - 'A');
431 if(bc >= 'A' && bc <= 'Z')
432 bc = 'a' + (bc - 'A');
443 cistrncmp(char *a, char *b, int n)
452 if(ac >= 'A' && ac <= 'Z')
453 ac = 'a' + (ac - 'A');
454 if(bc >= 'A' && bc <= 'Z')
455 bc = 'a' + (bc - 'A');