avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Where is the Startup Code source.


From: Anatoly Sokolov
Subject: Re: [avr-gcc-list] Where is the Startup Code source.
Date: Fri, 3 Nov 2006 01:14:44 +0300

Hi.

"Joerg Wunsch" <address@hidden> wrote in message 
news:address@hidden

> 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 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]