diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-05-13 19:12:41 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-05-13 19:12:41 +0200 |
commit | 3b36daa2bb8c0f4169455baf829b9695b520c5fc (patch) | |
tree | 9da4980fe24b4464e4e8d4c9698afcd1b9549c0e | |
parent | 157d7ebdbd7479b271e7b1df744b2dfc6b5816e9 (diff) |
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.
-rw-r--r-- | sys/src/9/bcm/bootargs.c | 34 | ||||
-rw-r--r-- | sys/src/9/bcm/dat.h | 1 | ||||
-rw-r--r-- | sys/src/9/bcm/main.c | 11 | ||||
-rw-r--r-- | sys/src/9/bcm/mmu.c | 4 |
4 files changed, 25 insertions, 25 deletions
diff --git a/sys/src/9/bcm/bootargs.c b/sys/src/9/bcm/bootargs.c index a361f2828..830e9bc65 100644 --- a/sys/src/9/bcm/bootargs.c +++ b/sys/src/9/bcm/bootargs.c @@ -88,34 +88,37 @@ plan9iniinit(char *s, int cmdline) void bootargsinit(void) { + static char maxmem[11]; + char x, *e; Atag *a; - int n; - a = (Atag*)BOOTARGS; + e = BOOTARGS; + a = (Atag*)e; if(a->tag != AtagCore){ - plan9iniinit((char*)a, 0); + plan9iniinit(e, 0); return; } - while(a->tag != AtagNone && a->size != 0){ + while(a->tag != AtagNone){ + e += a->size * sizeof(u32int); + if(a->size < 2 || e < (char*)a || e > &BOOTARGS[BOOTARGSLEN]) + break; switch(a->tag){ case AtagMem: - /* use only first bank */ - if(conf.mem[0].limit == 0 && a->mem.size != 0){ - memsize = a->mem.size; - conf.mem[0].base = a->mem.base; - conf.mem[0].limit = a->mem.base + memsize; + if(findconf("*maxmem") < 0){ + snprint(maxmem, sizeof(maxmem), "%ud", a->mem.base+a->mem.size); + addconf("*maxmem", maxmem); } break; case AtagCmdline: - n = (a->size * sizeof(u32int)) - offsetof(Atag, cmdline[0]); - if(a->cmdline + n < BOOTARGS + BOOTARGSLEN) - a->cmdline[n] = 0; - else - BOOTARGS[BOOTARGSLEN-1] = 0; + x = *e; + *e = 0; plan9iniinit(a->cmdline, 1); + *e = x; break; } - a = (Atag*)((u32int*)a + a->size); + if(e > &BOOTARGS[BOOTARGSLEN-8]) + break; + a = (Atag*)e; } } @@ -164,6 +167,7 @@ writeconf(void) if(n >= BOOTARGSLEN) error("kernel configuration too large"); memmove(BOOTARGS, p, n); + memset(BOOTARGS+n, 0, BOOTARGSLEN-n); poperror(); free(p); } diff --git a/sys/src/9/bcm/dat.h b/sys/src/9/bcm/dat.h index cf674cf3e..bbb287e6a 100644 --- a/sys/src/9/bcm/dat.h +++ b/sys/src/9/bcm/dat.h @@ -227,7 +227,6 @@ extern register Mach* m; /* R10 */ extern register Proc* up; /* R9 */ extern uintptr kseg0; extern Mach* machaddr[MAXMACH]; -extern ulong memsize; extern int normalprint; /* diff --git a/sys/src/9/bcm/main.c b/sys/src/9/bcm/main.c index 3c5f5695c..3cc30034f 100644 --- a/sys/src/9/bcm/main.c +++ b/sys/src/9/bcm/main.c @@ -18,7 +18,6 @@ uintptr kseg0 = KZERO; Mach* machaddr[MAXMACH]; Conf conf; -ulong memsize = 128*1024*1024; void machinit(void) @@ -241,7 +240,7 @@ void confinit(void) { int i, userpcnt; - ulong kpages; + ulong kpages, memsize = 0; uintptr pa; char *p; @@ -257,12 +256,10 @@ confinit(void) else userpcnt = 0; - if((p = getconf("*maxmem")) != nil){ + if(p = getconf("*maxmem")) memsize = strtoul(p, 0, 0) - PHYSDRAM; - if (memsize < 16*MB) /* sanity */ - memsize = 16*MB; - } - + if (memsize < 16*MB) /* sanity */ + memsize = 16*MB; getramsize(&conf.mem[0]); if(conf.mem[0].limit == 0){ conf.mem[0].base = PHYSDRAM; diff --git a/sys/src/9/bcm/mmu.c b/sys/src/9/bcm/mmu.c index 9d2e3709c..614a6fb4f 100644 --- a/sys/src/9/bcm/mmu.c +++ b/sys/src/9/bcm/mmu.c @@ -304,8 +304,8 @@ mmuuncache(void* v, usize size) uintptr cankaddr(uintptr pa) { - if(pa < PHYSDRAM + memsize) /* assumes PHYSDRAM is 0 */ - return PHYSDRAM + memsize - pa; + if(pa < PHYSDRAM+soc.dramsize) + return PHYSDRAM+soc.dramsize - pa; return 0; } |