changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/9/bcm/main.c

revision 7159: 66132ebbe687
parent 7155: 85c4b38d9a82
child 7234: fc141b91ed8a
     1.1--- a/sys/src/9/bcm/main.c
     1.2+++ b/sys/src/9/bcm/main.c
     1.3@@ -15,180 +15,11 @@
     1.4 #define	Minfirmrev	326770
     1.5 #define	Minfirmdate	"22 Jul 2012"
     1.6 
     1.7-/*
     1.8- * Where configuration info is left for the loaded programme.
     1.9- */
    1.10-#define BOOTARGS	((char*)CONFADDR)
    1.11-#define	BOOTARGSLEN	(REBOOTADDR-PADDR(CONFADDR))
    1.12-#define	MAXCONF		64
    1.13-#define MAXCONFLINE	160
    1.14-
    1.15 uintptr kseg0 = KZERO;
    1.16 Mach*	machaddr[MAXMACH];
    1.17 Conf	conf;
    1.18 ulong	memsize = 128*1024*1024;
    1.19 
    1.20-/*
    1.21- * Option arguments from the command line.
    1.22- * oargv[0] is the boot file.
    1.23- */
    1.24-static int oargc;
    1.25-static char* oargv[20];
    1.26-static char oargb[128];
    1.27-static int oargblen;
    1.28-
    1.29-static uintptr sp;		/* XXX - must go - user stack of init proc */
    1.30-
    1.31-/* store plan9.ini contents here at least until we stash them in #ec */
    1.32-static char confname[MAXCONF][KNAMELEN];
    1.33-static char confval[MAXCONF][MAXCONFLINE];
    1.34-static int nconf;
    1.35-
    1.36-typedef struct Atag Atag;
    1.37-struct Atag {
    1.38-	u32int	size;	/* size of atag in words, including this header */
    1.39-	u32int	tag;	/* atag type */
    1.40-	union {
    1.41-		u32int	data[1];	/* actually [size-2] */
    1.42-		/* AtagMem */
    1.43-		struct {
    1.44-			u32int	size;
    1.45-			u32int	base;
    1.46-		} mem;
    1.47-		/* AtagCmdLine */
    1.48-		char	cmdline[1];	/* actually [4*(size-2)] */
    1.49-	};
    1.50-};
    1.51-
    1.52-enum {
    1.53-	AtagNone	= 0x00000000,
    1.54-	AtagCore	= 0x54410001,
    1.55-	AtagMem		= 0x54410002,
    1.56-	AtagCmdline	= 0x54410009,
    1.57-};
    1.58-
    1.59-static int
    1.60-findconf(char *name)
    1.61-{
    1.62-	int i;
    1.63-
    1.64-	for(i = 0; i < nconf; i++)
    1.65-		if(cistrcmp(confname[i], name) == 0)
    1.66-			return i;
    1.67-	return -1;
    1.68-}
    1.69-
    1.70-char*
    1.71-getconf(char *name)
    1.72-{
    1.73-	int i;
    1.74-
    1.75-	i = findconf(name);
    1.76-	if(i >= 0)
    1.77-		return confval[i];
    1.78-	return nil;
    1.79-}
    1.80-
    1.81-void
    1.82-addconf(char *name, char *val)
    1.83-{
    1.84-	int i;
    1.85-
    1.86-	i = findconf(name);
    1.87-	if(i < 0){
    1.88-		if(val == nil || nconf >= MAXCONF)
    1.89-			return;
    1.90-		i = nconf++;
    1.91-		strecpy(confname[i], confname[i]+sizeof(confname[i]), name);
    1.92-	}
    1.93-	strecpy(confval[i], confval[i]+sizeof(confval[i]), val);
    1.94-}
    1.95-
    1.96-static void
    1.97-writeconf(void)
    1.98-{
    1.99-	char *p, *q;
   1.100-	int n;
   1.101-
   1.102-	p = getconfenv();
   1.103-
   1.104-	if(waserror()) {
   1.105-		free(p);
   1.106-		nexterror();
   1.107-	}
   1.108-
   1.109-	/* convert to name=value\n format */
   1.110-	for(q=p; *q; q++) {
   1.111-		q += strlen(q);
   1.112-		*q = '=';
   1.113-		q += strlen(q);
   1.114-		*q = '\n';
   1.115-	}
   1.116-	n = q - p + 1;
   1.117-	if(n >= BOOTARGSLEN)
   1.118-		error("kernel configuration too large");
   1.119-	memmove(BOOTARGS, p, n);
   1.120-	memset(BOOTARGS + n, '\n', BOOTARGSLEN - n);
   1.121-	poperror();
   1.122-	free(p);
   1.123-}
   1.124-
   1.125-static void
   1.126-plan9iniinit(char *s, int cmdline)
   1.127-{
   1.128-	char *toks[MAXCONF];
   1.129-	int i, c, n;
   1.130-	char *v;
   1.131-
   1.132-	if((c = *s) < ' ' || c >= 0x80)
   1.133-		return;
   1.134-	if(cmdline)
   1.135-		n = tokenize(s, toks, MAXCONF);
   1.136-	else
   1.137-		n = getfields(s, toks, MAXCONF, 1, "\n");
   1.138-	for(i = 0; i < n; i++){
   1.139-		if(toks[i][0] == '#')
   1.140-			continue;
   1.141-		v = strchr(toks[i], '=');
   1.142-		if(v == nil)
   1.143-			continue;
   1.144-		*v++ = '\0';
   1.145-		addconf(toks[i], v);
   1.146-	}
   1.147-}
   1.148-
   1.149-static void
   1.150-ataginit(Atag *a)
   1.151-{
   1.152-	int n;
   1.153-
   1.154-	if(a->tag != AtagCore){
   1.155-		plan9iniinit((char*)a, 0);
   1.156-		return;
   1.157-	}
   1.158-	while(a->tag != AtagNone){
   1.159-		switch(a->tag){
   1.160-		case AtagMem:
   1.161-			/* use only first bank */
   1.162-			if(conf.mem[0].limit == 0 && a->mem.size != 0){
   1.163-				memsize = a->mem.size;
   1.164-				conf.mem[0].base = a->mem.base;
   1.165-				conf.mem[0].limit = a->mem.base + memsize;
   1.166-			}
   1.167-			break;
   1.168-		case AtagCmdline:
   1.169-			n = (a->size * sizeof(u32int)) - offsetof(Atag, cmdline[0]);
   1.170-			if(a->cmdline + n < BOOTARGS + BOOTARGSLEN)
   1.171-				a->cmdline[n] = 0;
   1.172-			else
   1.173-				BOOTARGS[BOOTARGSLEN-1] = 0;
   1.174-			plan9iniinit(a->cmdline, 1);
   1.175-			break;
   1.176-		}
   1.177-		a = (Atag*)((u32int*)a + a->size);
   1.178-	}
   1.179-}
   1.180-
   1.181 void
   1.182 machinit(void)
   1.183 {
   1.184@@ -245,16 +76,6 @@ launchinit(void)
   1.185 		print("only %d cpu%s started\n", mach, mach == 1? "" : "s");
   1.186 }
   1.187 
   1.188-static void
   1.189-optionsinit(char* s)
   1.190-{
   1.191-	strecpy(oargb, oargb+sizeof(oargb), s);
   1.192-
   1.193-	oargblen = strlen(oargb);
   1.194-	oargc = tokenize(oargb, oargv, nelem(oargv)-1);
   1.195-	oargv[oargc] = nil;
   1.196-}
   1.197-
   1.198 void
   1.199 main(void)
   1.200 {
   1.201@@ -264,11 +85,8 @@ main(void)
   1.202 	m = (Mach*)MACHADDR;
   1.203 	memset(edata, 0, end - edata);	/* clear bss */
   1.204 	mach0init();
   1.205-
   1.206-	optionsinit("/boot/boot boot");
   1.207 	quotefmtinstall();
   1.208-	
   1.209-	ataginit((Atag*)BOOTARGS);
   1.210+	bootargsinit();
   1.211 	confinit();		/* figures out amount of memory */
   1.212 	xinit();
   1.213 	uartconsinit();
   1.214@@ -312,8 +130,7 @@ main(void)
   1.215 void
   1.216 init0(void)
   1.217 {
   1.218-	int i;
   1.219-	char buf[2*KNAMELEN];
   1.220+	char buf[2*KNAMELEN], **sp;
   1.221 
   1.222 	up->nerrlab = 0;
   1.223 	coherence();
   1.224@@ -342,48 +159,17 @@ init0(void)
   1.225 		ksetenv("etherargs", buf, 0);
   1.226 
   1.227 		/* convert plan9.ini variables to #e and #ec */
   1.228-		for(i = 0; i < nconf; i++) {
   1.229-			ksetenv(confname[i], confval[i], 0);
   1.230-			ksetenv(confname[i], confval[i], 1);
   1.231-		}
   1.232+		setconfenv();
   1.233 		poperror();
   1.234 	}
   1.235 	kproc("alarm", alarmkproc, 0);
   1.236-	touser(sp);
   1.237-	assert(0);			/* shouldn't have returned */
   1.238-}
   1.239-
   1.240-static void
   1.241-bootargs(uintptr base)
   1.242-{
   1.243-	int i;
   1.244-	ulong ssize;
   1.245-	char **av, *p;
   1.246 
   1.247-	/*
   1.248-	 * Push the boot args onto the stack.
   1.249-	 * The initial value of the user stack must be such
   1.250-	 * that the total used is larger than the maximum size
   1.251-	 * of the argument list checked in syscall.
   1.252-	 */
   1.253-	i = oargblen+1;
   1.254-	p = (void*)STACKALIGN(base + BY2PG - sizeof(Tos) - i);
   1.255-	memmove(p, oargb, i);
   1.256+	sp = (char**)(USTKTOP - sizeof(Tos) - 8 - sizeof(sp[0])*4);
   1.257+	sp[3] = sp[2] = sp[1] = nil;
   1.258+	strcpy(sp[0] = (char*)&sp[4], "boot");
   1.259 
   1.260-	/*
   1.261-	 * Now push the argv pointers.
   1.262-	 * The code jumped to by touser in lproc.s expects arguments
   1.263-	 *	main(char* argv0, ...)
   1.264-	 * and calls
   1.265-	 * 	startboot("/boot/boot", &argv0)
   1.266-	 * not the usual (int argc, char* argv[])
   1.267-	 */
   1.268-	av = (char**)(p - (oargc+1)*sizeof(char*));
   1.269-	ssize = base + BY2PG - (uintptr)av;
   1.270-	for(i = 0; i < oargc; i++)
   1.271-		*av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BY2PG);
   1.272-	*av = nil;
   1.273-	sp = USTKTOP - ssize;
   1.274+	touser((uintptr)sp);
   1.275+	assert(0);			/* shouldn't have returned */
   1.276 }
   1.277 
   1.278 /*
   1.279@@ -433,7 +219,7 @@ userinit(void)
   1.280 	pg = newpage(1, 0, USTKTOP-BY2PG);
   1.281 	segpage(s, pg);
   1.282 	k = kmap(pg);
   1.283-	bootargs(VA(k));
   1.284+	memset((void*)VA(k), 0, BY2PG);
   1.285 	kunmap(k);
   1.286 
   1.287 	/*