OSDev.org
https://forum.osdev.org/

Multiboot2 header: unrecognized tag
https://forum.osdev.org/viewtopic.php?f=1&t=32930
Page 1 of 1

Author:  alexander [ Fri May 11, 2018 10:24 am ]
Post subject:  Multiboot2 header: unrecognized tag

I am trying to load my kernel with grub. Grub tells me that it found an unrecognized tag(0x18). This is the assembly file with my header:
Code:
%include "multiboot2.inc"
BITS 32

section .multiboot
multiboot_header:
align MULTIBOOT_HEADER_ALIGN
    dd MULTIBOOT2_HEADER_MAGIC      ; magic
    dd MULTIBOOT_ARCHITECTURE_I386  ; architecture
    dd multiboot_header_end - multiboot_header
    dd -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header)) ; checksum
mbi_tag_start:
    dw MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST ; type
    dw MULTIBOOT_HEADER_TAG_OPTIONAL            ; flags
    dd mbi_tag_end - mbi_tag_start
    dd MULTIBOOT_TAG_TYPE_CMDLINE
    dd MULTIBOOT_TAG_TYPE_MMAP
    dd MULTIBOOT_TAG_TYPE_FRAMEBUFFER
mbi_tag_end:
address_tag_start:
    dw MULTIBOOT_HEADER_TAG_ADDRESS         ; type
    dw MULTIBOOT_HEADER_TAG_OPTIONAL        ; flags
    dd address_tag_end - address_tag_start  ; size
    dd multiboot_header                     ; header address
    dd text_start                           ; load address
    dd text_end                             ; load end address
    dd bss_end                              ; bss end address
address_tag_end:
entry_address_tag_start:
    dw MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS               ; type
    dw MULTIBOOT_HEADER_TAG_OPTIONAL                    ; flags
    dd entry_address_tag_end - entry_address_tag_start  ; size
    dd _start
entry_address_tag_end:
framebuffer_tag_start:
    dw MULTIBOOT_HEADER_TAG_FRAMEBUFFER ; type
    dw MULTIBOOT_HEADER_TAG_OPTIONAL    ; flags
    dd 1024                             ; width
    dd 720                              ; height
    dd 32                               ; depth
framebuffer_tag_end: ; I can't find this in the documentation :/
    dw MULTIBOOT_HEADER_TAG_END
    dw 0
    dd 8
multiboot_header_end:

section .text
text_start:
global _start
_start:
    cli
    mov esp, stack_top   ; Set stack pointer
    mov ebp, stack_top   ; Set stack base
    lgdt [gdt_ptr]
    push ebx    ; Push pointer to multiboot info
    push eax    ; Push magic value
    extern main32
    call main32

    ; Kernel ended somehow
loop:
    hlt
    jmp loop
gdt:
    ; null descriptor
    dd 0
    dd 0

    ; code descriptor
    dw 0FFFFh   ; limit low
    dw 0        ; base low
    db 0        ; base middle
    db 10011010b; access
    db 11001111b; granularity
    db 0        ; base high

    ; data descriptor
    dw 0FFFFh   ; limit low
    dw 0        ; base low
    db 0        ; base middle
    db 10010010b; access
    db 11001111b; granularity
    db 0        ; base high
end_of_gdt:
gdt_ptr:
    dw end_of_gdt - gdt - 1 ; limit (Size of GDT)
    dd gdt
text_end:

section .bootstrap_stack, nobits
bss_start:
align 4
stack_bottom:
resb 16384
stack_top:
bss_end:

NASM is giving me a warning when I assemble the file that says that the checksum value is too high for dd. I don't know if that is related but I get the feeling it might be.
While looking at the produced binary file in a hex editor I've come to the conclusion that the value 0x18 is actually the size specified in the address tag.
I have annotated what the hex editor showed me, I would appreciate it if you were tell me if I made any mistakes:
Image

My linker.ld:
Code:
ENTRY(_start)

SECTIONS
{
    . = 1M;

    .text BLOCK(4K) : ALIGN(4K)
    {
        *(.multiboot)
        *(.text)
    }

    .rodata BLOCK(4K) : ALIGN(4K)
    {
        *(.rodata)
    }

    .data BLOCK(4K) : ALIGN(4K)
    {
        *(.data)
    }

    .bss BLOCK(4K) : ALIGN(4K)
    {
        *(COMMON)
        *(.bss)
        *(.bootstrap_stack)
    }
}

I am assembling and linking like this:
Code:
nasm -f elf -isrc/headers/ src/kernel/arch/i686/boot.asm -o build/kernel/arch/i686/boot.o
/* A bunch c files are compiled inbetween */
i686-elf-gcc -T linker.ld -o build/isodir/boot/myos.bin -ffreestanding -O2 -nostdlib /* the object files compiled from the c code */ build/kernel/arch/i686/boot.o -lgcc


I've probably made a really obvious mistake and I hope you can find it because couldn't.

Author:  iansjack [ Sat May 12, 2018 1:12 pm ]
Post subject:  Re: Multiboot2 header: unrecognized tag

From the Multiboot 2 specification:

"Tags constitutes a buffer of structures following each other padded when necessary in order for each tag to start at 8-bytes aligned address."

Your second tag isn't aligned.

Author:  alexander [ Sun May 13, 2018 3:14 am ]
Post subject:  Re: Multiboot2 header: unrecognized tag

I had tried aligning all the header tags but I hadn't thought of aligning the mbi tags as well. Thank you this fixed the issue. I fixed the warning NASM was giving me by changing this:
Code:
    dd -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))

into this:
Code:
    dd 0x100000000-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/