[Tinyos-devel] what version of Gcc should I be using? Possible bug?

Vlado Handziski handzisk at tkn.tu-berlin.de
Tue May 20 05:05:49 PDT 2008


On Tue, May 20, 2008 at 9:37 AM, Eric Decker <cire831 at gmail.com> wrote:

> I've been chasing a problem where the following code doesn't do the right
> thing.
>   bool isSetSCCI() {
>     return (TACCTL2 & SCCI);
>   }
>
> SCCI has the value 0x0400 (bit 10 of TACCTLx).  I would expect this to
> return 0x0400 if
> SCCI is set and 0 otherwise.  The code generated both with and without
> optimization is
> given below.  It basically does nothing.  Am I missing something?  (As I
> get older my
> brain definitely misses things....)
>
> (gdb) x/3i 460c
> 0x460c <GPSByteCollectP$isSetSCCI>:     mov     &0x0166,r15     ;src addr
> 0x0166
> 0x4610 <GPSByteCollectP$isSetSCCI+4>:   clr     r15             ;
> 0x4612 <GPSByteCollectP$isSetSCCI+6>:   ret
>
>
The mspgcc is eager in optimizing things and sometimes has issues with
volatiles. Your function is returning a bool which in tos.h is defined as
uint8_t. The TACCTLx is a volatile int (i.e. 16-bit) via the sfrw macro. The
compiler makes a conclusion that he can safely ignore any modifications to
TACCTL2 in the upper byte, thus the result. Try specifying int as return
type of the function, you should get:

00004040 <isSetSCCI>:
    4040:       1f 42 66 01     mov     &0x0166,r15     ;0x0166
    4044:       3f f0 00 04     and     #1024,  r15     ;#0x0400
    4048:       30 41           ret

as expected.

I am not saying that what mspgcc is doing here is intuitive. Maybe John
Regehr can shed more light, I know that he has been testing the handling of
volatiles across the embedded gcc toolchains.



>
> Here is the code I'm running.  I'm a bit dubious of gcc 4.1.2.  What
> version should I be
> running?
>
> cire-laptop (47): ncc --version
> ncc: 1.2.4
> nescc: 1.2.9
> gcc: gcc (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
> Copyright (C) 2006 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
>
ncc --version is reporting the system gcc version, not the mspgcc version.

[hanjo at localhost Block]$ msp430-gcc -v
Reading specs from /opt/msp430/lib/gcc-lib/msp430/3.2.3/specs
Configured with: ../configure --target=msp430 --prefix=/opt/msp430
Thread model: single
gcc version 3.2.3


This (3.2.3) is the recommended version.

Vlado
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-devel/attachments/20080520/79d43b51/attachment-0001.htm 


More information about the Tinyos-devel mailing list