GRUB: no multiboot header found

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: GRUB: no multiboot header found

Post 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.
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post 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?
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: GRUB: no multiboot header found

Post 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
Post Reply