replace multiboot with good old textual configuration. this builds on the pcboot. instead of building a (partial) gnu multiboot header, just read *e820=... to from the configuration options and use that to map out memory. this should simplify both the loader and kernel. i also have a compatable 9load if anyone needs it. - erik Reference: /n/patches.lsub.org/patch/nomultiboot Date: Thu Jun 21 09:34:00 CES 2012 Signed-off-by: quanstro@quanstro.net # rm /sys/src/nix/k10/crap.c # rm /sys/src/nix/k10/multiboot.c --- /sys/src/nix/k10/options.c Thu Jan 1 00:00:00 1970 +++ /sys/src/nix/k10/options.c Thu Jun 21 06:28:18 2012 @@ -0,0 +1,175 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" + +/* + * Where configuration info is left for the loaded programme. + * This will turn into a structure as more is done by the boot loader + * (e.g. why parse the .ini file twice?). + * There are 3584 bytes available at CONFADDR. + */ +#define CONFADDR PTR2UINT(KADDR(0x0001200)) + +#define BOOTLINE ((char*)CONFADDR) +#define BOOTLINELEN 64 +#define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN)) +#define BOOTARGSLEN (4096-0x200-BOOTLINELEN) + +enum { + Maxconf = 64, +}; + +typedef struct C C; +struct C { + char *name; + char *val; +}; + +static C cfg[Maxconf]; +static int ncfg; + +static void +parseoptions(void) +{ + long i, n; + char *cp, *line[Maxconf]; + + /* + * parse configuration args from dos file plan9.ini + */ + cp = BOOTARGS; /* where b.com leaves its config */ + cp[BOOTARGSLEN-1] = 0; + + n = getfields(cp, line, Maxconf, 1, "\n"); + for(i = 0; i < n; i++){ + if(*line[i] == '#') + continue; + cp = strchr(line[i], '='); + if(cp == nil) + continue; + *cp++ = '\0'; + cfg[ncfg].name = line[i]; + cfg[ncfg].val = cp; + ncfg++; + } +} + +static void +cmdline(void) +{ + char *p, *f[32], **argv, buf[200]; + int argc, n, o; + + p = getconf("*cmdline"); + if(p == nil) + return; + snprint(buf, sizeof buf, "%s", p); + argc = tokenize(buf, f, nelem(f)); + argv = f; + + /* + * Process flags. + * Flags [A-Za-z] may be optionally followed by + * an integer level between 1 and 127 inclusive + * (no space between flag and level). + * '--' ends flag processing. + */ + while(--argc > 0 && (*++argv)[0] == '-' && (*argv)[1] != '-'){ + while(o = *++argv[0]){ + if(!(o >= 'A' && o <= 'Z') && !(o >= 'a' && o <= 'z')) + continue; + n = strtol(argv[0]+1, &p, 0); + if(p == argv[0]+1 || n < 1 || n > 127) + n = 1; + argv[0] = p-1; + dbgflg[o] = n; + } + } +} + +static void +e820(void) +{ + char *p, *s; + uvlong base, len, type; + + p = getconf("*e820"); + if(p == nil) + return; + for(s = p;;){ + if(*s == 0) + break; + type = strtoull(s, &s, 16); + if(*s != ' ') + break; + base = strtoull(s, &s, 16); + if(*s != ' ') + break; + len = strtoull(s, &s, 16) - base; + if(*s != ' ' && *s != 0 || len == 0) + break; + asmmapinit(base, len, type); + } +} + +void +options(void) +{ + parseoptions(); + e820(); + cmdline(); +} + + +char* +getconf(char *name) +{ + int i; + + for(i = 0; i < ncfg; i++) + if(cistrcmp(cfg[i].name, name) == 0) + return cfg[i].val; + return nil; +} + +void +confsetenv(void) +{ + int i; + + for(i = 0; i < ncfg; i++){ + if(cfg[i].name[0] != '*') + ksetenv(cfg[i].name, cfg[i].val, 0); + ksetenv(cfg[i].name, cfg[i].val, 1); + } +} + +int +pciconfig(char *class, int ctlrno, Pciconf *pci) +{ + char cc[32], *p; + int i; + + snprint(cc, sizeof cc, "%s%d", class, ctlrno); + p = getconf(cc); + if(p == nil) + return 0; + + pci->type = ""; + snprint(pci->optbuf, sizeof pci->optbuf, "%s", p); + pci->nopt = tokenize(pci->optbuf, pci->opt, nelem(pci->opt)); + for(i = 0; i < pci->nopt; i++){ + p = pci->opt[i]; + if(cistrncmp(p, "type=", 5) == 0) + pci->type = p + 5; + else if(cistrncmp(p, "port=", 5) == 0) + pci->port = strtoul(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); + } + return 1; +} --- /sys/src/nix/k10/asm.c Thu Apr 12 12:26:27 2012 +++ /sys/src/nix/k10/asm.c Thu Jun 21 06:39:23 2012 @@ -24,34 +24,62 @@ } Asm; enum { - AsmNONE = 0, - AsmMEMORY = 1, - AsmRESERVED = 2, - AsmACPIRECLAIM = 3, - AsmACPINVS = 4, + AsmNone = 0, + AsmMemory, + AsmReserved, + AsmAcpireclaim, + AsmAcpinvs, + AsmUnusable, + AsmDisable, - AsmDEV = 5, + AsmPci, /* invented */ + AsmLast = AsmPci, }; static Lock asmlock; -static Asm asmarray[64] = { - { 0, ~0, AsmNONE, nil, }, +static Asm asmarray[100] = { + { 0, ~0, AsmNone, nil, }, }; static int asmindex = 1; static Asm* asmlist = &asmarray[0]; static Asm* asmfreelist; +static char *tname[AsmLast+1] = { + "none", + "mem", + "res", + "reclaim", + "nvs", + "unusable", + "disable", -/*static*/ void + "pcimap", +}; + +static long +asmread(Chan*, void *v, long n, vlong off) +{ + char *s, *p, *e; + Asm *a; + + s = smalloc(16*1024); + e = s + 16*1024; + p = s; + for(a = asmlist; a != nil; a = a->next) + p = seprint(p, e, "%.8s %#.16p %#.16p\n", + tname[a->type], a->addr, a->addr+a->size); + n = readstr(off, v, n, s); + free(s); + return n; +} + +void asmdump(void) { - Asm* asm; + Asm *a; - print("asm: index %d:\n", asmindex); - for(asm = asmlist; asm != nil; asm = asm->next){ - print(" %#P %#P %d (%P)\n", - asm->addr, asm->addr+asm->size, - asm->type, asm->size); - } + for(a = asmlist; a != nil; a = a->next) + print("%.8s %#.16p %#.16p\n", + tname[a->type], a->addr, a->addr+a->size); } static Asm* @@ -84,6 +112,10 @@ DBG("asmfree: %#P@%#P, type %d\n", size, addr, type); if(size == 0) return 0; + if(type > AsmLast){ + print("asmfree: bad type from %#p\n", getcallerpc(&addr)); + return -1; + } lock(&asmlock); @@ -198,13 +230,16 @@ } unlock(&asmlock); +print("asmalloc: fail addr %p size %p type %s align %d\n", addr, size, tname[type], align); +asmdump(); + return 0; } static void asminsert(uintmem addr, uintmem size, int type) { - if(type == AsmNONE || asmalloc(addr, size, AsmNONE, 0) == 0) + if(type == AsmNone || asmalloc(addr, size, AsmNone, 0) == 0) return; if(asmfree(addr, size, type) == 0) return; @@ -216,14 +251,14 @@ { sys->pmstart = ROUNDUP(PADDR(end), PGSZ); sys->pmend = sys->pmstart; - asmalloc(0, sys->pmstart, AsmNONE, 0); + asmalloc(0, sys->pmstart, AsmNone, 0); + addarchfile("asm", 0444, asmread, nil); } /* * Notes: - * asmmapinit and asmmodinit called from multiboot; + * asmmapinit called from options.c:/^e820 * subject to change; the numerology here is probably suspect. - * Multiboot defines the alignment of modules as 4096. */ void asmmapinit(uintmem addr, uintmem size, int type) @@ -232,7 +267,7 @@ default: asminsert(addr, size, type); break; - case AsmMEMORY: + case AsmMemory: /* * Adjust things for the peculiarities of this * architecture. @@ -255,21 +290,6 @@ } } -void -asmmodinit(u32int start, u32int end, char* s) -{ - DBG("asmmodinit: %#ux -> %#ux: <%s> %#ux\n", - start, end, s, ROUNDUP(end, 4096)); - - if(start < sys->pmstart) - return; - end = ROUNDUP(end, 4096); - if(end > sys->pmstart){ - asmalloc(sys->pmstart, end-sys->pmstart, AsmNONE, 0); - sys->pmstart = end; - } -} - static int npg[4]; void* @@ -342,7 +362,7 @@ cx = 0; #endif /* ConfCrap */ for(asm = asmlist; asm != nil; asm = asm->next){ - if(asm->type != AsmMEMORY) + if(asm->type != AsmMemory) continue; va = KSEG2+asm->addr; print("asm: addr %#P end %#P type %d size %P\n", @@ -385,12 +405,8 @@ if(cx >= nelem(conf.mem)) continue; lo = ROUNDUP(asm->addr, PGSZ); -//if(lo >= 600ull*MiB) -// continue; conf.mem[cx].base = lo; hi = ROUNDDN(hi, PGSZ); -//if(hi > 600ull*MiB) -// hi = 600*MiB; conf.mem[cx].npage = (hi - lo)/PGSZ; conf.npage += conf.mem[cx].npage; print("cm %d: addr %#llux npage %lud\n", @@ -421,7 +437,7 @@ extern void physallocdump(void); for(asm = asmlist; asm != nil; asm = asm->next){ - if(asm->type != AsmMEMORY) + if(asm->type != AsmMemory) continue; physinit(asm->addr, asm->size); } --- /sys/src/nix/k10/l32p.s Thu Jun 14 09:36:22 2012 +++ /sys/src/nix/k10/l32p.s Thu Jun 21 06:43:48 2012 @@ -16,17 +16,12 @@ */ TEXT _protected<>(SB), 1, $-4 CLI - BYTE $0xe9; LONG $0x00000058; /* JMP _endofheader */ + BYTE $0xe9; LONG $0x4c; /* JMP _endofheader */ _startofheader: BYTE $0x90 /* NOP */ BYTE $0x90 /* NOP */ -TEXT _multibootheader<>(SB), 1, $-4 /* must be 4-byte aligned */ - LONG $0x1badb002 /* magic */ - LONG $0x00000003 /* flags */ - LONG $-(0x1badb002 + 0x00000003) /* checksum */ - TEXT _gdt32p<>(SB), 1, $-4 QUAD $0x0000000000000000 /* NULL descriptor */ QUAD $0x00cf9a000000ffff /* CS */ @@ -195,7 +190,7 @@ MOVQ AX, SP /* set stack */ _zap0pml4: - CMPQ DX, $PML4O(KZERO) /* KZER0 & 0x0000ff8000000000 */ + CMPQ DX, $PML4O(KZERO) /* KZERO & 0x0000ff8000000000 */ JEQ _zap0pdp MOVQ DX, PML4O(0)(AX) /* zap identity map PML4E */ _zap0pdp: --- /sys/src/nix/k10/k8cpufs Sun Apr 15 19:46:43 2012 +++ /sys/src/nix/k10/k8cpufs Thu Jun 21 08:17:03 2012 @@ -121,15 +121,15 @@ l64v l64idt l64acidt + l64cpuid l64syscall l64acsyscall l64fpu - cpuidamd64 acore arch archk10 cga - crap + options fpu i8254 i8259 @@ -138,7 +138,6 @@ map memory mmu - multiboot random syscall tcore --- /sys/src/nix/k10/k8cpukexec Thu Apr 12 12:26:27 2012 +++ /sys/src/nix/k10/k8cpukexec Thu Jun 21 06:52:09 2012 @@ -134,7 +134,7 @@ archk10 asm cga - crap + options fpu i8254 i8259 @@ -143,7 +143,6 @@ map memory mmu - multiboot qmalloc random syscall --- /sys/src/nix/k10/dat.h Thu Jun 14 09:36:22 2012 +++ /sys/src/nix/k10/dat.h Thu Jun 21 06:55:53 2012 @@ -4,7 +4,7 @@ typedef struct Fxsave Fxsave; typedef struct ICC ICC; typedef struct ICCparms ICCparms; -typedef struct ISAConf ISAConf; +typedef struct Pciconf Pciconf; typedef struct Label Label; typedef struct Lock Lock; typedef struct MCPU MCPU; @@ -377,19 +377,15 @@ /* * a parsed plan9.ini line */ -#define NISAOPT 8 - -struct ISAConf { +struct Pciconf { char *type; uintptr port; int irq; - ulong dma; uintptr mem; - usize size; - ulong freq; int nopt; - char *opt[NISAOPT]; + char optbuf[128]; + char *opt[8]; }; /* --- /sys/src/nix/k10/etherif.h Thu Apr 12 12:26:27 2012 +++ /sys/src/nix/k10/etherif.h Thu Jun 21 06:56:19 2012 @@ -11,7 +11,7 @@ typedef struct Ether Ether; struct Ether { - ISAConf; /* hardware info */ + Pciconf; /* hardware info */ int ctlrno; int tbdf; /* type+busno+devno+funcno */ --- /sys/src/nix/k10/fns.h Thu Jun 14 09:36:22 2012 +++ /sys/src/nix/k10/fns.h Thu Jun 21 06:56:35 2012 @@ -18,7 +18,6 @@ uvlong asmalloc(uintmem, uintmem, int, int); void asminit(void); void asmmapinit(uintmem, uintmem, int); -extern void asmmodinit(u32int, u32int, char*); void noerrorsleft(void); void archinit(void); void archreset(void); @@ -79,7 +78,7 @@ int ioalloc(int, int, int, char*); int ioreserve(int, int, int, char*); int iprint(char*, ...); -int isaconfig(char*, int, ISAConf*); +int pciconfig(char*, int, Pciconf*); void kbdenable(void); void kbdinit(void); void kexit(Ureg*); @@ -98,7 +97,6 @@ int mmukmapsync(uvlong); uintmem mmuphysaddr(uintptr); int mmuwalk(PTE*, uintptr, int, PTE**, PTE (*)(usize)); -int multiboot(u32int, u32int, int); void ndnr(void); uchar nvramread(int); void nvramwrite(int, uchar); --- /sys/src/nix/k10/main.c Thu Jun 14 09:36:23 2012 +++ /sys/src/nix/k10/main.c Thu Jun 21 08:19:33 2012 @@ -11,8 +11,8 @@ Conf conf; /* XXX - must go - gag */ -extern void crapoptions(void); /* XXX - must go */ -extern void confsetenv(void); /* XXX - must go */ +extern void options(void); +extern void confsetenv(void); static uintptr sp; /* XXX - must go - user stack of init proc */ @@ -22,9 +22,7 @@ /* * Option arguments from the command line. - * oargv[0] is the boot file. - * Optionsinit() is called from multiboot() to - * set it all up. + * not currently used. */ static int oargc; static char* oargv[20]; @@ -35,7 +33,6 @@ static int numtcs = 32; /* initial # of TCs */ char dbgflg[256]; -static int vflag = 0; void optionsinit(char* s) @@ -45,43 +42,6 @@ oargv[oargc] = nil; } -static void -options(int argc, char* argv[]) -{ - char *p; - int n, o; - - /* - * Process flags. - * Flags [A-Za-z] may be optionally followed by - * an integer level between 1 and 127 inclusive - * (no space between flag and level). - * '--' ends flag processing. - */ - while(--argc > 0 && (*++argv)[0] == '-' && (*argv)[1] != '-'){ - while(o = *++argv[0]){ - if(!(o >= 'A' && o <= 'Z') && !(o >= 'a' && o <= 'z')) - continue; - n = strtol(argv[0]+1, &p, 0); - if(p == argv[0]+1 || n < 1 || n > 127) - n = 1; - argv[0] = p-1; - dbgflg[o] = n; - } - } - vflag = dbgflg['v']; - if(argc > 0){ - maxcores = strtol(argv[0], 0, 0); - argc--; - argv++; - } - if(argc > 0){ - numtcs = strtol(argv[0], 0, 0); - //argc--; - //argv++; - } -} - static int istentacle; void @@ -258,7 +218,7 @@ } void -main(u32int ax, u32int bx) +main(u32int, u32int) { vlong hz; @@ -285,9 +245,7 @@ rolestable(m); asminit(); - multiboot(ax, bx, 0); - options(oargc, oargv); - crapoptions(); + options(); /* * Need something for initial delays @@ -306,10 +264,6 @@ fmtinit(); print("\nNIX\n"); - if(vflag){ - print("&ax = %#p, ax = %#ux, bx = %#ux\n", &ax, ax, bx); - multiboot(ax, bx, vflag); - } m->perf.period = 1; if((hz = archhz()) != 0ll){ @@ -341,7 +295,7 @@ * things like that completely broken). */ acpiinit(); - + umeminit(); trapinit(); printinit(); @@ -354,7 +308,6 @@ */ i8259init(32); - procinit0(); mpsinit(maxcores); apiconline(); @@ -566,7 +519,7 @@ void reboot(void*, void*, long) { - panic("reboot\n"); + panic("reboot"); } void --- /sys/src/nix/k10/k8cpu Tue Apr 24 10:39:34 2012 +++ /sys/src/nix/k10/k8cpu Thu Jun 21 08:32:39 2012 @@ -13,7 +13,7 @@ ssl cap kprof - pmc pmcio +# pmc pmcio segment acpi zp @@ -75,6 +75,7 @@ # boot cpu tcp + il rootdir bootk8cpu.out boot @@ -135,7 +136,7 @@ archk10 asm cga - crap + options fpu i8254 i8259 @@ -144,7 +145,6 @@ map memory mmu - multiboot qmalloc random syscall