[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] how to safely use register locked variables with avr-
Re: [avr-gcc-list] how to safely use register locked variables with avr-libc?
Sun, 31 May 2015 19:13:03 +1000
On 26.05.15 15:55, Britton Kerin wrote:
> What I don't know is what I must do to ensure that avr-libc isn't using the
> registers in an unsafe way. It does use the registers:
> $ avr-objdump -d /usr/lib/avr/lib/libc.a > /tmp/libc
> $ egrep '\<r2\>' /tmp/libc | more
> 1ac: 28 2e mov r2, r24
> 1f4: 20 2e mov r2, r16
> 204: 82 2d mov r24, r2
> and apparently since there are no push-pop pairs, it doesn't seem guaranteed
> that its saving/restoring them. But I'm told that it might not need to,
> because a compiler optimization causes only clobbered registers to be
> preserved. I'm told that what I need to check is whether avr-gcc "pushes
> the clobber list"?
What do you see when you "avr-objdump -d" the compiled object of a small
program which calls one avr-libc function? Does the compiler provide
push-pop pairs for registers used both by the calling function and the
It would be less efficient to push everything, whether needed or not.
Avr-gcc only needs to protect registers which are in use. What do you
find when you look?
My recollection of the AVR ABI is that r2-r17 are preserved across
function calls. As avr-libc lacks obvious signs of doing that
intrinsically, you can either hope that avr-gcc does it, or quickly and
easily verify the behaviour by observation.