Hi,
BasdP wrote:Ah thanks! I get it. I've found out about the memory map. But how can I know what areas of that memory map is used by multiboot data? Is it guaranteed to be continuous?
The boot loader tells you where the multiboot info structure is (via. EBX), and the structure itself is contiguous. However, anything "pointed to" by fields in the structure (e.g. the boot loader name, the VBE controller info, the VBE mode info, etc) are not guaranteed to be anywhere near the multiboot info structure itself.
Also; the memory map is just what the firmware told the boot loader and doesn't include special entries representing "used by multiboot info" or "used by your kernel" or "used by modules". Note that there's also other potential problems (entries in "random" order, entries describing "zero length" areas, entries describing overlapping areas, multiple areas describing adjacent areas of the same type, etc); so (for "100% bullet proof" code) you want to process the memory map (e.g. sort it and sanitise it).
The combination of these things means it's painful to allocate more memory very early during boot - initially, the only memory you're able to use safely is memory that's part of your ".bss" section.
My advice is to copy any data you want to keep from the multiboot information structure into your own ".bss" so that you don't have to worry about accidentally overwriting data you need; then process/sanitise the memory map (while moving it into your ".bss"); then initialise a physical memory manager while making sure that you don't include "usable but already used by kernel or modules" pages as free pages. Mostly; only use memory in your own ".bss" until your physical memory manager is initialised, and only after your physical memory manager is initialised can you (safely) allocate pages/memory without accidentally overwriting something.
Cheers,
Brendan