OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 6:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Multiboot 2
PostPosted: Mon Oct 26, 2015 5:19 pm 
Offline

Joined: Mon Oct 19, 2015 12:36 pm
Posts: 13
I'm trying to use Multiboot 2 (http://nongnu.askapache.com/grub/phcoder/multiboot.pdf) but I'm getting a "no multiboot header" found error.

boot.S

Code:
.extern kernel_main

.section .multiboot2

multiboot2_header_start:
/* magic number */
.long   0xe85250d6
/* architecture */
.long   0
/* header size */
.long   multiboot2_header_end - multiboot2_header_start
/* checksum */
.long   -(0xe85250d6 + (multiboot2_header_end - multiboot2_header_start))

/* tag end */
.align 8
.short   0
.short   0
.long   8
multiboot2_header_end:

# Reserve a stack for the initial thread.
.section .bootstrap_stack, "aw", @nobits
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .text.init

.global _start
.type _start, @function
_start:
   movl $stack_top, %esp

   /* Reset EFLAGS. */
   pushl   $0
   popf

   pushl %ebx
   pushl %eax

   call kernel_main

   cli
   hlt
.Lhang:
   jmp .Lhang

# Set the size of the _start symbol to the current location '.' minus its start.
# This is useful when debugging or when you implement call tracing.
.size _start, . - _start   


linker.ld

Code:
BOOT_ADDRESS   = 0x00100000;

PAGE_SIZE      = 0x1000;

ENTRY(_start)
SECTIONS {
   . = BOOT_ADDRESS;
   .text.init : {
      . = ALIGN(8);
      *(.multiboot2)
      *(.text.init)
   } : boot

   .data.init : {
      *(.data.init)
   }

   .bss.init : {
      *(.bss.init)
   }

   .text ALIGN(PAGE_SIZE) : AT(ADDR(.text)) {
      *(.text)
   } : text

   .rodata ALIGN(PAGE_SIZE) : AT(ADDR(.rodata)) {
      *(.rodata)
   } : rodata

   .data ALIGN(PAGE_SIZE) : AT(ADDR(.data)) {
      *(.data)
   } : data

   .bss ALIGN(PAGE_SIZE) : AT(ADDR(.bss)) {
      *(.bss)
      *(.bootstrap_stack)
   }

   kernel_image_size = .;
}

PHDRS {
   headers   PT_PHDR FILEHDR PHDRS;
   boot   PT_LOAD;
   text   PT_LOAD;
   rodata   PT_LOAD;
   data   PT_LOAD;
}


multiboot.h

http://fossies.org/linux/grub/include/multiboot2.h

main.cpp

Code:
#include <stddef.h>
#include <stdint.h>

void WriteCharacter(unsigned char c, unsigned char forecolour, unsigned char backcolour, int x, int y)
{
     uint16_t attrib = (backcolour << 4) | (forecolour & 0x0F);
     volatile uint16_t * where;
     where = (volatile uint16_t *)0xB8000 + (y * 80 + x) ;
     *where = c | (attrib << 8);
}

extern "C"
void kernel_main(uint32_t magic, uint32_t addr)
{
   WriteCharacter('A', 15, 0, 0, 0);
}


grub.cfg

Code:
menuentry "myos" {
   multiboot /boot/myos.bin
}


mkiso.sh

Code:
#!/bin/bash
mkdir -p isodir/boot/grub
cp myos.bin isodir/boot/myos.bin
cp grub.cfg isodir/boot/grub/grub.cfg
grub2-mkrescue -o myos.iso isodir


Compile commands

Code:
i686-elf-as boot.S -o boot.o
i686-elf-g++ -std=c++14 -Wall -Wextra -pedantic -O2 -ffreestanding -fno-exceptions -fno-rtti -c main.cpp -o main.o
i686-elf-g++ -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o main.o -lgcc


And I think I have the right grub version:

Code:
grub2-mkrescue --version
grub2-mkrescue (GRUB) 2.02~beta2


Most examples I've seen using Multiboot 2 are targetted for 64-bit and use their own bootloader. I'm starting to think either I have the wrong version of Grub or Grub doesn't implement Multiboot 2.


Top
 Profile  
 
 Post subject: Re: Multiboot 2
PostPosted: Mon Oct 26, 2015 7:32 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Ya, I lost an hour on that one myself.

Change:

Code:
menuentry "myos" {
   multiboot /boot/myos.bin
}


To:

Code:
menuentry "myos" {
   multiboot2 /boot/myos.bin
}


Grub... Seriously...

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Multiboot 2
PostPosted: Mon Oct 26, 2015 7:39 pm 
Offline

Joined: Mon Oct 19, 2015 12:36 pm
Posts: 13
kiznit wrote:
Ya, I lost an hour on that one myself..


HAHAHA. Thank you so much.


Top
 Profile  
 
 Post subject: Re: Multiboot 2
PostPosted: Fri Nov 01, 2019 9:44 pm 
Offline

Joined: Fri Nov 01, 2019 9:37 pm
Posts: 1
Thanks a lot!
I almost gave up on multiboot2


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 291 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