diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-01-26 19:01:36 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-01-26 19:01:36 +0100 |
commit | 8d51e7fa1a1dbcbde513c2b756d504c879598907 (patch) | |
tree | 4cd1a3aaab346ac990bc9058e8cc4928258be6ae /sys/src/9/mtx | |
parent | 60bb408acca3b48b17f9158132849b894ad9f234 (diff) |
kernel: implement portable userinit() and simplify process creation
replace machine specific userinit() by a portable
implemntation that uses kproc() to create the first
process. the initcode text is mapped using kmap(),
so there is no need for machine specific tmpmap()
functions.
initcode stack preparation should be done in init0()
where the stack is mapped and can be accessed directly.
replacing the machine specific userinit() allows some
big simplifications as sysrfork() and kproc() are now
the only callers of newproc() and we can avoid initializing
fields that we know are being initialized by these
callers.
rename autogenerated init.h and reboot.h headers.
the initcode[] and rebootcode[] blobs are now in *.i
files and hex generation was moved to portmkfile. the
machine specific mkfile only needs to specify how to
build rebootcode.out and initcode.out.
Diffstat (limited to 'sys/src/9/mtx')
-rw-r--r-- | sys/src/9/mtx/main.c | 90 | ||||
-rw-r--r-- | sys/src/9/mtx/mkfile | 14 | ||||
-rw-r--r-- | sys/src/9/mtx/trap.c | 4 |
3 files changed, 8 insertions, 100 deletions
diff --git a/sys/src/9/mtx/main.c b/sys/src/9/mtx/main.c index fb4132f37..71c31ce91 100644 --- a/sys/src/9/mtx/main.c +++ b/sys/src/9/mtx/main.c @@ -1,10 +1,10 @@ #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" Conf conf; @@ -101,23 +101,8 @@ getconf(char *name) void init0(void) { -// char **p, *q, name[KNAMELEN]; -// int n; char buf[2*KNAMELEN]; - 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()){ @@ -128,82 +113,11 @@ init0(void) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); - -/* - for(p = confenv; *p; p++) { - q = strchr(p[0], '='); - if(q == 0) - continue; - n = q-p[0]; - if(n >= KNAMELEN) - n = KNAMELEN-1; - memmove(name, p[0], n); - name[n] = 0; - if(name[0] != '*') - ksetenv(name, q+1, 0); - ksetenv(name, q+1, 1); - } -*/ poperror(); } kproc("alarm", alarmkproc, 0); kproc("mmusweep", mmusweep, 0); - touser((void*)(USTKTOP-8)); -} - -void -userinit(void) -{ - Proc *p; - Segment *s; - KMap *k; - 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); - - 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-(sizeof(Sargs)+BY2WD); - - /* - * User Stack - */ - s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG); - p->seg[SSEG] = s; - pg = newpage(1, 0, USTKTOP-BY2PG); - segpage(s, pg); - - /* - * Text - */ - s = newseg(SG_TEXT, UTZERO, 1); - s->flushme++; - p->seg[TSEG] = s; - pg = newpage(1, 0, UTZERO); - pg->txtflush = ~0; - segpage(s, pg); - k = kmap(s->map[0]->pages[0]); - memmove((ulong*)VA(k), initcode, sizeof initcode); - kunmap(k); - - ready(p); + touser((void*)(USTKTOP - sizeof(Tos))); } /* still to do */ diff --git a/sys/src/9/mtx/mkfile b/sys/src/9/mtx/mkfile index 10bbb6e02..797e96091 100644 --- a/sys/src/9/mtx/mkfile +++ b/sys/src/9/mtx/mkfile @@ -36,6 +36,7 @@ PORT=\ tod.$O\ xalloc.$O\ random.$O\ + userinit.$O\ OBJ=\ l.$O\ @@ -79,15 +80,12 @@ install:V: $p$CONF clock.$O: /$objtype/include/ureg.h devether.$O: /$objtype/include/ureg.h -main.$O: /$objtype/include/ureg.h errstr.h init.h -trap.$O: /$objtype/include/ureg.h +main.$O: /$objtype/include/ureg.h errstr.h +trap.$O: /$objtype/include/ureg.h /sys/include/tos.h $ETHER: ../port/etherif.h ../port/netif.h -init.h: initcode /sys/src/libc/9syscall/sys.h +initcode.$O: initcode /sys/src/libc/9syscall/sys.h $AS initcode - $LD -l -s -R4 -o init.out initcode.$O -lc - {echo 'uchar initcode[]={' - xd -r -1x init.out | - sed -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' - echo '};'} > init.h +initcode.out: initcode.$O + $LD -l -R4 -s -o $target $prereq diff --git a/sys/src/9/mtx/trap.c b/sys/src/9/mtx/trap.c index 3072e0849..5408a6fe2 100644 --- a/sys/src/9/mtx/trap.c +++ b/sys/src/9/mtx/trap.c @@ -560,10 +560,6 @@ forkchild(Proc *p, Ureg *ur) cur = (Ureg*)(p->sched.sp+2*BY2WD); memmove(cur, ur, sizeof(Ureg)); cur->r3 = 0; - - /* Things from bottom of syscall we never got to execute */ - p->psstate = 0; - p->insyscall = 0; } uintptr |