1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/unicore32/lib/copy_template.S
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 GUAN Xue-tao
14 * This file provides the core code for a forward memory copy used in
15 * the implementation of memcopy(), copy_to_user() and copy_from_user().
17 * The including file must define the following accessor macros
18 * according to the need of the given function:
22 * This loads one word from 'ptr', stores it in 'reg' and increments
23 * 'ptr' to the next word. The 'abort' argument is used for fixup tables.
25 * ldr4w ptr reg1 reg2 reg3 reg4 abort
26 * ldr8w ptr, reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
28 * This loads four or eight words starting from 'ptr', stores them
29 * in provided registers and increments 'ptr' past those words.
30 * The'abort' argument is used for fixup tables.
32 * ldr1b ptr reg cond abort
34 * Similar to ldr1w, but it loads a byte and increments 'ptr' one byte.
35 * It also must apply the condition code if provided, otherwise the
36 * "al" condition is assumed by default.
39 * str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
40 * str1b ptr reg cond abort
42 * Same as their ldr* counterparts, but data is stored to 'ptr' location
43 * rather than being loaded.
47 * Preserve the provided registers on the stack plus any additional
48 * data as needed by the implementation including this code. Called
53 * Restore registers with the values previously saved with the
54 * 'preserv' macro. Called upon code termination.
67 1: sub.a r2, r2, #(28)
68 stm.w (r5 - r8), [sp-]
72 4: ldr8w r1, r3, r4, r5, r6, r7, r8, r10, r11, abort=20f
74 str8w r0, r3, r4, r5, r6, r7, r8, r10, r11, abort=20f
80 add pc, pc, ip @ C is always clear here
83 ldr1w r1, r3, abort=20f
84 ldr1w r1, r4, abort=20f
85 ldr1w r1, r5, abort=20f
86 ldr1w r1, r6, abort=20f
87 ldr1w r1, r7, abort=20f
88 ldr1w r1, r8, abort=20f
89 ldr1w r1, r11, abort=20f
94 str1w r0, r3, abort=20f
95 str1w r0, r4, abort=20f
96 str1w r0, r5, abort=20f
97 str1w r0, r6, abort=20f
98 str1w r0, r7, abort=20f
99 str1w r0, r8, abort=20f
100 str1w r0, r11, abort=20f
102 7: ldm.w (r5 - r8), [sp]+
104 8: mov.a r2, r2 << #31
105 ldr1b r1, r3, ne, abort=21f
106 ldr1b r1, r4, ea, abort=21f
107 ldr1b r1, r10, ea, abort=21f
108 str1b r0, r3, ne, abort=21f
109 str1b r0, r4, ea, abort=21f
110 str1b r0, r10, ea, abort=21f
116 ldr1b r1, r3, sg, abort=21f
117 ldr1b r1, r4, eg, abort=21f
118 ldr1b r1, r11, abort=21f
119 str1b r0, r3, sg, abort=21f
120 str1b r0, r4, eg, abort=21f
122 str1b r0, r11, abort=21f
129 ldr1w r1, r11, abort=21f
134 .macro forward_copy_shift a b
139 11: stm.w (r5 - r9), [sp-]
142 ldr4w r1, r4, r5, r6, r7, abort=19f
145 ldr4w r1, r8, r9, r10, r11, abort=19f
146 or r3, r3, r4 push #\b
148 or r4, r4, r5 push #\b
150 or r5, r5, r6 push #\b
152 or r6, r6, r7 push #\b
154 or r7, r7, r8 push #\b
156 or r8, r8, r9 push #\b
158 or r9, r9, r10 push #\b
159 mov r10, r10 pull #\a
160 or r10, r10, r11 push #\b
161 str8w r0, r3, r4, r5, r6, r7, r8, r9, r10, , abort=19f
164 ldm.w (r5 - r9), [sp]+
166 14: and.a ip, r2, #28
169 15: mov r3, r11 pull #\a
170 ldr1w r1, r11, abort=21f
172 or r3, r3, r11 push #\b
173 str1w r0, r3, abort=21f
176 16: sub r1, r1, #(\b / 8)
182 forward_copy_shift a=8 b=24
184 17: forward_copy_shift a=16 b=16
186 18: forward_copy_shift a=24 b=8
190 * Abort preamble and completion macros.
191 * If a fixup handler is required then those macros must surround it.
192 * It is assumed that the fixup code will handle the private part of
196 .macro copy_abort_preamble
197 19: ldm.w (r5 - r9), [sp]+
199 299: .word 0 @ store lr
200 @ to avoid function call in fixup
201 20: ldm.w (r5 - r8), [sp]+
207 .macro copy_abort_end