[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] When does the Stack Frame Pointer (Y) get setup?
From: |
Bob Paddock |
Subject: |
[avr-gcc-list] When does the Stack Frame Pointer (Y) get setup? |
Date: |
Tue, 3 Jul 2012 13:05:31 -0400 |
When does the Stack Frame Pointer (Y) get setup?
Should the following code work? I find it trashing memory in bss:
void id_filter_init8( void ) __attribute__ ((naked)) __attribute__
((section(".init8")));
void id_filter_init8( void )
{
uint8_t ff_u8[128U];
/* memset() should really be used here */
for( uint16_t idx_u16 = 0U; idx_u16 < (uint16_t) sizeof( ff_u8 ); idx_u16++ )
{
ff_u8[ idx_u16 ] = 0U;
}
/* Anything that makes ff_u8 be used, so it is not optimized away in
this example: */
eeprom_update_block ( ff_u8, sysgrp_mask_eeprom_u8, sizeof(
sysgrp_mask_eeprom_u8 ) );
}
.lss:
00008cc4 <__ctors_end>:
8cc4: 11 24 eor r1, r1
8cc6: 1f be out 0x3f, r1 ; 63
8cc8: cf ef ldi r28, 0xFF ; 255 Set Y and stack
8cca: df e3 ldi r29, 0x3F ; 63
8ccc: de bf out 0x3e, r29 ; 62
8cce: cd bf out 0x3d, r28 ; 61
8cd0: 00 e0 ldi r16, 0x00 ; 0
8cd2: 0c bf out 0x3c, r16 ; 60
8cd4: 18 be out 0x38, r1 ; 56
8cd6: 19 be out 0x39, r1 ; 57
8cd8: 1a be out 0x3a, r1 ; 58
8cda: 1b be out 0x3b, r1 ; 59
[snip lots of stuff that changes r28/r29, doesn't save them]
[Is Y really a frame pointer value at this point?:]
void id_filter_init8( void ) __attribute__ ((naked)) __attribute__
((section(".init8")));
void id_filter_init8( void )
{
93b4: fe 01 movw r30, r28
93b6: 31 96 adiw r30, 0x01 ; 1
#include "event.h"
extern void event_bug( void );
#endif
void id_filter_init8( void ) __attribute__ ((naked)) __attribute__
((section(".init8")));
void id_filter_init8( void )
93b8: ce 01 movw r24, r28
93ba: 8f 57 subi r24, 0x7F ; 127
93bc: 9f 4f sbci r25, 0xFF ; 255
{
uint8_t ff_u8[128U];
for( uint16_t idx_u16 = 0U; idx_u16 < (uint16_t) sizeof( ff_u8 ); idx_u16++ )
{
ff_u8[ idx_u16 ] = 0U;
93be: 11 92 st Z+, r1
void id_filter_init8( void ) __attribute__ ((naked)) __attribute__
((section(".init8")));
void id_filter_init8( void )
{
uint8_t ff_u8[128U];
for( uint16_t idx_u16 = 0U; idx_u16 < (uint16_t) sizeof( ff_u8 ); idx_u16++ )
93c0: e8 17 cp r30, r24
93c2: f9 07 cpc r31, r25
93c4: e1 f7 brne .-8 ; 0x93be
<id_filter_init8+0xa>
{
ff_u8[ idx_u16 ] = 0U;
}
[Looks like Y Frame Pointer is set and used as such from here on, and
gets saved in function calls:]
MAIN_OS int main( void )
{
95d2: cd b7 in r28, 0x3d ; 61
95d4: de b7 in r29, 0x3e ; 62
95d6: cb 54 subi r28, 0x4B ; 75
95d8: d0 40 sbci r29, 0x00 ; 0
95da: cd bf out 0x3d, r28 ; 61
95dc: de bf out 0x3e, r29 ; 62
[more stuff]
return( 0 ); /* When main() returns the .FINIsh function will be
called to put I/O in its lowest power state. Probably the same as the
power up state */
}/* main() */
9aec: 80 e0 ldi r24, 0x00 ; 0
9aee: 90 e0 ldi r25, 0x00 ; 0
9af0: c5 5b subi r28, 0xB5 ; 181
9af2: df 4f sbci r29, 0xFF ; 255
9af4: cd bf out 0x3d, r28 ; 61
9af6: de bf out 0x3e, r29 ; 62
9af8: 08 95 ret
Did I miss anything in the documentation that would tell me not to use
auto variables in .initX sections after .init2 that sets the stack?
- [avr-gcc-list] When does the Stack Frame Pointer (Y) get setup?,
Bob Paddock <=
Re: [avr-gcc-list] When does the Stack Frame Pointer (Y) get setup?, Joerg Wunsch, 2012/07/04
Re: [avr-gcc-list] When does the Stack Frame Pointer (Y) get setup?, Joerg Wunsch, 2012/07/04