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/xen | |
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/xen')
-rw-r--r-- | sys/src/9/xen/main.c | 127 | ||||
-rw-r--r-- | sys/src/9/xen/mkfile | 27 | ||||
-rw-r--r-- | sys/src/9/xen/trap.c | 4 |
3 files changed, 18 insertions, 140 deletions
diff --git a/sys/src/9/xen/main.c b/sys/src/9/xen/main.c index e28716a28..19af3a820 100644 --- a/sys/src/9/xen/main.c +++ b/sys/src/9/xen/main.c @@ -1,14 +1,13 @@ #include "u.h" +#include "tos.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "io.h" #include "ureg.h" -#include "init.h" #include "pool.h" -#include "reboot.h" -#include <tos.h> +#include "rebootcode.i" Mach *m; @@ -16,16 +15,10 @@ Mach *m; #define BOOTARGSLEN (sizeof xenstart->cmd_line) #define MAXCONF 64 -enum { - /* space for syscall args, return PC, top-of-stack struct */ - Ustkheadroom = sizeof(Sargs) + sizeof(uintptr) + sizeof(Tos), -}; - Conf conf; char *confname[MAXCONF]; char *confval[MAXCONF]; int nconf; -uchar *sp; /* user stack of init proc */ int idle_spin; static void @@ -152,21 +145,8 @@ machinit(void) void init0(void) { + char buf[2*KNAMELEN], **sp; int i; - 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(); @@ -186,104 +166,13 @@ init0(void) } poperror(); } - kproc("alarm", alarmkproc, 0); - touser(sp); -} -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; - fpoff(); - - /* - * 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 - */ - s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG); - 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); - 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); -} - -uchar * -pusharg(char *p) -{ - int n; - - n = strlen(p)+1; - sp -= n; - memmove(sp, p, n); - return sp; -} - -void -bootargs(ulong base) -{ - int i, ac; - uchar *av[32]; - uchar **lsp; - - sp = (uchar*)base + BY2PG - Ustkheadroom; - - ac = 0; - av[ac++] = pusharg("boot"); - av[ac++] = pusharg("-D"); - - /* 4 byte word align stack */ - sp = (uchar*)((ulong)sp & ~3); - - /* build argc, argv on stack */ - sp -= (ac+1)*sizeof(sp); - lsp = (uchar**)sp; - for(i = 0; i < ac; i++) - *lsp++ = av[i] + ((USTKTOP - BY2PG) - base); - *lsp = 0; - sp += (USTKTOP - BY2PG) - base - sizeof(ulong); + sp = (char**)(USTKTOP - sizeof(Tos) - 8 - sizeof(sp[0])*4); + sp[3] = sp[2] = nil; + strcpy(sp[1] = (char*)&sp[4], "boot"); + sp[0] = nil; + touser(sp); } char* diff --git a/sys/src/9/xen/mkfile b/sys/src/9/xen/mkfile index 4649210aa..9fc3131a7 100644 --- a/sys/src/9/xen/mkfile +++ b/sys/src/9/xen/mkfile @@ -37,6 +37,7 @@ PORT=\ taslock.$O\ tod.$O\ xalloc.$O\ + userinit.$O\ XEN=\ xengrant.$O\ @@ -131,8 +132,8 @@ REPCC=`{../port/mkfilelist ../pc} # we inherited these.. revisit. $ETHER: ../port/etherif.h ../port/netif.h $SDEV: ../port/sd.h -main.$O: init.h reboot.h -trap.$O: /sys/include/tos.h +main.$O: rebootcode.i +main.$O trap.$O: /sys/include/tos.h %.$O: /$objtype/include/u.h ../port/lib.h mem.h dat.h fns.h io.h ../port/error.h ../port/portdat.h ../port/portfns.h xendat.h xendefs.h @@ -146,22 +147,14 @@ xendat.h: cat xen-public/^($XENHEADERS) } | \ ./cppx > $target -init.h: ../port/initcode.c ../pc/init9.c - $CC ../port/initcode.c - $CC ../pc/init9.c - $LD -l -R1 -o init.out init9.$O initcode.$O /386/lib/libc.a - {echo 'uchar initcode[]={' - strip -o /fd/1 init.out | xd -1x | - sed -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' - echo '};'} > init.h +initcode.out: init9.$O initcode.$O /$objtype/lib/libc.a + $LD -l -R1 -s -o $target $prereq -reboot.h: ../pc/rebootcode.s +rebootcode.$O: ../pc/rebootcode.s mem.h $AS ../pc/rebootcode.s - $LD -l -s -T0x1000 -R4 -o reboot.out rebootcode.$O - {echo 'uchar rebootcode[]={' - xd -1x reboot.out | - sed -e '1,2d' -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' - echo '};'} > reboot.h + +rebootcode.out: rebootcode.$O + $LD -l -R4 -s -o $target -T0x1000 $prereq acid:V: $CC -a -w main.c>acid @@ -176,6 +169,6 @@ xenbin.$cputype xenelf.$cputype: utilmkfile mk -f utilmkfile $target %.clean:V: - rm -f $stem.c [9bz]$stem [9bz]$stem.gz 9$stem.elf boot$stem.* reboot.h init.h xendat.h xendefs.h $PCHEADERS dpart xenbin.$cputype xenelf.$cputype xenstore + rm -f $stem.c [9bz]$stem [9bz]$stem.gz 9$stem.elf boot$stem.* xendat.h xendefs.h $PCHEADERS dpart xenbin.$cputype xenelf.$cputype xenstore diff --git a/sys/src/9/xen/trap.c b/sys/src/9/xen/trap.c index e8e401585..8d77b8c43 100644 --- a/sys/src/9/xen/trap.c +++ b/sys/src/9/xen/trap.c @@ -1015,10 +1015,6 @@ forkchild(Proc *p, Ureg *ureg) memmove(cureg, ureg, sizeof(Ureg)); /* return value of syscall in child */ cureg->ax = 0; - - /* Things from bottom of syscall which were never executed */ - p->psstate = 0; - p->insyscall = 0; } /* Give enough context in the ureg to produce a kernel stack for |