Having trouble with gcc/binutils

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
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Having trouble with gcc/binutils

Post by cyr1x »

Hi,
I want to port my kernel to x86-64, so i built gcc/bintuils with "x86_64-pc-elf" support according to the wiki. Now my problem is that my kernel grows > 1MB. It seems that it depends on the physical address I link to. If I link it to say 0x100000 it has > 1MB if i link it to 0x1 it has only several KB's.
Has someone an idea how to fix it?

GCC-version 4.2.2 (tried 4.2.1 too same error)/ binutils-version 2.18 built with Cygwin 3.4.4 on Vista64

My Linkerscript:

Code: Select all

OUTPUT_FORMAT("elf64-x86-64")
INPUT(loader.o kernel.o idt.o video.o atomic.o)
ENTRY(start)
addr = 0x100000;
SECTIONS
{
	. = addr;
	
	start_kernel_ = .;
	.text   ALIGN(0x1000) :
	{	
		code = .;
		*(.text)
		*(.rodata)
	}
	
	.data   ALIGN(0x1000) : 
	{
		data = .;
		*(.data)

		_ctors_start = .;		/* constructors */
		*(.ctor*)
		_ctors_end = .;
	}

	.bss 	ALIGN(0x1000)   : 
	{
		bss = .;
		*(.bss)
	}
	end_kernel_ = .;

	/DISCARD/ : { *(.comment .note.GNU-stack .eh_frame) }

}
Buildscript:

Code: Select all

yasm -m amd64 -f elf64 src/loader.asm

x86_64-pc-elf-g++ -O0 -c src/*.cpp -Wall -nostdinc -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-stack-protector -nostartfiles -I./src/include
x86_64-pc-elf-ld -T link.txt -o kernel.sys -nostdlib -Map kernelmap.map
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

You should try a linker script like the one on the wiki: http://www.osdev.org/wiki/Higher_Half_bare_bones

You currently seem to tell LD to add bytes rather than telling where it is to be loaded.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

Well, I fixed the size problem by adding -r (relocatable) to ld now.
But my code doesn't boot either. I don't know if my bootloader (grub + 64-patch) is broken or there's something else wrong with the output :roll:.
Maybe someone has got a working grub with elf64?

EDIT: Should be GRUB, because with out loading the kernel the shell doesn't work too.
Post Reply