multiboot header doesn't work in boot file

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.
Post Reply
salmane
Posts: 2
Joined: Tue Aug 20, 2013 1:54 am

multiboot header doesn't work in boot file

Post by salmane »

I'm trying to write a multiboot kernel compliant using the grub (legacy) specification , here is the content of my boot.s (written with the gnu as)

Code: Select all

#include "boot.h"
    .code32
    .globl start
    .type start, @function
    .extern kernel_main
    .type kernel_main, @function
    .bss
    .comm stack, STACK_SIZE

    .section .mboot
    .align 4
    .long MBOOT_HEADER_MAGIC
    .long MBOOT_HEADER_FLAGS
    .long MBOOT_CHECKSUM
        .text
start:
    movl $(stack + STACK_SIZE) , %esp
    cli
    call kernel_main
    sti
    hlt
    jmp .
The boot.h file content some definition for grub:

Code: Select all

#ifndef _BOOT_H_
#define _BOOT_H_
#define MBOOT_PAGE_ALIGN 1<<0
#define MBOOT_MEM_INFO 1<<1
#define MBOOT_HEADER_MAGIC 0x1BADB002
#define MBOOT_HEADER_FLAGS MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
#define MBOOT_CHECKSUM -( MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
#define STACK_SIZE 0x4000
#endif /* _BOOT_H_ */
I also set up the linker like this:

Code: Select all

ENTRY(start)
OUTPUT_ARCH(i386)
OUTPUT_FORMAT("elf32-i386")
SECTIONS
{
    . = 1M;
    .mboot ALIGN(4K) :
    {
        *(.mboot)

    }
    .text ALIGN(4K) :
    {
        *(.text)
        *(.rodata)
    }
    .data ALIGN(4K) :
    {
        *(.data)
    }
    .bss ALIGN(4K) :
    {
        *(.bss)
    }
}
For the moment , my kernel_main simply return the value 0x01 which i'm expecting in the %eax register, however when i execute the kernel with:

Code: Select all

qemu -kernel kernel.bin -monitor stdio
and then issue the command info registers in qemu , i always find a value of 18 for %eax. So my questions are: is my boot.s file correctly defined to be grub compliant? and why the value 18 in %eax instead of 0x01?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: multiboot header doesn't work in boot file

Post by Combuster »

sti
(...)
my kernel_main simply return the value 0x01
In other words, if the multiboot header is accepted, the next expected result is a crash/reboot.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
salmane
Posts: 2
Joined: Tue Aug 20, 2013 1:54 am

Re: multiboot header doesn't work in boot file

Post by salmane »

Even if i remove the

Code: Select all

 sti 
instruction , nothing change.
Post Reply