]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/arm/arm/copystr.S
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / arm / arm / copystr.S
1 /*      $NetBSD: copystr.S,v 1.8 2002/10/13 14:54:48 bjh21 Exp $        */
2
3 /*-
4  * Copyright (c) 1995 Mark Brinicombe.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Mark Brinicombe.
18  * 4. The name of the company nor the name of the author may be used to
19  *    endorse or promote products derived from this software without specific
20  *    prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * copystr.S
35  *
36  * optimised and fault protected copystr functions
37  *
38  * Created      : 16/05/95
39  */
40
41         
42 #include "assym.s"
43 #include <machine/asm.h>
44 #include <machine/armreg.h>
45 #include <machine/asmacros.h>
46 __FBSDID("$FreeBSD$");
47
48 #include <sys/errno.h>
49
50         .text
51         .align  0
52
53 #ifdef _ARM_ARCH_6
54 #define GET_PCB(tmp) \
55         mrc p15, 0, tmp, c13, c0, 4; \
56         add     tmp, tmp, #(PC_CURPCB)
57 #else
58 .Lpcb:
59         .word   _C_LABEL(__pcpu) + PC_CURPCB
60
61 #define GET_PCB(tmp) \
62         ldr     tmp, .Lpcb
63 #endif
64
65 /*
66  * r0 - from
67  * r1 - to
68  * r2 - maxlens
69  * r3 - lencopied
70  *
71  * Copy string from r0 to r1
72  */
73 ENTRY(copystr)
74         stmfd   sp!, {r4-r5}                    /* stack is 8 byte aligned */
75         teq     r2, #0x00000000
76         mov     r5, #0x00000000
77         moveq   r0, #ENAMETOOLONG
78         beq     2f
79
80 1:      ldrb    r4, [r0], #0x0001
81         add     r5, r5, #0x00000001
82         teq     r4, #0x00000000
83         strb    r4, [r1], #0x0001
84         teqne   r5, r2
85         bne     1b
86
87         teq     r4, #0x00000000
88         moveq   r0, #0x00000000
89         movne   r0, #ENAMETOOLONG
90
91 2:      teq     r3, #0x00000000
92         strne   r5, [r3]
93
94         ldmfd   sp!, {r4-r5}                    /* stack is 8 byte aligned */
95         RET
96 END(copystr)
97
98 #define SAVE_REGS       stmfd   sp!, {r4-r6}
99 #define RESTORE_REGS    ldmfd   sp!, {r4-r6}
100
101 /*
102  * r0 - user space address
103  * r1 - kernel space address
104  * r2 - maxlens
105  * r3 - lencopied
106  *
107  * Copy string from user space to kernel space
108  */
109 ENTRY(copyinstr)
110         SAVE_REGS
111
112         teq     r2, #0x00000000
113         mov     r6, #0x00000000
114         moveq   r0, #ENAMETOOLONG
115         beq     2f
116
117         GET_PCB(r4)
118         ldr     r4, [r4]
119
120 #ifdef DIAGNOSTIC
121         teq     r4, #0x00000000
122         beq     .Lcopystrpcbfault
123 #endif
124
125         adr     r5, .Lcopystrfault
126         str     r5, [r4, #PCB_ONFAULT]
127
128 1:      ldrbt   r5, [r0], #0x0001
129         add     r6, r6, #0x00000001
130         teq     r5, #0x00000000
131         strb    r5, [r1], #0x0001
132         teqne   r6, r2
133         bne     1b
134
135         mov     r0, #0x00000000
136         str     r0, [r4, #PCB_ONFAULT]
137
138         teq     r5, #0x00000000
139         moveq   r0, #0x00000000
140         movne   r0, #ENAMETOOLONG
141
142 2:      teq     r3, #0x00000000
143         strne   r6, [r3]
144
145         RESTORE_REGS
146         RET
147 END(copyinstr)
148
149 /*
150  * r0 - kernel space address
151  * r1 - user space address
152  * r2 - maxlens
153  * r3 - lencopied
154  *
155  * Copy string from kernel space to user space
156  */
157 ENTRY(copyoutstr)
158         SAVE_REGS
159
160         teq     r2, #0x00000000
161         mov     r6, #0x00000000
162         moveq   r0, #ENAMETOOLONG
163         beq     2f
164
165         GET_PCB(r4)
166         ldr     r4, [r4]
167
168 #ifdef DIAGNOSTIC
169         teq     r4, #0x00000000
170         beq     .Lcopystrpcbfault
171 #endif
172
173         adr     r5, .Lcopystrfault
174         str     r5, [r4, #PCB_ONFAULT]
175
176 1:      ldrb    r5, [r0], #0x0001
177         add     r6, r6, #0x00000001
178         teq     r5, #0x00000000
179         strbt   r5, [r1], #0x0001
180         teqne   r6, r2
181         bne     1b
182
183         mov     r0, #0x00000000
184         str     r0, [r4, #PCB_ONFAULT]
185
186         teq     r5, #0x00000000
187         moveq   r0, #0x00000000
188         movne   r0, #ENAMETOOLONG
189
190 2:      teq     r3, #0x00000000
191         strne   r6, [r3]
192
193         RESTORE_REGS
194         RET
195 END(copyoutstr)
196
197 /* A fault occurred during the copy */
198 .Lcopystrfault:
199         mov     r1, #0x00000000
200         str     r1, [r4, #PCB_ONFAULT]
201         RESTORE_REGS
202         RET
203
204 #ifdef DIAGNOSTIC
205 .Lcopystrpcbfault:
206         mov     r2, r1
207         mov     r1, r0
208         adr     r0, Lcopystrpcbfaulttext
209         bic     sp, sp, #7                      /* align stack to 8 bytes */
210         b       _C_LABEL(panic)
211
212 Lcopystrpcbfaulttext:
213         .asciz  "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n"
214         .align  0
215 #endif