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 __FBSDID("$FreeBSD$");
47 #include <sys/errno.h>
53 #define GET_PCB(tmp) \
54 mrc p15, 0, tmp, c13, c0, 4; \
55 add tmp, tmp, #(TD_PCB)
58 .word _C_LABEL(__pcpu) + PC_CURPCB
60 #define GET_PCB(tmp) \
70 * Copy string from r0 to r1
73 stmfd sp!, {r4-r5} /* stack is 8 byte aligned */
76 moveq r0, #ENAMETOOLONG
79 1: ldrb r4, [r0], #0x0001
80 add r5, r5, #0x00000001
82 strb r4, [r1], #0x0001
88 movne r0, #ENAMETOOLONG
90 2: teq r3, #0x00000000
93 ldmfd sp!, {r4-r5} /* stack is 8 byte aligned */
97 #define SAVE_REGS stmfd sp!, {r4-r6}
98 #define RESTORE_REGS ldmfd sp!, {r4-r6}
101 * r0 - user space address
102 * r1 - kernel space address
106 * Copy string from user space to kernel space
113 moveq r0, #ENAMETOOLONG
121 beq .Lcopystrpcbfault
124 adr r5, .Lcopystrfault
125 str r5, [r4, #PCB_ONFAULT]
127 1: ldrbt r5, [r0], #0x0001
128 add r6, r6, #0x00000001
130 strb r5, [r1], #0x0001
135 str r0, [r4, #PCB_ONFAULT]
138 moveq r0, #0x00000000
139 movne r0, #ENAMETOOLONG
141 2: teq r3, #0x00000000
149 * r0 - kernel space address
150 * r1 - user space address
154 * Copy string from kernel space to user space
161 moveq r0, #ENAMETOOLONG
169 beq .Lcopystrpcbfault
172 adr r5, .Lcopystrfault
173 str r5, [r4, #PCB_ONFAULT]
175 1: ldrb r5, [r0], #0x0001
176 add r6, r6, #0x00000001
178 strbt r5, [r1], #0x0001
183 str r0, [r4, #PCB_ONFAULT]
186 moveq r0, #0x00000000
187 movne r0, #ENAMETOOLONG
189 2: teq r3, #0x00000000
196 /* A fault occurred during the copy */
199 str r1, [r4, #PCB_ONFAULT]
207 adr r0, Lcopystrpcbfaulttext
208 bic sp, sp, #7 /* align stack to 8 bytes */
211 Lcopystrpcbfaulttext:
212 .asciz "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n"