gettimeofday seconds rollover problem?

Chris Johns chrisj at rtems.org
Thu Feb 23 10:07:07 UTC 2006


Thomas Doerfler wrote:
> 
> Any comments on my sugestion?
> 

Add a barrier. I almost have a patch for the m68k target:

#define M68K_BARRIER() asm volatile ( "" : : : "memory" )

#if ( M68K_COLDFIRE_ARCH == 1 )
#define m68k_disable_interrupts( _level ) \
    do { register uint32_t   _tmpsr = 0x0700; \
         asm volatile ( "move.w %%sr,%0\n\t" \
  		       "or.l   %0,%1\n\t" \
  		       "move.w %1,%%sr" \
  		       : "=d" (_level), "=d"(_tmpsr) : "1"(_tmpsr) ); \
         M68K_BARRIER( ); \
    } while( 0 )
#else
#define m68k_disable_interrupts( _level ) \
    do { asm volatile ( "move.w  %%sr,%0\n\t" \
                        "or.w    #0x0700,%%sr"    \
                        : "=d" (_level));         \
        M68K_BARRIER( );                      \
    } while( 0 )
#endif

#define m68k_enable_interrupts( _level ) \
    do { asm volatile ( "move.w  %0,%%sr " : : "d" (_level)); \
         M68K_BARRIER( );                                     \

generates:

00000000 <gettimeofday>:
gettimeofday():
    0:   2f02            movel %d2,%sp at -
    2:   206f 0008       moveal %sp@(8),%a0
    6:   4a88            tstl %a0
    8:   6736            beqs 40 <gettimeofday+0x40>
    a:   203c 0000 0700  movel #1792,%d0
   10:   2200            movel %d0,%d1
   12:   40c0            movew %sr,%d0
   14:   8280            orl %d0,%d1
   16:   46c1            movew %d1,%sr
   18:   2239 0000 0000  movel 0 <gettimeofday>,%d1
   1e:   2439 0000 0000  movel 0 <gettimeofday>,%d2
   24:   46c0            movew %d0,%sr
   26:   0681 21da e500  addil #567993600,%d1
   2c:   2081            movel %d1,%a0@
   2e:   2039 0000 0000  movel 0 <gettimeofday>,%d0
   34:   4c02 0800       mulsl %d2,%d0
   38:   2140 0004       movel %d0,%a0@(4)
   3c:   4280            clrl %d0
   3e:   6010            bras 50 <gettimeofday+0x50>
   40:   4eb9 0000 0000  jsr 0 <gettimeofday>
   46:   2040            moveal %d0,%a0
   48:   20bc 0000 000e  movel #14,%a0@
   4e:   70ff            moveq #-1,%d0
   50:   241f            movel %sp at +,%d2
   52:   4e75            rts

This is build with RTEMS from CVS and gcc 4.0.2 and the latest binutils etc.

Regards
Chris



More information about the users mailing list