OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:43 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 12:54 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
Hi, again here (as expected). I ported almost successfully my OS to GRUB, but I get this error:
Code:
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:
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.


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 1:51 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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!


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:08 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
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


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:11 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:16 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
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:
error: out of memory

Also I tried running my OS in VirtualBox, but I get the same error.


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:19 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
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.


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:24 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:33 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
Could you commit the new code?


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:35 pm 
Offline
Member
Member

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

Yes, it's already commited.


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:42 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
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


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Tue Feb 19, 2019 2:54 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Wed Feb 20, 2019 2:06 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
You're probably getting that error because your multiboot header is still malformed. Did you read this post?


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Wed Feb 20, 2019 5:51 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
Change bootg.asm to:
Code:
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:
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:
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 .


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Wed Feb 20, 2019 10:48 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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:
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!


Top
 Profile  
 
 Post subject: Re: GRUB: no multiboot header found
PostPosted: Wed Feb 20, 2019 11:04 am 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
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:
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:
uint32_t memsiz = 1024 + mbd->mem_lower + mbd->mem_upper * 64;

Using multiboot struct from multiboot.h btw
Can't I do anything right? :|


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: belliash and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group