Page 1 of 1

grub can't load my kernel

Posted: Sun Aug 01, 2004 4:25 am
by ich_will
Hi, i try to load my kernel with grub but i get the following screen:

grub> kernel (fd0)/kernel
[FreeBSD-a.out, loadaddr=0x100000, text=0x2000, data=0x1000

Error 13: Invalid or unsupported executable format

grub>

what's happend?

My linker skript:

Code: Select all

/* Link.ld */
OUTPUT_FORMAT("a.out-i386")
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}

.data :
{
__CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) *(.ctors) LONG(0) __CTOR_END__ = .; 
__DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors) LONG(0) __DTOR_END__ = .; 

data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}

.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}

end = .; _end = .; __end = .;
} 
my _start.asm:

Code: Select all

[BITS 32]
[GLOBAL start]
[EXTERN _main]

start:
jmp start2

multiboot_header:
        magic           dd 0x1BADB002
        flags_0..15     dw 0            ; requirements
        flags_16.32     dw 0            ; optional futures
        checksum        dd 0 - 0x1BADB002

start2:
      mov [0xB8000], byte 't'
      mov [0xB8001], byte 5
      cli
      hlt
      jmp $-2
my main.c:

Code: Select all

int main()
{
  return 0;
}
I build the files with DJGPP and NASM:

nasm -f aout _start.asm -o kernel.o
gcc -fno-builtin -c -O3 main.c

ld -T link.ld *.o -o kernel

Re:grub can't load my kernel

Posted: Sun Aug 01, 2004 4:47 am
by Legend
As I see, you compile your kernel to an a.out format.
To load this, GRUB requires you add an a.out kludge to the multiboot header!

Re:grub can't load my kernel

Posted: Sun Aug 01, 2004 4:58 am
by ich_will
how can i do that?

Re:grub can't load my kernel

Posted: Sun Aug 01, 2004 6:56 am
by Solar
By following the instructions in the Multiboot specification, chapter "the address fields of the multiboot header".

Or by building an ELF executable.

Re:grub can't load my kernel

Posted: Sun Aug 01, 2004 8:38 pm
by FaizBond
Try writing this right after "start:"

call _main

Re:grub can't load my kernel

Posted: Mon Aug 02, 2004 2:14 am
by Legend
He would never get that far without an a.out kludge or an elf binary ...