[Top][All Lists]

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

Re: [avr-gcc-list] When does the Stack Frame Pointer (Y) get setup?

From: Georg-Johann Lay
Subject: Re: [avr-gcc-list] When does the Stack Frame Pointer (Y) get setup?
Date: Sun, 08 Jul 2012 19:58:56 +0200
User-agent: Thunderbird (Windows/20100228)

Bob Paddock wrote:

Did I miss anything in the documentation that would tell me not to
use auto variables in .initX sections after .init2 that sets the
If you declare the function being "naked", you cannot expect the
compiler to allocate a stack frame.

What one expects and reality are often different.  Before I submit a
patch for the documentation, to prevent others from shooting
themselves in the foot, I wanted to make sure I understood how stack
frames are working.

The documentation says clearly that a naked function will neither get
a prologue nor an epilogue:


Is the timing of the XMega OUT instruction different than a non-XMega
part, in that it would prevent an interrupt between two sequential
OUT instructions?

Writing SPL will switch off I-flag for some ticks.

I'm fine with the above code, however I question this
XMega run:

# This code DOES NOT disable interrupts when modifying the stack
# pointer 0x3D/0x3E:
000002b0 <__prologue_saves__>:
[snip pushs]
 2d4:   cd b7           in      r28, 0x3d       ; 61
 2d6:   de b7           in      r29, 0x3e       ; 62
 2d8:   ca 1b           sub     r28, r26
 2da:   db 0b           sbc     r29, r27
 2dc:   cd bf           out     0x3d, r28       ; 61
; [What happens if an interrupt happens between these two out instructions?]
 2de:   de bf           out     0x3e, r29       ; 62
 2e0:   19 94           eijmp

The code does not disable IRQs because the hardware does.

For anyone that wants to reproduce:

Hint:  To reproduce it is helpful to show an example that
is as easy as it can get. In particular, to compile the code
and see the generated assembly no Makefile is needed.


$ avr-gcc -mmcu=avrxmega5 foo.c -Os -S

for example with foo.c

void foo (void)
    long volatile a = 0;

The epilogue then reads:

/* epilogue start */
        adiw r28,4
        out __SP_L__,r28
        out __SP_H__,r29
        pop r29
        pop r28

As frame setup is handled by prologue epilogue, you don't get frame
handling/setup with a naked function, of course.

The impact of naked will be the same is if you delete all
instructions up to the /* prologue: function */ comment and all
instructions after the /* epilogue start */ comment.

Besides acting on generated code, -mmcu= also takes effect on the
multilib variant of libgcc/libc that is linked with your code.

prologue_saves and epilogue_restores reside in libgcc. The xmega's
multilibs take advantage of the hardware magic that disables I.

See __prologue_saves__ for example:



reply via email to

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