Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/lib/memmove.S |
| 3 | * |
| 4 | * Author: Nicolas Pitre |
| 5 | * Created: Sep 28, 2005 |
| 6 | * Copyright: (C) MontaVista Software Inc. |
| 7 | * |
| 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. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/linkage.h> |
| 14 | #include <asm/assembler.h> |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 15 | #include <asm/unwind.h> |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 16 | |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 17 | .text |
| 18 | |
| 19 | /* |
| 20 | * Prototype: void *memmove(void *dest, const void *src, size_t n); |
| 21 | * |
| 22 | * Note: |
| 23 | * |
| 24 | * If the memory regions don't overlap, we simply branch to memcpy which is |
| 25 | * normally a bit faster. Otherwise the copy is done going downwards. This |
| 26 | * is a transposition of the code from copy_template.S but with the copy |
| 27 | * occurring in the opposite direction. |
| 28 | */ |
| 29 | |
| 30 | ENTRY(memmove) |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 31 | UNWIND( .fnstart ) |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 32 | |
| 33 | subs ip, r0, r1 |
| 34 | cmphi r2, ip |
| 35 | bls memcpy |
| 36 | |
| 37 | stmfd sp!, {r0, r4, lr} |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 38 | UNWIND( .fnend ) |
| 39 | |
| 40 | UNWIND( .fnstart ) |
| 41 | UNWIND( .save {r0, r4, lr} ) @ in first stmfd block |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 42 | add r1, r1, r2 |
| 43 | add r0, r0, r2 |
| 44 | subs r2, r2, #4 |
| 45 | blt 8f |
| 46 | ands ip, r0, #3 |
| 47 | PLD( pld [r1, #-4] ) |
| 48 | bne 9f |
| 49 | ands ip, r1, #3 |
| 50 | bne 10f |
| 51 | |
| 52 | 1: subs r2, r2, #(28) |
| 53 | stmfd sp!, {r5 - r8} |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 54 | UNWIND( .fnend ) |
| 55 | |
| 56 | UNWIND( .fnstart ) |
| 57 | UNWIND( .save {r0, r4, lr} ) |
| 58 | UNWIND( .save {r5 - r8} ) @ in second stmfd block |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 59 | blt 5f |
| 60 | |
Nicolas Pitre | 2239aff | 2008-03-31 12:38:31 -0400 | [diff] [blame] | 61 | CALGN( ands ip, r0, #31 ) |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 62 | CALGN( sbcnes r4, ip, r2 ) @ C is always set here |
| 63 | CALGN( bcs 2f ) |
| 64 | CALGN( adr r4, 6f ) |
| 65 | CALGN( subs r2, r2, ip ) @ C is set here |
Nicolas Pitre | 4c4925c | 2008-06-11 12:40:13 -0400 | [diff] [blame] | 66 | CALGN( rsb ip, ip, #32 ) |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 67 | CALGN( add pc, r4, ip ) |
| 68 | |
| 69 | PLD( pld [r1, #-4] ) |
| 70 | 2: PLD( subs r2, r2, #96 ) |
| 71 | PLD( pld [r1, #-32] ) |
| 72 | PLD( blt 4f ) |
| 73 | PLD( pld [r1, #-64] ) |
| 74 | PLD( pld [r1, #-96] ) |
| 75 | |
| 76 | 3: PLD( pld [r1, #-128] ) |
| 77 | 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr} |
| 78 | subs r2, r2, #32 |
| 79 | stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr} |
| 80 | bge 3b |
| 81 | PLD( cmn r2, #96 ) |
| 82 | PLD( bge 4b ) |
| 83 | |
| 84 | 5: ands ip, r2, #28 |
| 85 | rsb ip, ip, #32 |
| 86 | addne pc, pc, ip @ C is always clear here |
| 87 | b 7f |
Catalin Marinas | fd522a8 | 2010-03-29 10:29:46 +0100 | [diff] [blame] | 88 | 6: W(nop) |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 89 | W(ldr) r3, [r1, #-4]! |
| 90 | W(ldr) r4, [r1, #-4]! |
| 91 | W(ldr) r5, [r1, #-4]! |
| 92 | W(ldr) r6, [r1, #-4]! |
| 93 | W(ldr) r7, [r1, #-4]! |
| 94 | W(ldr) r8, [r1, #-4]! |
| 95 | W(ldr) lr, [r1, #-4]! |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 96 | |
| 97 | add pc, pc, ip |
| 98 | nop |
Catalin Marinas | fd522a8 | 2010-03-29 10:29:46 +0100 | [diff] [blame] | 99 | W(nop) |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 100 | W(str) r3, [r0, #-4]! |
| 101 | W(str) r4, [r0, #-4]! |
| 102 | W(str) r5, [r0, #-4]! |
| 103 | W(str) r6, [r0, #-4]! |
| 104 | W(str) r7, [r0, #-4]! |
| 105 | W(str) r8, [r0, #-4]! |
| 106 | W(str) lr, [r0, #-4]! |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 107 | |
| 108 | CALGN( bcs 2b ) |
| 109 | |
| 110 | 7: ldmfd sp!, {r5 - r8} |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 111 | UNWIND( .fnend ) @ end of second stmfd block |
| 112 | |
| 113 | UNWIND( .fnstart ) |
| 114 | UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 115 | |
| 116 | 8: movs r2, r2, lsl #31 |
| 117 | ldrneb r3, [r1, #-1]! |
| 118 | ldrcsb r4, [r1, #-1]! |
| 119 | ldrcsb ip, [r1, #-1] |
| 120 | strneb r3, [r0, #-1]! |
| 121 | strcsb r4, [r0, #-1]! |
| 122 | strcsb ip, [r0, #-1] |
| 123 | ldmfd sp!, {r0, r4, pc} |
| 124 | |
| 125 | 9: cmp ip, #2 |
| 126 | ldrgtb r3, [r1, #-1]! |
| 127 | ldrgeb r4, [r1, #-1]! |
| 128 | ldrb lr, [r1, #-1]! |
| 129 | strgtb r3, [r0, #-1]! |
| 130 | strgeb r4, [r0, #-1]! |
| 131 | subs r2, r2, ip |
| 132 | strb lr, [r0, #-1]! |
| 133 | blt 8b |
| 134 | ands ip, r1, #3 |
| 135 | beq 1b |
| 136 | |
| 137 | 10: bic r1, r1, #3 |
| 138 | cmp ip, #2 |
| 139 | ldr r3, [r1, #0] |
| 140 | beq 17f |
| 141 | blt 18f |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 142 | UNWIND( .fnend ) |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 143 | |
| 144 | |
| 145 | .macro backward_copy_shift push pull |
| 146 | |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 147 | UNWIND( .fnstart ) |
| 148 | UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 149 | subs r2, r2, #28 |
| 150 | blt 14f |
| 151 | |
Nicolas Pitre | 2239aff | 2008-03-31 12:38:31 -0400 | [diff] [blame] | 152 | CALGN( ands ip, r0, #31 ) |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 153 | CALGN( sbcnes r4, ip, r2 ) @ C is always set here |
| 154 | CALGN( subcc r2, r2, ip ) |
| 155 | CALGN( bcc 15f ) |
| 156 | |
| 157 | 11: stmfd sp!, {r5 - r9} |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 158 | UNWIND( .fnend ) |
| 159 | |
| 160 | UNWIND( .fnstart ) |
| 161 | UNWIND( .save {r0, r4, lr} ) |
| 162 | UNWIND( .save {r5 - r9} ) @ in new second stmfd block |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 163 | |
| 164 | PLD( pld [r1, #-4] ) |
| 165 | PLD( subs r2, r2, #96 ) |
| 166 | PLD( pld [r1, #-32] ) |
| 167 | PLD( blt 13f ) |
| 168 | PLD( pld [r1, #-64] ) |
| 169 | PLD( pld [r1, #-96] ) |
| 170 | |
| 171 | 12: PLD( pld [r1, #-128] ) |
| 172 | 13: ldmdb r1!, {r7, r8, r9, ip} |
Victor Kamensky | d98b90e | 2014-02-25 08:41:09 +0100 | [diff] [blame] | 173 | mov lr, r3, lspush #\push |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 174 | subs r2, r2, #32 |
| 175 | ldmdb r1!, {r3, r4, r5, r6} |
Victor Kamensky | d98b90e | 2014-02-25 08:41:09 +0100 | [diff] [blame] | 176 | orr lr, lr, ip, lspull #\pull |
| 177 | mov ip, ip, lspush #\push |
| 178 | orr ip, ip, r9, lspull #\pull |
| 179 | mov r9, r9, lspush #\push |
| 180 | orr r9, r9, r8, lspull #\pull |
| 181 | mov r8, r8, lspush #\push |
| 182 | orr r8, r8, r7, lspull #\pull |
| 183 | mov r7, r7, lspush #\push |
| 184 | orr r7, r7, r6, lspull #\pull |
| 185 | mov r6, r6, lspush #\push |
| 186 | orr r6, r6, r5, lspull #\pull |
| 187 | mov r5, r5, lspush #\push |
| 188 | orr r5, r5, r4, lspull #\pull |
| 189 | mov r4, r4, lspush #\push |
| 190 | orr r4, r4, r3, lspull #\pull |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 191 | stmdb r0!, {r4 - r9, ip, lr} |
| 192 | bge 12b |
| 193 | PLD( cmn r2, #96 ) |
| 194 | PLD( bge 13b ) |
| 195 | |
| 196 | ldmfd sp!, {r5 - r9} |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 197 | UNWIND( .fnend ) @ end of the second stmfd block |
| 198 | |
| 199 | UNWIND( .fnstart ) |
| 200 | UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 201 | |
| 202 | 14: ands ip, r2, #28 |
| 203 | beq 16f |
| 204 | |
Victor Kamensky | d98b90e | 2014-02-25 08:41:09 +0100 | [diff] [blame] | 205 | 15: mov lr, r3, lspush #\push |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 206 | ldr r3, [r1, #-4]! |
| 207 | subs ip, ip, #4 |
Victor Kamensky | d98b90e | 2014-02-25 08:41:09 +0100 | [diff] [blame] | 208 | orr lr, lr, r3, lspull #\pull |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 209 | str lr, [r0, #-4]! |
| 210 | bgt 15b |
| 211 | CALGN( cmp r2, #0 ) |
| 212 | CALGN( bge 11b ) |
| 213 | |
| 214 | 16: add r1, r1, #(\pull / 8) |
| 215 | b 8b |
Lin Yongting | 207a6cb | 2014-11-26 14:36:15 +0100 | [diff] [blame] | 216 | UNWIND( .fnend ) |
Nicolas Pitre | 7549423 | 2005-11-01 19:52:23 +0000 | [diff] [blame] | 217 | |
| 218 | .endm |
| 219 | |
| 220 | |
| 221 | backward_copy_shift push=8 pull=24 |
| 222 | |
| 223 | 17: backward_copy_shift push=16 pull=16 |
| 224 | |
| 225 | 18: backward_copy_shift push=24 pull=8 |
| 226 | |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 227 | ENDPROC(memmove) |