Wrong Placement of the Multiboot-Header

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.
Post Reply
Neatoro
Posts: 2
Joined: Sun Jul 14, 2019 12:52 am

Wrong Placement of the Multiboot-Header

Post by Neatoro »

Hey folks,

yesterday I added some code to my kernel after I followed the Bare Bones tutorial (https://wiki.osdev.org/Bare_Bones). Afterwards I got the error that GRUB is not anymore able to find the multiboot header. I checked the .bin file and saw that for some reasons the multiboot header is placed after the actual kernel code. At least I am guessing that it is placed after the kernel code because I see "Hello World" some bytes before.

I currently have the feeling that something is off with my linker configuration, but I have no clue what. Maybe someone of you could give my some insights:

Code: Select all

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)
    }

}

Code: Select all

.set ALIGN, 1<<0
.set MEMINFO, 1<<1
.set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)

.section multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

.section .bss
.align 16

stack_bottom:
.skip 16384
stack_top:

.section .text
.global _start
.type _start, @function
_start:
    mov $stack_top, %esp
    
    call kernel_main

    cli
1:  hlt
    jmp 1b

.size _start, . - _start
multibootheader.PNG
Thanks for your help!
Neatoro
Posts: 2
Joined: Sun Jul 14, 2019 12:52 am

Re: Wrong Placement of the Multiboot-Header

Post by Neatoro »

I fixed it, was missing a dot in the assembly code

Code: Select all

.section .multiboot
Post Reply