Page 1 of 2

GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 12:54 pm
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.

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 1:51 pm
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.

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:08 pm
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

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:11 pm
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).

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:16 pm
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.

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:19 pm
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.

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:24 pm
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.

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:33 pm
by thomtl
Could you commit the new code?

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:35 pm
by deleted8917
thomtl wrote:Could you commit the new code?
Yes, it's already commited.

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:42 pm
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

Re: GRUB: no multiboot header found

Posted: Tue Feb 19, 2019 2:54 pm
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!

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 2:06 am
by Octocontrabass
You're probably getting that error because your multiboot header is still malformed. Did you read this post?

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 5:51 am
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 .

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 10:48 am
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.

Re: GRUB: no multiboot header found

Posted: Wed Feb 20, 2019 11:04 am
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? :|