#include "u.h"
+#include "tos.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
-#include "init.h"
#include <pool.h>
-#include "reboot.h"
+#include "rebootcode.i"
/*
* Where configuration info is left for the loaded programme.
uintptr kseg0 = KZERO;
Mach* machaddr[MAXMACH];
-/*
- * Option arguments from the command line.
- * oargv[0] is the boot file.
- * Optionsinit() is called from multiboot()
- * or some other machine-dependent place
- * to set it all up.
- */
-static int oargc;
-static char* oargv[20];
-static char oargb[128];
-static int oargblen;
-static char oenv[4096];
-
-static uintptr sp; /* XXX - must go - user stack of init proc */
-
int vflag;
int normalprint;
char debug[256];
}
}
-static void
-optionsinit(char* s)
-{
- char *o;
-
- strcpy(oenv, "");
- o = strecpy(oargb, oargb+sizeof(oargb), s)+1;
- if(getenv("bootargs", o, o - oargb) != nil)
- *(o-1) = ' ';
-
- oargblen = strlen(oargb);
- oargc = tokenize(oargb, oargv, nelem(oargv)-1);
- oargv[oargc] = nil;
-}
-
-char*
-getenv(char* name, char* buf, int n)
-{
- char *e, *p, *q;
-
- p = oenv;
- while(*p != 0){
- if((e = strchr(p, '=')) == nil)
- break;
- for(q = name; p < e; p++){
- if(*p != *q)
- break;
- q++;
- }
- if(p == e && *q == 0){
- strecpy(buf, buf+n, e+1);
- return buf;
- }
- p += strlen(p)+1;
- }
-
- return nil;
-}
-
void
main(void)
{
machinit();
mmuinit();
- optionsinit("/boot/boot boot");
quotefmtinstall();
/* want plan9.ini to be able to affect memory sizing in confinit */
// i8250console(); /* too early; see init0 */
pageinit();
- swapinit();
userinit();
schedinit();
}
conf.nmach = 1;
- active.machs = 1;
+ active.machs[0] = 1;
active.exiting = 0;
up = nil;
}
-static void
-shutdown(int ispanic)
-{
- int ms, once;
-
- lock(&active);
- if(ispanic)
- active.ispanic = ispanic;
- else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
- active.ispanic = 0;
- once = active.machs & (1<<m->machno);
- active.machs &= ~(1<<m->machno);
- active.exiting = 1;
- unlock(&active);
-
- if(once)
- iprint("cpu%d: exiting\n", m->machno);
- spllo();
- for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
- delay(TK2MS(2));
- if(active.machs == 0 && consactive() == 0)
- break;
- }
- delay(1000);
-}
-
/*
* exit kernel either on a panic or user request
*/
void
-exit(int code)
+exit(int)
{
- shutdown(code);
+ cpushutdown();
splhi();
archreboot();
}
int
isaconfig(char *class, int ctlrno, ISAConf *isa)
{
- char cc[32], *p;
+ char cc[32], *p, *x;
int i;
snprint(cc, sizeof cc, "%s%d", class, ctlrno);
if(p == nil)
return 0;
+ x = nil;
+ kstrdup(&x, p);
+ p = x;
+
isa->type = "";
isa->nopt = tokenize(p, isa->opt, NISAOPT);
for(i = 0; i < isa->nopt; i++){
{
void (*f)(ulong, ulong, ulong);
- print("starting reboot...");
writeconf();
- shutdown(0);
-
- /*
- * should be the only processor running now
- */
-
- print("reboot entry %#lux code %#lux size %ld\n",
- PADDR(entry), PADDR(code), size);
- delay(100);
+ cpushutdown();
/* turn off buffered serial console */
serialoq = nil;
/* off we go - never to return */
(*f)(PADDR(entry), PADDR(code), size);
-
- iprint("loaded kernel returned!\n");
- delay(1000);
- archreboot();
}
/*
void
init0(void)
{
+ char buf[2*KNAMELEN], **sp;
int i;
- char buf[2*KNAMELEN];
-
- up->nerrlab = 0;
- coherence();
- spllo();
-
- /*
- * These are o.k. because rootinit is null.
- * Then early kproc's will have a root and dot.
- */
- up->slash = namec("#/", Atodir, 0, 0);
- pathclose(up->slash->path);
- up->slash->path = newpath("/");
- up->dot = cclone(up->slash);
dmatest(); /* needs `up' set, so can't do it earlier */
chandevinit();
poperror();
}
kproc("alarm", alarmkproc, 0);
- touser(sp);
-}
-
-static void
-bootargs(uintptr base)
-{
- int i;
- ulong ssize;
- char **av, *p;
- /*
- * Push the boot args onto the stack.
- * The initial value of the user stack must be such
- * that the total used is larger than the maximum size
- * of the argument list checked in syscall.
- */
- i = oargblen+1;
- p = UINT2PTR(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i));
- memmove(p, oargb, i);
-
- /*
- * Now push argc and the argv pointers.
- * This isn't strictly correct as the code jumped to by
- * touser in init9.s calls startboot (port/initcode.c) which
- * expects arguments
- * startboot(char *argv0, char **argv)
- * not the usual (int argc, char* argv[]), but argv0 is
- * unused so it doesn't matter (at the moment...).
- */
- av = (char**)(p - (oargc+2)*sizeof(char*));
- ssize = base + BY2PG - PTR2UINT(av);
- *av++ = (char*)oargc;
- for(i = 0; i < oargc; i++)
- *av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
- *av = nil;
-
- /*
- * Leave space for the return PC of the
- * caller of initcode.
- */
- sp = USTKTOP - ssize - sizeof(void*);
-}
-
-/*
- * create the first process
- */
-void
-userinit(void)
-{
- Proc *p;
- Segment *s;
- KMap *k;
- Page *pg;
-
- /* no processes yet */
- up = nil;
-
- p = newproc();
- p->pgrp = newpgrp();
- p->egrp = smalloc(sizeof(Egrp));
- p->egrp->ref = 1;
- p->fgrp = dupfgrp(nil);
- p->rgrp = newrgrp();
- p->procmode = 0640;
-
- kstrdup(&eve, "");
- kstrdup(&p->text, "*init*");
- kstrdup(&p->user, eve);
-
- /*
- * Kernel Stack
- */
- p->sched.pc = PTR2UINT(init0);
- p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
- p->sched.sp = STACKALIGN(p->sched.sp);
-
- /*
- * User Stack
- *
- * Technically, newpage can't be called here because it
- * should only be called when in a user context as it may
- * try to sleep if there are no pages available, but that
- * shouldn't be the case here.
- */
- s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
- s->flushme++;
- p->seg[SSEG] = s;
- pg = newpage(1, 0, USTKTOP-BY2PG);
- segpage(s, pg);
- k = kmap(pg);
- bootargs(VA(k));
- kunmap(k);
-
- /*
- * Text
- */
- s = newseg(SG_TEXT, UTZERO, 1);
- p->seg[TSEG] = s;
- pg = newpage(1, 0, UTZERO);
- memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
- segpage(s, pg);
- k = kmap(s->map[0]->pages[0]);
- memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
- kunmap(k);
-
- ready(p);
+ sp = (char**)(USTKTOP - sizeof(Tos) - 8 - sizeof(sp[0])*4);
+ sp[3] = sp[2] = sp[1] = nil;
+ strcpy(sp[0] = (char*)&sp[4], "boot");
+ touser((uintptr)sp);
}
Conf conf; /* XXX - must go - gag */
memmove(conf.mem, omapmem, sizeof(omapmem));
conf.npage = 0;
- pa = PADDR(PGROUND(PTR2UINT(end)));
+ pa = PADDR(PGROUND((uintptr)end));
/*
* we assume that the kernel is at the beginning of one of the
/*
* Guess how much is taken by the large permanent
- * datastructures. Mntcache and Mntrpc are not accounted for
- * (probably ~300KB).
+ * datastructures. Mntcache and Mntrpc are not accounted for.
*/
kpages = conf.npage - conf.upages;
kpages *= BY2PG;
{
return cas32(addr, old, new);
}
+
+void
+setupwatchpts(Proc *, Watchpt *, int n)
+{
+ if(n > 0)
+ error("no watchpoints");
+}