My OS does not boot in real hardware

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

Re: My OS does not boot in real hardware

Post by deleted8917 »

If I remember correctly, GRUB enables the protected mode, A20 and GDT?
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: My OS does not boot in real hardware

Post by Octocontrabass »

The CPU will be in protected mode. The A20 line will be enabled. The GDT will not be set up, so you must set up your own GDT before you can load any segment registers.

That's all explained in the multiboot specification in section 3.3, "I386 machine state". You should search the specification before asking here; otherwise you'll just get a lot of answers telling you to look in the spec.
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: My OS does not boot in real hardware

Post by MichaelPetch »

GRUB enables A20, enters 32-bit Protected mode with its own GDT. However, this is important - you should be establishing your own GDT because The Multiboot spec makes it clear the GDT record that gets loaded with LGDT should be considered invalid. You also don't know which selectors GRUB will use for code and data. The first time you attempt to load/reload a selector it could cause a crash. This is a real possibility if you enable your Interrupt Descriptor table and establish your own interrupt handlers. The documentation for Multiboot (legacy) is here: https://www.gnu.org/software/grub/manua ... iboot.html
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: My OS does not boot in real hardware

Post by deleted8917 »

Thanks for the info. I'm gonna to port my OS to use GRUB.
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: My OS does not boot in real hardware

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
User avatar
zity
Member
Member
Posts: 99
Joined: Mon Jul 13, 2009 5:52 am
Location: Denmark

Re: My OS does not boot in real hardware

Post by zity »

I'm not entirely sure this is the reason you get "no multiboot header found", but your header is incomplete. When using the MULTIBOOT_AOUT_KLUDGE you need to specify information about the layout of your binary file. Have a look here https://www.gnu.org/software/grub/manua ... der-layout

For example, in my own loader I have the following header:

Code: Select all

mboot:
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
    dd  mboot                    ; Location of this descriptor
    dd  code                     ; Start of the .text (code) section (defined in linker script)
    dd  bss                      ; End of the .data section (defined in linker script)
    dd  end                      ; End of loader (defined in linker script)
    dd  start                    ; Entry point below
deleted8917
Member
Member
Posts: 119
Joined: Wed Dec 12, 2018 12:16 pm

Re: My OS does not boot in real hardware

Post by deleted8917 »

zity wrote:I'm not entirely sure this is the reason you get "no multiboot header found"
Also, I don't know, just bad luck I think. Using the bare bones NASM bootloader I get "invalid arch dependent elf magic" error.
#-o
Post Reply