blob: 19592dbfaf791c300f623eeee980a99e36db2347 [file] [log] [blame]
Stefan Reinauer52db0b92012-12-07 17:15:04 -08001/*
Martin Roth155c8022019-07-28 19:25:07 -06002 * This file is part of the coreboot project.
Stefan Reinauer52db0b92012-12-07 17:15:04 -08003 *
Martin Roth155c8022019-07-28 19:25:07 -06004 * 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.
Martin Roth4af58862016-01-21 13:15:16 -07007 *
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.
Martin Roth155c8022019-07-28 19:25:07 -060012 *
13 * Based on linux/arch/arm/lib/memcpy.S
Stefan Reinauer52db0b92012-12-07 17:15:04 -080014 */
15
Julius Wernerd65e2142013-12-13 12:59:57 -080016#include <arch/asm.h>
17#include "asmlib.h"
Stefan Reinauer52db0b92012-12-07 17:15:04 -080018
19#define LDR1W_SHIFT 0
20#define STR1W_SHIFT 0
21
22 .macro ldr1w ptr reg abort
23 W(ldr) \reg, [\ptr], #4
24 .endm
25
26 .macro ldr4w ptr reg1 reg2 reg3 reg4 abort
27 ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4}
28 .endm
29
30 .macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
31 ldmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
32 .endm
33
34 .macro ldr1b ptr reg cond=al abort
35 ldr\cond\()b \reg, [\ptr], #1
36 .endm
37
38 .macro str1w ptr reg abort
39 W(str) \reg, [\ptr], #4
40 .endm
41
42 .macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
43 stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
44 .endm
45
46 .macro str1b ptr reg cond=al abort
47 str\cond\()b \reg, [\ptr], #1
48 .endm
49
50 .macro enter reg1 reg2
51 stmdb sp!, {r0, \reg1, \reg2}
52 .endm
53
54 .macro exit reg1 reg2
55 ldmfd sp!, {r0, \reg1, \reg2}
56 .endm
57
Stefan Reinauer52db0b92012-12-07 17:15:04 -080058/* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
59
Julius Wernerd65e2142013-12-13 12:59:57 -080060ENTRY(memcpy)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080061
62 enter r4, lr
63
64 subs r2, r2, #4
65 blt 8f
66 ands ip, r0, #3
67 PLD( pld [r1, #0] )
68 bne 9f
69 ands ip, r1, #3
70 bne 10f
71
721: subs r2, r2, #(28)
73 stmfd sp!, {r5 - r8}
74 blt 5f
75
76 CALGN( ands ip, r0, #31 )
77 CALGN( rsb r3, ip, #32 )
78 CALGN( sbcnes r4, r3, r2 ) @ C is always set here
79 CALGN( bcs 2f )
80 CALGN( adr r4, 6f )
81 CALGN( subs r2, r2, r3 ) @ C gets set
82 CALGN( add pc, r4, ip )
83
84 PLD( pld [r1, #0] )
852: PLD( subs r2, r2, #96 )
86 PLD( pld [r1, #28] )
87 PLD( blt 4f )
88 PLD( pld [r1, #60] )
89 PLD( pld [r1, #92] )
90
913: PLD( pld [r1, #124] )
924: ldr8w r1, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
93 subs r2, r2, #32
94 str8w r0, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
95 bge 3b
96 PLD( cmn r2, #96 )
97 PLD( bge 4b )
98
995: ands ip, r2, #28
100 rsb ip, ip, #32
101#if LDR1W_SHIFT > 0
102 lsl ip, ip, #LDR1W_SHIFT
103#endif
104 addne pc, pc, ip @ C is always clear here
105 b 7f
1066:
107 .rept (1 << LDR1W_SHIFT)
108 W(nop)
109 .endr
110 ldr1w r1, r3, abort=20f
111 ldr1w r1, r4, abort=20f
112 ldr1w r1, r5, abort=20f
113 ldr1w r1, r6, abort=20f
114 ldr1w r1, r7, abort=20f
115 ldr1w r1, r8, abort=20f
116 ldr1w r1, lr, abort=20f
117
118#if LDR1W_SHIFT < STR1W_SHIFT
119 lsl ip, ip, #STR1W_SHIFT - LDR1W_SHIFT
120#elif LDR1W_SHIFT > STR1W_SHIFT
121 lsr ip, ip, #LDR1W_SHIFT - STR1W_SHIFT
122#endif
123 add pc, pc, ip
124 nop
125 .rept (1 << STR1W_SHIFT)
126 W(nop)
127 .endr
128 str1w r0, r3, abort=20f
129 str1w r0, r4, abort=20f
130 str1w r0, r5, abort=20f
131 str1w r0, r6, abort=20f
132 str1w r0, r7, abort=20f
133 str1w r0, r8, abort=20f
134 str1w r0, lr, abort=20f
135
136 CALGN( bcs 2b )
137
1387: ldmfd sp!, {r5 - r8}
139
1408: movs r2, r2, lsl #31
141 ldr1b r1, r3, ne, abort=21f
142 ldr1b r1, r4, cs, abort=21f
143 ldr1b r1, ip, cs, abort=21f
144 str1b r0, r3, ne, abort=21f
145 str1b r0, r4, cs, abort=21f
146 str1b r0, ip, cs, abort=21f
147
148 exit r4, pc
149
1509: rsb ip, ip, #4
151 cmp ip, #2
152 ldr1b r1, r3, gt, abort=21f
153 ldr1b r1, r4, ge, abort=21f
154 ldr1b r1, lr, abort=21f
155 str1b r0, r3, gt, abort=21f
156 str1b r0, r4, ge, abort=21f
157 subs r2, r2, ip
158 str1b r0, lr, abort=21f
159 blt 8b
160 ands ip, r1, #3
161 beq 1b
162
16310: bic r1, r1, #3
164 cmp ip, #2
165 ldr1w r1, lr, abort=21f
166 beq 17f
167 bgt 18f
168
169
170 .macro forward_copy_shift pull push
171
172 subs r2, r2, #28
173 blt 14f
174
175 CALGN( ands ip, r0, #31 )
176 CALGN( rsb ip, ip, #32 )
177 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
178 CALGN( subcc r2, r2, ip )
179 CALGN( bcc 15f )
180
18111: stmfd sp!, {r5 - r9}
182
183 PLD( pld [r1, #0] )
184 PLD( subs r2, r2, #96 )
185 PLD( pld [r1, #28] )
186 PLD( blt 13f )
187 PLD( pld [r1, #60] )
188 PLD( pld [r1, #92] )
189
19012: PLD( pld [r1, #124] )
19113: ldr4w r1, r4, r5, r6, r7, abort=19f
192 mov r3, lr, pull #\pull
193 subs r2, r2, #32
194 ldr4w r1, r8, r9, ip, lr, abort=19f
195 orr r3, r3, r4, push #\push
196 mov r4, r4, pull #\pull
197 orr r4, r4, r5, push #\push
198 mov r5, r5, pull #\pull
199 orr r5, r5, r6, push #\push
200 mov r6, r6, pull #\pull
201 orr r6, r6, r7, push #\push
202 mov r7, r7, pull #\pull
203 orr r7, r7, r8, push #\push
204 mov r8, r8, pull #\pull
205 orr r8, r8, r9, push #\push
206 mov r9, r9, pull #\pull
207 orr r9, r9, ip, push #\push
208 mov ip, ip, pull #\pull
209 orr ip, ip, lr, push #\push
210 str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
211 bge 12b
212 PLD( cmn r2, #96 )
213 PLD( bge 13b )
214
215 ldmfd sp!, {r5 - r9}
216
21714: ands ip, r2, #28
218 beq 16f
219
22015: mov r3, lr, pull #\pull
221 ldr1w r1, lr, abort=21f
222 subs ip, ip, #4
223 orr r3, r3, lr, push #\push
224 str1w r0, r3, abort=21f
225 bgt 15b
226 CALGN( cmp r2, #0 )
227 CALGN( bge 11b )
228
22916: sub r1, r1, #(\push / 8)
230 b 8b
231
232 .endm
233
234
235 forward_copy_shift pull=8 push=24
236
23717: forward_copy_shift pull=16 push=16
238
23918: forward_copy_shift pull=24 push=8
Julius Wernerd65e2142013-12-13 12:59:57 -0800240ENDPROC(memcpy)