1 /* $NetBSD: copystr.S,v 1.8 2002/10/13 14:54:48 bjh21 Exp $ */
4 * Copyright (c) 1995 Mark Brinicombe.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
36 * optimised and fault protected copystr functions
43 #include <machine/asm.h>
44 #include <machine/armreg.h>
45 #include <machine/asmacros.h>
46 __FBSDID("$FreeBSD$");
48 #include <sys/errno.h>
54 .word _C_LABEL(cpu_info)
57 .word _C_LABEL(__pcpu) + PC_CURPCB
66 * Copy string from r0 to r1
69 stmfd sp!, {r4-r5} /* stack is 8 byte aligned */
72 moveq r0, #ENAMETOOLONG
75 1: ldrb r4, [r0], #0x0001
76 add r5, r5, #0x00000001
78 strb r4, [r1], #0x0001
84 movne r0, #ENAMETOOLONG
86 2: teq r3, #0x00000000
89 ldmfd sp!, {r4-r5} /* stack is 8 byte aligned */
92 #define SAVE_REGS stmfd sp!, {r4-r6}
93 #define RESTORE_REGS ldmfd sp!, {r4-r6}
96 * r0 - user space address
97 * r1 - kernel space address
101 * Copy string from user space to kernel space
108 moveq r0, #ENAMETOOLONG
111 #ifdef MULTIPROCESSOR
112 /* XXX Probably not appropriate for non-Hydra SMPs */
113 stmfd sp!, {r0-r3, r14}
114 bl _C_LABEL(cpu_number)
116 ldr r4, [r4, r0, lsl #2]
117 ldr r4, [r4, #CI_CURPCB]
118 ldmfd sp!, {r0-r3, r14}
126 beq .Lcopystrpcbfault
129 adr r5, .Lcopystrfault
130 str r5, [r4, #PCB_ONFAULT]
132 1: ldrbt r5, [r0], #0x0001
133 add r6, r6, #0x00000001
135 strb r5, [r1], #0x0001
140 str r0, [r4, #PCB_ONFAULT]
143 moveq r0, #0x00000000
144 movne r0, #ENAMETOOLONG
146 2: teq r3, #0x00000000
153 * r0 - kernel space address
154 * r1 - user space address
158 * Copy string from kernel space to user space
165 moveq r0, #ENAMETOOLONG
168 #ifdef MULTIPROCESSOR
169 /* XXX Probably not appropriate for non-Hydra SMPs */
170 stmfd sp!, {r0-r3, r14}
171 bl _C_LABEL(cpu_number)
173 ldr r4, [r4, r0, lsl #2]
174 ldr r4, [r4, #CI_CURPCB]
175 ldmfd sp!, {r0-r3, r14}
183 beq .Lcopystrpcbfault
186 adr r5, .Lcopystrfault
187 str r5, [r4, #PCB_ONFAULT]
189 1: ldrb r5, [r0], #0x0001
190 add r6, r6, #0x00000001
192 strbt r5, [r1], #0x0001
197 str r0, [r4, #PCB_ONFAULT]
200 moveq r0, #0x00000000
201 movne r0, #ENAMETOOLONG
203 2: teq r3, #0x00000000
209 /* A fault occurred during the copy */
212 str r1, [r4, #PCB_ONFAULT]
220 adr r0, Lcopystrpcbfaulttext
221 bic sp, sp, #7 /* align stack to 8 bytes */
224 Lcopystrpcbfaulttext:
225 .asciz "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n"