Bug in m68k memcpy/memcmp

Eric Norum norume@aps.anl.gov
Fri Apr 27 22:13:00 GMT 2007


The proposed patch to the M68k versions of memcpy/memset has a nasty  
bug:


+.Lcopy:
+#if !defined (__mcoldfire__)
+	dbra	%d0,1b
+#else
+	subq.l	#1,%d0
+	bpl	1b
+#endif

The non-ColdFire version uses dbra -- which uses only the lower 16- 
bits of the counter register.
The above code will fail for transfers greater than 16*65535 bytes.

There needs to be another decrement of the most-significant 16-bits  
of the count register and another conditional branch and conditional  
branch added to all the 'dbra' loop tests.

Off the top of my head, I think that there needs to be something like:
+.Lcopy:
+#if !defined (__mcoldfire__)
+	dbra	%d0,1b
+      subl         #0x10000,d0
+     bpl           1b
+#else
+	subq.l	#1,%d0
+	bpl	1b
+#endif


-- 
Eric Norum <norume@aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793




More information about the Newlib mailing list