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;
166 machinit(); /* calls clockinit */
176 ckpagemask(PGSZ, BY2PG);
187 panic("schedinit returned");
191 * initialize a processor's mach structure. each processor does this
197 extern void gevector(void); /* l.s */
198 extern void utlbmiss(void);
199 extern void vector0(void);
200 extern void vector180(void);
202 void **sbp = (void*)SPBADDR;
204 m->stb = stlb[m->machno];
206 /* install exception handlers */
207 sbp[0x18/4] = utlbmiss;
208 sbp[0x14/4] = gevector;
210 /* we could install our own vectors directly, but we'll try to play nice */
212 memmove((void*)(KSEG0+0x0), (void*)vector0, 0x80);
213 memmove((void*)(KSEG0+0x180), (void*)vector180, 0x80);
214 icflush((void*)(KSEG0+0x0), 0x80);
215 icflush((void*)(KSEG0+0x180), 0x80);
218 /* Ensure CU1 is off */
233 * These are o.k. because rootinit is null.
234 * Then early kproc's will have a root and dot.
236 up->slash = namec("#/", Atodir, 0, 0);
237 pathclose(up->slash->path);
238 up->slash->path = newpath("/");
239 up->dot = cclone(up->slash);
244 ksetenv("cputype", "mips", 0);
245 snprint(buf, sizeof buf, "mips %s", conffile);
246 ksetenv("terminal", buf, 0);
248 ksetenv("service", "cpu", 0);
250 ksetenv("service", "terminal", 0);
252 ksetenv("bootargs", "tcp", 0);
254 /* make kbdfs attach to /dev/eia0 arcs console */
255 ksetenv("console", "0", 0);
258 ksetenv("usbwait", "0", 0);
259 ksetenv("nousbrc", "1", 0);
264 /* process input for arcs console */
265 kproc("arcs", arcsproc, 0);
267 kproc("alarm", alarmkproc, 0);
283 bootargs(uintptr base)
288 sp = (uchar *) base + BY2PG - sizeof(Tos);
291 av[ac++] = pusharg("boot");
292 sp = (uchar *) ((ulong) sp & ~7);
293 sp -= ROUND((ac + 1) * sizeof(sp), 8) + 4;
295 for(i = 0; i < ac; i++)
296 lsp[i] = av[i] + ((USTKTOP - BY2PG) - (ulong) base);
298 sp += (USTKTOP - BY2PG) - (ulong) base;
311 p->egrp = smalloc(sizeof(Egrp));
313 p->fgrp = dupfgrp(nil);
318 kstrdup(&p->text, "*init*");
319 kstrdup(&p->user, eve);
326 p->sched.pc = (ulong)init0;
327 p->sched.sp = (ulong)p->kstack+KSTACK-Stkheadroom;
328 p->sched.sp = STACKALIGN(p->sched.sp);
333 * Technically, newpage can't be called here because it
334 * should only be called when in a user context as it may
335 * try to sleep if there are no pages available, but that
336 * shouldn't be the case here.
338 s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
340 pg = newpage(1, 0, USTKTOP-BY2PG);
349 s = newseg(SG_TEXT, UTZERO, 1);
352 pg = newpage(1, 0, UTZERO);
355 k = kmap(s->map[0]->pages[0]);
356 memset((void *)VA(k), 0, BY2PG);
357 memmove((ulong*)VA(k), initcode, sizeof initcode);
368 arcs(0x18); /* reboot */
372 reboot(void *, void *, ulong)
381 postnote(up, 1, "sys: odd address", NDebug);
393 p->pcycles = -p->kentry;
401 p->kentry = up->kentry;
402 p->pcycles = -p->kentry;
405 switch(up->fpstate & ~FPillegal){
407 savefpregs(&up->fpsave);
408 up->fpstate = FPinactive;
411 p->fpsave = up->fpsave;
412 p->fpstate = FPinactive;
422 if(p->fpstate == FPactive){
423 if(p->state != Moribund) {
424 savefpregs(&p->fpsave);
425 p->fpstate = FPinactive;
455 * set up CPU's mach structure
456 * cpu0's was zeroed in l.s and our stack is in Mach, so don't zero it.
459 m->speed = 150; /* initial guess at MHz */
460 m->hz = m->speed * Mhz;
463 /* set up other configuration parameters */
469 conf.copymode = 0; /* copy on write */
471 kpages = conf.npage - (conf.npage*80)/100;
472 if(kpages > (64*MB + conf.npage*sizeof(Page))/BY2PG){
473 kpages = (64*MB + conf.npage*sizeof(Page))/BY2PG;
474 kpages += (conf.nproc*KSTACK)/BY2PG;
476 conf.upages = conf.npage - kpages;
477 conf.ialloc = (kpages/2)*BY2PG;
480 kpages -= conf.upages*sizeof(Page)
481 + conf.nproc*sizeof(Proc)
482 + conf.nimage*sizeof(Image)
484 + conf.nswppo*sizeof(Page*);
485 mainmem->maxsize = kpages;
486 // mainmem->flags |= POOL_PARANOIA;