My CPU is a MC9S12DT256 with 12KB of RAM located at 0x1000-0x3FFF.
Code is compiled with the following flags:
GCC: -m68hc12 -g -Os -fomit-frame-pointer
LD: -nostdlib -nostartfiles
when my hardware init routine ends and calls main(), SP is point at the
top of the stack 0x3FFF.
In my linker script, I have PROVIDE(_stack = 0x3FFF ) to tell GCC where
the top of my stack is.
Now here's where the problem comes in...I discovered it when parameters
didn't get correctly passed to a function of mine.
For debug purposes currently, my main looks like this:
void main()
{
unsigned short test = 0xABCD;
asm("bgnd"); // break for debug
// remaining code following here
}
The generated code by GCC looks like this:
movw #-21299,0,sp
bgnd
So with the stack pointer as 0x3FFF, that can't possibly work and sure
enough doesn't.
Looking at the RAM, I get the AB at address 0x3FFF and the CD goes off
into nothingness. That also explains why in my test code a variable
wasn't passed to my function right because GCC was doing the same thing
there causing existing data on the stack to be overwritten.
It seems to me as if GCC is treating the stack as if it was incrementing
instead of decrementing.
Any thoughts anyone? GCC Version is 3.3.6
Thanks,
Stephan