I'm using grub (I LIKE IT) on a machine that reports only 512K of low
memory via get_memsize, but reports all 640K via the memory map. So
I've moved the memory map scanner in init_bios_info out to a separate
function, and used it for both high and low memory.
2000-05-19 Chip Salzenberg <[EMAIL PROTECTED]>
* stage2/common.c (mmap_avail_at): New function, abstracted out of
init_bios_info, to scan E820 memory map.
(init_bios_info): Use it for _both_ high and low memory.
Index: stage2/common.c
diff -u -2 -r1.8 common.c
--- stage2/common.c 2000/05/05 11:31:43 1.8
+++ stage2/common.c 2000/05/20 05:05:46
@@ -91,8 +91,45 @@
{20, 0x1000000, 0, 0, 0, MB_ARD_MEMORY}
};
-#endif /* STAGE1_5 */
/*
+ * A big problem is that the memory areas aren't guaranteed
+ * to be: (1) contiguous, (2) sorted in ascending order, or
+ * (3) non-overlapping. Thus this kludge.
+ */
+unsigned long
+mmap_avail_at (unsigned long bottom)
+{
+ unsigned long top, addr;
+ int cont;
+
+ top = bottom;
+ do
+ {
+ for (cont = 0, addr = mbi.mmap_addr;
+ addr < mbi.mmap_addr + mbi.mmap_length;
+ addr += *((unsigned long *) addr) + 4)
+ {
+ if (((struct AddrRangeDesc *) addr)->BaseAddrHigh == 0
+ && ((struct AddrRangeDesc *) addr)->Type == MB_ARD_MEMORY
+ && ((struct AddrRangeDesc *) addr)->BaseAddrLow <= top
+ && (((struct AddrRangeDesc *) addr)->BaseAddrLow
+ + ((struct AddrRangeDesc *) addr)->LengthLow) > top)
+ {
+ top = (((struct AddrRangeDesc *) addr)->BaseAddrLow
+ + ((struct AddrRangeDesc *) addr)->LengthLow);
+ cont++;
+ }
+ }
+ }
+ while (cont);
+
+ return top - bottom;
+}
+
+#endif /* !STAGE1_5 */
+
+
+/*
* This queries for BIOS information.
*/
@@ -141,5 +178,5 @@
cont = get_mmap_entry ((void *) addr, cont);
- /* If the returned buffer's base is zero, quit. */
+ /* If the returned buffer's length is zero, quit. */
if (! *((unsigned long *) addr))
break;
@@ -153,38 +190,14 @@
{
/*
- * This is to get the upper memory up to the first memory
- * hole into the "mbi.mem_upper" element, for OS's that
- * don't care about the memory map, but might care about
- * 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.
+ * This is to get the lower memory, and upper memory (up to the
+ * first memory hole), into the "mbi.mem_{lower,upper}"
+ * elements. This is for OS's that don't care about the memory
+ * map, but might care about total RAM available.
*/
- memtmp = 0x100000;
-
- do
- {
- for (cont = 0, addr = mbi.mmap_addr;
- addr < mbi.mmap_addr + mbi.mmap_length;
- addr += *((unsigned long *) addr) + 4)
- {
- if (((struct AddrRangeDesc *) addr)->BaseAddrHigh == 0
- && ((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++;
- }
- }
- }
- while (cont);
+ mbi.mem_lower = mmap_avail_at(0) >> 10;
+ mbi.mem_upper = mmap_avail_at(0x100000) >> 10;
- mbi.mem_upper = (memtmp - 0x100000) >> 10;
-
/* Find the maximum available address. Ignore any memory holes. */
+ memtmp = 0;
for (addr = mbi.mmap_addr;
addr < mbi.mmap_addr + mbi.mmap_length;
--
Chip Salzenberg - a.k.a. - <[EMAIL PROTECTED]>
"I wanted to play hopscotch with the impenetrable mystery of existence,
but he stepped in a wormhole and had to go in early." // MST3K