Grub - Error 13 - Invalid or unsupported executable format

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
gommo

Grub - Error 13 - Invalid or unsupported executable format

Post by gommo »

I'm trying to right a simple kernel following
http://www.osdever.net/tutorials/basick ... ?the_id=12

I also am using grub as the bootloader. To enable this I need to make my kernel image multiboot. So rather than simply use the kernel_start.asm file in the tutorial I used the boot.S and multiheader.h files from grub.

in boot.S I changed the call to main to EXT_C(k_main) and then called hlt straight after that. Removing references to printf and stuff

I then compiled that with gcc
gcc -c boot.S -o ks.o

My kernel.c file is the same as in the tutorial so
gcc -c kernel.c -o kernel.o

I then use the tutorials linker script and go
ld -T link.ld -o kernel.bin ks.o kernel.o

I now have a kernel.bin file of about 20k or so

I downloaded the grub_disk.img file that has grub installed on it. I then prepared this as /dev/loop0 and mounted it under /mnt/temp
browsing into temp I can see the dir /boot. I copy my kernel.bin file into /mnt/temp/boot, unmount the image

I then setup Bochs and pointed its floppya and my image file,
it boots grub fine but when I select 'My Kernel' from the list it attempts to load but generates a

Error 13: Invalid or unsupported executable format

Is there something wrong that I am doing above or is there something else I need to do? I am assuming grub puts the computer into protected mode etc.. etc..

Thanks for any help
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Grub - Error 13 - Invalid or unsupported executable forma

Post by bubach »

Comments on the article:
Retro:
when i use the command "ld -T link.ld -o kernel.bin ks.o kernel.o" it keep getting the error message "ks.0: file not recongnized: File format not recognized" ne1 know what i'm doing wrong and sort it?
Pype:
@retro & friends:
it looks like your version of LD does not support A.OUT files. Either try "-f coff" instead of "-f aout" (for DjGpp) or "-f elf" (for Linux)
Maybe this helps?

/ Christoffer
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
gommo

Re:Grub - Error 13 - Invalid or unsupported executable forma

Post by gommo »

I'm using gcc to compile both my boot.S and kernel.c. What does gcc compile to by default? Or is it LD that I need to specificy the aout or elf file? I'm assuming gcc defaults to elf? but maybe not?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Grub - Error 13 - Invalid or unsupported executable forma

Post by bubach »

i don?t use C for os dev so i don?t know... u will have to test.. :-P
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Grub - Error 13 - Invalid or unsupported executable forma

Post by Pype.Clicker »

gcc generates a .S file which it passes to AS ... so it's up to AS and LD to know what binary format you use, not 'GCC' (the compiler) itself... iirc, there is a switch to pass options directly to the linker (it might be -D .... i should RTFM again) and a similar one to pass options to the assembler ...

If it sounds confusing, remind that gcc plays both the role of the front-end *and* the compiler ...
Therx

Re:Grub - Error 13 - Invalid or unsupported executable forma

Post by Therx »

You need the multiboot header for grub and if you use the aout features then it can load basically any format

Pete
gommo

Re:Grub - Error 13 - Invalid or unsupported executable forma

Post by gommo »

Yep, thanks all.

I went away from using grubs boot.S and did my own kernel starting asm file. Then I used NASM with the -f aout option and it works now.

However, I'm using Bochs and it seems to run although the screen doesn't show anything on it.

Could this be because the machine is being halted (hlt)??
Post Reply