Thursday, April 7, 2022

[SOLVED] Multiboot 1 Boot Information total size

Issue

Is there a quick and reliable way find out the total size of the Multiboot 1 boot information in memory?

Just to clarify: I'm not asking about the size of the structure pointed to by the value in the EBX register, I'm asking about the total size of all the information in memory.

I'm currently working on an x86 Multiboot 1 compatible Kernel. The standard offers no guarantees about where GRUB will place this information or its total size. The standard states:

"The Multiboot information structure and its related substructures may be placed anywhere in memory by the boot loader (with the exception of the memory reserved for the kernel and boot modules, of course). It is the operating system’s responsibility to avoid overwriting this memory until it is done using it."

In practice this always seems to be loaded within the lowest 1MB of memory. Up until this point, during boot I initialise my boot paging structures with identity mapping for the lowest 1MB as a way to ensure that the Multiboot information is accessible. Finding out the location of this structure is trivial, but I haven't found any information about finding an accurate size. ( Ideally without walking the entire structure ).


Solution

I've since come to realise that the data pointed to by the Multiboot information structure is not guaranteed to be stored contiguously, and is not the only data loaded into memory by GRUB. As such, without manually walking the structure there is not a reliable way to gauge the total size or location of this memory.

Given this limitation, it seems like the best course of action is to ensure that all data required from the Multiboot structure is copied out to a known location prior to implementing paging.



Answered By - ajxs
Answer Checked By - Candace Johnson (WPSolving Volunteer)