Page 4 of 4

Re: My OS does not boot in real hardware

Posted: Mon Feb 18, 2019 3:22 pm
by deleted8917
If I remember correctly, GRUB enables the protected mode, A20 and GDT?

Re: My OS does not boot in real hardware

Posted: Mon Feb 18, 2019 3:30 pm
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.

Re: My OS does not boot in real hardware

Posted: Mon Feb 18, 2019 3:32 pm
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

Re: My OS does not boot in real hardware

Posted: Mon Feb 18, 2019 3:35 pm
by deleted8917
Thanks for the info. I'm gonna to port my OS to use GRUB.

Re: My OS does not boot in real hardware

Posted: Mon Feb 18, 2019 4:46 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

Re: My OS does not boot in real hardware

Posted: Tue Feb 19, 2019 12:20 am
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

Re: My OS does not boot in real hardware

Posted: Tue Feb 19, 2019 7:18 am
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