[Top][All Lists]

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

[avr-gcc-list] how to safely use register locked variables with avr-libc

From: Britton Kerin
Subject: [avr-gcc-list] how to safely use register locked variables with avr-libc?
Date: Tue, 26 May 2015 15:55:11 -0800

On 13.05.15 15:49, Britton Kerin wrote:

I've got some code with tight timing that works at 10MHz only if I register
lock some globals as described here:


I'm using registers r2 through r5.  The FAQ seems to be saying that this is
safe in the above faq_regbind section, and also in


but it also says that extreme care is required to make sure other code
including possibly used library functions doesn't use these registers.

I'm trying to figure out how to do that.

Currently, I have the global uint8_t register vars declared at the top of the
source file that uses them, and I compile all my source files with -ffixed-r2
-ffixed-r3 -ffixed-r4 -ffixed-r5 as the GCC manual advises.  But I haven't
recompiled avr-libc that way.   This seems to work, but is it really ok?

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"?


reply via email to

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