Grub 13 Error

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
xfceslacker
Posts: 2
Joined: Wed Nov 22, 2006 10:29 am

Grub 13 Error

Post by xfceslacker »

Hi,
I'm just trying to make a real simple OS for fun. I'm following the tutorial on that's at http://www.osdever.net/bkerndev/index.php?the_id=90. I'm to the section titled "Printing onscreen". I compiled the kernel and wrote the grub image download from the tutorial to a floppy. With dd if=dev_kernel_grub_image of=/dev/fd0. All went fine. I then tried the floppy in my computer and all went well. So then I copied my kernel.bin over the kernel.bin on the floppy. I then got the "Error 13: Invalid or unsupported executable format" error. So then I copied the authors link.ld and start.asm over mine to make sure I didn't type anything wrong in. I rebuilt the kernel and the same thing happened. I hope that was enough information. Where do you think I went wrong? What would be the best way to find out what's wrong? Any tips or help would be great.

Thanks.
TheQuux
Member
Member
Posts: 73
Joined: Sun Oct 22, 2006 6:49 pm

Post by TheQuux »

Invalid format usually means that you either forgot the multiboot header, or the a.out kludge.

Given that you have dd, I'm assuming that your on some UN*X. Try running
mbchk <kernel>
to check the multiboot header.

Next, try running "file" on the kernel (file <kernel>) Unless that reports an ELF kernel, you need the a.out kludge; from the .bin suffix, that would seem to be the problem.

If mbchk doesn't find the multiboot header, but you did include it, make sure that you put it at the beginning of your kernel; (if you're using GNU ld to link the kernel, make sure that the file with multiboot header is the first one on the link command line.

Hope that helped!

EDIT: Just looked at the linker script... AAUGH!
I've learned to stop worrying and love ELF... it does make things easier.

To fix the problems I see with the tutorial (a matter of opinion, definitely), here's the linker script that I use:

Code: Select all

SECTIONS
{
    . = 0x00100000;
    .mbheader ALIGN (0x04) :
    {
        *(.mbheader)
    }
    .text :
    {
        *(.text)
    }

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

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

    .bss :
    {
        _sbss = .;
        *(COMMON)
        *(.bss)
        _ebss = .;
    }
}
The .mbheader in there is designed to protect against my own idiocy... before the multiboot header, use

Code: Select all

section .mbheader       progbits  alloc  noexec nowrite align=4
and after it,

Code: Select all

section .text
[/code[

Then, change the nasm command line so that the -f binary becomes -f elf

If you want, you can look at a fairly recent snapshot of my kernel... just go to [url]http://www.seas.ucla.edu/~hirsch/[/url], and grab the top link.

That doesn't include two cool new features: PCI probing and basic serial debugging... but those are a while away, but it should be enough to get you started. (and, if you need the serial debugger, well... there's a reason its semi-official slogan is "Abandon all hope" :- )
xfceslacker
Posts: 2
Joined: Wed Nov 22, 2006 10:29 am

Post by xfceslacker »

Thanks for the help. I got it working! :D
Post Reply