1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Based on linux/arch/arm/lib/memcpy.S
14 .macro ldr1w ptr reg abort
15 W(ldr) \reg, [\ptr], #4
18 .macro ldr4w ptr reg1 reg2 reg3 reg4 abort
19 ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4}
22 .macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
23 ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
26 .macro ldr1b ptr reg cond=al abort
27 ldrb\cond \reg, [\ptr], #1
30 .macro str1w ptr reg abort
31 W(str) \reg, [\ptr], #4
34 .macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
35 stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
38 .macro str1b ptr reg cond=al abort
39 strb\cond \reg, [\ptr], #1
42 .macro enter reg1 reg2
43 stmdb sp!, {r0, \reg1, \reg2}
47 ldmfd sp!, {r0, \reg1, \reg2}
50 /* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
68 CALGN( ands ip, r0, #31 )
69 CALGN( rsb r3, ip, #32 )
70 CALGN( sbcnes r4, r3, r2 ) @ C is always set here
73 CALGN( subs r2, r2, r3 ) @ C gets set
74 CALGN( add pc, r4, ip )
77 2: PLD( subs r2, r2, #96 )
83 3: PLD( pld [r1, #124] )
84 4: ldr8w r1, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
86 str8w r0, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
94 lsl ip, ip, #LDR1W_SHIFT
96 addne pc, pc, ip @ C is always clear here
99 .rept (1 << LDR1W_SHIFT)
102 ldr1w r1, r3, abort=20f
103 ldr1w r1, r4, abort=20f
104 ldr1w r1, r5, abort=20f
105 ldr1w r1, r6, abort=20f
106 ldr1w r1, r7, abort=20f
107 ldr1w r1, r8, abort=20f
108 ldr1w r1, lr, abort=20f
110 #if LDR1W_SHIFT < STR1W_SHIFT
111 lsl ip, ip, #STR1W_SHIFT - LDR1W_SHIFT
112 #elif LDR1W_SHIFT > STR1W_SHIFT
113 lsr ip, ip, #LDR1W_SHIFT - STR1W_SHIFT
117 .rept (1 << STR1W_SHIFT)
120 str1w r0, r3, abort=20f
121 str1w r0, r4, abort=20f
122 str1w r0, r5, abort=20f
123 str1w r0, r6, abort=20f
124 str1w r0, r7, abort=20f
125 str1w r0, r8, abort=20f
126 str1w r0, lr, abort=20f
130 7: ldmfd sp!, {r5 - r8}
132 8: movs r2, r2, lsl #31
133 ldr1b r1, r3, ne, abort=21f
134 ldr1b r1, r4, cs, abort=21f
135 ldr1b r1, ip, cs, abort=21f
136 str1b r0, r3, ne, abort=21f
137 str1b r0, r4, cs, abort=21f
138 str1b r0, ip, cs, abort=21f
144 ldr1b r1, r3, gt, abort=21f
145 ldr1b r1, r4, ge, abort=21f
146 ldr1b r1, lr, abort=21f
147 str1b r0, r3, gt, abort=21f
148 str1b r0, r4, ge, abort=21f
150 str1b r0, lr, abort=21f
157 ldr1w r1, lr, abort=21f
162 .macro forward_copy_shift pull push
167 CALGN( ands ip, r0, #31 )
168 CALGN( rsb ip, ip, #32 )
169 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
170 CALGN( subcc r2, r2, ip )
173 11: stmfd sp!, {r5 - r9}
176 PLD( subs r2, r2, #96 )
182 12: PLD( pld [r1, #124] )
183 13: ldr4w r1, r4, r5, r6, r7, abort=19f
184 mov r3, lr, pull #\pull
186 ldr4w r1, r8, r9, ip, lr, abort=19f
187 orr r3, r3, r4, push #\push
188 mov r4, r4, pull #\pull
189 orr r4, r4, r5, push #\push
190 mov r5, r5, pull #\pull
191 orr r5, r5, r6, push #\push
192 mov r6, r6, pull #\pull
193 orr r6, r6, r7, push #\push
194 mov r7, r7, pull #\pull
195 orr r7, r7, r8, push #\push
196 mov r8, r8, pull #\pull
197 orr r8, r8, r9, push #\push
198 mov r9, r9, pull #\pull
199 orr r9, r9, ip, push #\push
200 mov ip, ip, pull #\pull
201 orr ip, ip, lr, push #\push
202 str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, abort=19f
212 15: mov r3, lr, pull #\pull
213 ldr1w r1, lr, abort=21f
215 orr r3, r3, lr, push #\push
216 str1w r0, r3, abort=21f
221 16: sub r1, r1, #(\push / 8)
227 forward_copy_shift pull=8 push=24
229 17: forward_copy_shift pull=16 push=16
231 18: forward_copy_shift pull=24 push=8