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/sgi | |
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/sgi')
-rw-r--r-- | sys/src/9/sgi/main.c | 120 | ||||
-rw-r--r-- | sys/src/9/sgi/mkfile | 16 | ||||
-rw-r--r-- | sys/src/9/sgi/trap.c | 6 |
3 files changed, 13 insertions, 129 deletions
diff --git a/sys/src/9/sgi/main.c b/sys/src/9/sgi/main.c index 13d7b9888..c86f8801b 100644 --- a/sys/src/9/sgi/main.c +++ b/sys/src/9/sgi/main.c @@ -1,21 +1,14 @@ #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 "../ip/ip.h" -#include <tos.h> #include <../port/error.h> -enum { - /* space for syscall args, return PC, top-of-stack struct */ - Stkheadroom = sizeof(Sargs) + sizeof(uintptr) + sizeof(Tos), -}; - -static uchar *sp; /* XXX - must go - user stack of init proc */ static FPsave initfp; /* @@ -233,20 +226,7 @@ machinit(void) void init0(void) { - char buf[128]; - - 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); + char buf[128], **sp; chandevinit(); @@ -274,99 +254,11 @@ init0(void) kproc("arcs", arcsproc, 0); kproc("alarm", alarmkproc, 0); - touser(sp); -} - -static uchar * -pusharg(char *p) -{ - int n; - - n = strlen(p) + 1; - sp -= n; - memmove(sp, p, n); - return sp; -} - -static void -bootargs(uintptr base) -{ int i, ac; - uchar *av[32]; - uchar **lsp; - - sp = (uchar *) base + BY2PG - sizeof(Tos); - - ac = 0; - av[ac++] = pusharg("boot"); - sp = (uchar *) ((ulong) sp & ~7); - sp -= ROUND((ac + 1) * sizeof(sp), 8) + 4; - lsp = (uchar **) sp; - for(i = 0; i < ac; i++) - lsp[i] = av[i] + ((USTKTOP - BY2PG) - (ulong) base); - lsp[i] = 0; - sp += (USTKTOP - BY2PG) - (ulong) base; -} - -void -userinit(void) -{ - Proc *p; - KMap *k; - Page *pg; - Segment *s; - - 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 - */ - p->sched.pc = (ulong)init0; - p->sched.sp = (ulong)p->kstack+KSTACK-Stkheadroom; - 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); - 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]); - memset((void *)VA(k), 0, BY2PG); - memmove((ulong*)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(sp); } void diff --git a/sys/src/9/sgi/mkfile b/sys/src/9/sgi/mkfile index 1e39e89f8..ff0ea189f 100644 --- a/sys/src/9/sgi/mkfile +++ b/sys/src/9/sgi/mkfile @@ -44,6 +44,7 @@ PORT=\ taslock.$O\ tod.$O\ xalloc.$O\ + userinit.$O\ OBJ=\ l.$O\ @@ -79,17 +80,12 @@ install:V: $p$CONF <../port/portmkfile <|../port/mkbootrules $CONF -init.h: init9.s ../port/initcode.c /sys/src/libc/9syscall/sys.h - va init9.s - vc ../port/initcode.c - vl -T$UTZERO -R4 -o init.out init9.$O initcode.$O - {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: init9.$O initcode.$O /$objtype/lib/libc.a + $LD -T$UTZERO -R4 -s -o $target $prereq faultmips.$O mmu.$O syscall.$O trap.$O: /$objtype/include/ureg.h -main.$O: /$objtype/include/ureg.h errstr.h init.h +main.$O: /$objtype/include/ureg.h errstr.h +main.$O trap.$O: /sys/include/tos.h %.clean:V: - rm -f $stem.c [9bz]$stem [9bz]$stem.gz boot$stem.* init.h + rm -f $stem.c [9bz]$stem [9bz]$stem.gz boot$stem.* diff --git a/sys/src/9/sgi/trap.c b/sys/src/9/sgi/trap.c index 588e6861d..08b3960df 100644 --- a/sys/src/9/sgi/trap.c +++ b/sys/src/9/sgi/trap.c @@ -2,13 +2,13 @@ * traps, exceptions, faults and interrupts on ar7161 */ #include "u.h" +#include "tos.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "ureg.h" #include "io.h" -#include <tos.h> #include "../port/error.h" typedef struct Handler Handler; @@ -792,10 +792,6 @@ forkchild(Proc *p, Ureg *ur) cur->r1 = 0; cur->pc += 4; - - /* Things from bottom of syscall we never got to execute */ - p->psstate = 0; - p->insyscall = 0; } static |