Multiboot specification

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
apples
Posts: 6
Joined: Fri Oct 12, 2007 6:13 pm
Location: hillsborough, nc

Multiboot specification

Post 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!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Multiboot specification

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: Multiboot specification

Post 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 ^_^
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
apples
Posts: 6
Joined: Fri Oct 12, 2007 6:13 pm
Location: hillsborough, nc

Re: Multiboot specification

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Multiboot specification

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
apples
Posts: 6
Joined: Fri Oct 12, 2007 6:13 pm
Location: hillsborough, nc

Re: Multiboot specification

Post 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!
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 specification

Post 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).
"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 ]
Post Reply