diff options
Diffstat (limited to 'firmware/target/arm/memcpy-arm.S')
-rw-r--r-- | firmware/target/arm/memcpy-arm.S | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/firmware/target/arm/memcpy-arm.S b/firmware/target/arm/memcpy-arm.S new file mode 100644 index 0000000000..b8cbff02d7 --- /dev/null +++ b/firmware/target/arm/memcpy-arm.S | |||
@@ -0,0 +1,174 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 Free Software Foundation, Inc. | ||
11 | * This file was originally part of the GNU C Library | ||
12 | * Contributed to glibc by MontaVista Software, Inc. (written by Nicolas Pitre) | ||
13 | * Adapted for Rockbox by Daniel Ankers | ||
14 | * | ||
15 | * All files in this archive are subject to the GNU General Public License. | ||
16 | * See the file COPYING in the source tree root for full license agreement. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | #include "config.h" | ||
24 | |||
25 | /* | ||
26 | * Endian independent macros for shifting bytes within registers. | ||
27 | */ | ||
28 | #ifndef __ARMEB__ | ||
29 | #define pull lsr | ||
30 | #define push lsl | ||
31 | #else | ||
32 | #define pull lsl | ||
33 | #define push lsr | ||
34 | #endif | ||
35 | |||
36 | /* Prototype: void *memcpy(void *dest, const void *src, size_t n); */ | ||
37 | |||
38 | .section .icode,"ax",%progbits | ||
39 | |||
40 | .align 2 | ||
41 | .global memcpy | ||
42 | .type memcpy,%function | ||
43 | |||
44 | memcpy: | ||
45 | stmfd sp!, {r0, r4, lr} | ||
46 | |||
47 | subs r2, r2, #4 | ||
48 | blt 8f | ||
49 | ands ip, r0, #3 | ||
50 | bne 9f | ||
51 | ands ip, r1, #3 | ||
52 | bne 10f | ||
53 | |||
54 | 1: subs r2, r2, #(28) | ||
55 | stmfd sp!, {r5 - r8} | ||
56 | blt 5f | ||
57 | |||
58 | 2: | ||
59 | 3: | ||
60 | 4: ldmia r1!, {r3, r4, r5, r6, r7, r8, ip, lr} | ||
61 | subs r2, r2, #32 | ||
62 | stmia r0!, {r3, r4, r5, r6, r7, r8, ip, lr} | ||
63 | bge 3b | ||
64 | |||
65 | 5: ands ip, r2, #28 | ||
66 | rsb ip, ip, #32 | ||
67 | addne pc, pc, ip @ C is always clear here | ||
68 | b 7f | ||
69 | 6: nop | ||
70 | ldr r3, [r1], #4 | ||
71 | ldr r4, [r1], #4 | ||
72 | ldr r5, [r1], #4 | ||
73 | ldr r6, [r1], #4 | ||
74 | ldr r7, [r1], #4 | ||
75 | ldr r8, [r1], #4 | ||
76 | ldr lr, [r1], #4 | ||
77 | |||
78 | add pc, pc, ip | ||
79 | nop | ||
80 | nop | ||
81 | str r3, [r0], #4 | ||
82 | str r4, [r0], #4 | ||
83 | str r5, [r0], #4 | ||
84 | str r6, [r0], #4 | ||
85 | str r7, [r0], #4 | ||
86 | str r8, [r0], #4 | ||
87 | str lr, [r0], #4 | ||
88 | |||
89 | 7: ldmfd sp!, {r5 - r8} | ||
90 | |||
91 | 8: movs r2, r2, lsl #31 | ||
92 | ldrneb r3, [r1], #1 | ||
93 | ldrcsb r4, [r1], #1 | ||
94 | ldrcsb ip, [r1] | ||
95 | strneb r3, [r0], #1 | ||
96 | strcsb r4, [r0], #1 | ||
97 | strcsb ip, [r0] | ||
98 | |||
99 | ldmfd sp!, {r0, r4, pc} | ||
100 | |||
101 | 9: rsb ip, ip, #4 | ||
102 | cmp ip, #2 | ||
103 | ldrgtb r3, [r1], #1 | ||
104 | ldrgeb r4, [r1], #1 | ||
105 | ldrb lr, [r1], #1 | ||
106 | strgtb r3, [r0], #1 | ||
107 | strgeb r4, [r0], #1 | ||
108 | subs r2, r2, ip | ||
109 | strb lr, [r0], #1 | ||
110 | blt 8b | ||
111 | ands ip, r1, #3 | ||
112 | beq 1b | ||
113 | |||
114 | 10: bic r1, r1, #3 | ||
115 | cmp ip, #2 | ||
116 | ldr lr, [r1], #4 | ||
117 | beq 17f | ||
118 | bgt 18f | ||
119 | |||
120 | |||
121 | .macro forward_copy_shift pull push | ||
122 | |||
123 | subs r2, r2, #28 | ||
124 | blt 14f | ||
125 | |||
126 | 11: stmfd sp!, {r5 - r9} | ||
127 | |||
128 | 12: | ||
129 | 13: ldmia r1!, {r4, r5, r6, r7} | ||
130 | mov r3, lr, pull #\pull | ||
131 | subs r2, r2, #32 | ||
132 | ldmia r1!, {r8, r9, ip, lr} | ||
133 | orr r3, r3, r4, push #\push | ||
134 | mov r4, r4, pull #\pull | ||
135 | orr r4, r4, r5, push #\push | ||
136 | mov r5, r5, pull #\pull | ||
137 | orr r5, r5, r6, push #\push | ||
138 | mov r6, r6, pull #\pull | ||
139 | orr r6, r6, r7, push #\push | ||
140 | mov r7, r7, pull #\pull | ||
141 | orr r7, r7, r8, push #\push | ||
142 | mov r8, r8, pull #\pull | ||
143 | orr r8, r8, r9, push #\push | ||
144 | mov r9, r9, pull #\pull | ||
145 | orr r9, r9, ip, push #\push | ||
146 | mov ip, ip, pull #\pull | ||
147 | orr ip, ip, lr, push #\push | ||
148 | stmia r0!, {r3, r4, r5, r6, r7, r8, r9, ip} | ||
149 | bge 12b | ||
150 | |||
151 | ldmfd sp!, {r5 - r9} | ||
152 | |||
153 | 14: ands ip, r2, #28 | ||
154 | beq 16f | ||
155 | |||
156 | 15: mov r3, lr, pull #\pull | ||
157 | ldr lr, [r1], #4 | ||
158 | subs ip, ip, #4 | ||
159 | orr r3, r3, lr, push #\push | ||
160 | str r3, [r0], #4 | ||
161 | bgt 15b | ||
162 | |||
163 | 16: sub r1, r1, #(\push / 8) | ||
164 | b 8b | ||
165 | |||
166 | .endm | ||
167 | |||
168 | |||
169 | forward_copy_shift pull=8 push=24 | ||
170 | |||
171 | 17: forward_copy_shift pull=16 push=16 | ||
172 | |||
173 | 18: forward_copy_shift pull=24 push=8 | ||
174 | |||