2 * linux/arch/unicore32/lib/copy_template.S
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
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.
17 * This file provides the core code for a forward memory copy used in
18 * the implementation of memcopy(), copy_to_user() and copy_from_user().
20 * The including file must define the following accessor macros
21 * according to the need of the given function:
25 * This loads one word from 'ptr', stores it in 'reg' and increments
26 * 'ptr' to the next word. The 'abort' argument is used for fixup tables.
28 * ldr4w ptr reg1 reg2 reg3 reg4 abort
29 * ldr8w ptr, reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
31 * This loads four or eight words starting from 'ptr', stores them
32 * in provided registers and increments 'ptr' past those words.
33 * The'abort' argument is used for fixup tables.
35 * ldr1b ptr reg cond abort
37 * Similar to ldr1w, but it loads a byte and increments 'ptr' one byte.
38 * It also must apply the condition code if provided, otherwise the
39 * "al" condition is assumed by default.
42 * str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
43 * str1b ptr reg cond abort
45 * Same as their ldr* counterparts, but data is stored to 'ptr' location
46 * rather than being loaded.
50 * Preserve the provided registers on the stack plus any additional
51 * data as needed by the implementation including this code. Called
56 * Restore registers with the values previously saved with the
57 * 'preserv' macro. Called upon code termination.
70 1: sub.a r2, r2, #(28)
71 stm.w (r5 - r8), [sp-]
75 4: ldr8w r1, r3, r4, r5, r6, r7, r8, r10, r11, abort=20f
77 str8w r0, r3, r4, r5, r6, r7, r8, r10, r11, abort=20f
83 add pc, pc, ip @ C is always clear here
86 ldr1w r1, r3, abort=20f
87 ldr1w r1, r4, abort=20f
88 ldr1w r1, r5, abort=20f
89 ldr1w r1, r6, abort=20f
90 ldr1w r1, r7, abort=20f
91 ldr1w r1, r8, abort=20f
92 ldr1w r1, r11, abort=20f
97 str1w r0, r3, abort=20f
98 str1w r0, r4, abort=20f
99 str1w r0, r5, abort=20f
100 str1w r0, r6, abort=20f
101 str1w r0, r7, abort=20f
102 str1w r0, r8, abort=20f
103 str1w r0, r11, abort=20f
105 7: ldm.w (r5 - r8), [sp]+
107 8: mov.a r2, r2 << #31
108 ldr1b r1, r3, ne, abort=21f
109 ldr1b r1, r4, ea, abort=21f
110 ldr1b r1, r10, ea, abort=21f
111 str1b r0, r3, ne, abort=21f
112 str1b r0, r4, ea, abort=21f
113 str1b r0, r10, ea, abort=21f
119 ldr1b r1, r3, sg, abort=21f
120 ldr1b r1, r4, eg, abort=21f
121 ldr1b r1, r11, abort=21f
122 str1b r0, r3, sg, abort=21f
123 str1b r0, r4, eg, abort=21f
125 str1b r0, r11, abort=21f
132 ldr1w r1, r11, abort=21f
137 .macro forward_copy_shift a b
142 11: stm.w (r5 - r9), [sp-]
145 ldr4w r1, r4, r5, r6, r7, abort=19f
148 ldr4w r1, r8, r9, r10, r11, abort=19f
149 or r3, r3, r4 push #\b
151 or r4, r4, r5 push #\b
153 or r5, r5, r6 push #\b
155 or r6, r6, r7 push #\b
157 or r7, r7, r8 push #\b
159 or r8, r8, r9 push #\b
161 or r9, r9, r10 push #\b
162 mov r10, r10 pull #\a
163 or r10, r10, r11 push #\b
164 str8w r0, r3, r4, r5, r6, r7, r8, r9, r10, , abort=19f
167 ldm.w (r5 - r9), [sp]+
169 14: and.a ip, r2, #28
172 15: mov r3, r11 pull #\a
173 ldr1w r1, r11, abort=21f
175 or r3, r3, r11 push #\b
176 str1w r0, r3, abort=21f
179 16: sub r1, r1, #(\b / 8)
185 forward_copy_shift a=8 b=24
187 17: forward_copy_shift a=16 b=16
189 18: forward_copy_shift a=24 b=8
193 * Abort preamble and completion macros.
194 * If a fixup handler is required then those macros must surround it.
195 * It is assumed that the fixup code will handle the private part of
199 .macro copy_abort_preamble
200 19: ldm.w (r5 - r9), [sp]+
202 299: .word 0 @ store lr
203 @ to avoid function call in fixup
204 20: ldm.w (r5 - r8), [sp]+
210 .macro copy_abort_end