Problems with kernel linking

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
pianohacker
Posts: 4
Joined: Thu Dec 14, 2006 9:53 am

Problems with kernel linking

Post by pianohacker »

I'm writing a basic kernel right now. It's written in C++, and is based on the tutorial kernel at http://osdever.net/bkerndev/ , with some minor changes to function names, etc. I've gotten as far as trying to print on the screen, but the linker is messing up. To print something, I'm passing the "Hello, World!" string constant to kernel::screen::write(). Once I link this, though, grub decides to give me an "Unrecognized executable format" error. This is for good reason: when I "less" the compiled kernel, it starts with "Hello, World!" Any idea what's wrong?
I can post linker scripts, compile options, etc. if anyone wants them.
ntfs
Posts: 19
Joined: Tue Dec 12, 2006 9:55 am
Location: Czech Republic Prague

Post by ntfs »

You have to be sure the header is included in right manner. Try to run mbchk.exe (multiboot checker) on the file. I got riddiculously the same message when using ELF and compliing to multiboot specs.
pianohacker
Posts: 4
Joined: Thu Dec 14, 2006 9:53 am

Post by pianohacker »

No need to do that, actually:

$ od -c -N 13 ceres-kernel.bin
0000000 H e l l o , W o r l d !
0000015

The first 13 bytes of the compiled kernel are actually Hello, World! I'm passing the compiled ASM loader as the first argument to ld, but still that damn string is the first thing in the file...

EDIT: $ mbchk ceres-kernel.bin
ceres-kernel.bin: No Multiboot header.
Attachments
link.ld
My linker script.
(338 Bytes) Downloaded 34 times
loader.asm
The loader source.
(1.82 KiB) Downloaded 38 times
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post by urxae »

You don't have a .rodata section in your linker script. Copy-paste the .data section, and replace data by rodata in the copy. Don't forget to change the appropriate AT() clauses as well.
Post Reply