I'm experiencing a problem with local data that is pointed to by the Y-register.
I'm using avr-gcc (GCC) 3.3 20030421 (prerelease), AvrX 2.6e, ATmega8.
The WinAVR documentation (manual section 7.3.14) states that the Y-register may be used as a pointer for local data and should be restored if changed.
As far as I can tell, the Y-register is initialised to top of RAM during initialisation. It is not initialised in the relevant subroutine. Y is used to store the return value from a function call like this: std Y+1, r24. I assume that if Y is pointing to top of RAM, then Y+1 is pointing to R0 (i.e. wraps around).
AvrX initialises its task stacks with all zeros, so when the task switch occurs at the end of main() Y is no longer pointing at top of RAM, but at zero. This is obviously a problem. Because Y+1, now points to R1, which GCC assumes to be always equal to zero. R1 not equal to zero is causing grief elsewhere. It is the bug caused by this that I originally started tracking down.
So the solution should be simple: Y should have the correct value. However, I don't know what the correct value should be. In AvrX this should be different for each task. It can't be initialised to the current value of the stack pointer, because Y+1 would then point the the most recent value pushed on the stack.
Can somebody please shed some light on how WinAVR uses the Y-register? Is it just an alternative way of referring to R0? How to determine an appropriate alternative value for Y? Is there more then one problem here?
Thanks in advance
Arthur