Fixed some problems in memory probe.

This commit is contained in:
erich 1996-10-06 03:06:41 +00:00
parent 9a37393599
commit d30c778c28

View file

@ -30,7 +30,6 @@ struct multiboot_info mbi;
unsigned long saved_drive; unsigned long saved_drive;
unsigned long saved_partition; unsigned long saved_partition;
unsigned long saved_mem_upper; unsigned long saved_mem_upper;
int mem_map = 0;
/* /*
* Error code stuff. * Error code stuff.
@ -90,6 +89,8 @@ static struct AddrRangeDesc fakemap[3] =
void void
init_bios_info(void) init_bios_info(void)
{ {
int cont, memtmp, addr;
/* /*
* Get information from BIOS on installed RAM. * Get information from BIOS on installed RAM.
*/ */
@ -107,17 +108,15 @@ init_bios_info(void)
gateA20(1); gateA20(1);
/* /*
* The "mem_upper" variable only recognizes upper memory in the * The "mbi.mem_upper" variable only recognizes upper memory in the
* first memory region. If there are multiple memory regions, * first memory region. If there are multiple memory regions,
* the rest are reported to a Multiboot-compliant OS, but otherwise * the rest are reported to a Multiboot-compliant OS, but otherwise
* unused by GRUB. * unused by GRUB.
*/ */
{
int cont = 0, mem1, mem2, addr;
mbi.mmap_addr = (addr = (((int) end) & ~3) + 4); mbi.mmap_addr = (addr = (((int) end) & ~3) + 4);
mbi.mmap_length = 0; mbi.mmap_length = 0;
cont = 0;
do do
{ {
@ -126,39 +125,54 @@ init_bios_info(void)
if ( ! *((int *)addr) ) if ( ! *((int *)addr) )
break; break;
mbi.mmap_length += *((int *)addr) + 4;
addr += *((int *)addr) + 4;
}
while (cont);
if (mbi.mmap_length)
{
/* /*
* This is to get the upper memory up to the first memory * This is to get the upper memory up to the first memory
* hole into the "mbi.mem_upper" element, for OS's that * hole into the "mbi.mem_upper" element, for OS's that
* don't care about the memory map, but might care about * don't care about the memory map, but might care about
* RAM above 64MB. * RAM above 64MB.
*
* A big problem is that the memory areas aren't guaranteed
* to be: (1) contiguous, (2) sorted in ascending order, or
* (3) non-overlapping.
*/ */
if (((struct AddrRangeDesc *)addr)->BaseAddrLow == 0x100000 memtmp = 0x100000;
&& ((struct AddrRangeDesc *)addr)->BaseAddrHigh == 0
&& ((struct AddrRangeDesc *)addr)->Type == MB_ARD_MEMORY) do
{ {
/* limit to 4G, as most OS's would probably break with more */ for (cont = 0, addr = mbi.mmap_addr;
addr < mbi.mmap_addr + mbi.mmap_length;
if (!((struct AddrRangeDesc *)addr)->LengthHigh) addr += *((int *) addr) + 4)
mbi.mem_upper = ((struct AddrRangeDesc *)addr)->LengthLow >> 10; {
else if (((struct AddrRangeDesc *)addr)->BaseAddrHigh == 0
mbi.mem_upper = 0x3FBFC0; /* 4G - 1M - 64K */ && ((struct AddrRangeDesc *)addr)->Type == MB_ARD_MEMORY
&& ((struct AddrRangeDesc *)addr)->BaseAddrLow <= memtmp
&& (((struct AddrRangeDesc *)addr)->BaseAddrLow
+ ((struct AddrRangeDesc *)addr)->LengthLow) > memtmp)
{
memtmp = (((struct AddrRangeDesc *)addr)->BaseAddrLow
+ ((struct AddrRangeDesc *)addr)->LengthLow);
cont++;
}
} }
mbi.mmap_length += *((int *)addr) + 4;
addr += *((int *)addr) + 4;
mem_map++;
} }
while (cont); while (cont);
if (!mem_map && (mem1 = get_eisamemsize()) != -1) mbi.mem_upper = (memtmp - 0x100000) >> 10;
}
else if ((memtmp = get_eisamemsize()) != -1)
{ {
mem2 = mem1 >> 16; cont = memtmp & ~0xFFFF;
mem1 &= 0xFFFF; memtmp = memtmp & 0xFFFF;
mbi.mem_upper = mem1;
if (!mem2 || (mem1 == 0x3c00)) if (!cont || (memtmp == 0x3c00))
mbi.mem_upper += (mem2 << 6); memtmp += (cont >> 10);
else else
{ {
/* XXX should I do this at all ??? */ /* XXX should I do this at all ??? */
@ -166,11 +180,11 @@ init_bios_info(void)
mbi.mmap_addr = (int)fakemap; mbi.mmap_addr = (int)fakemap;
mbi.mmap_length = sizeof(fakemap); mbi.mmap_length = sizeof(fakemap);
fakemap[0].LengthLow = (mbi.mem_lower << 10); fakemap[0].LengthLow = (mbi.mem_lower << 10);
fakemap[1].LengthLow = (mem1 << 10); fakemap[1].LengthLow = (memtmp << 10);
fakemap[2].LengthLow = (mem2 << 16); fakemap[2].LengthLow = cont;
mem_map++;
}
} }
mbi.mem_upper = memtmp;
} }
saved_mem_upper = mbi.mem_upper; saved_mem_upper = mbi.mem_upper;