2 * linux/arch/arm/lib/memmove.S
4 * Author: Nicolas Pitre
5 * Created: Sep 28, 2005
6 * Copyright: (C) MontaVista Software Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
15 #include <asm/unwind.h>
16 #include <asm/export.h>
21 * Prototype: void *memmove(void *dest, const void *src, size_t n);
25 * If the memory regions don't overlap, we simply branch to memcpy which is
26 * normally a bit faster. Otherwise the copy is done going downwards. This
27 * is a transposition of the code from copy_template.S but with the copy
28 * occurring in the opposite direction.
38 stmfd sp!, {r0, r4, lr}
42 UNWIND( .save {r0, r4, lr} ) @ in first stmfd block
58 UNWIND( .save {r0, r4, lr} )
59 UNWIND( .save {r5 - r8} ) @ in second stmfd block
62 CALGN( ands ip, r0, #31 )
63 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
66 CALGN( subs r2, r2, ip ) @ C is set here
67 CALGN( rsb ip, ip, #32 )
68 CALGN( add pc, r4, ip )
71 2: PLD( subs r2, r2, #96 )
77 3: PLD( pld [r1, #-128] )
78 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
80 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
87 addne pc, pc, ip @ C is always clear here
101 W(str) r3, [r0, #-4]!
102 W(str) r4, [r0, #-4]!
103 W(str) r5, [r0, #-4]!
104 W(str) r6, [r0, #-4]!
105 W(str) r7, [r0, #-4]!
106 W(str) r8, [r0, #-4]!
107 W(str) lr, [r0, #-4]!
111 7: ldmfd sp!, {r5 - r8}
112 UNWIND( .fnend ) @ end of second stmfd block
115 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
117 8: movs r2, r2, lsl #31
118 ldrneb r3, [r1, #-1]!
119 ldrcsb r4, [r1, #-1]!
121 strneb r3, [r0, #-1]!
122 strcsb r4, [r0, #-1]!
124 ldmfd sp!, {r0, r4, pc}
127 ldrgtb r3, [r1, #-1]!
128 ldrgeb r4, [r1, #-1]!
130 strgtb r3, [r0, #-1]!
131 strgeb r4, [r0, #-1]!
146 .macro backward_copy_shift push pull
149 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
153 CALGN( ands ip, r0, #31 )
154 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
155 CALGN( subcc r2, r2, ip )
158 11: stmfd sp!, {r5 - r9}
162 UNWIND( .save {r0, r4, lr} )
163 UNWIND( .save {r5 - r9} ) @ in new second stmfd block
166 PLD( subs r2, r2, #96 )
167 PLD( pld [r1, #-32] )
169 PLD( pld [r1, #-64] )
170 PLD( pld [r1, #-96] )
172 12: PLD( pld [r1, #-128] )
173 13: ldmdb r1!, {r7, r8, r9, ip}
174 mov lr, r3, lspush #\push
176 ldmdb r1!, {r3, r4, r5, r6}
177 orr lr, lr, ip, lspull #\pull
178 mov ip, ip, lspush #\push
179 orr ip, ip, r9, lspull #\pull
180 mov r9, r9, lspush #\push
181 orr r9, r9, r8, lspull #\pull
182 mov r8, r8, lspush #\push
183 orr r8, r8, r7, lspull #\pull
184 mov r7, r7, lspush #\push
185 orr r7, r7, r6, lspull #\pull
186 mov r6, r6, lspush #\push
187 orr r6, r6, r5, lspull #\pull
188 mov r5, r5, lspush #\push
189 orr r5, r5, r4, lspull #\pull
190 mov r4, r4, lspush #\push
191 orr r4, r4, r3, lspull #\pull
192 stmdb r0!, {r4 - r9, ip, lr}
198 UNWIND( .fnend ) @ end of the second stmfd block
201 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
206 15: mov lr, r3, lspush #\push
209 orr lr, lr, r3, lspull #\pull
215 16: add r1, r1, #(\pull / 8)
222 backward_copy_shift push=8 pull=24
224 17: backward_copy_shift push=16 pull=16
226 18: backward_copy_shift push=24 pull=8
229 EXPORT_SYMBOL(memmove)