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

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

[avr-gcc-list] compiler function prologue/epilogue incorrect?


From: craig
Subject: [avr-gcc-list] compiler function prologue/epilogue incorrect?
Date: Tue, 26 Sep 2006 11:32:32 +0200
User-agent: Mutt/1.4.1i

Hi

I'm chasing a strange bug which occurs with gcc > 3.3.2 in my code ...
I haven't found it yet but I stumbled across the issue below while
digging for it. Can someone comment on the assembler below please?

     400:       0f 93           push    r16
     402:       1f 93           push    r17
     404:       cf 93           push    r28
     406:       df 93           push    r29
     408:       cd b7           in      r28, 0x3d       ; 61 (SPL)
     40a:       de b7           in      r29, 0x3e       ; 62 (SPH)
     40c:       21 97           sbiw    r28, 0x01       ; 1
     40e:       0f b6           in      r0, 0x3f        ; 63 (SREG)
     410:       f8 94           cli
     412:       de bf           out     0x3e, r29       ; 62 (SPH)
     414:       0f be           out     0x3f, r0        ; 63 (SREG)
     416:       cd bf           out     0x3d, r28       ; 61 (SPL)

This is the function prologue which seems to be adjusting the
stack pointer for a char on the stack. What doesn't seem to make
sense for me is that SREG is being restored (and perhaps interrupts
enabled) before SPL is updated. The assembler tutorial I have
suggests that SEI will execute at least one more instruction
before reacting to an interrupt but it's not obvious that
out 0x3f, r0 will do the same thing or if an interrupt could occur
before SPL is updated. I think it would be safer if the compiler
swapped the last two lines? The same issue occurs in the function
epilogue.

Thank you!

--Craig




reply via email to

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