Page 1 of 1

ld problem

Posted: Sun Dec 28, 2003 12:00 am
by Glitch
My problem is this:  I am trying to compile something under windows XP home, using the newest dev cpp tools, but i get an error when using ld.  Here's the whole compile process:

nasmw -f aout -o kernel.o kernel.asm

gcc -O3 -c kernel_c.c

ld -Ttext 0xFF800000 --oformat binary -o kernel.bin kernel.o kernel_c.o

The error is with ld, and is "kernel.o: file not recongized: File format not recongized"

I am very new to this and i have tried changing the -f option of nasmw from '-f aout' to '-f coff' and i get another error, "PE operations on non-PE file".  i just want my os to link!  Thank you very much, let me know if you need more info.  Thanks!

RE:ld problem

Posted: Sun Dec 28, 2003 12:00 am
by Glitch
Is it possible to use jloc for this?  I just thought of this as an idea..  Would anyone know how to set up the config file for this?  As i said, i am very new to this and i really have no idea how to use ld.....

RE:ld problem

Posted: Mon Dec 29, 2003 12:00 am
by qflash
very simple:
one object use this:

ALL:
kernel.o
kernel: 0 100 0
*

two objects use:

ALL:
boot.o
kernel.o
kernel: 0 100 0
*

RE:ld problem

Posted: Mon Dec 29, 2003 12:00 am
by qflash
very simple:
one object use this:

ALL:
kernel.o
kernel: 0 100 0
*

two objects use:

ALL:
boot.o
kernel.o
kernel: 0 100 0
*

RE:ld problem

Posted: Mon Dec 29, 2003 12:00 am
by Glitch
Thanks.

RE:ld problem

Posted: Mon Jan 05, 2004 12:00 am
by pepito
If you still have the problem, you can try this steps to compile your kernel:

1. nasmw -f aout -o kernel.o kernel.asm
2. gcc -c -ffreestanding -o kernel_c.o kernel_c.c
3. ld -Ttext 0x0000 --oformat binary -o kernel.bin kernel.o kernel_c.o

I don't know why you use the parameter -Ttext 0xFF800000, but maybe works too.

pepito

RE:ld problem

Posted: Mon Jan 05, 2004 12:00 am
by Dangamoose
-Ttext is an option to specify the hex address of where you want the text (code) section to be placed inside the linked binary.

for example.
-Ttext 0x100000
specifies you want the text section to start at 1mb mark. This means when loaded by the bootloader it should get placed at 1mb mark and onwards.

By using -Ttext 0x0000 all you're doing is making the kernel link at 1mb. This would work fine, assuming your kernel is not greater than 640k of lower memory, otherwise it wont fit into the gap and cant be executed on bootup. You may not necessarily be fixing the problem.

Dangamoose.

RE:ld problem

Posted: Mon Jan 05, 2004 12:00 am
by Dangamoose
Sorry,
By using -Ttext 0x0000 all you're doing is making the kernel link at 0mb mark, lowest address in ram.

RE:ld problem

Posted: Mon Jan 05, 2004 12:00 am
by Dangamoose
On that note,
in nasm assembling, you're using the format aout.
when you link your using plain binary.

Can this actually be done? Should the nasm line not be binary too?

Dangamoose.

RE:ld problem

Posted: Wed Jan 07, 2004 12:00 am
by pepito
I am using these steps to compile my kernel and it works fine, and I tried many combinations before I get these steps. But I am not an expert using LD...

I understand that the address where the kernel is placed depends on the bootloader code. You can set -Ttext 0x0000, but load the kernel at 0x100000.

pepito