Page 1 of 1

Multiboot specification

Posted: Tue Jan 13, 2009 4:36 pm
by apples
hi, i've been toying around with OS dev for awhile, and recently decided to scrap all of my code and do a rewrite. however, this time around, i ran into multiboot trouble, but haven't been able to find errors. when i try to run my kernel through GRUB, it gives the "Invalid or unsupported executable format" error. i'm a bit unsure as to why, i can't find any errors within my multiboot header or lnkscript (which was pretty much copied verbatim from the bare bones tutorial). here they are:

Code: Select all

.set FLAG_PAGE_ALIGN, (1 << 0)
.set FLAG_MEMORY_INFO, (1 << 1)
.set FLAG_AOUT_KLUDGE, (1 << 16)

.set GRUB_HEADER, 0x1badb002
.set GRUB_FLAGS, FLAG_PAGE_ALIGN | FLAG_MEMORY_INFO | FLAG_AOUT_KLUDGE
.set GRUB_CHECKSUM, -(GRUB_HEADER + GRUB_FLAGS)

.set STACK_SIZE, 0x4000

.section .text

.align 4
multiboot_header:
	.long GRUB_HEADER
	.long GRUB_FLAGS
	.long GRUB_CHECKSUM
	.long multiboot_header
	.long text
	.long sbss
	.long ebss
	.long GrubEntryPoint
	
.globl GrubEntryPoint
GrubEntryPoint:
	movl $(stack + STACK_SIZE), %esp
	push %ebx
	call _loki
	hlt

.section .bss
.align 32
.lcomm stack, STACK_SIZE

Code: Select all

ENTRY (GrubEntryPoint)

SECTIONS{
    . = 0x00100000;

    .text :{
        text = .;
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}
any help would be appreciated. thanks!

Re: Multiboot specification

Posted: Tue Jan 13, 2009 7:44 pm
by Brendan
Hi,
apples wrote:hi, i've been toying around with OS dev for awhile, and recently decided to scrap all of my code and do a rewrite. however, this time around, i ran into multiboot trouble, but haven't been able to find errors.
The code looks fine to me. Could you post the output of "hexdump -C yourkernel.bin" (or something similar)?


Cheers,

Brendan

Re: Multiboot specification

Posted: Wed Jan 14, 2009 2:30 am
by finarfin
Probably you compile your kernel, in a format that is not recognized by grub.

In my os i use that option for ld:

Code: Select all

ld -static -oformat elf32-i386 -output=kernel.bin -script=kernel.lds bl.img $(OBJ)
-Ttext 0x100000 -Map kernel.map
And for verify that your header doesn't contain errors you can use mbchk:

Code: Select all

mbchk imageofyouros
I hope that could help you ^_^

Re: Multiboot specification

Posted: Wed Jan 14, 2009 6:04 am
by apples
hi, i ran hexdump as you said, and here is the resulting output:

http://rafb.net/p/4zzzYr20.html [pasted there because of space]

i know i'm using PE/COFF as my executable format, but AFAIK GRUB supports that too and that should not be the issue as long as i provide my AOUT kludge. i wouldn't like to have to rebuild an i386-elf cross compiler, but i guess i will if i have to.

i'm on windows so i don't have access to the mbchk command.

Re: Multiboot specification

Posted: Wed Jan 14, 2009 6:30 am
by Brendan
Hi,
apples wrote:hi, i ran hexdump as you said, and here is the resulting output:

http://rafb.net/p/4zzzYr20.html [pasted there because of space]
That looks like a PE format file to me. I didn't know if GRUB supported PE (or COFF) so I did a google search hoping to find some GRUB documentation or something, and found Combuster's post saying GRUB doesn't support PE.

I also took a look at the GRUB header:

Code: Select all

0200  02 b0 ad 1b 03 00 01 00  fb 4f 51 e4 00 00 10 00  .��..... �OQ�....
0210  00 00 10 00 20 10 10 00  40 50 10 00 20 00 10 00  .... ... @P.. ...
Which works out to:

Code: Select all

    dd 0x1BADB002   ;Magic
    dd 0x00010003     ;Flags
    dd 0xE4514FFB    ;Checksum
    dd 0x00100000    ;Address of header
    dd 0x00100000    ;Load address
    dd 0x00101020    ;Load end address
    dd 0x00105040    ;BSS end address
    dd 0x00100020    ;Entry address
If GRUB loads the file into RAM as a flat binary, then most of these addresses will be wrong. For e.g. the address of the header would be 0x00100200, the load end address would be 0x00100e28, etc.

If it was me, I'd try to use "objcopy --output-target binary" to convert it into a flat binary file and see if that works...


Cheers,

Brendan

Re: Multiboot specification

Posted: Wed Jan 14, 2009 11:09 am
by apples
ah, for some reason i had the notion in my head that i could use PE/COFF. guess i do have to compile a cross compiler after all. thanks!

Re: Multiboot specification

Posted: Wed Jan 14, 2009 2:11 pm
by Combuster
The message was that PE doesn't work with GRUB. You can still use PE, just not for your kernel (which should be a flat binary in that case).