123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #include "u.h"
- #include "../port/lib.h"
- #include "mem.h"
- #include "dat.h"
- #include "fns.h"
- #include "../port/error.h"
- #include "io.h"
- #include "version.h"
- Mach *m = (Mach*)MACHADDR;
- Proc *up = 0;
- Vectorpage *page0 = (Vectorpage*)KZERO; /* doubly-mapped to AIVECADDR */
- Conf conf;
- extern ulong kerndate;
- extern int cflag;
- extern int main_pool_pcnt;
- extern int heap_pool_pcnt;
- extern int image_pool_pcnt;
- ulong cpuidlecount;
- static void
- poolsizeinit(void)
- {
- ulong nb;
- nb = conf.npage*BY2PG;
- poolsize(mainmem, (nb*main_pool_pcnt)/100, 0);
- poolsize(heapmem, (nb*heap_pool_pcnt)/100, 0);
- poolsize(imagmem, (nb*image_pool_pcnt)/100, 1);
- }
- void
- main(void)
- {
- memset(edata, 0, end-edata); /* clear the BSS */
- memset(m, 0, sizeof(Mach)); /* clear the mach struct */
- conf.nmach = 1;
- archreset();
- dmareset();
- quotefmtinstall();
- confinit();
- xinit();
- mmuinit();
- poolinit();
- poolsizeinit();
- trapinit();
- clockinit();
- printinit();
- screeninit();
- procinit();
- links();
- chandevreset();
- eve = strdup("inferno");
- archconsole();
- kbdinit();
- print("%ld MHz id %8.8lux\n", (m->cpuhz+500000)/1000000, getcpuid());
- print("\nInferno %s\n", VERSION);
- print("Vita Nuova\n");
- print("conf %s (%lud) jit %d\n\n",conffile, kerndate, cflag);
- userinit();
- schedinit();
- }
- void
- reboot(void)
- {
- exit(0);
- }
- void
- halt(void)
- {
- spllo();
- print("cpu halted\n");
- for(;;){
- /* nothing to do */
- }
- }
- void
- confinit(void)
- {
- ulong base;
- archconfinit();
- base = PGROUND((ulong)end);
- conf.base0 = base;
- conf.base1 = 0;
- conf.npage1 = 0;
- conf.npage0 = (conf.topofmem - base)/BY2PG;
- conf.npage = conf.npage0 + conf.npage1;
- conf.ialloc = (((conf.npage*(main_pool_pcnt))/100)/2)*BY2PG;
- conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
- conf.nmach = 1;
- }
- void
- init0(void)
- {
- Osenv *o;
- char buf[2*KNAMELEN];
- up->nerrlab = 0;
- spllo();
- if(waserror())
- panic("init0 %r");
- /*
- * These are o.k. because rootinit is null.
- * Then early kproc's will have a root and dot.
- */
- o = up->env;
- o->pgrp->slash = namec("#/", Atodir, 0, 0);
- cnameclose(o->pgrp->slash->name);
- o->pgrp->slash->name = newcname("/");
- o->pgrp->dot = cclone(o->pgrp->slash);
- chandevinit();
- if(!waserror()){
- ksetenv("cputype", "arm", 0);
- snprint(buf, sizeof(buf), "arm %s", conffile);
- ksetenv("terminal", buf, 0);
- poperror();
- }
- poperror();
- disinit("/osinit.dis");
- }
- void
- userinit(void)
- {
- Proc *p;
- Osenv *o;
- p = newproc();
- o = p->env;
- o->fgrp = newfgrp(nil);
- o->pgrp = newpgrp();
- o->egrp = newegrp();
- kstrdup(&o->user, eve);
- strcpy(p->text, "interp");
- p->fpstate = FPINIT;
- /*
- * Kernel Stack
- *
- * N.B. The -12 for the stack pointer is important.
- * 4 bytes for gotolabel's return PC
- */
- p->sched.pc = (ulong)init0;
- p->sched.sp = (ulong)p->kstack+KSTACK-8;
- ready(p);
- }
- void
- exit(int inpanic)
- {
- up = 0;
- /* Shutdown running devices */
- chandevshutdown();
- if(inpanic && 0){
- print("Hit the reset button\n");
- for(;;)
- clockpoll();
- }
- archreboot();
- }
- static void
- linkproc(void)
- {
- spllo();
- if (waserror())
- print("error() underflow: %r\n");
- else
- (*up->kpfun)(up->arg);
- pexit("end proc", 1);
- }
- void
- kprocchild(Proc *p, void (*func)(void*), void *arg)
- {
- p->sched.pc = (ulong)linkproc;
- p->sched.sp = (ulong)p->kstack+KSTACK-8;
- p->kpfun = func;
- p->arg = arg;
- }
- void
- idlehands(void)
- {
- cpuidlecount++;
- INTRREG->iccr = 1; /* only unmasked interrupts will stop idle mode */
- idle();
- }
- /* stubs */
- void
- setfsr(ulong)
- {
- }
- ulong
- getfsr()
- {
- return 0;
- }
- void
- setfcr(ulong)
- {
- }
- ulong
- getfcr()
- {
- return 0;
- }
- void
- fpinit(void)
- {
- }
- void
- FPsave(void*)
- {
- }
- void
- FPrestore(void*)
- {
- }
|