grub can't load my kernel

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
ich_will

grub can't load my kernel

Post 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
Legend

Re:grub can't load my kernel

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

Re:grub can't load my kernel

Post by ich_will »

how can i do that?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:grub can't load my kernel

Post by Solar »

By following the instructions in the Multiboot specification, chapter "the address fields of the multiboot header".

Or by building an ELF executable.
Every good solution is obvious once you've found it.
FaizBond

Re:grub can't load my kernel

Post by FaizBond »

Try writing this right after "start:"

call _main
Legend

Re:grub can't load my kernel

Post by Legend »

He would never get that far without an a.out kludge or an elf binary ...
Post Reply