Page 2 of 2

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 11:06 am
by MichaelPetch
Did you pass the pointer to the multiboot structure to your kernelmain? EBX contains the pointer to the multiboot structure, EAX should contain the value 0x2BADB002. You could pass both to kernelmain with something like:

Code: Select all

    mov esp, _sys_stack
    call InstallGDT

    push eax
    push ebx
    call kernelmain
    jmp $
Then in kmain.c modify kernelmain's definition to be:

Code: Select all

void kernelmain(multiboot_info_t *mbd, uint32_t magic) {
.You will need to include multiboot.h at the top of kmain.c. That file can be found here: https://www.gnu.org/software/grub/manua ... 002eh.html . Assuming you have tested mbd->flags and bit 0 is set then

Code: Select all

memsiz = 1024 * (mbd->mem_lower + mbd->mem_upper);
where memsiz would be in bytes.

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 2:06 pm
by deleted8917
MichaelPetch wrote:Did you pass the pointer to the multiboot structure to your kernelmain? EBX contains the pointer to the multiboot structure, EAX should contain the value 0x2BADB002. You could pass both to kernelmain with something like:

Code: Select all

    mov esp, _sys_stack
    call InstallGDT

    push eax
    push ebx
    call kernelmain
    jmp $
Then in kmain.c modify kernelmain's definition to be:

Code: Select all

void kernelmain(multiboot_info_t *mbd, uint32_t magic) {
.You will need to include multiboot.h at the top of kmain.c. That file can be found here: https://www.gnu.org/software/grub/manua ... 002eh.html . Assuming you have tested mbd->flags and bit 0 is set then

Code: Select all

memsiz = 1024 * (mbd->mem_lower + mbd->mem_upper);
where memsiz would be in bytes.
Yes, I've pushed the values to stack, and modified the kernelmain definition.
The problem was my formula, which was wrong. I should later convert it to Mebibytes, right?

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 2:32 pm
by MichaelPetch
To get MiB the formula would be (lower+upper)/1024 . If you want that rounded up to the nearest MiB it would be (lower+upper+1023)/1024