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

bug in gen5200/tod/pcf8563.c



Ingolf Steinbach schrieb:
> On 2007-05-11, Wolfram Wadepohl <Wolfram.Wadepohl at ek-automation.com> wrote:
> 
>> The macro
>> #define From_BCD( _x ) ((((_x) >> 4) * 10) + ((_x) & 0x0F))
>> produces wrong code in pcf8563_get_time().
> 
> 
> Without looking at the source, I'd guess the reason is that this is quite
> a dangerous macro (it evaluates the _x argument twice). If this macro is
> invoked with an argument which directly references a (volatile) register,
> it might see two different values when evaluating _x.

Sure this macro isn't pretty. The argument is a local variable, which in 
this case, is held in a register. I think the compiler must take care, that 
the register is preserverd for multiple evaluations:

pcf8563_get_time(int minor, rtems_time_of_day *time)
{
	(...)
	uint8_t  info[10];
	uint32_t v1, v2;

	(...)
	v1 = info[PCF8563_HOUR_ADR-PCF8563_SECOND_ADR] & PCF8563_HOUR_MASK;
	/* i. e. v1 = info[2] & 0x3F; */
	time->hour = From_BCD(v1);
	(...)
}

For the other parts minutes, seconds there is pretty similiar c code, 
working perfectly. Only this fragment fail.

Disasembler code is available but i'm nat capable to interpret PPC assembly 
language:

          165|    v1 = info[PCF8563_DAY_ADR-PCF8563_SECOND_ADR] & 
PCF8563_DAY_MASK;
  SF:000C6840|8961000B            lbz       r11,0x0B(r1)   ; r11,11(r1)
          166|    time->day = From_BCD(v1);
  SF:000C6844|5569E7BE            extrwi    r9,r11,0x2,0x1A; 
r9,r11,CTRL_PRECHARGE,26
  SF:000C6848|1D29000A            mulli     r9,r9,0x0A     ; r9,r9,10
  SF:000C684C|556B073E            clrlwi    r11,r11,0x1C   ; r11,r11,GP_18
  SF:000C6850|7D295A14            add       r9,r9,r11
  SF:000C6854|913E0008            stw       r9,0x8(r30)    ; r9,CS0STP(r30)
             |
          168|    v1 = info[PCF8563_HOUR_ADR-PCF8563_SECOND_ADR] & 
PCF8563_HOUR_MASK;
  SF:000C6858|8801000A            lbz       r0,0x0A(r1)    ; r0,10(r1)
          169|    time->hour = From_BCD(v1);
_SF:000C685C|5400077A            rlwinm    r0,r0,0x0,0x1D,0x1D;_r0,r0,0,29,29
  SF:000C6860|901E000C            stw       r0,0x0C(r30)   ; r0,CS1STR(r30)
             |


Defining From_BCD() as an inline function works perfectly.

-- 
Sch?ne Gr??e aus Reutlingen

Wolfram Wadepohl
Forschung & Entwicklung

E&K AUTOMATION
Indumat GmbH & Co. KG
Siemensstra?e 3
72766 Reutlingen
Deutschland

Tel.  +49 7121 514-289
Fax   +49 7121 514-299
eMail Wolfram.Wadepohl at ek-automation.com
       W.Wadepohl at ieee.org
WWW   http://www.ek-automation.com
       http://www.indumat.de

Diese Nachricht ist keine gesch?ftliche Mitteilung i. S. des EHUG.

Bitte senden Sie mir keine Word- oder PowerPoint- (tm Microsoft) Anh?nge.
Senden Sie mir einfachen Text, HTML oder PDF.
Siehe http://www.gnu.org/philosophy/no-word-attachments.de.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3210 bytes
Desc: S/MIME Cryptographic Signature
Url : http://rtems.rtems.org/pipermail/rtems-users/attachments/20070514/c8ed9321/attachment.bin