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

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

[avr-gcc-list] incorrect function prolog/epilog?


From: Michal Grégr
Subject: [avr-gcc-list] incorrect function prolog/epilog?
Date: Fri, 01 Sep 2006 10:23:42 +0200 (CEST)

Hi,

I have the following function:

void Test(void)
{
    unsigned char t;
}

which compiles to:

void Test(void)
{
  d2: cf 93 push r28
  d4: df 93 push r29
  d6: cd b7 in r28, 0x3d ; 61
  d8: de b7 in r29, 0x3e ; 62
  da: 21 97 sbiw r28, 0x01 ; 1
  dc: 0f b6 in r0, 0x3f ; 63
  de: f8 94 cli
  e0: de bf out 0x3e, r29 ; 62
  e2: 0f be out 0x3f, r0 ; 63
  e4: cd bf out 0x3d, r28 ; 61
  e6: 21 96 adiw r28, 0x01 ; 1
  e8: 0f b6 in r0, 0x3f ; 63
  ea: f8 94 cli
  ec: de bf out 0x3e, r29 ; 62
  ee: 0f be out 0x3f, r0 ; 63
  f0: cd bf out 0x3d, r28 ; 61
  f2: df 91 pop r29
  f4: cf 91 pop r28
  f6: 08 95 ret

000000f8 <main>:
    unsigned char t;
}

The target device is mega16, but it does the same thing for other megas.
The compiler is avr-gcc 3.4.6.

I/O locations in the code above are:
SREG 0x3f
SPH 0x3e
SPL 0x3d

The function prolog code saves the Y register, loads into it the stack pointer, 
decrements by one, disables interrupts, sets new stack pointer and restores 
interrupts. However, it sets only SPH with interrupts disabled, but SPL is 
written with interrupts enabled.

I think it should restore SREG after both SPH and SPL is updated, otherwise an 
incorrect stack is used if an interrupt occurs between SPH and SPL write. Or am 
I wrong?

thanks,
mike




reply via email to

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