2 #include "../port/lib.h"
11 #include <../port/error.h>
14 /* space for syscall args, return PC, top-of-stack struct */
15 Stkheadroom = sizeof(Sargs) + sizeof(uintptr) + sizeof(Tos),
18 static uchar *sp; /* XXX - must go - user stack of init proc */
22 * software tlb simulation
24 static Softtlb stlb[MAXMACH][STLBSIZE];
31 return (char*)arcs(0x78, name);
39 /* ipreset installs these when chandevreset runs */
40 fmtinstall('i', eipfmt);
41 fmtinstall('I', eipfmt);
42 fmtinstall('E', eipfmt);
43 fmtinstall('V', eipfmt);
44 fmtinstall('M', eipfmt);
48 ckpagemask(ulong mask, ulong size)
58 iprint("page size %ldK not supported on this cpu; "
59 "mask %#lux read back as %#lux\n", size/1024, mask, pm);
66 addmem(uintptr base, uintptr top)
77 e = PADDR(PGROUND((uintptr)end));
78 if(s < top && e > base){
86 /* exclude reserved firmware memory regions */
88 while((m = (ulong*)arcs(0x48, m)) != nil){
92 case 2: /* FreeMemory */
93 case 3: /* BadMemory */
96 if(s < top && e > base){
104 for(i=0; i<nelem(conf.mem); i++){
105 if(conf.mem[i].npage == 0){
106 conf.mem[i].base = base;
107 conf.mem[i].npage = (top - base)/BY2PG;
109 conf.npage += conf.mem[i].npage;
113 print("conf.mem[] too small\n");
117 * get memory configuration word for a bank
124 return *(ulong *)(KSEG1|MEMCFG0) >> 16;
126 return *(ulong *)(KSEG1|MEMCFG0) & 0xffff;
128 return *(ulong *)(KSEG1|MEMCFG1) >> 16;
130 return *(ulong *)(KSEG1|MEMCFG1) & 0xffff;
138 uintptr base, size, top;
143 * divide memory twixt user pages and kernel.
147 mconf = bank_conf(i);
148 if(!(mconf & 0x2000))
150 base = (mconf & 0xff) << 22;
151 size = ((mconf & 0x1f00) + 0x0100) << 14;
160 char *s = getconf("ConsoleOut");
161 return s != nil && strstr(s, "video()") != nil;
173 machinit(); /* calls clockinit */
188 ckpagemask(PGSZ, BY2PG);
197 panic("schedinit returned");
201 * initialize a processor's mach structure. each processor does this
207 extern void gevector(void); /* l.s */
208 extern void utlbmiss(void);
209 extern void vector0(void);
210 extern void vector180(void);
212 void **sbp = (void*)SPBADDR;
214 m->stb = stlb[m->machno];
216 /* install exception handlers */
217 sbp[0x18/4] = utlbmiss;
218 sbp[0x14/4] = gevector;
220 /* we could install our own vectors directly, but we'll try to play nice */
222 memmove((void*)(KSEG0+0x0), (void*)vector0, 0x80);
223 memmove((void*)(KSEG0+0x180), (void*)vector180, 0x80);
224 icflush((void*)(KSEG0+0x0), 0x80);
225 icflush((void*)(KSEG0+0x180), 0x80);
228 /* Ensure CU1 is off */
243 * These are o.k. because rootinit is null.
244 * Then early kproc's will have a root and dot.
246 up->slash = namec("#/", Atodir, 0, 0);
247 pathclose(up->slash->path);
248 up->slash->path = newpath("/");
249 up->dot = cclone(up->slash);
254 ksetenv("cputype", "mips", 0);
255 snprint(buf, sizeof buf, "mips %s", conffile);
256 ksetenv("terminal", buf, 0);
258 ksetenv("service", "cpu", 0);
260 ksetenv("service", "terminal", 0);
262 ksetenv("bootargs", "tcp", 0);
263 ksetenv("console", "0", 0);
266 ksetenv("usbwait", "0", 0);
267 ksetenv("nousbrc", "1", 0);
272 /* process input for arcs console */
274 kproc("arcs", arcsproc, 0);
276 kproc("alarm", alarmkproc, 0);
292 bootargs(uintptr base)
297 sp = (uchar *) base + BY2PG - sizeof(Tos);
300 av[ac++] = pusharg("boot");
301 sp = (uchar *) ((ulong) sp & ~7);
302 sp -= ROUND((ac + 1) * sizeof(sp), 8) + 4;
304 for(i = 0; i < ac; i++)
305 lsp[i] = av[i] + ((USTKTOP - BY2PG) - (ulong) base);
307 sp += (USTKTOP - BY2PG) - (ulong) base;
320 p->egrp = smalloc(sizeof(Egrp));
322 p->fgrp = dupfgrp(nil);
327 kstrdup(&p->text, "*init*");
328 kstrdup(&p->user, eve);
335 p->sched.pc = (ulong)init0;
336 p->sched.sp = (ulong)p->kstack+KSTACK-Stkheadroom;
337 p->sched.sp = STACKALIGN(p->sched.sp);
342 * Technically, newpage can't be called here because it
343 * should only be called when in a user context as it may
344 * try to sleep if there are no pages available, but that
345 * shouldn't be the case here.
347 s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
349 pg = newpage(1, 0, USTKTOP-BY2PG);
358 s = newseg(SG_TEXT, UTZERO, 1);
361 pg = newpage(1, 0, UTZERO);
364 k = kmap(s->map[0]->pages[0]);
365 memset((void *)VA(k), 0, BY2PG);
366 memmove((ulong*)VA(k), initcode, sizeof initcode);
377 arcs(0x18); /* reboot */
381 reboot(void *, void *, ulong)
390 postnote(up, 1, "sys: odd address", NDebug);
399 memmove(p->fpsave, &initfp, sizeof(FPsave));
402 p->pcycles = -p->kentry;
410 p->kentry = up->kentry;
411 p->pcycles = -p->kentry;
414 switch(up->fpstate & ~FPillegal){
416 savefpregs(up->fpsave);
417 up->fpstate = FPinactive;
420 memmove(p->fpsave, up->fpsave, sizeof(FPsave));
421 p->fpstate = FPinactive;
431 if(p->fpstate == FPactive){
432 if(p->state != Moribund) {
433 savefpregs(p->fpsave);
434 p->fpstate = FPinactive;
464 * set up CPU's mach structure
465 * cpu0's was zeroed in l.s and our stack is in Mach, so don't zero it.
468 m->speed = 150; /* initial guess at MHz */
469 m->hz = m->speed * Mhz;
472 /* set up other configuration parameters */
478 conf.copymode = 0; /* copy on write */
480 kpages = conf.npage - (conf.npage*80)/100;
481 if(kpages > (64*MB + conf.npage*sizeof(Page))/BY2PG){
482 kpages = (64*MB + conf.npage*sizeof(Page))/BY2PG;
483 kpages += (conf.nproc*KSTACK)/BY2PG;
485 conf.upages = conf.npage - kpages;
486 conf.ialloc = (kpages/2)*BY2PG;
489 kpages -= conf.upages*sizeof(Page)
490 + conf.nproc*sizeof(Proc)
491 + conf.nimage*sizeof(Image)
493 + conf.nswppo*sizeof(Page*);
494 mainmem->maxsize = kpages;
495 imagmem->maxsize = kpages;
496 // mainmem->flags |= POOL_PARANOIA;
500 setupwatchpts(Proc *, Watchpt *, int n)
503 error("no watchpoints");
507 isaconfig(char *, int, ISAConf*)