Linker Script
Posted: Mon Dec 04, 2006 3:44 pm
Hi, can someone explain a little bit about the linker script to me. I have followed the beginners tutorials and got a 32bit bootloader which starts my C kernel, which just prints some text out on the screen.
My makefile features the following lines (amongst others):
nasmw -f bin $(SOURCE_DIRECTORY)\bootloader.asm -o $(BOOTLOADER_PATH)
gcc -ffreestanding -c $(SOURCE_DIRECTORY)\main.c -o $(INTERMEDIATE_DIRECTORY)\main.o
ld -e _main -Ttext 0x1000 -o $(INTERMEDIATE_DIRECTORY)\kernel.o $(INTERMEDIATE_DIRECTORY)\main.o $(INTERMEDIATE_DIRECTORY)\video.o $(INTERMEDIATE_DIRECTORY)\ports.o
ld -i -e _main -Ttext 0x1000 -o $(INTERMEDIATE_DIRECTORY)\kernel.o $(INTERMEDIATE_DIRECTORY)\main.o $(INTERMEDIATE_DIRECTORY)\video.o $(INTERMEDIATE_DIRECTORY)\ports.o
objcopy -R .note -R .comment -S -O binary $(INTERMEDIATE_DIRECTORY)\kernel.o $(INTERMEDIATE_DIRECTORY)\kernel.bin
I'm not entirely sure what the "freestanding" flag on gcc does, nor what the 2 calls to ld are doing. I understand the objcopy command removes sections from the binary file, but again, I don't know why.
Can someone recommend some good resources on linker scripts and possibly what I need to look at to make the build process a little easier, i.e.
1x nasmw
nx gcc
1x ld
then run bochs
Cheers,
My makefile features the following lines (amongst others):
nasmw -f bin $(SOURCE_DIRECTORY)\bootloader.asm -o $(BOOTLOADER_PATH)
gcc -ffreestanding -c $(SOURCE_DIRECTORY)\main.c -o $(INTERMEDIATE_DIRECTORY)\main.o
ld -e _main -Ttext 0x1000 -o $(INTERMEDIATE_DIRECTORY)\kernel.o $(INTERMEDIATE_DIRECTORY)\main.o $(INTERMEDIATE_DIRECTORY)\video.o $(INTERMEDIATE_DIRECTORY)\ports.o
ld -i -e _main -Ttext 0x1000 -o $(INTERMEDIATE_DIRECTORY)\kernel.o $(INTERMEDIATE_DIRECTORY)\main.o $(INTERMEDIATE_DIRECTORY)\video.o $(INTERMEDIATE_DIRECTORY)\ports.o
objcopy -R .note -R .comment -S -O binary $(INTERMEDIATE_DIRECTORY)\kernel.o $(INTERMEDIATE_DIRECTORY)\kernel.bin
I'm not entirely sure what the "freestanding" flag on gcc does, nor what the 2 calls to ld are doing. I understand the objcopy command removes sections from the binary file, but again, I don't know why.
Can someone recommend some good resources on linker scripts and possibly what I need to look at to make the build process a little easier, i.e.
1x nasmw
nx gcc
1x ld
then run bochs
Cheers,