summaryrefslogtreecommitdiff
path: root/sys/src/9/teg2
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/teg2
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/teg2')
-rw-r--r--sys/src/9/teg2/fns.h1
-rw-r--r--sys/src/9/teg2/init9.s25
-rw-r--r--sys/src/9/teg2/main.c184
-rw-r--r--sys/src/9/teg2/mkfile36
-rw-r--r--sys/src/9/teg2/syscall.c4
5 files changed, 18 insertions, 232 deletions
diff --git a/sys/src/9/teg2/fns.h b/sys/src/9/teg2/fns.h
index d4bf7e919..9ddec97b2 100644
--- a/sys/src/9/teg2/fns.h
+++ b/sys/src/9/teg2/fns.h
@@ -177,7 +177,6 @@ extern int fpuemu(Ureg*);
* Miscellaneous machine dependent stuff.
*/
extern int cas(int *, int, int);
-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/teg2/init9.s b/sys/src/9/teg2/init9.s
deleted file mode 100644
index 1d7f2bec3..000000000
--- a/sys/src/9/teg2/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/teg2/main.c b/sys/src/9/teg2/main.c
index 53c5ed456..b08a00178 100644
--- a/sys/src/9/teg2/main.c
+++ b/sys/src/9/teg2/main.c
@@ -1,15 +1,15 @@
#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 "arm.h"
-#include "reboot.h"
+#include "rebootcode.i"
/*
* Where configuration info is left for the loaded programme.
@@ -40,21 +40,6 @@ Memcache cachel[8]; /* arm arch v7 supports 1-7 */
*/
Lowmemcache *cacheconf;
-/*
- * 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];
@@ -165,45 +150,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;
-}
-
/* enable scheduling of this cpu */
void
machon(uint cpu)
@@ -386,7 +332,6 @@ main(void)
l2pageinit();
mmuinit();
- optionsinit("/boot/boot boot");
quotefmtinstall();
/* want plan9.ini to be able to affect memory sizing in confinit */
@@ -586,21 +531,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);
chandevinit();
i8250console(); /* might be redundant, but harmless */
@@ -626,112 +558,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);
- 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/teg2/mkfile b/sys/src/9/teg2/mkfile
index 3f8150af7..6ea2c9894 100644
--- a/sys/src/9/teg2/mkfile
+++ b/sys/src/9/teg2/mkfile
@@ -40,6 +40,7 @@ PORT=\
taslock.$O\
tod.$O\
xalloc.$O\
+ userinit.$O\
OBJ=\
l.$O\
@@ -121,32 +122,17 @@ archtegra.$O devether.$0 ether9221.$O: ../port/etherif.h ../port/netif.h
archtegra.$O devflash.$O flashtegra.$O flashigep.$O: ../port/flashif.h
ecc.$O flashtegra.$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 mem.h
+l.$O lexception.$O lproc.$O mmu.$O rebootcode.$O: arm.s mem.h
l.$O rebootcode.$O: cache.v7.s
-main.$O: errstr.h init.h reboot.h
+main.$O: errstr.h rebootcode.i /sys/include/tos.h
devusb.$O: ../port/usb.h
usbehci.$O usbohci.$O usbuhci.$O: ../port/usb.h usbehci.h uncached.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
-
-$CONF.clean:
- rm -rf $p$CONF s$p$CONF errstr.h reboot.h $CONF.c boot$CONF.c
+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
diff --git a/sys/src/9/teg2/syscall.c b/sys/src/9/teg2/syscall.c
index 4a5ec8559..6f49ac4d5 100644
--- a/sys/src/9/teg2/syscall.c
+++ b/sys/src/9/teg2/syscall.c
@@ -353,8 +353,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;
}