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/bcm64 | |
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/bcm64')
-rw-r--r-- | sys/src/9/bcm64/main.c | 83 | ||||
-rw-r--r-- | sys/src/9/bcm64/mkfile | 36 | ||||
-rw-r--r-- | sys/src/9/bcm64/trap.c | 3 |
3 files changed, 12 insertions, 110 deletions
diff --git a/sys/src/9/bcm64/main.c b/sys/src/9/bcm64/main.c index c76f388c8..6679d75d7 100644 --- a/sys/src/9/bcm64/main.c +++ b/sys/src/9/bcm64/main.c @@ -6,9 +6,8 @@ #include "fns.h" #include "../port/error.h" #include "io.h" -#include "init.h" #include "sysreg.h" -#include "reboot.h" +#include "rebootcode.i" #include <pool.h> #include <libsec.h> @@ -23,17 +22,6 @@ init0(void) { 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()){ @@ -57,76 +45,7 @@ init0(void) sp[3] = sp[2] = sp[1] = nil; strcpy(sp[1] = (char*)&sp[4], "boot"); sp[0] = (void*)&sp[1]; - touser((uintptr)sp); - - assert(0); /* shouldn't have returned */ -} - -/* - * 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 = (uintptr)init0; - p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr); - p->sched.sp = STACKALIGN(p->sched.sp); - *(void**)p->sched.sp = kproc; // fake - - /* - * 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); - memset((void*)VA(k), 0, BY2PG); - kunmap(k); - - /* - * Text - */ - s = newseg(SG_TEXT, UTZERO, 1); - p->seg[TSEG] = s; - pg = newpage(1, 0, UTZERO); - pg->txtflush = ~0; - segpage(s, pg); - k = kmap(pg); - memmove((void*)VA(k), initcode, sizeof initcode); - kunmap(k); - - ready(p); } void diff --git a/sys/src/9/bcm64/mkfile b/sys/src/9/bcm64/mkfile index 51ca9bedd..6177f4b70 100644 --- a/sys/src/9/bcm64/mkfile +++ b/sys/src/9/bcm64/mkfile @@ -37,6 +37,7 @@ PORT=\ taslock.$O\ tod.$O\ xalloc.$O\ + userinit.$O\ OBJ=\ l.$O\ @@ -99,10 +100,10 @@ REPCC=`{../port/mkfilelist ../bcm} arch.$O clock.$O fpiarm.$O main.$O mmu.$O screen.$O syscall.$O trap.$O: \ /$objtype/include/ureg.h - -l.$O cache.v8.$O mmu.$O: mem.h -l.$O cache.v8.$O archbcm3.$O clock.$O fpu.$O trap.$O mmu.$O: sysreg.h -main.$O: reboot.h +trap.$O main.$O: /sys/include/tos.h +l.$O cache.v8.$O mmu.$O rebootcode.$O: mem.h +l.$O cache.v8.$O archbcm3.$O clock.$O fpu.$O trap.$O mmu.$O rebootcode.$O: sysreg.h +main.$O: rebootcode.i devmouse.$O mouse.$O screen.$O: screen.h usbdwc.$O: dwcotg.h ../port/usb.h @@ -114,26 +115,11 @@ screen.h:D: ../bcm/screen.h dwcotg.h:D: ../bcm/dwcotg.h echo '#include "../bcm/dwcotg.h"' > dwcotg.h -init.h:D: ../port/initcode.c init9.s - $CC ../port/initcode.c - $AS init9.s - $LD -l -R1 -s -o init.out init9.$O initcode.$O /$objtype/lib/libc.a - {echo 'uchar initcode[]={' - xd -1x <init.out | - sed -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' - echo '};'} > init.h - -reboot.h:D: rebootcode.s cache.v8.$O mem.h sysreg.h - $AS rebootcode.s - # -T arg is REBOOTADDR - $LD -l -o reboot.out -H6 -R1 -T0x1c00 rebootcode.$O cache.v8.$O - {echo 'uchar rebootcode[]={' - xd -1x reboot.out | - sed -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' - echo '};'} > reboot.h - -errstr.h:D: ../port/mkerrstr ../port/error.h - rc ../port/mkerrstr > errstr.h +initcode.out: init9.$O initcode.$O /$objtype/lib/libc.a + $LD -l -R1 -s -o $target $prereq + +rebootcode.out: rebootcode.$O cache.v8.$O + $LD -l -H6 -R1 -T0x1c00 -s -o $target $prereq $CONF.clean: - rm -rf $p$CONF s$p$CONF errstr.h reboot.h screen.h dwcotg.h $CONF.c boot$CONF.c + rm -rf $p$CONF s$p$CONF errstr.h screen.h dwcotg.h $CONF.c boot$CONF.c diff --git a/sys/src/9/bcm64/trap.c b/sys/src/9/bcm64/trap.c index 3d74362a3..3c683765b 100644 --- a/sys/src/9/bcm64/trap.c +++ b/sys/src/9/bcm64/trap.c @@ -628,9 +628,6 @@ forkchild(Proc *p, Ureg *ureg) cureg = (Ureg*) (p->sched.sp + 16); memmove(cureg, ureg, sizeof(Ureg)); cureg->r0 = 0; - - p->psstate = 0; - p->insyscall = 0; } uintptr |