2 #include "../port/lib.h"
14 * Where configuration info is left for the loaded programme.
15 * This will turn into a structure as more is done by the boot loader
16 * (e.g. why parse the .ini file twice?).
17 * There are 3584 bytes available at CONFADDR.
19 #define BOOTARGS ((char*)CONFADDR)
20 #define BOOTARGSLEN (16*KiB) /* limit in devenv.c */
22 #define MAXCONFLINE 160
24 #define isascii(c) ((uchar)(c) > 0 && (uchar)(c) < 0177)
26 uintptr kseg0 = KZERO;
27 Mach* machaddr[MAXMACH];
30 * Option arguments from the command line.
31 * oargv[0] is the boot file.
32 * Optionsinit() is called from multiboot()
33 * or some other machine-dependent place
37 static char* oargv[20];
38 static char oargb[128];
40 static char oenv[4096];
42 static uintptr sp; /* XXX - must go - user stack of init proc */
47 /* store plan9.ini contents here at least until we stash them in #ec */
48 static char confname[MAXCONF][KNAMELEN];
49 static char confval[MAXCONF][MAXCONFLINE];
53 uchar sandbox[64*1024+BY2PG];
61 for(i = 0; i < nconf; i++)
62 if(cistrcmp(confname[i], name) == 0)
79 addconf(char *name, char *val)
85 if(val == nil || nconf >= MAXCONF)
88 strecpy(confname[i], confname[i]+sizeof(confname[i]), name);
91 strecpy(confval[i], confval[i]+sizeof(confval[i]), val);
107 /* convert to name=value\n format */
116 error("kernel configuration too large");
117 memmove(BOOTARGS, p, n);
123 * assumes that we have loaded our /cfg/pxe/mac file at 0x1000 with
124 * tftp in u-boot. no longer uses malloc, so can be called early.
131 k = (char *)CONFADDR;
135 for(; k && *k != '\0'; k = next) {
136 if (!isascii(*k)) /* sanity check */
138 next = strchr(k, '\n');
142 if (*k == '\0' || *k == '\n' || *k == '#')
146 continue; /* mal-formed line */
158 o = strecpy(oargb, oargb+sizeof(oargb), s)+1;
159 if(getenv("bootargs", o, o - oargb) != nil)
162 oargblen = strlen(oargb);
163 oargc = tokenize(oargb, oargv, nelem(oargv)-1);
168 getenv(char* name, char* buf, int n)
174 if((e = strchr(p, '=')) == nil)
176 for(q = name; p < e; p++){
181 if(p == e && *q == 0){
182 strecpy(buf, buf+n, e+1);
193 typedef struct Spiregs Spiregs;
195 ulong ictl; /* interface ctl */
196 ulong icfg; /* interface config */
197 ulong out; /* data out */
198 ulong in; /* data in */
199 ulong ic; /* interrupt cause */
200 ulong im; /* interrupt mask */
202 ulong dwrcfg; /* direct write config */
203 ulong dwrhdr; /* direct write header */
208 Csnact = 1<<0, /* serial memory activated */
211 Bytelen = 1<<5, /* 2^(this_bit) bytes per transfer */
212 Dirrdcmd= 1<<10, /* flag: fast read */
216 dumpbytes(uchar *bp, long max)
219 for (; max > 0; max--)
220 iprint("%02.2ux ", *bp++);
227 Spiregs *rp = (Spiregs *)soc.spi;
231 rp->icfg |= Dirrdcmd | 3<<8; /* fast reads, 4-byte addresses */
232 rp->icfg &= ~Bytelen; /* one-byte reads */
235 // print("spi flash at %#ux: memory reads enabled\n", PHYSSPIFLASH);
238 void archconsole(void);
242 isaconfig(char *, int, ISAConf *)
248 * entered from l.s with mmu enabled.
250 * we may have to realign the data segment; apparently 5l -H0 -R4096
251 * does not pad the text segment. on the other hand, we may have been
252 * loaded by another kernel.
254 * be careful not to touch the data segment until we know it's aligned.
259 extern char bdata[], edata[], end[], etext[];
260 static ulong vfy = 0xcafebabe;
263 if (vfy != 0xcafebabe)
264 memmove(bdata, etext, edata - bdata);
265 if (vfy != 0xcafebabe) {
267 panic("misaligned data segment");
269 memset(edata, 0, end - edata); /* zero bss */
277 optionsinit("/boot/boot boot");
282 /* want plan9.ini to be able to affect memory sizing in confinit */
283 plan9iniinit(); /* before we step on plan9.ini in low memory */
286 /* xinit would print if it could */
290 * Printinit will cause the first malloc call.
291 * (printinit->qopen->malloc) unless any of the
292 * above (like clockintr) do an irqenable, which
294 * If the system dies here it's probably due
295 * to malloc(->xalloc) not being initialised
296 * correctly, or the data segment is misaligned
297 * (it's amazing how far you can get with
298 * things like that completely broken).
300 * (Should be) boilerplate from here on.
306 uartkirkwoodconsole();
307 /* only now can we print */
308 print("from Bell Labs\n\n");
311 print("sandbox: 64K at physical %#lux, mapped to 0xf10b0000\n",
312 PADDR((uintptr)sandbox & ~(BY2PG-1)));
322 chandevreset(); /* most devices are discovered here */
327 panic("schedinit returned");
335 cputype2name(name, sizeof name);
336 print("cpu%d: %lldMHz ARM %s\n", m->machno, m->cpuhz/1000000, name);
342 memset(m, 0, sizeof(Mach));
344 machaddr[m->machno] = m;
358 * exit kernel either on a panic or user request
369 * the new kernel is already loaded at address `code'
370 * of size `size' and entry point `entry'.
373 reboot(void *entry, void *code, ulong size)
375 void (*f)(ulong, ulong, ulong);
380 /* turn off buffered serial console */
383 /* shutdown devices */
386 /* call off the dog */
391 /* setup reboot trampoline function */
392 f = (void*)REBOOTADDR;
393 memmove(f, rebootcode, sizeof(rebootcode));
397 /* off we go - never to return */
400 (*f)(PADDR(entry), PADDR(code), size);
404 * starting place for first process
410 char buf[2*KNAMELEN];
418 * These are o.k. because rootinit is null.
419 * Then early kproc's will have a root and dot.
421 up->slash = namec("#/", Atodir, 0, 0);
422 pathclose(up->slash->path);
423 up->slash->path = newpath("/");
424 up->dot = cclone(up->slash);
429 snprint(buf, sizeof(buf), "%s %s", "ARM", conffile);
430 ksetenv("terminal", buf, 0);
431 ksetenv("cputype", "arm", 0);
433 ksetenv("service", "cpu", 0);
435 ksetenv("service", "terminal", 0);
437 /* convert plan9.ini variables to #e and #ec */
438 for(i = 0; i < nconf; i++) {
439 ksetenv(confname[i], confval[i], 0);
440 ksetenv(confname[i], confval[i], 1);
444 kproc("alarm", alarmkproc, 0);
450 bootargs(uintptr base)
457 * Push the boot args onto the stack.
458 * The initial value of the user stack must be such
459 * that the total used is larger than the maximum size
460 * of the argument list checked in syscall.
463 p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
464 memmove(p, oargb, i);
467 * Now push argc and the argv pointers.
468 * This isn't strictly correct as the code jumped to by
469 * touser in init9.s calls startboot (port/initcode.c) which
471 * startboot(char *argv0, char **argv)
472 * not the usual (int argc, char* argv[]), but argv0 is
473 * unused so it doesn't matter (at the moment...).
475 av = (char**)(p - (oargc+2)*sizeof(char*));
476 ssize = base + BY2PG - PTR2UINT(av);
477 *av++ = (char*)oargc;
478 for(i = 0; i < oargc; i++)
479 *av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
483 * Leave space for the return PC of the
484 * caller of initcode.
486 sp = USTKTOP - ssize - sizeof(void*);
490 * create the first process
500 /* no processes yet */
505 p->egrp = smalloc(sizeof(Egrp));
507 p->fgrp = dupfgrp(nil);
512 kstrdup(&p->text, "*init*");
513 kstrdup(&p->user, eve);
518 p->sched.pc = PTR2UINT(init0);
519 p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
520 p->sched.sp = STACKALIGN(p->sched.sp);
525 * Technically, newpage can't be called here because it
526 * should only be called when in a user context as it may
527 * try to sleep if there are no pages available, but that
528 * shouldn't be the case here.
530 s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
532 pg = newpage(1, 0, USTKTOP-BY2PG);
541 s = newseg(SG_TEXT, UTZERO, 1);
544 pg = newpage(1, 0, UTZERO);
547 k = kmap(s->map[0]->pages[0]);
548 memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
554 Conf conf; /* XXX - must go - gag */
556 Confmem sheevamem[] = {
558 * Memory available to Plan 9:
559 * the 8K is reserved for ethernet dma access violations to scribble on.
561 { .base = 0, .limit = 512*MB - 8*1024, },
572 * Copy the physical memory configuration to Conf.mem.
574 if(nelem(sheevamem) > nelem(conf.mem)){
575 iprint("memory configuration botch\n");
578 memmove(conf.mem, sheevamem, sizeof(sheevamem));
581 pa = PADDR(PGROUND(PTR2UINT(end)));
584 * we assume that the kernel is at the beginning of one of the
585 * contiguous chunks of memory and fits therein.
587 for(i=0; i<nelem(conf.mem); i++){
588 /* take kernel out of allocatable space */
589 if(pa > conf.mem[i].base && pa < conf.mem[i].limit)
590 conf.mem[i].base = pa;
592 conf.mem[i].npage = (conf.mem[i].limit - conf.mem[i].base)/BY2PG;
593 conf.npage += conf.mem[i].npage;
596 conf.upages = (conf.npage*90)/100;
597 conf.ialloc = ((conf.npage-conf.upages)/2)*BY2PG;
599 /* only one processor */
602 /* set up other configuration parameters */
603 conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
606 if(conf.nproc > 2000)
608 conf.nswap = conf.npage*3;
612 conf.copymode = 0; /* copy on write */
615 * Guess how much is taken by the large permanent
616 * datastructures. Mntcache and Mntrpc are not accounted for.
618 kpages = conf.npage - conf.upages;
620 kpages -= conf.upages*sizeof(Page)
621 + conf.nproc*sizeof(Proc)
622 + conf.nimage*sizeof(Image)
624 + conf.nswppo*sizeof(Page*);
625 mainmem->maxsize = kpages;
628 * give terminals lots of image memory, too; the dynamic
629 * allocation will balance the load properly, hopefully.
630 * be careful with 32-bit overflow.
632 imagmem->maxsize = kpages;
636 cmpswap(long *addr, long old, long new)
638 return cas32(addr, old, new);
642 setupwatchpts(Proc *, Watchpt *, int n)
645 error("no watchpoints");