Detecting Memory (x86): Difference between revisions

m
→‎Memory Map Via GRUB: Corrected info about pushing EAX and EBX, since the C Bare Bones tutorial no longer does this
[unchecked revision][unchecked revision]
(Added note about gcc packing multiboot structure wrong)
m (→‎Memory Map Via GRUB: Corrected info about pushing EAX and EBX, since the C Bare Bones tutorial no longer does this)
Line 293:
However, it does not take into account any bugs that are known to effect some BIOSs (see entries in [[RBIL]]). It does not check "E801" and/or "88" returning with carry set.
 
To utilize the information that GRUB passes to you, first include the file [https://www.gnu.org/software/grub/manual/multiboot/html_node/multiboot_002eh.html multiboot.h] in your kernel's main file. Then, make sure that when you load your _main function from your assembly loader, you push EAX and EBX onto the stack. TheMake [[:Category:Baresure bonesto tutorialsdo this before calling any other initialization functions, such as [[Calling_Global_Constructors|Bareglobal bonesconstructor tutorialsinitialization]], haveor alreadythe doneinitialization thisfunction(s) forwill youprobably clobber the registers. Then, define your start function as such:
 
The key for memory detection lies in the multiboot_info struct. To get access to it, you've already pushed it onto the stack...define your start function as such:
 
_main (multiboot_info_t* mbd, unsigned int magic) {...}
 
The key for memory detection lies in the multiboot_info struct. To determine the contiguous memory size, you may simply check <tt>mbd->flags</tt> to verify bit 0 is set, and then you can safely refer to <tt>mbd->mem_lower</tt> for conventional memory (e.g. physical addresses ranging between 0 and 640KB) and <tt>mbd->mem_upper</tt> for high memory (e.g. from 1MB). Both are given in kibibytes, i.e. blocks of 1024 bytes each.
 
To get a complete memory map, check bit 6 of <tt>mbd->flags</tt> and use <tt>mbd->mmap_addr</tt> to access the BIOS-provided memory map. Quoting [http://www.gnu.org/software/grub/manual/multiboot/html_node/Boot-information-format.html#Boot%20information%20format specifications],
Anonymous user