Linker script problems
Posted: Sat Jun 14, 2003 11:00 pm
Hey
I've got my operating system to boot into the kernel image, but I don't think the ld linker script is working right. The bootstrap copies the kernel image to 0x1000 , so I have an overlay set up to link the code for that location. Right now, all the kernel does is print a string to the screen, and if I specify an absolute location (i.e print(0x2008)), then it works, but if I specify the variable that points to the data (print(buffer)), then it prints stuff at the wrong location in memory. Also, the trampoline has the same problem: I am currently telling it to jump to an absolute location to enter the kernel code. If I tell it to jump to main, it is linked to jump to 0x0.
The code is compiled with:
nasm trampoline.asm -o trampoline.o -f elf
gcc -ffreestanding -fPIC -c main
ld -M -T link.ld
Here is the linker script:
OUTPUT(kernel.bin)
INPUT(main.o)
ENTRY(start)
OUTPUT_FORMAT("binary")
SECTIONS
{
OVERLAY : AT (0x1000)
{
stage1
{
trampoline.o(.text)
trampoline.o(.data)
trampoline.o(.bss)
}
.text
{
/* -fPIC requires this */
PROVIDE(_GLOBAL_OFFSET_TABLE_ = 0x1000);
*(.text)
. = ALIGN(4096);
}
.data
{
*(.data)
*(.bss)
*(.rodata)
. = ALIGN(4096);
}
}
}
Thanks for any help,
Michael VE3MTM
73 33
I've got my operating system to boot into the kernel image, but I don't think the ld linker script is working right. The bootstrap copies the kernel image to 0x1000 , so I have an overlay set up to link the code for that location. Right now, all the kernel does is print a string to the screen, and if I specify an absolute location (i.e print(0x2008)), then it works, but if I specify the variable that points to the data (print(buffer)), then it prints stuff at the wrong location in memory. Also, the trampoline has the same problem: I am currently telling it to jump to an absolute location to enter the kernel code. If I tell it to jump to main, it is linked to jump to 0x0.
The code is compiled with:
nasm trampoline.asm -o trampoline.o -f elf
gcc -ffreestanding -fPIC -c main
ld -M -T link.ld
Here is the linker script:
OUTPUT(kernel.bin)
INPUT(main.o)
ENTRY(start)
OUTPUT_FORMAT("binary")
SECTIONS
{
OVERLAY : AT (0x1000)
{
stage1
{
trampoline.o(.text)
trampoline.o(.data)
trampoline.o(.bss)
}
.text
{
/* -fPIC requires this */
PROVIDE(_GLOBAL_OFFSET_TABLE_ = 0x1000);
*(.text)
. = ALIGN(4096);
}
.data
{
*(.data)
*(.bss)
*(.rodata)
. = ALIGN(4096);
}
}
}
Thanks for any help,
Michael VE3MTM
73 33