pc, pc64: preserve last KB of conventional memory (might contain bios tables)
we add new function convmemsize() that returns the size of *usable* conventional memory that does some sanity checking and reserves the last KB below the top of memory pointer. this avoids lowraminit() overriding potential bios tables and sigsearch() going off the rails looking for tables at above 640K.
This commit is contained in:
parent
5a6131ea09
commit
529082d34d
2 changed files with 44 additions and 20 deletions
|
@ -340,6 +340,24 @@ sigscan(uchar* addr, int len, char* signature)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uintptr
|
||||||
|
convmemsize(void)
|
||||||
|
{
|
||||||
|
uintptr top;
|
||||||
|
uchar *bda;
|
||||||
|
|
||||||
|
bda = KADDR(0x400);
|
||||||
|
top = ((bda[0x14]<<8) | bda[0x13])*KB;
|
||||||
|
|
||||||
|
if(top < 64*KB || top > 640*KB)
|
||||||
|
top = 640*KB; /* sanity */
|
||||||
|
|
||||||
|
/* reserved for bios tables (EBDA) */
|
||||||
|
top -= 1*KB;
|
||||||
|
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
sigsearch(char* signature)
|
sigsearch(char* signature)
|
||||||
{
|
{
|
||||||
|
@ -362,11 +380,9 @@ sigsearch(char* signature)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if((r = sigscan(KADDR(convmemsize()), 1024, signature)) != nil)
|
||||||
|
return r;
|
||||||
|
|
||||||
if((p = ((bda[0x14]<<8)|bda[0x13])*1024) != 0){
|
|
||||||
if((r = sigscan(KADDR(p-1024), 1024, signature)) != nil)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
/* hack for virtualbox: look in KiB below 0xa0000 */
|
/* hack for virtualbox: look in KiB below 0xa0000 */
|
||||||
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature)) != nil)
|
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature)) != nil)
|
||||||
return r;
|
return r;
|
||||||
|
@ -377,8 +393,7 @@ sigsearch(char* signature)
|
||||||
static void
|
static void
|
||||||
lowraminit(void)
|
lowraminit(void)
|
||||||
{
|
{
|
||||||
ulong pa, x;
|
uintptr pa, x;
|
||||||
uchar *bda;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise the memory bank information for conventional memory
|
* Initialise the memory bank information for conventional memory
|
||||||
|
@ -387,16 +402,13 @@ lowraminit(void)
|
||||||
* the BIOS data area.
|
* the BIOS data area.
|
||||||
*/
|
*/
|
||||||
x = PADDR(CPU0END);
|
x = PADDR(CPU0END);
|
||||||
bda = (uchar*)KADDR(0x400);
|
pa = convmemsize();
|
||||||
pa = ((bda[0x14]<<8)|bda[0x13])*KB;
|
|
||||||
if(pa > 640*KB)
|
|
||||||
pa = 640*KB;
|
|
||||||
if(x < pa){
|
if(x < pa){
|
||||||
mapfree(&rmapram, x, pa-x);
|
mapfree(&rmapram, x, pa-x);
|
||||||
memset(KADDR(x), 0, pa-x); /* keep us honest */
|
memset(KADDR(x), 0, pa-x); /* keep us honest */
|
||||||
}
|
}
|
||||||
|
|
||||||
x = PADDR(PGROUND((ulong)end));
|
x = PADDR(PGROUND((uintptr)end));
|
||||||
pa = MemMin;
|
pa = MemMin;
|
||||||
if(x > pa)
|
if(x > pa)
|
||||||
panic("kernel too big");
|
panic("kernel too big");
|
||||||
|
|
|
@ -337,6 +337,24 @@ sigscan(uchar* addr, int len, char* signature)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uintptr
|
||||||
|
convmemsize(void)
|
||||||
|
{
|
||||||
|
uintptr top;
|
||||||
|
uchar *bda;
|
||||||
|
|
||||||
|
bda = KADDR(0x400);
|
||||||
|
top = ((bda[0x14]<<8) | bda[0x13])*KB;
|
||||||
|
|
||||||
|
if(top < 64*KB || top > 640*KB)
|
||||||
|
top = 640*KB; /* sanity */
|
||||||
|
|
||||||
|
/* reserved for bios tables (EBDA) */
|
||||||
|
top -= 1*KB;
|
||||||
|
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
sigsearch(char* signature)
|
sigsearch(char* signature)
|
||||||
{
|
{
|
||||||
|
@ -359,11 +377,9 @@ sigsearch(char* signature)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if((r = sigscan(KADDR(convmemsize()), 1024, signature)) != nil)
|
||||||
|
return r;
|
||||||
|
|
||||||
if((p = ((bda[0x14]<<8)|bda[0x13])*1024) != 0){
|
|
||||||
if((r = sigscan(KADDR(p-1024), 1024, signature)) != nil)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
/* hack for virtualbox: look in KiB below 0xa0000 */
|
/* hack for virtualbox: look in KiB below 0xa0000 */
|
||||||
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature)) != nil)
|
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature)) != nil)
|
||||||
return r;
|
return r;
|
||||||
|
@ -375,7 +391,6 @@ static void
|
||||||
lowraminit(void)
|
lowraminit(void)
|
||||||
{
|
{
|
||||||
uintptr pa, x;
|
uintptr pa, x;
|
||||||
uchar *bda;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise the memory bank information for conventional memory
|
* Initialise the memory bank information for conventional memory
|
||||||
|
@ -384,10 +399,7 @@ lowraminit(void)
|
||||||
* the BIOS data area.
|
* the BIOS data area.
|
||||||
*/
|
*/
|
||||||
x = PADDR(CPU0END);
|
x = PADDR(CPU0END);
|
||||||
bda = (uchar*)KADDR(0x400);
|
pa = convmemsize();
|
||||||
pa = ((bda[0x14]<<8)|bda[0x13])*KB;
|
|
||||||
if(pa > 640*KB)
|
|
||||||
pa = 640*KB;
|
|
||||||
if(x < pa){
|
if(x < pa){
|
||||||
mapfree(&rmapram, x, pa-x);
|
mapfree(&rmapram, x, pa-x);
|
||||||
memset(KADDR(x), 0, pa-x); /* keep us honest */
|
memset(KADDR(x), 0, pa-x); /* keep us honest */
|
||||||
|
|
Loading…
Reference in a new issue