I'm trying to parse the multiboot structure passed by the bootloader to my kernel in order to implement memory allocation for paging. I've followed the example from the multiboot specifications (https://www.gnu.org/software/grub/manua ... rnel_002ec), but the memory map from GRUB is invalid... all I'm getting is type = 0. I've tried booting from both bin (qemu-system-i386 -kernel myos.bin) and iso (qemu-system-i386 -cdrom myos.iso) but none of them give me a correct memory map.
Here is the output
Here is the assembly that calls kernel_main:
Code: Select all
_start:
; To set up a stack, we simply set the esp register to point to the top of
; our stack (as it grows downwards).
mov esp, stack_top
; Push pointer to the Multiboot information structure
push ebx
extern kernel_main
call kernel_main
cli
.hang:
hlt
jmp .hang
Code: Select all
if (mbi->flags & MULTIBOOT_INFO_MEMORY)
{
vga_printf("mem_lower = %uKB, mem_upper = %uKB\n",
(uint32_t)mbi->mem_lower, (uint32_t)mbi->mem_upper);
}
if (mbi->flags & MULTIBOOT_INFO_MEM_MAP)
{
vga_printf("mmap_addr = 0x%x, mmap_length = 0x%x\n",
(uint32_t)mbi->mmap_addr, (uint32_t)mbi->mmap_length);
for (mmap = (struct multiboot_mmap_entry*)mbi->mmap_addr;
(uint32_t)mmap < (mbi->mmap_addr + mbi->mmap_length);
mmap = (struct multiboot_mmap_entry*)((uint32_t)mmap
+ mmap->size + sizeof(mmap->size)))
{
vga_printf("base_addr_high = 0x%x, base_addr_low = 0x%x, "
"length_high = 0x%x, length_low = 0x%x, type = 0x%x\n",
mmap->addr >> 32,
mmap->addr & 0xFFFFFFFF,
mmap->len >> 32,
mmap->len & 0xFFFFFFFF,
(uint32_t)mmap->type);
}
}