1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#include <variant/core.h>
57
58#ifdef __XTENSA_EB__
59#define ALIGN(R, W0, W1) src R, W0, W1
60#define SSA8(R) ssa8b R
61#else
62#define ALIGN(R, W0, W1) src R, W1, W0
63#define SSA8(R) ssa8l R
64#endif
65
66
67
68#define EX(insn,reg1,reg2,offset,handler) \
699: insn reg1, reg2, offset; \
70 .section __ex_table, "a"; \
71 .word 9b, handler; \
72 .previous
73
74
75 .text
76 .align 4
77 .global __xtensa_copy_user
78 .type __xtensa_copy_user,@function
79__xtensa_copy_user:
80 entry sp, 16
81
82 mov a5, a2
83 mov a11, a4
84.Lcommon:
85 bbsi.l a2, 0, .Ldst1mod2
86 bbsi.l a2, 1, .Ldst2mod4
87.Ldstaligned:
88 srli a7, a4, 4
89
90 movi a8, 3
91 bnone a3, a8, .Laligned
92 SSA8( a3)
93 bnez a4, .Lsrcunaligned
94 movi a2, 0
95 retw
96
97
98
99
100
101.Ldst1mod2:
102 bltui a4, 7, .Lbytecopy
103
104
105 EX(l8ui, a6, a3, 0, l_fixup)
106 addi a3, a3, 1
107 EX(s8i, a6, a5, 0, s_fixup)
108 addi a5, a5, 1
109 addi a4, a4, -1
110 bbci.l a5, 1, .Ldstaligned
111
112.Ldst2mod4:
113
114 bltui a4, 6, .Lbytecopy
115 EX(l8ui, a6, a3, 0, l_fixup)
116 EX(l8ui, a7, a3, 1, l_fixup)
117 addi a3, a3, 2
118 EX(s8i, a6, a5, 0, s_fixup)
119 EX(s8i, a7, a5, 1, s_fixup)
120 addi a5, a5, 2
121 addi a4, a4, -2
122 j .Ldstaligned
123
124
125
126
127 .align 4
128 .byte 0
129
130.Lbytecopy:
131
132 loopnez a4, .Lbytecopydone
133#else
134 beqz a4, .Lbytecopydone
135 add a7, a3, a4
136#endif
137.Lnextbyte:
138 EX(l8ui, a6, a3, 0, l_fixup)
139 addi a3, a3, 1
140 EX(s8i, a6, a5, 0, s_fixup)
141 addi a5, a5, 1
142
143 blt a3, a7, .Lnextbyte
144#endif
145.Lbytecopydone:
146 movi a2, 0
147 retw
148
149
150
151
152
153 .align 4
154 .byte 0
155.Laligned:
156
157 loopnez a7, .Loop1done
158#else
159 beqz a7, .Loop1done
160 slli a8, a7, 4
161 add a8, a8, a3
162#endif
163.Loop1:
164 EX(l32i, a6, a3, 0, l_fixup)
165 EX(l32i, a7, a3, 4, l_fixup)
166 EX(s32i, a6, a5, 0, s_fixup)
167 EX(l32i, a6, a3, 8, l_fixup)
168 EX(s32i, a7, a5, 4, s_fixup)
169 EX(l32i, a7, a3, 12, l_fixup)
170 EX(s32i, a6, a5, 8, s_fixup)
171 addi a3, a3, 16
172 EX(s32i, a7, a5, 12, s_fixup)
173 addi a5, a5, 16
174
175 blt a3, a8, .Loop1
176#endif
177.Loop1done:
178 bbci.l a4, 3, .L2
179
180 EX(l32i, a6, a3, 0, l_fixup)
181 EX(l32i, a7, a3, 4, l_fixup)
182 addi a3, a3, 8
183 EX(s32i, a6, a5, 0, s_fixup)
184 EX(s32i, a7, a5, 4, s_fixup)
185 addi a5, a5, 8
186.L2:
187 bbci.l a4, 2, .L3
188
189 EX(l32i, a6, a3, 0, l_fixup)
190 addi a3, a3, 4
191 EX(s32i, a6, a5, 0, s_fixup)
192 addi a5, a5, 4
193.L3:
194 bbci.l a4, 1, .L4
195
196 EX(l16ui, a6, a3, 0, l_fixup)
197 addi a3, a3, 2
198 EX(s16i, a6, a5, 0, s_fixup)
199 addi a5, a5, 2
200.L4:
201 bbci.l a4, 0, .L5
202
203 EX(l8ui, a6, a3, 0, l_fixup)
204 EX(s8i, a6, a5, 0, s_fixup)
205.L5:
206 movi a2, 0
207 retw
208
209
210
211
212
213 .align 4
214 .byte 0
215
216.Lsrcunaligned:
217
218 and a10, a3, a8
219 sub a3, a3, a10
220 EX(l32i, a6, a3, 0, l_fixup)
221
222 loopnez a7, .Loop2done
223#else
224 beqz a7, .Loop2done
225 slli a10, a7, 4
226 add a10, a10, a3
227#endif
228.Loop2:
229 EX(l32i, a7, a3, 4, l_fixup)
230 EX(l32i, a8, a3, 8, l_fixup)
231 ALIGN( a6, a6, a7)
232 EX(s32i, a6, a5, 0, s_fixup)
233 EX(l32i, a9, a3, 12, l_fixup)
234 ALIGN( a7, a7, a8)
235 EX(s32i, a7, a5, 4, s_fixup)
236 EX(l32i, a6, a3, 16, l_fixup)
237 ALIGN( a8, a8, a9)
238 EX(s32i, a8, a5, 8, s_fixup)
239 addi a3, a3, 16
240 ALIGN( a9, a9, a6)
241 EX(s32i, a9, a5, 12, s_fixup)
242 addi a5, a5, 16
243
244 blt a3, a10, .Loop2
245#endif
246.Loop2done:
247 bbci.l a4, 3, .L12
248
249 EX(l32i, a7, a3, 4, l_fixup)
250 EX(l32i, a8, a3, 8, l_fixup)
251 ALIGN( a6, a6, a7)
252 EX(s32i, a6, a5, 0, s_fixup)
253 addi a3, a3, 8
254 ALIGN( a7, a7, a8)
255 EX(s32i, a7, a5, 4, s_fixup)
256 addi a5, a5, 8
257 mov a6, a8
258.L12:
259 bbci.l a4, 2, .L13
260
261 EX(l32i, a7, a3, 4, l_fixup)
262 addi a3, a3, 4
263 ALIGN( a6, a6, a7)
264 EX(s32i, a6, a5, 0, s_fixup)
265 addi a5, a5, 4
266 mov a6, a7
267.L13:
268 add a3, a3, a10
269 bbci.l a4, 1, .L14
270
271 EX(l8ui, a6, a3, 0, l_fixup)
272 EX(l8ui, a7, a3, 1, l_fixup)
273 addi a3, a3, 2
274 EX(s8i, a6, a5, 0, s_fixup)
275 EX(s8i, a7, a5, 1, s_fixup)
276 addi a5, a5, 2
277.L14:
278 bbci.l a4, 0, .L15
279
280 EX(l8ui, a6, a3, 0, l_fixup)
281 EX(s8i, a6, a5, 0, s_fixup)
282.L15:
283 movi a2, 0
284 retw
285
286
287 .section .fixup, "ax"
288 .align 4
289
290
291
292
293
294
295
296
297
298
299
300.Lmemset:
301 .word memset
302
303s_fixup:
304 sub a2, a5, a2
305 sub a2, a11, a2
306 retw
307
308l_fixup:
309 sub a2, a5, a2
310 sub a2, a11, a2
311
312
313 mov a6, a5
314 movi a7, 0
315 mov a8, a2
316 l32r a4, .Lmemset
317 callx4 a4
318
319
320 retw
321
322