Hi.

"Joerg Wunsch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> Remember that the stack pointer is currently initialized twice: once
> in the startup code, and another time at the beginning of main().  The
> latter is rather historical baggage, and might go away in a future
> release.

Here it is impossible to change anything!

1. Stack pointer sould be initialized in the startup code.

Let's consider such code:

void test(void) __attribute__ (section (".init8")) __attribute__(naked);
void test(void)
{
...
 a = b / c;
....
}

It is located in (".init8"))  section, and run before 'main' function. But 
operation of division is realized as subroutine call, and stack sould be 
alredy initialized here.

2. In 'main' function NO the stack pointer is initialized.  At the beginning 
'main' function the function frame is initialized.

Look code from main.c:
....
 main:
.LFB2:
.LM1:
/* prologue: frame size=0 */
 ldi r28,lo8(__stack - 0)
 ldi r29,hi8(__stack - 0)
 out __SP_H__,r29
 out __SP_L__,r28
...

It is equal:
SP (stack pointer) = Y (frame pointer) = __stack - frame_size.

Where:
__stack -> usually is RAMEND
frame_size ->   size of all (non optimized) local variables in 'main' 
function.

Try to add local variable in 'main', and will see that SP not equally 
RAMEND.

> (For new AVRs, it's actually initialed three times: the
> hardware itself initializes the SP to the top of internal RAM now.)


You have full list of these devices?  For them it is possible to remove 
initialization of stack pointer in the startup code.

Anatoly 




_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to