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/omap | |
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/omap')
-rw-r--r-- | sys/src/9/omap/fns.h | 1 | ||||
-rw-r--r-- | sys/src/9/omap/main.c | 183 | ||||
-rw-r--r-- | sys/src/9/omap/mkfile | 32 | ||||
-rw-r--r-- | sys/src/9/omap/syscall.c | 4 |
4 files changed, 16 insertions, 204 deletions
diff --git a/sys/src/9/omap/fns.h b/sys/src/9/omap/fns.h index 39e0adbda..4e239355c 100644 --- a/sys/src/9/omap/fns.h +++ b/sys/src/9/omap/fns.h @@ -120,7 +120,6 @@ extern int fpuemu(Ureg*); /* * Miscellaneous machine dependent stuff. */ -extern char* getenv(char*, char*, int); char* getconf(char*); uintptr mmukmap(uintptr, uintptr, usize); uintptr mmukunmap(uintptr, uintptr, usize); diff --git a/sys/src/9/omap/main.c b/sys/src/9/omap/main.c index ab27d0f2b..839a6795e 100644 --- a/sys/src/9/omap/main.c +++ b/sys/src/9/omap/main.c @@ -1,14 +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 "reboot.h" +#include "rebootcode.i" /* * Where configuration info is left for the loaded programme. @@ -30,21 +30,6 @@ enum { uintptr kseg0 = KZERO; Mach* machaddr[MAXMACH]; -/* - * Option arguments from the command line. - * oargv[0] is the boot file. - * Optionsinit() is called from multiboot() - * or some other machine-dependent place - * to set it all up. - */ -static int oargc; -static char* oargv[20]; -static char oargb[128]; -static int oargblen; -static char oenv[4096]; - -static uintptr sp; /* XXX - must go - user stack of init proc */ - int vflag; int normalprint; char debug[256]; @@ -152,45 +137,6 @@ plan9iniinit(void) } } -static void -optionsinit(char* s) -{ - char *o; - - strcpy(oenv, ""); - o = strecpy(oargb, oargb+sizeof(oargb), s)+1; - if(getenv("bootargs", o, o - oargb) != nil) - *(o-1) = ' '; - - oargblen = strlen(oargb); - oargc = tokenize(oargb, oargv, nelem(oargv)-1); - oargv[oargc] = nil; -} - -char* -getenv(char* name, char* buf, int n) -{ - char *e, *p, *q; - - p = oenv; - while(*p != 0){ - if((e = strchr(p, '=')) == nil) - break; - for(q = name; p < e; p++){ - if(*p != *q) - break; - q++; - } - if(p == e && *q == 0){ - strecpy(buf, buf+n, e+1); - return buf; - } - p += strlen(p)+1; - } - - return nil; -} - void main(void) { @@ -222,7 +168,6 @@ wave('l'); machinit(); mmuinit(); - optionsinit("/boot/boot boot"); quotefmtinstall(); /* want plan9.ini to be able to affect memory sizing in confinit */ @@ -390,21 +335,8 @@ reboot(void *entry, void *code, ulong size) void init0(void) { + char buf[2*KNAMELEN], **sp; int i; - char buf[2*KNAMELEN]; - - up->nerrlab = 0; - coherence(); - 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); dmatest(); /* needs `up' set, so can't do it earlier */ chandevinit(); @@ -430,112 +362,11 @@ init0(void) poperror(); } kproc("alarm", alarmkproc, 0); - touser(sp); -} - -static void -bootargs(uintptr base) -{ - int i; - ulong ssize; - char **av, *p; - - /* - * Push the boot args onto the stack. - * The initial value of the user stack must be such - * that the total used is larger than the maximum size - * of the argument list checked in syscall. - */ - i = oargblen+1; - p = (void*)(STACKALIGN(base + BY2PG - sizeof(up->s.args) - i)); - memmove(p, oargb, i); - /* - * Now push argc and the argv pointers. - * This isn't strictly correct as the code jumped to by - * touser in init9.s calls startboot (port/initcode.c) which - * expects arguments - * startboot(char *argv0, char **argv) - * not the usual (int argc, char* argv[]), but argv0 is - * unused so it doesn't matter (at the moment...). - */ - av = (char**)(p - (oargc+2)*sizeof(char*)); - ssize = base + BY2PG - (uintptr)av; - *av++ = (char*)oargc; - for(i = 0; i < oargc; i++) - *av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG); - *av = nil; - - /* - * Leave space for the return PC of the - * caller of initcode. - */ - sp = USTKTOP - ssize - sizeof(void*); -} - -/* - * 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); - - /* - * 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); - bootargs(VA(k)); - 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(s->map[0]->pages[0]); - memmove((void*)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((uintptr)sp); } Conf conf; /* XXX - must go - gag */ diff --git a/sys/src/9/omap/mkfile b/sys/src/9/omap/mkfile index 0695e8cfa..b3a359f2b 100644 --- a/sys/src/9/omap/mkfile +++ b/sys/src/9/omap/mkfile @@ -39,6 +39,7 @@ PORT=\ tod.$O\ xalloc.$O\ random.$O\ + userinit.$O\ OBJ=\ l.$O\ @@ -100,35 +101,20 @@ CFLAGS= -I. -I../port $CFLAGS # hack to compile private sysproc.c (e.g.) arch.$O clock.$O fpiarm.$O main.$O mmu.$O screen.$O sdscsi.$O syscall.$O \ trap.$O: /$objtype/include/ureg.h - +arch.$O syscall.$O: /sys/include/tos.h archomap.$O devether.$0 ether9221.$O: ../port/etherif.h ../port/netif.h archomap.$O devflash.$O flashbeagle.$O flashigep.$O: ../port/flashif.h ecc.$O flashbeagle.$O flashigep.$O: ../port/nandecc.h io.h fpi.$O fpiarm.$O fpimem.$O: fpi.h -l.$O lexception.$O lproc.$O mmu.$O: arm.s arm.h mem.h +l.$O lexception.$O lproc.$O mmu.$O rebootcode.$O: arm.s arm.h mem.h l.$O rebootcode.$O: cache.v7.s -main.$O: errstr.h init.h reboot.h +main.$O: errstr.h rebootcode.i devdss.$O devmouse.$O mouse.$O screen.$O: screen.h devusb.$O: ../port/usb.h usbehci.$O usbohci.$O usbuhci.$O: ../port/usb.h usbehci.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.v7.s arm.s arm.h mem.h - $AS rebootcode.s - # -lc is only for memmove. -T arg is PADDR(REBOOTADDR) -# $LD -l -a -s -T0x100 -R4 -o reboot.out rebootcode.$O -lc >reboot.list - $LD -l -s -T0x100 -R4 -o reboot.out rebootcode.$O -lc - {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 -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 + $LD -l -R4 -T0x100 -s -o $target $prereq -lc diff --git a/sys/src/9/omap/syscall.c b/sys/src/9/omap/syscall.c index 08089093c..9c957a701 100644 --- a/sys/src/9/omap/syscall.c +++ b/sys/src/9/omap/syscall.c @@ -322,8 +322,4 @@ forkchild(Proc *p, Ureg *ureg) /* syscall returns 0 for child */ cureg->r0 = 0; - - /* Things from bottom of syscall which were never executed */ - p->psstate = 0; - p->insyscall = 0; } |