Clock not running (was Re: RTEMS4.7 and its tool chain (Re: powerpc mvme5500 clock off by factor of 150))

Till Straumann strauman at
Wed Mar 9 17:29:16 UTC 2005

Peter Dufault wrote:

> On Mar 8, 2005, at 9:46 PM, Till Straumann wrote:
>> Hmm - I smell something: could you try to insert a '&' after the '=' ?
>> asm volatile ("mfdec %0; add %0, %0, %1; mtdec 
>> %0":"=&r(decr):"r"(Clock_Decrementer_value));
> It's working.  Thanks, you're Hero of the Day. Can you translate into 
> English, or into C? 

I must shamefully decline - I feel more like the loser of the day since I'm
actually responsible for that bug, sorry.

 From the gcc manual:

"   Unless an output operand has the `&' constraint modifier, GCC may
allocate it in the same register as an unrelated input operand, on the
assumption the inputs are consumed before the outputs are produced.
This assumption may be false if the assembler code actually consists of
more than one instruction.  In such a case, use `&' for each output
operand that may not overlap an input.  "

--> the 4.7 gcc seems to be a little more aggressive or you used different
optimization flags which triggers the bug.

   mfdec %0                       decrementer -> 1st register (mapped to 
'decr' var)
   add %0, %0, %1          add 2nd reg. (decrementer value) to first
   mtdec %0                       move 1st reg to decrementer

If the compiler allocates the same register to the input variable
(Clock_Decrementer_value) and output variable (decr), [something
it is allowed to do without marking the output variable '&'] the
input variable is overwritten by the first statement, before it is
used [in the second one] and the 3 lines effectively multiply
the decrementer by two (modulo 2^32).

My sincere apologies - I just filed PR#773

-- Till

> Peter
> Peter Dufault
> HD Associates, Inc.

More information about the users mailing list