GCC stack problem
Posted: Sun Jun 17, 2007 5:25 am
I have an interesting problem. I'm mixing C and assembly to create my OS. I created this program that gets combined into my kernel.(to avoid having to read from HDD or FDD) I then copy the program from my kernel into another place in memory that it expects to be in and enable paging. Then I use the call instruction to jump to the code. The program has it's own linker file that looks like this:
In the assembly part of the code. I have a SECTION .bss at the end to declare a stack. Now the problem I notice is this. If I declare a GLOBAL array in the C code, for some odd reason, gcc thinks it's a good idea to start the array at the END of the stack! I looked at the code, and for some strange reason. it actually loads the end of the stack into ECX. If I declare the array as a local variable, it works as expected. What am I doing wrong, here? Is my linker script wrong? No matter what I do, the darn gcc compiler always puts the global array at the end of the stack. Stacks grow downward...Why is it doing this? Thanks!
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0xA00000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata*)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}