From MAILER-DAEMON Tue May 26 19:55:17 2015 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YxOgn-0005Wv-4a for mharc-avr-gcc-list@gnu.org; Tue, 26 May 2015 19:55:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxOgk-0005Wn-HO for avr-gcc-list@nongnu.org; Tue, 26 May 2015 19:55:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxOgj-0008KA-Dm for avr-gcc-list@nongnu.org; Tue, 26 May 2015 19:55:14 -0400 Received: from mail-oi0-x236.google.com ([2607:f8b0:4003:c06::236]:33085) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxOgj-0008Jp-7h for avr-gcc-list@nongnu.org; Tue, 26 May 2015 19:55:13 -0400 Received: by oiww2 with SMTP id w2so90541870oiw.0 for ; Tue, 26 May 2015 16:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=ye2QW7vz8WB34aK+IH/YTlyyA15DSA4CQSQCVRPx0gc=; b=MEkcJriMVR85szpY7eCECVdSj3B+Q+KXXhc1a7WymK/GjGOfzIzsS/pdpWSKcGLobX MWibQi+GywV8FxbnU9KVf1U+O28BDjeT3ZYP9polVgEhEic+ahaBRcnegsFDk+JWpI2q 4OBfVgZ2KvRivO3YbPGBBjGRTmp5til8SOGM1KQr48wWr2vYErSHp66GD3yZfsue50pq FjrAMJEbbBFc19VuiMw6+pODCKCrR/IB5X9XvlDOOaATpXelm0SkPE/5l6pPRkYupht5 UVTI6ZgKB82rqYbr62jH6qK0oe3BH8zBrWLkOE/WhsiXVylnWkTH3ZmNjVUQE35NWr65 uvEQ== MIME-Version: 1.0 X-Received: by 10.60.144.201 with SMTP id so9mr23830513oeb.3.1432684512024; Tue, 26 May 2015 16:55:12 -0700 (PDT) Received: by 10.202.206.139 with HTTP; Tue, 26 May 2015 16:55:11 -0700 (PDT) Date: Tue, 26 May 2015 15:55:11 -0800 Message-ID: From: Britton Kerin To: avr-gcc-list@nongnu.org Content-Type: text/plain; charset=UTF-8 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::236 Subject: [avr-gcc-list] how to safely use register locked variables with avr-libc? X-BeenThere: avr-gcc-list@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the AVR-GCC toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 May 2015 23:55:15 -0000 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: http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_regbind 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 http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_reg_usage 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 '\' /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"? Britton From MAILER-DAEMON Sun May 31 05:08:16 2015 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YyzE8-0002IT-HL for mharc-avr-gcc-list@gnu.org; Sun, 31 May 2015 05:08:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YyzE5-0002GJ-Td for avr-gcc-list@nongnu.org; Sun, 31 May 2015 05:08:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YyzE1-0006Xk-Sb for avr-gcc-list@nongnu.org; Sun, 31 May 2015 05:08:13 -0400 Received: from ipmail07.adl2.internode.on.net ([150.101.137.131]:33736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YyzE1-0006WW-GX for avr-gcc-list@nongnu.org; Sun, 31 May 2015 05:08:09 -0400 Received: from ppp118-209-102-42.lns20.mel4.internode.on.net (HELO ratatosk) ([118.209.102.42]) by ipmail07.adl2.internode.on.net with ESMTP; 31 May 2015 18:37:51 +0930 Received: by ratatosk (Postfix, from userid 1000) id C79C8921; Sun, 31 May 2015 19:13:03 +1000 (AEST) Date: Sun, 31 May 2015 19:13:03 +1000 From: Erik Christiansen To: avr-gcc-list@nongnu.org Message-ID: <20150531091303.GA3427@ratatosk> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 150.101.137.131 Subject: Re: [avr-gcc-list] how to safely use register locked variables with avr-libc? X-BeenThere: avr-gcc-list@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: dvalin@internode.on.net List-Id: Discussions about the AVR-GCC toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 May 2015 09:08:15 -0000 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 '\' /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 avr-libc function? 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. Erik