M pc/ether8003.c => pc/ether8003.c +3 -3
@@ 242,7 242,7 @@ reset(Ether* ether)
ctlr->pstop = HOWMANY(ether->size, Dp8390BufSz);
/*
- * Finally, init the 8390,set the ethernet address
+ * Finally, init the 8390, set the ethernet address
* and claim the memory used.
*/
dp8390reset(ether);
@@ 253,8 253,8 @@ reset(Ether* ether)
}
dp8390setea(ether);
- if(umbmalloc(ether->mem, ether->size, 0) == 0)
- panic("ether8003: 0x%lux reused", ether->mem);
+ if(umbrmalloc(PADDR(ether->mem), ether->size, 0) == 0)
+ panic("ether8003: 0x%luX unavailable", PADDR(ether->mem));
return 0;
}
M pc/fns.h => pc/fns.h +2 -2
@@ 57,8 57,7 @@ void lidt(ushort[3]);
void ltr(ulong);
void mathinit(void);
#define mmuflushtlb(pdb) putcr3(pdb)
-void meminit(void);
-void memscan(void);
+void meminit(ulong);
void mmuinit(void);
#define mmunewpage(x)
ulong* mmuwalk(ulong*, ulong, int);
@@ 98,6 97,7 @@ void touser(void*);
void trapinit(void);
int tas(void*);
ulong umbmalloc(ulong, int, int);
+ulong umbrmalloc(ulong, int, int);
void umbfree(ulong, int);
ulong upamalloc(ulong, int, int);
void upafree(ulong, int);
M pc/main.c => pc/main.c +32 -25
@@ 17,7 17,7 @@ static uchar *sp; /* stack pointer for /boot */
* (e.g. why parse the .ini file twice?).
* There are 1024 bytes available at CONFADDR.
*/
-#define BOOTLINE ((char *)CONFADDR)
+#define BOOTLINE ((char*)CONFADDR)
#define BOOTLINELEN 64
#define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
#define BOOTARGSLEN (1024-BOOTLINELEN)
@@ 57,17 57,17 @@ main(void)
/*
* There is a little leeway here in the ordering but care must be
* taken with dependencies:
- * function depends on
- * ======== ==========
- * machinit m->machno, m->pdb
- * cpuidentify m
- * memscan cpuidentify (needs to know processor
- * type for caching, etc.)
- * archinit memscan (MP config table may be at the
- * top of system physical memory);
+ * function dependencies
+ * ======== ============
+ * machinit depends on: m->machno, m->pdb
+ * cpuidentify depends on :m
+ * confinit calls: meminit
+ * meminit depends on: cpuidentify (needs to know processor
+ * type for caching, etc.)
+ * archinit depends on: meminit (MP config table may be at the
+ * top of system physical memory);
* conf.nmach (not critical, mpinit will check);
- * confinit meminit
- * arch->intrinit trapinit
+ * arch->intrinit depends on: trapinit
*/
conf.nmach = 1;
MACHP(0) = (Mach*)CPU0MACH;
@@ 75,15 75,14 @@ main(void)
machinit();
active.machs = 1;
active.exiting = 0;
+ screeninit();
cpuidentify();
bcompatibility();
- memscan();
- archinit();
confinit();
+ archinit();
xinit();
dmainit();
trapinit();
- screeninit();
printinit();
if(isoldbcom)
print(" ****OLD B.COM - UPGRADE****\n");
@@ 152,8 151,12 @@ init0(void)
strcat(tstr, " %s");
ksetterm(tstr);
ksetenv("cputype", "386");
+ if(cpuserver)
+ ksetenv("service", "cpu");
+ else
+ ksetenv("service", "terminal");
for(i = 0; i < nconf; i++)
- if(confname[i])
+ if(confname[i] && confname[i][0] != '*')
ksetenv(confname[i], confval[i]);
poperror();
}
@@ 246,19 249,19 @@ bootargs(ulong base)
cp[BOOTLINELEN-1] = 0;
buf[0] = 0;
if(strncmp(cp, "fd!", 3) == 0){
- sprint(buf, "local!#f/fd%ddisk", atoi(cp+3));
+ sprint(buf, "local!#f/fd%ddisk", strtol(cp+3, 0, 0));
av[ac++] = pusharg(buf);
} else if(strncmp(cp, "h!", 2) == 0){
- sprint(buf, "local!#H/hd%dfs", atoi(cp+2));
+ sprint(buf, "local!#H/hd%dfs", strtol(cp+2, 0, 0));
av[ac++] = pusharg(buf);
} else if(strncmp(cp, "hd!", 3) == 0){
- sprint(buf, "local!#H/hd%ddisk", atoi(cp+3));
+ sprint(buf, "local!#H/hd%ddisk", strtol(cp+3, 0, 0));
av[ac++] = pusharg(buf);
} else if(strncmp(cp, "s!", 2) == 0){
- sprint(buf, "local!#w/sd%dfs", atoi(cp+2));
+ sprint(buf, "local!#w/sd%dfs", strtol(cp+2, 0, 0));
av[ac++] = pusharg(buf);
} else if(strncmp(cp, "sd!", 3) == 0){
- sprint(buf, "local!#w/sd%ddisk", atoi(cp+3));
+ sprint(buf, "local!#w/sd%ddisk", strtol(cp+3, 0, 0));
av[ac++] = pusharg(buf);
} else if(strncmp(cp, "e!", 2) == 0)
av[ac++] = pusharg("-n");
@@ 334,6 337,7 @@ confinit(void)
char *cp;
char *line[MAXCONF], *p, *q;
extern int defmaxmsg;
+ ulong maxmem;
/*
* parse configuration args from dos file plan9.ini
@@ 354,6 358,7 @@ confinit(void)
}
*p = 0;
+ maxmem = 0;
pcnt = 0;
n = getcfields(cp, line, MAXCONF, "\n");
for(j = 0; j < n; j++){
@@ 367,17 372,19 @@ confinit(void)
*(line[j]+NAMELEN-1) = 0;
confname[nconf] = line[j];
confval[nconf] = cp;
- if(cistrcmp(confname[nconf], "kernelpercent") == 0)
- pcnt = 100 - atoi(confval[nconf]);
- if(cistrcmp(confname[nconf], "defmaxmsg") == 0){
- i = atoi(confval[nconf]);
+ if(cistrcmp(confname[nconf], "*maxmem") == 0)
+ maxmem = strtoul(confval[nconf], 0, 0);
+ if(cistrcmp(confname[nconf], "*kernelpercent") == 0)
+ pcnt = 100 - strtol(confval[nconf], 0, 0);
+ if(cistrcmp(confname[nconf], "*defmaxmsg") == 0){
+ i = strtol(confval[nconf], 0, 0);
if(i < defmaxmsg && i >=128)
defmaxmsg = i;
}
nconf++;
}
- meminit();
+ meminit(maxmem);
conf.npage = conf.npage0 + conf.npage1;
if(pcnt < 10)
M pc/memory.c => pc/memory.c +77 -48
@@ 67,6 67,38 @@ static RMap rmapumb = {
&mapumb[63],
};
+static Map mapumbr[8];
+static RMap rmapumbr = {
+ "UMB device memory",
+ mapumbr,
+ &mapumbr[7],
+};
+
+#define notdef
+#ifdef notdef
+void
+dumpmembank(void)
+{
+ Map *mp;
+ ulong maxpa, maxpa1, maxpa2;
+
+ maxpa = (nvramread(0x18)<<8)|nvramread(0x17);
+ maxpa1 = (nvramread(0x31)<<8)|nvramread(0x30);
+ maxpa2 = (nvramread(0x16)<<8)|nvramread(0x15);
+ print("maxpa = %uX -> %uX, maxpa1 = %uXm maxpa2 = %uX\n",
+ maxpa, MB+maxpa*KB, maxpa1, maxpa2);
+
+ for(mp = rmapram.map; mp->size; mp++)
+ print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
+ for(mp = rmapumb.map; mp->size; mp++)
+ print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
+ for(mp = rmapumbr.map; mp->size; mp++)
+ print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
+ for(mp = rmapupa.map; mp->size; mp++)
+ print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
+}
+#endif /* notdef */
+
void
mapfree(RMap* rmap, ulong addr, int size)
{
@@ 98,7 130,8 @@ mapfree(RMap* rmap, ulong addr, int size)
}
else do{
if(mp >= rmap->mapend){
- print("mapfree: losing %d, %d\n", addr, size);
+ print("mapfree: %s: losing 0x%uX, %d\n",
+ rmap->name, addr, size);
break;
}
t = mp->addr;
@@ 177,17 210,20 @@ umbscan(void)
*/
p = KADDR(0xC8000);
while(p < (uchar*)KADDR(0xE0000)){
- p[0] = 0x55;
- p[1] = 0xAA;
- p[2] = 4;
- if(p[0] == 0x55 && p[1] == 0xAA){
- p += p[2]*512;
- continue;
- }
p[0] = 0xCC;
p[2*KB-1] = 0xCC;
- if(p[0] != 0xCC && p[2*KB-1] != 0xCC)
+ if(p[0] != 0xCC && p[2*KB-1] != 0xCC){
+ p[0] = 0x55;
+ p[1] = 0xAA;
+ p[2] = 4;
+ if(p[0] == 0x55 && p[1] == 0xAA){
+ p += p[2]*512;
+ continue;
+ }
mapfree(&rmapumb, PADDR(p), 2*KB);
+ }
+ else
+ mapfree(&rmapumbr, PADDR(p), 2*KB);
p += 2*KB;
}
@@ 201,7 237,7 @@ umbscan(void)
}
static void
-ramscan(void)
+ramscan(ulong maxmem)
{
ulong *k0, kzero, map, maxpa, pa, *pte, *table, *va, x;
int nvalid[NMemType];
@@ 220,7 256,6 @@ ramscan(void)
* the BIOS data area.
*/
x = PADDR(CPU0MACH+BY2PG);
-
bda = (uchar*)(KZERO|0x400);
mapfree(&rmapram, x, ((bda[0x14]<<8)|bda[0x13])*KB-x);
@@ 230,14 265,20 @@ ramscan(void)
* at least 24MB in case there's a memory gap (up to 8MB) below 16MB;
* in this case the memory from the gap is remapped to the top of
* memory.
- * The value in CMOS is supposed to be the number of KB minus one.
+ * The value in CMOS is supposed to be the number of KB above 1MB.
*/
- maxpa = (nvramread(0x18)<<8)|nvramread(0x17);
- maxpa = MB+(maxpa+1)*KB;
- if(maxpa == 0 || maxpa >= 64*MB)
- maxpa = MemMaxMB*MB;
- if(maxpa < 24*MB)
- maxpa = 24*MB;
+ if(maxmem == 0){
+ x = (nvramread(0x18)<<8)|nvramread(0x17);
+ if(x == 0 || x >= (63*KB))
+ maxpa = MemMaxMB*MB;
+ else
+ maxpa = MB+x*KB;
+ if(maxpa < 24*MB)
+ maxpa = 24*MB;
+ maxmem = MemMaxMB*MB;
+ }
+ else
+ maxpa = maxmem;
/*
* March up memory from the end of the loaded kernel to maxpa
@@ 331,8 372,8 @@ ramscan(void)
}
if(map)
mapfree(&rmapram, map, BY2PG);
- if(pa < MemMaxMB*MB)
- mapfree(&rmapupa, pa, MemMaxMB*MB-pa);
+ if(pa < maxmem)
+ mapfree(&rmapupa, pa, maxmem-pa);
*k0 = kzero;
}
@@ 373,9 414,11 @@ upainit(void)
mapfree(&xrmapupa, addr, pa-addr);
}
+
void
-memscan(void)
+meminit(ulong maxmem)
{
+ Map *mp, *xmp;
ulong pa, *pte;
/*
@@ 395,34 438,9 @@ memscan(void)
mmuflushtlb(PADDR(m->pdb));
umbscan();
- ramscan();
+dumpmembank();
+ ramscan(maxmem);
upainit();
-}
-
-#ifdef notdef
-void
-dumpmembank(void)
-{
- Map *mp;
- ulong maxpa, maxpa1;
-
- maxpa = (nvramread(0x18)<<8)|nvramread(0x17);
- maxpa1 = (nvramread(0x31)<<8)|nvramread(0x30);
- print("maxpa = %uX -> %uX, maxpa1 = %uX\n", maxpa, MB+(maxpa+1)*KB, maxpa1);
-
- for(mp = rmapram.map; mp->size; mp++)
- print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
- for(mp = rmapumb.map; mp->size; mp++)
- print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
- for(mp = rmapupa.map; mp->size; mp++)
- print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
-}
-#endif /* notdef */
-
-void
-meminit(void)
-{
- Map *mp, *xmp;
/*
* Set the conf entries describing two banks of allocatable memory.
@@ 463,6 481,17 @@ umbfree(ulong addr, int size)
}
ulong
+umbrmalloc(ulong addr, int size, int align)
+{
+ ulong a;
+
+ if(a = mapalloc(&rmapumbr, addr, size, align))
+ return KZERO|a;
+
+ return 0;
+}
+
+ulong
upamalloc(ulong addr, int size, int align)
{
ulong a;
M pc/pci.c => pc/pci.c +2 -2
@@ 162,13 162,13 @@ pcicfginit(void)
outb(PciCSE, 0);
if(inb(PciCSE) == 0){
pcicfgmode = 2;
- pcimaxdno = 31;
+ pcimaxdno = 15;
}
else{
outl(PciADDR, 0);
if(inl(PciADDR) == 0){
pcicfgmode = 1;
- pcimaxdno = 15;
+ pcimaxdno = 31;
}
}