Page 1 of 1

GRUB and ELF

Posted: Wed Oct 19, 2005 1:10 pm
by Vladaz
I have a problem, I can't link my kernel files.

Linker:
OUTPUT_FORMAT("elf32-i386")
ENTRY(entry)
virt = 0xC0000000; /* 3 gig */
phys = 0x100000; /* 1 meg */
SECTIONS
{ .text virt : AT(phys)
{ code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{ data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{ bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
end = .;
}

makefile:
SRC = kernel.c

OBJ = kernel_asm.o kernel.o

all:   asm link delfiles
asm:
   nasmw -f elf kernel_asm.asm

   gcc -c $(SRC)
link:
   ld-elf -T link.ld --cref -Map krnl.map -o ktnl.elf $(OBJ)

delfiles:
   del *.o

kernel_asm.asm:
[BITS 32]
[GLOBAL start]
[EXTERN _k_main]

MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1

MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

; The Multiboot header (in NASM syntax)
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM

start:

   call _k_main

   cli
   hlt


kernel.c:
k_main () {
   
   while(1);
}

That is shown when i execute my makefile.
Error message:
nasmw -f elf kernel_asm.asm
gcc -c kernel.c
ld-elf -T link.ld --cref -Map krnl.map -o ktnl.elf
Exiting due to signal SIGSEGV
General Protection Fault at eip=00067ac7
eax=fff50200 ebx=00000007 ecx=000002b5 edx=fff50000 esi=00000200 edi=00000006
ebp=000b989c esp=000b988c program=L☺♥
cs: sel=0387 base=02b50000 limit=7d49ffff
ds: sel=038f base=02b50000 limit=7d49ffff
es: sel=038f base=02b50000 limit=7d49ffff
fs: sel=035f base=00014160 limit=0000ffff
gs: sel=039f base=00000000 limit=ffffffff
ss: sel=038f base=02b50000 limit=7d49ffff

Call frame traceback EIPs:
0x00067ac7
0x00067a4d
0x00067136
0x000671ed
make.exe: *** [link] Error -1

Re:GRUB and ELF

Posted: Wed Oct 19, 2005 10:29 pm
by AR
That's a problem with your linker build. What OS and Binutils version are you using? You may want to rebuild binutils.

Re:GRUB and ELF

Posted: Thu Oct 20, 2005 2:20 am
by Pype.Clicker
i'd say you're missing some sections (.rodata ?) in your linker script. that means your linker may be trying to create a 3GB file to please you ... and that may not please the OS.

Re:GRUB and ELF

Posted: Thu Oct 20, 2005 2:40 am
by Solar
Since your code doesn't seem to do anything beyond the most basic setup, you might want to check the HigherHalfBareBones and see if that works for you.

Re:GRUB and ELF

Posted: Thu Oct 20, 2005 9:51 am
by Vladaz
i've downloaded my binutils from here http://membres.lycos.fr/placr/binutils.html
There are special binutils for making ELF, because, i think default ld file doesn't support elf, so I thought to use these.

Re:GRUB and ELF

Posted: Thu Oct 20, 2005 10:34 pm
by Solar
Please consider setting up a GCC Cross-Compiler environment. That's well-tested and works for many of us.