Search code examples
kernelnasmosdevgrubmultiboot

Why does grub-file say that NASM raw binary is not multiboot2 compliant?


I am trying to make a minimal kernel. My goal is to make this not-yet-existing kernel to be multiboot2 compliant. So I started out by creating a minimal multiboot2-header in NASM-Assembly.

I am using grub-file to test whether my binary is compliant.

The problem: When I assemble my file to an elf32, grub-file is happy. However, when i assemble my header to a raw binary using nasm, the resulting file is not compliant.

Why is that? In the multiboot2 specification no specific executable-format is specified.

multiboot2header.asm:

section .multiboot
align 8,db 0
multibootheader_start:
    dd 0xE85250D6
    dd 0
    dd (multibootheader_end - multibootheader_start)
    dd -(0xE85250D6 + multibootheader_end - multibootheader_start)
multibootheader_end:

NASM commands:

nasm -felf32 multiboot2header.asm -o multiboot2header.bin

nasm -fbin multiboot2header.asm -o multiboot2header.bin

grub-file command:

grub-file --is-x86-multiboot2 multiboot2header.bin


Solution

  • I suspect that the problem is caused by not having an address tag structure (see https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html#Address-header-tag ).

    This tag is optional for Elf format files (because the boot loader can just use Elf's headers); but is required for other cases (because the boot loader won't have a clue where to load the file otherwise).