Page 2 of 2
Re: Wrong addresses being pushed on the stack
Posted: Fri Feb 11, 2011 7:47 pm
by Tosi
Loading a single character can be hardcoded into the code, such as
If you want to use strings, include the section .rodata in your linker script.
Re: Wrong addresses being pushed on the stack
Posted: Fri Feb 11, 2011 8:12 pm
by Davidm44
Tosi wrote:Loading a single character can be hardcoded into the code, such as
If you want to use strings, include the section .rodata in your linker script.
I'm not using a linker script at the moment ( but I tried one ), I guess I should be.. I'll try it out and post results.
Edit: The linker script I was using already had the .rodata section defined. I'm not sure if it's correct though, I got this from the osdev wiki.
Code: Select all
ENTRY (main)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
Re: Wrong addresses being pushed on the stack
Posted: Sat Feb 12, 2011 5:27 am
by Chandra
Davidm44 wrote:Tosi wrote:Loading a single character can be hardcoded into the code, such as
If you want to use strings, include the section .rodata in your linker script.
I'm not using a linker script at the moment ( but I tried one ), I guess I should be.. I'll try it out and post results.
Edit: The linker script I was using already had the .rodata section defined. I'm not sure if it's correct though, I got this from the osdev wiki.
Code: Select all
ENTRY (main)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
You were loading your kernel @ 0x1000, right? So what is 0x100000 for?
Re: Wrong addresses being pushed on the stack
Posted: Thu Feb 17, 2011 6:30 pm
by Davidm44
Chandra wrote:Davidm44 wrote:Tosi wrote:Loading a single character can be hardcoded into the code, such as
If you want to use strings, include the section .rodata in your linker script.
I'm not using a linker script at the moment ( but I tried one ), I guess I should be.. I'll try it out and post results.
Edit: The linker script I was using already had the .rodata section defined. I'm not sure if it's correct though, I got this from the osdev wiki.
Code: Select all
ENTRY (main)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
You were loading your kernel @ 0x1000, right? So what is 0x100000 for?
Sorry for bumping & late reply, but changing 100000 to 1000 didn't do anything. Same output..
Re: Wrong addresses being pushed on the stack
Posted: Thu Feb 17, 2011 11:23 pm
by thepowersgang
A random stab in the dark points me to your GDT being slightly dodgy.
Have you tried the bochs debugger, and single stepping through the code to spot why it doesn't work.
Re: Wrong addresses being pushed on the stack
Posted: Fri Feb 18, 2011 12:17 am
by Chandra
As far as I can hit stone in the darkness, there is some problem in the relocation. Since he is not using 'Cross Compiler', I guess one of the following might work out.
1. Change the entry point to kmain(which is your actual entry point as specified in your code) and not main(which you are using now).
2. Insert the output format "elf32-i386" in your linker script.
3. Since you are turning your kernel to flat binary anyway, you may tell the linker to do this job for you.This remove hassles for employing 'objcopy' to remove elf headers for you. And thus if the problem is relocation, this option might help.
4. Use the 'Cross Compiler'.
If none of this option helps in anyway, its time to do some debugging.
Re: Wrong addresses being pushed on the stack
Posted: Fri Feb 18, 2011 11:52 am
by Davidm44
Chandra wrote:As far as I can hit stone in the darkness, there is some problem in the relocation. Since he is not using 'Cross Compiler', I guess one of the following might work out.
1. Change the entry point to kmain(which is your actual entry point as specified in your code) and not main(which you are using now).
2. Insert the output format "elf32-i386" in your linker script.
3. Since you are turning your kernel to flat binary anyway, you may tell the linker to do this job for you.This remove hassles for employing 'objcopy' to remove elf headers for you. And thus if the problem is relocation, this option might help.
4. Use the 'Cross Compiler'.
If none of this option helps in anyway, its time to do some debugging.
Sorry about that, I fixed it now. I changed 10000 to 1000 as someone mentioned above and changed align to 4 instead of 1000. It was a complete shot in the dark but its working now.
Do you have any links to tutorials or references that would help me understand linker scripts a bit more clearly? I checked the osdev wiki but it seems a little complicated.
Thanks.
Re: Wrong addresses being pushed on the stack
Posted: Sat Feb 19, 2011 6:21 am
by Tosi
The wiki's description of linker scripts is vastly oversimplified and not really useful for everything. The best resource would be the documentation for whatever version of binutils you are using.