blob: 1f9e2638ab6f9ced622531ae90086c81805b3da9 [file] [log] [blame]
Furquan Shaikh2af76f42014-04-28 16:39:40 -07001/*
2 * Copyright (C) 2013 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <arch/asm.h>
18/*
19 * Move a buffer from src to test (alignment handled by the hardware).
20 * If dest <= src, call memcpy, otherwise copy in reverse order.
21 *
22 * Parameters:
23 * x0 - dest
24 * x1 - src
25 * x2 - n
26 * Returns:
27 * x0 - dest
28 */
29ENTRY(memmove)
30 cmp x0, x1
31 b.ls memcpy
32 add x4, x0, x2
33 add x1, x1, x2
34 subs x2, x2, #8
35 b.mi 2f
361: ldr x3, [x1, #-8]!
37 subs x2, x2, #8
38 str x3, [x4, #-8]!
39 b.pl 1b
402: adds x2, x2, #4
41 b.mi 3f
42 ldr w3, [x1, #-4]!
43 sub x2, x2, #4
44 str w3, [x4, #-4]!
453: adds x2, x2, #2
46 b.mi 4f
47 ldrh w3, [x1, #-2]!
48 sub x2, x2, #2
49 strh w3, [x4, #-2]!
504: adds x2, x2, #1
51 b.mi 5f
52 ldrb w3, [x1, #-1]
53 strb w3, [x4, #-1]
545: ret
55ENDPROC(memmove)