Page 1 of 1

Higher Half and GRUB loading problems [solved]

Posted: Wed Aug 19, 2009 11:50 am
by wolfram
I try to write a higher half kernel. I think to use manipulation with sections. I wrote a linker script, but when I try to load my kernel with GRUB, GRUB says me "Selected item can't fit into memory".
My ld script:

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(_start)
SECTIONS
{
	. = 0x00100000;
	.loader :
	{
		*(.loader)
	}
	
	. = 0xc0000000;
	.text ALIGN(0x1000) :
	{
		_sttext = . - 0xc0000000;
		*(.text)
		*(.rodata)
	}
	.data ALIGN(0x1000) :
	{
		_stdata = . - 0xc0000000;
		*(.data)
	}
	.bss ALIGN(0x1000) :
	{
		*(.bss)
		*(COMMON)
	}
	_sztext = SIZEOF(.text);
	_szdata = SIZEOF(.data);
}
I think somebody helps to stupid noob.

P.S. Sorry for my bad English, English is not my native language.

Re: Higher Half and GRUB loading problems

Posted: Wed Aug 19, 2009 12:17 pm
by manonthemoon
I believe GRUB is trying to load your kernel at location 0xC0000000, which obviously requires too much memory.

Try changing each section to something like this:

Code: Select all

.text ALIGN(0x1000) : AT(ADDR(.text) - 0xC0000000)
EDIT: See the linker script on the Higher Half bare bones page. I just updated the Wiki to include this error.

Re: Higher Half and GRUB loading problems

Posted: Thu Aug 20, 2009 2:15 am
by wolfram
Thanks. I changed sections and now my ld-script looks as

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(_start)
SECTIONS
{
	. = 0x00100000;
	.loader :
	{
		*(.loader)
	}
	. = 0xC0100000 + SIZEOF(.loader);
	.text ALIGN(0x1000) : AT(ADDR(.text) - 0xC0000000)
	{
		_sttext = .;
		*(.text)
		*(.rodata*)
		_sztext = SIZEOF(.text);
	}
	.data ALIGN(0x1000) : AT(ADDR(.data) - 0xC0000000)
	{
		_stdata = .;
		*(.data)
		_szdata = SIZEOF(.data);
	}
	.bss : AT(ADDR(.bss) - 0xC0000000)
	{
		*(.bss)
		*(COMMON)
	}
}
Now GRUB loads my kernel correctly.