2 #include "../port/lib.h"
16 memset(edata, 0, (ulong)end-(ulong)edata);
47 memset(m, 0, sizeof(Mach));
48 m->cputype = getpvr()>>16;
51 * For polled uart output at boot, need
52 * a default delay constant. 100000 should
53 * be enough for a while. Cpuidentify will
54 * calculate the real value later.
56 m->loopconst = 100000;
59 puthid0(gethid0() | BIT(16) | BIT(17));
70 id = "unknown PowerPC";
76 print("cpu0: %s\n", id);
87 { "ether0", "type=2114x" },
95 for(i = 0; i < nelem(plan9ini); i++)
96 if(cistrcmp(name, plan9ini[i].name) == 0)
97 return plan9ini[i].val;
104 // char **p, *q, name[KNAMELEN];
106 char buf[2*KNAMELEN];
113 * These are o.k. because rootinit is null.
114 * Then early kproc's will have a root and dot.
116 up->slash = namec("#/", Atodir, 0, 0);
117 pathclose(up->slash->path);
118 up->slash->path = newpath("/");
119 up->dot = cclone(up->slash);
124 snprint(buf, sizeof(buf), "power %s mtx", conffile);
125 ksetenv("terminal", buf, 0);
126 ksetenv("cputype", "power", 0);
128 ksetenv("service", "cpu", 0);
130 ksetenv("service", "terminal", 0);
133 for(p = confenv; *p; p++) {
134 q = strchr(p[0], '=');
140 memmove(name, p[0], n);
143 ksetenv(name, q+1, 0);
144 ksetenv(name, q+1, 1);
149 kproc("alarm", alarmkproc, 0);
150 kproc("mmusweep", mmusweep, 0);
151 touser((void*)(USTKTOP-8));
164 p->egrp = smalloc(sizeof(Egrp));
166 p->fgrp = dupfgrp(nil);
171 kstrdup(&p->text, "*init*");
172 kstrdup(&p->user, eve);
179 * N.B. The -12 for the stack pointer is important.
180 * 4 bytes for gotolabel's return PC
182 p->sched.pc = (ulong)init0;
183 p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);
188 s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
190 pg = newpage(1, 0, USTKTOP-BY2PG);
196 s = newseg(SG_TEXT, UTZERO, 1);
199 pg = newpage(1, 0, UTZERO);
202 k = kmap(s->map[0]->pages[0]);
203 memmove((ulong*)VA(k), initcode, sizeof initcode);
211 reboot(void*, void*, ulong)
223 * set up floating point for a new process
237 * Save the mach dependent part of the process state.
242 if(p->fpstate == FPactive){
243 if(p->state != Moribund)
245 p->fpstate = FPinactive;
255 extern ulong memsize; /* passed in from ROM monitor */
257 if(p = getconf("*kernelpercent"))
258 userpcnt = 100 - strtol(p, 0, 0);
262 pa = PGROUND(PADDR(end));
264 conf.mem[0].npage = memsize/BY2PG;
265 conf.mem[0].base = pa;
266 conf.npage = conf.mem[0].npage;
269 conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
272 if(conf.nproc > 2000)
275 conf.nswap = conf.nproc*80;
277 conf.copymode = 0; /* copy on write */
282 kpages = conf.npage - (conf.npage*userpcnt)/100;
285 * Hack for the big boys. Only good while physmem < 4GB.
286 * Give the kernel a max. of 16MB + enough to allocate the
288 * This is an overestimate as conf.upages < conf.npages.
289 * The patch of nimage is a band-aid, scanning the whole
290 * page list in imagereclaim just takes too long.
292 if(kpages > (16*MB + conf.npage*sizeof(Page))/BY2PG){
293 kpages = (16*MB + conf.npage*sizeof(Page))/BY2PG;
295 kpages += (conf.nproc*KSTACK)/BY2PG;
299 if(conf.npage*BY2PG < 16*MB)
304 kpages = conf.npage - (conf.npage*userpcnt)/100;
307 * Make sure terminals with low memory get at least
308 * 4MB on the first Image chunk allocation.
310 if(conf.npage*BY2PG < 16*MB)
311 imagmem->minarena = 4*1024*1024;
313 conf.upages = conf.npage - kpages;
314 conf.ialloc = (kpages/2)*BY2PG;
317 * Guess how much is taken by the large permanent
318 * datastructures. Mntcache and Mntrpc are not accounted for.
321 kpages -= conf.upages*sizeof(Page)
322 + conf.nproc*sizeof(Proc)
323 + conf.nimage*sizeof(Image)
325 + conf.nswppo*sizeof(Page*);
326 mainmem->maxsize = kpages;
329 * give terminals lots of image memory, too; the dynamic
330 * allocation will balance the load properly, hopefully.
331 * be careful with 32-bit overflow.
333 imagmem->maxsize = kpages;
336 // conf.monitor = 1; /* BUG */
340 getcfields(char* lp, char** fields, int n, char* sep)
344 for(i = 0; lp && *lp && i < n; i++){
345 while(*lp && strchr(sep, *lp) != 0)
350 while(*lp && strchr(sep, *lp) == 0){
351 if(*lp == '\\' && *(lp+1) == '\n')
361 isaconfig(char *class, int ctlrno, ISAConf *isa)
364 char cc[KNAMELEN], *p;
366 sprint(cc, "%s%d", class, ctlrno);
371 isa->nopt = tokenize(p, isa->opt, NISAOPT);
372 for(i = 0; i < isa->nopt; i++){
374 if(cistrncmp(p, "type=", 5) == 0)
376 else if(cistrncmp(p, "port=", 5) == 0)
377 isa->port = strtoul(p+5, &p, 0);
378 else if(cistrncmp(p, "irq=", 4) == 0)
379 isa->irq = strtoul(p+4, &p, 0);
380 else if(cistrncmp(p, "dma=", 4) == 0)
381 isa->dma = strtoul(p+4, &p, 0);
382 else if(cistrncmp(p, "mem=", 4) == 0)
383 isa->mem = strtoul(p+4, &p, 0);
384 else if(cistrncmp(p, "size=", 5) == 0)
385 isa->size = strtoul(p+5, &p, 0);
386 else if(cistrncmp(p, "freq=", 5) == 0)
387 isa->freq = strtoul(p+5, &p, 0);
393 cistrcmp(char *a, char *b)
401 if(ac >= 'A' && ac <= 'Z')
402 ac = 'a' + (ac - 'A');
403 if(bc >= 'A' && bc <= 'Z')
404 bc = 'a' + (bc - 'A');
415 cistrncmp(char *a, char *b, int n)
424 if(ac >= 'A' && ac <= 'Z')
425 ac = 'a' + (ac - 'A');
426 if(bc >= 'A' && bc <= 'Z')
427 bc = 'a' + (bc - 'A');
440 setupwatchpts(Proc *, Watchpt *, int n)
443 error("no watchpoints");