Hi,
zman97211 wrote:My first thought is that some older computers don't seem to support the method Grub uses to build it's memory map (I have a 486 on which Grub doesn't pass one to my kernel). So, in this case, can I take the "mmap_upper", add 1024 to it, multiply by 1024 to get the highest address? When I do this, I get a value that is 64kb short (it stops where the ACPI reclaimable memory is at).
The "int 0x15, eax=0xE820" BIOS function (that GRUB uses to get the memory map) is part of the ACPI specification. If GRUB can't tell you a memory map, then the computer is too old to support this BIOS function and too old to support ACPI, and there won't be any ACPI reclaimable area. In this case, adding anything to "mmap_upper" would be a mistake.
Also note that (for older computers that don't support "int 0x15, eax=0xE820") the "mmap_upper" may be incorrect and/or inadequate. Incorrect because GRUB isn't very good and doesn't take into account various BIOS bugs. There's several reasons why it could be inadequate.
To begin with, RAM above 0x00100000 may not be contiguous (e.g. there may be a hole for ISA devices from 0x00F00000 to 0x00FFFFFF), and in this case the BIOS (and GRUB) will only return the RAM that starts at 0x00100000 (e.g. it might say that there's 14 MiB of RAM at 0x00100000 but can't tell you that there's another 16 MiB of RAM at 0x01000000). Also some of the BIOS functions GRUB relies on are limited. For example, "int 0x15, ah=0x88" returns the number of contiguous 1 KiB blocks of RAM starting at 0x00100000 as a 16-bit integer, which is limited to 65536 KiB of RAM starting at 0x00100000. If there's 32 MiB of RAM (or 31 MiB starting at 0x00100000) some BIOSs will only tell you about 65536 KiB (the maximum it can tell you about) and some BIOSs will only tell you about 64512 KiB.
If GRUB's dodgy memory detection creates dodgy results then the user can override it with the "uppermem" command. This is also unable to handle systems with more than one area of RAM above 0x00100000 (and there's no way for the user to supply a correct/complete memory map). It also means that when GRUB's memory detection does return correct results, the end user can stuff things up by overriding it with their own wrong results...
For a hobby OS, GRUB is probably "good enough". If you care about reliability and want to make sure the OS works correctly on the largest number of computers possible, then my advice is to do it yourself. For example, after GRUB has booted your code you can switch back to real mode, detect the memory properly, then switch back to protected mode.
Finally, if you're building a bitmap that has to cover all possible pages of RAM, and if you want to support "hot add" memory some time in the future, then you need to look for and parse the "SRAT" ACPI table before deciding how large your bitmap needs to be.
Cheers,
Brendan