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

GRUB: no multiboot header found

Post by deleted8917 »

Hi, again here (as expected). I ported almost successfully my OS to GRUB, but I get this error:

Code: Select all

error: no multiboot header found
I already searched the error in Google, but I find no solution. (that can help me)
Here is bootg.asm:

Code: Select all

bits 32

%include "gdt.inc"
%include "idt.inc"

global start
extern kernelmain

start:
    mov esp, _sys_stack    
    jmp stublet

ALIGN 4
mboot:
    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM

    call InstallGDT

    call kernelmain
stublet:
    jmp $

SECTION .bss
    resb 8192              
_sys_stack:

The linker script is the same that can be finded in Bare bones
PS: I reposted this in a different thread, because the original was taking to much pages and the thread went out of the original theme.
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: GRUB: no multiboot header found

Post by nullplan »

Inspect your kernel file. Is the multiboot header within the first 4kB? If not, why not? What else is there?

The linker script you mentioned uses a multiboot section, but you don't define one here.
Carpe diem!
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: GRUB: no multiboot header found

Post by thomtl »

In your linker script you put the multiboot header in the .multiboot section your code doesn't do this this would be correct code

https://pastebin.com/mSPh9hi1
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post by deleted8917 »

nullplan wrote:Inspect your kernel file. Is the multiboot header within the first 4kB? If not, why not? What else is there?

The linker script you mentioned uses a multiboot section, but you don't define one here.
Well, now I used the same bootloader file (NASM) that can be finded in the Bare bones tutorial, but I get (again) this error:

Code: Select all

error: invalid arch dependent ELF magic
My kernel is compiled into an ELF, but then transformed into a flat binary using objdump. It doesn't make sense (at least for me).
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post by deleted8917 »

thomtl wrote:In your linker script you put the multiboot header in the .multiboot section your code doesn't do this this would be correct code

https://pastebin.com/mSPh9hi1
Your answer appeared just before I published my answer. I tried the code you passed through pastebin (is it the same code I posted?), but I get this error:

Code: Select all

error: out of memory
Also I tried running my OS in VirtualBox, but I get the same error.
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: GRUB: no multiboot header found

Post by thomtl »

I just looked through your git repo and you seem to be having a weird combination of a custom bootloader and GRUB. Please read through Bare Bones and choose one GRUB or custom. Or if the git repo is outdated please update it so I can see your entire codebase and see what is going wrong.
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post by deleted8917 »

thomtl wrote:I just looked through your git repo and you seem to be having a weird combination of a custom bootloader and GRUB. Please read through Bare Bones and choose one GRUB or custom. Or if the git repo is outdated please update it so I can see your entire codebase and see what is going wrong.
No, there's no "weird" combination. It's just that I haven't commited the current code yet.
The code that is in my repo uses custom bootloader, but now I'm working to use GRUB instead.
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: GRUB: no multiboot header found

Post by thomtl »

Could you commit the new code?
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post by deleted8917 »

thomtl wrote:Could you commit the new code?
Yes, it's already commited.
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: GRUB: no multiboot header found

Post by thomtl »

First, GRUB loads ELF and A.OUT files and not flat binaries, so you'd want to change your build script (also make a makefile)
and you set the A.OUT kludge flag when you don't even have a A.OUT file
EDIT: you might also want to change the stublet label to not infinetly loop
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post by deleted8917 »

I fixed the bootloader. I know that I need to make a makefile.
Now I get "error: out of memory" #-o
Any idea? I'm getting crazy!
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: GRUB: no multiboot header found

Post by Octocontrabass »

You're probably getting that error because your multiboot header is still malformed. Did you read this post?
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: GRUB: no multiboot header found

Post by MichaelPetch »

Change bootg.asm to:

Code: Select all

bits 32

%include "gdt.inc"
%include "idt.inc"

global start
extern kernelmain

section .multiboot
ALIGN 4
mboot:
    MULTIBOOT_PAGE_ALIGN   equ 1<<0
    MULTIBOOT_MEMORY_INFO   equ 1<<1
    MULTIBOOT_HEADER_MAGIC   equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS   equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
    MULTIBOOT_CHECKSUM   equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM

section .text
start:
    mov esp, _sys_stack
    call InstallGDT
    call kernelmain
    jmp $

section .bss
    resb 8192
_sys_stack:
Change grub.cfg to:

Code: Select all

menuentry "Gryphus" {
        echo Gryphus is loading. Please wait.
        multiboot /boot/os.elf
}
In gdt.inc you have an STI instruction after loading the GDT but you don't have an IDT installed. You will probably want to remove that STI. Your InstallGDT doesn't reload the segment registers so it should probably look something like:

Code: Select all

InstallGDT:
    pusha               ; save registers
    lgdt[toc]           ; load GDT into GDTR
    jmp 0x08:.setcs     ; Set CS to 0x08
.setcs:
    mov ax, 0x10        ; Set the data segment registers
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax

    popa                ; restore registers
    ret                 ; All done!
I'd also highly recommend putting a section .text at the top of idt.inc. a section .text before InstallGDT in gdt.inc and a section .data before the GDT data in gdt.inc . This is useful to put the code and data in the right sections when they are included by bootg.asm .
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: GRUB: no multiboot header found

Post by nullplan »

hextakatt wrote:
nullplan wrote:Inspect your kernel file. Is the multiboot header within the first 4kB? If not, why not? What else is there?

The linker script you mentioned uses a multiboot section, but you don't define one here.
Well, now I used the same bootloader file (NASM) that can be finded in the Bare bones tutorial, but I get (again) this error:

Code: Select all

error: invalid arch dependent ELF magic
My kernel is compiled into an ELF, but then transformed into a flat binary using objdump. It doesn't make sense (at least for me).
That means you successfully negotiated the first pass (having GRUB find the multiboot header). But since your kernel isn't ELF (you make it a flat bin, after all), your multiboot header also needs the a.out kludge in order for GRUB to know where to load your kernel and where to jump to for the start. The specification calls those the address fields, and you need to set flags[16] as well.
Carpe diem!
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: GRUB: no multiboot header found

Post by deleted8917 »

nullplan wrote:
hextakatt wrote:
nullplan wrote:Inspect your kernel file. Is the multiboot header within the first 4kB? If not, why not? What else is there?

The linker script you mentioned uses a multiboot section, but you don't define one here.
Well, now I used the same bootloader file (NASM) that can be finded in the Bare bones tutorial, but I get (again) this error:

Code: Select all

error: invalid arch dependent ELF magic
My kernel is compiled into an ELF, but then transformed into a flat binary using objdump. It doesn't make sense (at least for me).
That means you successfully negotiated the first pass (having GRUB find the multiboot header). But since your kernel isn't ELF (you make it a flat bin, after all), your multiboot header also needs the a.out kludge in order for GRUB to know where to load your kernel and where to jump to for the start. The specification calls those the address fields, and you need to set flags[16] as well.
Well, now my kernel is an ELF, and thanks, now it works properly.
Now I'm trying to get a memory map, so I can get available memory, total memory and well you know...
But I get a incorrect value, In VirtualBox with 512MB of RAM. I get 33486463.
I use this to get total memory:

Code: Select all

uint32_t memsiz = 1024 + mbd->mem_lower + mbd->mem_upper * 64;
Using multiboot struct from multiboot.h btw
Can't I do anything right? :|
Post Reply