Skip to content

Commit 588c19e

Browse files
yunkya2github-cygwin
authored andcommitted
Fix memcpy alignment problems for m68k architecture
1. On CPUs that do not support misaligned access (MISALIGNED_OK=0), such as the 68000, memcpy() does not correctly copy regions larger than 64 KB when the destination is not long-word aligned. 2. The 68020 supports misaligned access, but this is not currently implemented. 3. The 68000 can access long-word data at even addresses, but alignment is checked as if the address must be a multiple of 4. 4. Because the loop count is checked using signed comparison, memcpy() fails for data sizes larger than 2 GB. This patch fixes these issues.
1 parent 2a953c1 commit 588c19e

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

newlib/libc/machine/m68k/memcpy.S

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "m68kasm.h"
1717

18-
#if defined (__mcoldfire__) || defined (__mc68030__) || defined (__mc68040__) || defined (__mc68060__)
18+
#if defined (__mcoldfire__) || defined (__mc68020__) || defined (__mc68030__) || defined (__mc68040__) || defined (__mc68060__)
1919
# define MISALIGNED_OK 1
2020
#else
2121
# define MISALIGNED_OK 0
@@ -49,10 +49,10 @@ SYM(memcpy):
4949
#if !MISALIGNED_OK
5050
/* Goto .Lresidue if either dest or src is not 4-byte aligned */
5151
move.l a0,d0
52-
and.l #3,d0
52+
and.l #1,d0
5353
bne .Lresidue
5454
move.l a1,d0
55-
and.l #3,d0
55+
and.l #1,d0
5656
bne .Lresidue
5757
#else /* MISALIGNED_OK */
5858
/* align dest */
@@ -95,7 +95,7 @@ SYM(memcpy):
9595
#else
9696
subq.l #1,d0
9797
#endif
98-
bpl 1b
98+
bcc 1b
9999
bra .Lresidue
100100

101101
1:
@@ -104,9 +104,13 @@ SYM(memcpy):
104104
.Lresidue:
105105
#if !defined (__mcoldfire__)
106106
dbra d1,1b | loop until done
107+
#if !MISALIGNED_OK
108+
sub.l #0x10000,d1
109+
bcc 1b
110+
#endif /* !MISALIGNED_OK */
107111
#else
108112
subq.l #1,d1
109-
bpl 1b
113+
bcc 1b
110114
#endif
111115
move.l 4(sp),d0 | return value
112116
rts

0 commit comments

Comments
 (0)