newb question: gcc, elf, and grub...
Posted: Sat May 30, 2009 5:49 pm
OK, I've looked around on the web for the past 2 hours looking for the answer, but so far I've come up empty.
I'm following Brandon Friesen's kernel dev tutorial and what I'm trying to do is port his kernel start up code from nasm to gas. The program is very simple. All it does is create a stack and jmp into an infinite loop. So here's what my gas syntax looks like:
Everything compiles and links okay, but where I'm running into trouble is when grub attempts to load this simple kernel. I get an "invalid or unsupported executable format" error. So I think my problem is that I'm not compiling/linking correctly:
/* remove c stub, set to compile for 32bit i386 architecture */
gcc -I./ -c -nostdlib -nodefaultlibs -m32 -mtune=i386 -o start.o start.S
/* code at 1 MB, use script link.ld (below), use elf_i386 emulation */
ld -Ttext=0x100000 -T link.ld -m elf_i386 -o start start.o
Link script from tutorial:
What am I missing if grub doesn't look the above compiled and linked kernel image?
edit: I have also checked the multiboot header with mbchk:
start.elf: The Multiboot header is found at the offset 7.
start.elf: Page alignment is turned on.
start.elf: Memory information is turned on.
start.elf: Address fields is turned off.
start.elf: All checks passed.
So I don't think the problem is caused by an incorrect mb header
I'm following Brandon Friesen's kernel dev tutorial and what I'm trying to do is port his kernel start up code from nasm to gas. The program is very simple. All it does is create a stack and jmp into an infinite loop. So here's what my gas syntax looks like:
Code: Select all
#include <start.h>
.file "start.S"
.text
.code32
.globl _start;
_start:
movl $_sys_stack, %esp
jmp stublet
mboot:
.long MB_HEADER_MAGIC
.long MB_HEADER_FLAGS
.long MB_CHECKSUM
stublet:
loop:
jmp loop
.bss
.skip 8192
_sys_stack:
/* remove c stub, set to compile for 32bit i386 architecture */
gcc -I./ -c -nostdlib -nodefaultlibs -m32 -mtune=i386 -o start.o start.S
/* code at 1 MB, use script link.ld (below), use elf_i386 emulation */
ld -Ttext=0x100000 -T link.ld -m elf_i386 -o start start.o
Link script from tutorial:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(_start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
edit: I have also checked the multiboot header with mbchk:
start.elf: The Multiboot header is found at the offset 7.
start.elf: Page alignment is turned on.
start.elf: Memory information is turned on.
start.elf: Address fields is turned off.
start.elf: All checks passed.
So I don't think the problem is caused by an incorrect mb header