Kernel won't boot - ld script problems [solved]

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
User avatar
stinkfly
Posts: 6
Joined: Fri Aug 17, 2007 4:29 am

Kernel won't boot - ld script problems [solved]

Post by stinkfly »

Hiya, I'm trying to link to kludge a.out format following bkerndev and it's not working - everything will build and stuff, just it won't boot.

It says it's an unreadable format and I need a new linker script, can anyone help!
Attachments
link.ld
The useless script
(350 Bytes) Downloaded 71 times
Last edited by stinkfly on Tue Jan 01, 2008 4:19 am, edited 1 time in total.
Stinkfly rules... watch out for my os soon
User avatar
fontknocker
Posts: 16
Joined: Mon Dec 11, 2006 1:49 am
Location: Canberra, Australia

Post by fontknocker »

Just checking, but in your multiboot header did you mark bit 16 in the flags (the a.out kludge) and provide the load addresses? If I recall those are in Brandon's tutorial anyway but it never hurts to double check.
User avatar
stinkfly
Posts: 6
Joined: Fri Aug 17, 2007 4:29 am

Post by stinkfly »

fontknocker wrote:Just checking, but in your multiboot header did you mark bit 16 in the flags (the a.out kludge) and provide the load addresses? If I recall those are in Brandon's tutorial anyway but it never hurts to double check.
I don't really know! I've found this in start.asm:

Code: Select all

 MULTIBOOT_AOUT_KLUDGE	equ 1<<16
Attachments
start.asm
My Start.asm
(8.98 KiB) Downloaded 34 times
Stinkfly rules... watch out for my os soon
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

You don't know? :shock:

What do you think this code does (together with the line you posted)?

Code: Select all

    MULTIBOOT_HEADER_FLAGS      equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
...
    dd MULTIBOOT_HEADER_FLAGS
User avatar
stinkfly
Posts: 6
Joined: Fri Aug 17, 2007 4:29 am

..

Post by stinkfly »

Can, you just help me to get it working? I'm just starting os development, so I don't have many ideas what things are.
Stinkfly rules... watch out for my os soon
User avatar
fontknocker
Posts: 16
Joined: Mon Dec 11, 2006 1:49 am
Location: Canberra, Australia

Post by fontknocker »

GRUB cannot load non-ELF format kernels natively. It needs additional information to load these kernels - this information is provided in the multiboot header. The header includes information on where your code, data and bss sections are as well as where your entry point is located. If the bootloader can't find this information (i.e. it's been put in the wrong place in the output binary or doesn't exist at all) it will complain about an unreadable format.

Definitive Reference Here

Double check your boot.asm with the one provided in the tutorial. Chances are you've forgotten to put in the load addresses. They should go immediately after you output the checksum in the mboot section. To ensure your Multiboot information is all in order after linking run:

Code: Select all

mbchk kernel.bin
I also suggest you study the Multiboot specification so you know exactly how the headers work and why you need to do things the way Brandon describes in his tutorial.

The other option to avoid the a.out kludge is to use an ELF-based kernel.
User avatar
stinkfly
Posts: 6
Joined: Fri Aug 17, 2007 4:29 am

Post by stinkfly »

I don't seem to have a boot.asm, there's only start.asm... but they are headers in there... It looks like it's over to ELF. What would I need to change to get elf?
Stinkfly rules... watch out for my os soon
User avatar
fontknocker
Posts: 16
Joined: Mon Dec 11, 2006 1:49 am
Location: Canberra, Australia

Post by fontknocker »

Sorry, I meant to say start.asm. boot.asm is my own source file, oops. Rather than going to ELF straight up it might be worth finding out what's going wrong; best way to learn is to stuff it all up. :D

Going to ELF isn't hard; it's just a matter of changing NASM's output to elf (instead of aout) and specifying elf32-i386 as the output format in your linker script (instead of binary).

But before trying that, did you run your kernel image through mbchk? Did it get a clean bill of health?
User avatar
stinkfly
Posts: 6
Joined: Fri Aug 17, 2007 4:29 am

Post by stinkfly »

Well.. i did do mbchk and I got:

Code: Select all

stinkfly@stink-laptop:~/OperatingSystem$ mbchk kernel.bin
kernel.bin: No Multiboot header.
I'm trying elf....
Stinkfly rules... watch out for my os soon
User avatar
stinkfly
Posts: 6
Joined: Fri Aug 17, 2007 4:29 am

Wahoo!

Post by stinkfly »

Yay! Making it elf worked! Hope i can rely on you lot again some time!
Stinkfly rules... watch out for my os soon
Post Reply