#include "u.h"
+#include "tos.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
-#include "tos.h"
#include "ureg.h"
-#include "init.h"
#include "pool.h"
-#include "reboot.h"
+#include "rebootcode.i"
Mach *m;
Conf conf;
trapinit0();
i8253init();
cpuidentify();
+ meminit0();
+ archinit();
meminit();
ramdiskinit();
confinit();
xinit();
- archinit();
bootscreeninit();
if(i8237alloc != nil)
i8237alloc();
{
char buf[2*KNAMELEN], **sp;
- up->nerrlab = 0;
-
- 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);
-
chandevinit();
if(!waserror()){
touser(sp);
}
-void
-userinit(void)
-{
- void *v;
- Proc *p;
- Segment *s;
- Page *pg;
-
- 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);
-
- procsetup(p);
-
- /*
- * Kernel Stack
- *
- * N.B. make sure there's enough space for syscall to check
- * for valid args and
- * 4 bytes for gotolabel's return PC
- */
- p->sched.pc = (ulong)init0;
- p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);
-
- /*
- * User Stack
- *
- * N.B. cannot call newpage() with clear=1, because pc kmap
- * requires up != nil. use tmpmap instead.
- */
- s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
- p->seg[SSEG] = s;
- pg = newpage(0, 0, USTKTOP-BY2PG);
- segpage(s, pg);
- v = tmpmap(pg);
- memset(v, 0, BY2PG);
- tmpunmap(v);
-
- /*
- * Text
- */
- s = newseg(SG_TEXT, UTZERO, 1);
- s->flushme++;
- p->seg[TSEG] = s;
- pg = newpage(0, 0, UTZERO);
- pg->txtflush = ~0;
- segpage(s, pg);
- v = tmpmap(pg);
- memset(v, 0, BY2PG);
- memmove(v, initcode, sizeof initcode);
- tmpunmap(v);
-
- ready(p);
-}
-
void
confinit(void)
{
p->fpstate = FPinit;
fpoff();
- cycles(&p->kentry);
- p->pcycles = -p->kentry;
-
memset(p->gdt, 0, sizeof(p->gdt));
- p->ldt = nil;
p->nldt = 0;
+ /* clear debug registers */
memset(p->dr, 0, sizeof(p->dr));
+ if(m->dr7 != 0){
+ m->dr7 = 0;
+ putdr7(0);
+ }
+
+ cycles(&p->kentry);
+ p->pcycles = -p->kentry;
}
void
memmove(p->fpsave, up->fpsave, sizeof(FPsave));
p->fpstate = FPinactive;
}
-
- /* clear debug registers */
- memset(p->dr, 0, sizeof(p->dr));
splx(s);
}
{
uvlong t;
+ cycles(&t);
+ p->kentry -= t;
+ p->pcycles += t;
+
/* we could just always putdr7(0) but accessing DR7 might be slow in a VM */
if(m->dr7 != 0){
m->dr7 = 0;
putdr7(0);
}
-
- cycles(&t);
- p->kentry -= t;
- p->pcycles += t;
+ if(p->state == Moribund)
+ p->dr[7] = 0;
if(p->fpstate == FPactive){
if(p->state == Moribund)
mmuflushtlb(PADDR(m->pdb));
}
-void
-reboot(void *entry, void *code, ulong size)
+static void
+rebootjump(uintptr entry, uintptr code, ulong size)
{
- void (*f)(ulong, ulong, ulong);
+ void (*f)(uintptr, uintptr, ulong);
ulong *pdb;
- writeconf();
- vmxshutdown();
-
- /*
- * the boot processor is cpu0. execute this function on it
- * so that the new kernel has the same cpu0. this only matters
- * because the hardware has a notion of which processor was the
- * boot processor and we look at it at start up.
- */
- if (m->machno != 0) {
- procwired(up, 0);
- sched();
- }
- cpushutdown();
-
splhi();
-
- /* turn off buffered serial console */
- serialoq = nil;
-
- /* shutdown devices */
- chandevshutdown();
arch->introff();
/*
/* off we go - never to return */
coherence();
- (*f)((ulong)entry & ~0xF0000000UL, PADDR(code), size);
+ (*f)(entry, code, size);
+ for(;;);
}
exit(int)
{
cpushutdown();
+ if(m->machno)
+ rebootjump(0, 0, 0);
arch->reset();
}
+
+void
+reboot(void *entry, void *code, ulong size)
+{
+ writeconf();
+ vmxshutdown();
+
+ /*
+ * the boot processor is cpu0. execute this function on it
+ * so that the new kernel has the same cpu0. this only matters
+ * because the hardware has a notion of which processor was the
+ * boot processor and we look at it at start up.
+ */
+ if (m->machno != 0) {
+ procwired(up, 0);
+ sched();
+ }
+ cpushutdown();
+ delay(1000);
+ splhi();
+
+ /* turn off buffered serial console */
+ serialoq = nil;
+
+ /* shutdown devices */
+ chandevshutdown();
+
+ rebootjump((ulong)entry & ~0xF0000000UL, PADDR(code), size);
+}