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__FBSDID("$FreeBSD$"); 46 47#include <sys/errno.h> 48 49 .text 50 .align 2 51 52#ifdef _ARM_ARCH_6 53#define GET_PCB(tmp) \ 54 mrc p15, 0, tmp, c13, c0, 4; \ 55 add tmp, tmp, #(TD_PCB) 56#else 57.Lpcb: 58 .word _C_LABEL(__pcpu) + PC_CURPCB 59 60#define GET_PCB(tmp) \ 61 ldr tmp, .Lpcb 62#endif 63 64/* 65 * r0 - from 66 * r1 - to 67 * r2 - maxlens 68 * r3 - lencopied 69 * 70 * Copy string from r0 to r1 71 */ 72ENTRY(copystr) 73 stmfd sp!, {r4-r5} /* stack is 8 byte aligned */ 74 teq r2, #0x00000000 75 mov r5, #0x00000000 76 moveq r0, #ENAMETOOLONG 77 beq 2f 78 791: ldrb r4, [r0], #0x0001 80 add r5, r5, #0x00000001 81 teq r4, #0x00000000 82 strb r4, [r1], #0x0001 83 teqne r5, r2 84 bne 1b 85 86 teq r4, #0x00000000 87 moveq r0, #0x00000000 88 movne r0, #ENAMETOOLONG 89 902: teq r3, #0x00000000 91 strne r5, [r3] 92 93 ldmfd sp!, {r4-r5} /* stack is 8 byte aligned */ 94 RET 95END(copystr) 96 97#define SAVE_REGS stmfd sp!, {r4-r6} 98#define RESTORE_REGS ldmfd sp!, {r4-r6} 99 100/* 101 * r0 - user space address 102 * r1 - kernel space address 103 * r2 - maxlens 104 * r3 - lencopied 105 * 106 * Copy string from user space to kernel space 107 */ 108ENTRY(copyinstr) 109 SAVE_REGS 110 111 teq r2, #0x00000000 112 mov r6, #0x00000000 113 moveq r0, #ENAMETOOLONG 114 beq 2f 115 116 GET_PCB(r4) 117 ldr r4, [r4] 118 119#ifdef DIAGNOSTIC 120 teq r4, #0x00000000 121 beq .Lcopystrpcbfault 122#endif 123 124 adr r5, .Lcopystrfault 125 str r5, [r4, #PCB_ONFAULT] 126 1271: ldrbt r5, [r0], #0x0001 128 add r6, r6, #0x00000001 129 teq r5, #0x00000000 130 strb r5, [r1], #0x0001 131 teqne r6, r2 132 bne 1b 133 134 mov r0, #0x00000000 135 str r0, [r4, #PCB_ONFAULT] 136 137 teq r5, #0x00000000 138 moveq r0, #0x00000000 139 movne r0, #ENAMETOOLONG 140 1412: teq r3, #0x00000000 142 strne r6, [r3] 143 144 RESTORE_REGS 145 RET 146END(copyinstr) 147 148/* 149 * r0 - kernel space address 150 * r1 - user space address 151 * r2 - maxlens 152 * r3 - lencopied 153 * 154 * Copy string from kernel space to user space 155 */ 156ENTRY(copyoutstr) 157 SAVE_REGS 158 159 teq r2, #0x00000000 160 mov r6, #0x00000000 161 moveq r0, #ENAMETOOLONG 162 beq 2f 163 164 GET_PCB(r4) 165 ldr r4, [r4] 166 167#ifdef DIAGNOSTIC 168 teq r4, #0x00000000 169 beq .Lcopystrpcbfault 170#endif 171 172 adr r5, .Lcopystrfault 173 str r5, [r4, #PCB_ONFAULT] 174 1751: ldrb r5, [r0], #0x0001 176 add r6, r6, #0x00000001 177 teq r5, #0x00000000 178 strbt r5, [r1], #0x0001 179 teqne r6, r2 180 bne 1b 181 182 mov r0, #0x00000000 183 str r0, [r4, #PCB_ONFAULT] 184 185 teq r5, #0x00000000 186 moveq r0, #0x00000000 187 movne r0, #ENAMETOOLONG 188 1892: teq r3, #0x00000000 190 strne r6, [r3] 191 192 RESTORE_REGS 193 RET 194END(copyoutstr) 195 196/* A fault occurred during the copy */ 197.Lcopystrfault: 198 mov r1, #0x00000000 199 str r1, [r4, #PCB_ONFAULT] 200 RESTORE_REGS 201 RET 202 203#ifdef DIAGNOSTIC 204.Lcopystrpcbfault: 205 mov r2, r1 206 mov r1, r0 207 adr r0, Lcopystrpcbfaulttext 208 bic sp, sp, #7 /* align stack to 8 bytes */ 209 b _C_LABEL(panic) 210 211Lcopystrpcbfaulttext: 212 .asciz "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n" 213 .align 2 214#endif 215