changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: bcm, bcm64: preserve memsize across reboots, avoid trashing atags while parsing cmdline

changeset 7234: fc141b91ed8a
parent 7233: 24d21d7c0868
child 7235: b1dc95374307
author: cinap_lenrek@felloff.net
date: Mon, 13 May 2019 19:12:41 +0200
files: sys/src/9/bcm/bootargs.c sys/src/9/bcm/dat.h sys/src/9/bcm/main.c sys/src/9/bcm/mmu.c
description: bcm, bcm64: preserve memsize across reboots, avoid trashing atags while parsing cmdline

we override atag memory on reboot, so preserve
the memsize learned from atag as *maxmem plan9
variable. the global memsize variable is not
needed anymore.

avoid trashing the following atag when zero
terminating the cmdline string.

zero memory after plan9.ini variables.
     1.1--- a/sys/src/9/bcm/bootargs.c
     1.2+++ b/sys/src/9/bcm/bootargs.c
     1.3@@ -88,34 +88,37 @@ plan9iniinit(char *s, int cmdline)
     1.4 void
     1.5 bootargsinit(void)
     1.6 {
     1.7+	static char maxmem[11];
     1.8+	char x, *e;
     1.9 	Atag *a;
    1.10-	int n;
    1.11 
    1.12-	a = (Atag*)BOOTARGS;
    1.13+	e = BOOTARGS;
    1.14+	a = (Atag*)e;
    1.15 	if(a->tag != AtagCore){
    1.16-		plan9iniinit((char*)a, 0);
    1.17+		plan9iniinit(e, 0);
    1.18 		return;
    1.19 	}
    1.20-	while(a->tag != AtagNone && a->size != 0){
    1.21+	while(a->tag != AtagNone){
    1.22+		e += a->size * sizeof(u32int);
    1.23+		if(a->size < 2 || e < (char*)a || e > &BOOTARGS[BOOTARGSLEN])
    1.24+			break;
    1.25 		switch(a->tag){
    1.26 		case AtagMem:
    1.27-			/* use only first bank */
    1.28-			if(conf.mem[0].limit == 0 && a->mem.size != 0){
    1.29-				memsize = a->mem.size;
    1.30-				conf.mem[0].base = a->mem.base;
    1.31-				conf.mem[0].limit = a->mem.base + memsize;
    1.32+			if(findconf("*maxmem") < 0){
    1.33+				snprint(maxmem, sizeof(maxmem), "%ud", a->mem.base+a->mem.size);
    1.34+				addconf("*maxmem", maxmem);
    1.35 			}
    1.36 			break;
    1.37 		case AtagCmdline:
    1.38-			n = (a->size * sizeof(u32int)) - offsetof(Atag, cmdline[0]);
    1.39-			if(a->cmdline + n < BOOTARGS + BOOTARGSLEN)
    1.40-				a->cmdline[n] = 0;
    1.41-			else
    1.42-				BOOTARGS[BOOTARGSLEN-1] = 0;
    1.43+			x = *e;
    1.44+			*e = 0;
    1.45 			plan9iniinit(a->cmdline, 1);
    1.46+			*e = x;
    1.47 			break;
    1.48 		}
    1.49-		a = (Atag*)((u32int*)a + a->size);
    1.50+		if(e > &BOOTARGS[BOOTARGSLEN-8])
    1.51+			break;
    1.52+		a = (Atag*)e;
    1.53 	}
    1.54 }
    1.55 
    1.56@@ -164,6 +167,7 @@ writeconf(void)
    1.57 	if(n >= BOOTARGSLEN)
    1.58 		error("kernel configuration too large");
    1.59 	memmove(BOOTARGS, p, n);
    1.60+	memset(BOOTARGS+n, 0, BOOTARGSLEN-n);
    1.61 	poperror();
    1.62 	free(p);
    1.63 }
     2.1--- a/sys/src/9/bcm/dat.h
     2.2+++ b/sys/src/9/bcm/dat.h
     2.3@@ -227,7 +227,6 @@ extern register Mach* m;			/* R10 */
     2.4 extern register Proc* up;			/* R9 */
     2.5 extern uintptr kseg0;
     2.6 extern Mach* machaddr[MAXMACH];
     2.7-extern ulong memsize;
     2.8 extern int normalprint;
     2.9 
    2.10 /*
     3.1--- a/sys/src/9/bcm/main.c
     3.2+++ b/sys/src/9/bcm/main.c
     3.3@@ -18,7 +18,6 @@
     3.4 uintptr kseg0 = KZERO;
     3.5 Mach*	machaddr[MAXMACH];
     3.6 Conf	conf;
     3.7-ulong	memsize = 128*1024*1024;
     3.8 
     3.9 void
    3.10 machinit(void)
    3.11@@ -241,7 +240,7 @@ void
    3.12 confinit(void)
    3.13 {
    3.14 	int i, userpcnt;
    3.15-	ulong kpages;
    3.16+	ulong kpages, memsize = 0;
    3.17 	uintptr pa;
    3.18 	char *p;
    3.19 
    3.20@@ -257,12 +256,10 @@ confinit(void)
    3.21 	else
    3.22 		userpcnt = 0;
    3.23 
    3.24-	if((p = getconf("*maxmem")) != nil){
    3.25+	if(p = getconf("*maxmem"))
    3.26 		memsize = strtoul(p, 0, 0) - PHYSDRAM;
    3.27-		if (memsize < 16*MB)		/* sanity */
    3.28-			memsize = 16*MB;
    3.29-	}
    3.30-
    3.31+	if (memsize < 16*MB)		/* sanity */
    3.32+		memsize = 16*MB;
    3.33 	getramsize(&conf.mem[0]);
    3.34 	if(conf.mem[0].limit == 0){
    3.35 		conf.mem[0].base = PHYSDRAM;
     4.1--- a/sys/src/9/bcm/mmu.c
     4.2+++ b/sys/src/9/bcm/mmu.c
     4.3@@ -304,8 +304,8 @@ mmuuncache(void* v, usize size)
     4.4 uintptr
     4.5 cankaddr(uintptr pa)
     4.6 {
     4.7-	if(pa < PHYSDRAM + memsize)		/* assumes PHYSDRAM is 0 */
     4.8-		return PHYSDRAM + memsize - pa;
     4.9+	if(pa < PHYSDRAM+soc.dramsize)
    4.10+		return PHYSDRAM+soc.dramsize - pa;
    4.11 	return 0;
    4.12 }
    4.13