Furquan Shaikh | 464f5ca | 2015-06-08 10:31:55 -0700 | [diff] [blame] | 1 | /* |
| 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. |
Furquan Shaikh | 464f5ca | 2015-06-08 10:31:55 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <arch/asm.h> |
| 15 | |
| 16 | /* |
| 17 | * Copy a buffer from src to dest (alignment handled by the hardware) |
| 18 | * |
| 19 | * Parameters: |
| 20 | * x0 - dest |
| 21 | * x1 - src |
| 22 | * x2 - n |
| 23 | * Returns: |
| 24 | * x0 - dest |
| 25 | */ |
| 26 | ENTRY(memcpy) |
| 27 | mov x4, x0 |
| 28 | subs x2, x2, #8 |
| 29 | b.mi 2f |
| 30 | 1: ldr x3, [x1], #8 |
| 31 | subs x2, x2, #8 |
| 32 | str x3, [x4], #8 |
| 33 | b.pl 1b |
| 34 | 2: adds x2, x2, #4 |
| 35 | b.mi 3f |
| 36 | ldr w3, [x1], #4 |
| 37 | sub x2, x2, #4 |
| 38 | str w3, [x4], #4 |
| 39 | 3: adds x2, x2, #2 |
| 40 | b.mi 4f |
| 41 | ldrh w3, [x1], #2 |
| 42 | sub x2, x2, #2 |
| 43 | strh w3, [x4], #2 |
| 44 | 4: adds x2, x2, #1 |
| 45 | b.mi 5f |
| 46 | ldrb w3, [x1] |
| 47 | strb w3, [x4] |
| 48 | 5: ret |
| 49 | ENDPROC(memcpy) |