rewrite configuration to confaddr for eventual quick reboot for amd64. this code takes a different approach than plan9. plan 9 builds a malloc'd buffer of null terminated names and values. then writeconf() replaces the nulls with alternating = and \n. this code simply has devenv stuff the environment with = and \n delimiters directly in a provided buffer (no malloc). Reference: /n/atom/patch/applied2013/nixwriteconf Date: Mon Dec 30 21:24:10 CET 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/k10/fns.h Mon Dec 30 21:20:30 2013 +++ /sys/src/nix/k10/fns.h Mon Dec 30 21:20:31 2013 @@ -119,6 +119,7 @@ void rdrandbuf(void*, usize); u64int rdtsc(void); void trput(u64int); +void writeconf(void); void wrmsr(u32int, u64int); int cas32(void*, u32int, u32int); @@ -159,7 +160,6 @@ * i8259.c */ int i8259init(int); -int i8259isr(int); /* * mp.c --- /sys/src/nix/k10/options.c Mon Dec 30 21:20:32 2013 +++ /sys/src/nix/k10/options.c Mon Dec 30 21:20:33 2013 @@ -36,28 +36,39 @@ parseoptions(void) { long i, n; - char *cp, *line[Maxconf]; + char *p, *line[Maxconf]; /* * parse configuration args from dos file plan9.ini */ - cp = BOOTARGS; /* where b.com leaves its config */ - cp[BOOTARGSLEN-1] = 0; + p = BOOTARGS; /* where b.com leaves its config */ + p[BOOTARGSLEN-1] = 0; - n = getfields(cp, line, Maxconf, 1, "\n"); + n = getfields(p, line, Maxconf, 1, "\n"); for(i = 0; i < n; i++){ if(*line[i] == '#') continue; - cp = strchr(line[i], '='); - if(cp == nil) + p = strchr(line[i], '='); + if(p == nil) continue; - *cp++ = '\0'; + *p++ = '\0'; cfg[ncfg].name = line[i]; - cfg[ncfg].val = cp; + cfg[ncfg].val = p; ncfg++; } } +void +writeconf(void) +{ + char *p, *e; + int n; + + e = BOOTARGS+BOOTARGSLEN; + p = confenv(BOOTARGS, e); + memset(p, 0, e-p); +} + static void cmdline(void) { @@ -179,11 +190,11 @@ if(cistrncmp(p, "type=", 5) == 0) pci->type = p + 5; else if(cistrncmp(p, "port=", 5) == 0) - pci->port = strtoul(p+5, &p, 0); + pci->port = strtoull(p+5, &p, 0); else if(cistrncmp(p, "irq=", 4) == 0) pci->irq = strtoul(p+4, &p, 0); else if(cistrncmp(p, "mem=", 4) == 0) - pci->mem = strtoul(p+4, &p, 0); + pci->mem = strtoull(p+4, &p, 0); else if(cistrncmp(p, "tbdf=", 5) == 0) pci->tbdf = strtotbdf(p+5, &p, 0); } --- /sys/src/nix/port/portfns.h Mon Dec 30 21:20:34 2013 +++ /sys/src/nix/port/portfns.h Mon Dec 30 21:20:35 2013 @@ -41,6 +41,7 @@ void cmderror(Cmdbuf*, char*); int cmount(Chan**, Chan*, int, char*); Block* concatblock(Block*); +char* confenv(char*, char*); int consactive(void); void (*consdebug)(void); void (*consputs)(char*, int); @@ -114,7 +115,6 @@ void freeblist(Block*); int freebroken(void); void freepte(Segment*, Pte*); -char* getconfenv(void); int getpgszi(usize); void gotolabel(Label*); int haswaitq(void*); --- /sys/src/nix/port/devenv.c Mon Dec 30 21:20:36 2013 +++ /sys/src/nix/port/devenv.c Mon Dec 30 21:20:37 2013 @@ -396,45 +396,25 @@ cclose(c); } -/* - * Return a copy of configuration environment as a sequence of strings. - * The strings alternate between name and value. A zero length name string - * indicates the end of the list - */ -char * -getconfenv(void) +/* copy configuration environment to the given buffer. */ +char* +confenv(char *p, char *e) { - Egrp *eg = &confegrp; - Evalue *e; - char *p, *q; - int i, n; + int i; + Egrp *eg; + Evalue *v; + eg = &confegrp; rlock(eg); if(waserror()) { runlock(eg); nexterror(); } - - /* determine size */ - n = 0; - for(i=0; inent; i++){ - e = eg->ent[i]; - n += strlen(e->name) + e->len + 2; - } - p = malloc(n + 1); - if(p == nil) - error(Enomem); - q = p; for(i=0; inent; i++){ - e = eg->ent[i]; - strcpy(q, e->name); - q += strlen(q) + 1; - memmove(q, e->value, e->len); - q[e->len] = 0; - /* move up to the first null */ - q += strlen(q) + 1; + v = eg->ent[i]; + p = seprint(p, e, "%s=%*s\n", v->name, v->len, v->value); } - *q = 0; + *p = 0; poperror(); runlock(eg);