summaryrefslogtreecommitdiff
path: root/sys/src/9/kw
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-01-26 19:01:36 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-01-26 19:01:36 +0100
commit8d51e7fa1a1dbcbde513c2b756d504c879598907 (patch)
tree4cd1a3aaab346ac990bc9058e8cc4928258be6ae /sys/src/9/kw
parent60bb408acca3b48b17f9158132849b894ad9f234 (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/kw')
-rw-r--r--sys/src/9/kw/fns.h1
-rw-r--r--sys/src/9/kw/init9.s25
-rw-r--r--sys/src/9/kw/main.c184
-rw-r--r--sys/src/9/kw/mkfile34
-rw-r--r--sys/src/9/kw/syscall.c4
5 files changed, 19 insertions, 229 deletions
diff --git a/sys/src/9/kw/fns.h b/sys/src/9/kw/fns.h
index 6fcc3878f..e4cb96857 100644
--- a/sys/src/9/kw/fns.h
+++ b/sys/src/9/kw/fns.h
@@ -104,7 +104,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/kw/init9.s b/sys/src/9/kw/init9.s
deleted file mode 100644
index 1d7f2bec3..000000000
--- a/sys/src/9/kw/init9.s
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * This is the same as the C programme:
- *
- * void
- * main(char* argv0)
- * {
- * startboot(argv0, &argv0);
- * }
- *
- * It is in assembler because SB needs to be
- * set and doing this in C drags in too many
- * other routines.
- */
-TEXT main(SB), 1, $8
- MOVW $setR12(SB), R12 /* load the SB */
- MOVW $boot(SB), R0
-
- ADD $12, R13, R1 /* pointer to 0(FP) */
-
- MOVW R0, 4(R13) /* pass argc, argv */
- MOVW R1, 8(R13)
-
- BL startboot(SB)
-_loop:
- B _loop
diff --git a/sys/src/9/kw/main.c b/sys/src/9/kw/main.c
index c0665ec77..060fe8b32 100644
--- a/sys/src/9/kw/main.c
+++ b/sys/src/9/kw/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 "init.h"
#include "arm.h"
#include <pool.h>
-#include "reboot.h"
+#include "rebootcode.i"
/*
* Where configuration info is left for the loaded programme.
@@ -26,21 +26,6 @@
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;
char debug[256];
@@ -150,44 +135,6 @@ plan9iniinit(void)
}
}
-static void
-optionsinit(char* s)
-{
- char *o;
-
- 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;
-}
-
#include "io.h"
typedef struct Spiregs Spiregs;
@@ -274,7 +221,6 @@ wave('9');
archreset();
mmuinit();
- optionsinit("/boot/boot boot");
quotefmtinstall();
archconsole();
wave(' ');
@@ -406,22 +352,8 @@ reboot(void *entry, void *code, ulong size)
void
init0(void)
{
+ char buf[2*KNAMELEN], **sp;
int i;
- char buf[2*KNAMELEN];
-
- assert(up != nil);
- 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);
chandevinit();
@@ -443,112 +375,10 @@ init0(void)
}
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);
- 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((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/kw/mkfile b/sys/src/9/kw/mkfile
index 2f5af40d2..cf3564e38 100644
--- a/sys/src/9/kw/mkfile
+++ b/sys/src/9/kw/mkfile
@@ -39,6 +39,7 @@ PORT=\
tod.$O\
xalloc.$O\
random.$O\
+ userinit.$O\
OBJ=\
l.$O\
@@ -122,36 +123,25 @@ paqdisk:
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 main.$O: /sys/include/tos.h
archkw.$O devether.$O ether1116.$O ethermii.$O: \
ethermii.h ../port/etherif.h ../port/netif.h
archkw.$O devflash.$O flashkw.$O: ../port/flashif.h
fpi.$O fpiarm.$O fpimem.$O: fpi.h
-l.$O lexception.$O lproc.$O mmu.$O: arm.s arm.h mem.h
-main.$O: errstr.h init.h reboot.h
+l.$O lexception.$O lproc.$O mmu.$O rebootcode.$O: arm.s arm.h mem.h
+main.$O: errstr.h rebootcode.i
mouse.$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 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
- {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
+init9.$O: ../omap/init9.s
+ $AS ../omap/init9.s
+
+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
plug.clean:
rm -rf $p$CONF s$p$CONF armpaq paqdisk $CONF.c boot$CONF.c ../boot/libboot.a5
diff --git a/sys/src/9/kw/syscall.c b/sys/src/9/kw/syscall.c
index 79ea7642e..773a151d5 100644
--- a/sys/src/9/kw/syscall.c
+++ b/sys/src/9/kw/syscall.c
@@ -325,8 +325,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;
}