1/* $NetBSD: copystr.S,v 1.12 2018/01/24 09:04:44 skrll 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#include "opt_multiprocessor.h" 42#include "opt_cpuoptions.h" 43 44#include "assym.h" 45 46#include <machine/asm.h> 47 48#include <arm/locore.h> 49 50RCSID("$NetBSD: copystr.S,v 1.12 2018/01/24 09:04:44 skrll Exp $") 51 52#include <sys/errno.h> 53 54 .text 55 .align 0 56/* 57 * r0 - from 58 * r1 - to 59 * r2 - maxlens 60 * r3 - lencopied 61 * 62 * Copy string from r0 to r1 63 */ 64ENTRY(copystr) 65 push {r4-r5} /* stack is 8 byte aligned */ 66 teq r2, #0x00000000 67 mov r5, #0x00000000 68 moveq r0, #ENAMETOOLONG 69 beq 2f 70 711: ldrb r4, [r0], #0x0001 72 add r5, r5, #0x00000001 73 teq r4, #0x00000000 74 strb r4, [r1], #0x0001 75 teqne r5, r2 76 bne 1b 77 78 teq r4, #0x00000000 79 moveq r0, #0x00000000 80 movne r0, #ENAMETOOLONG 81 822: teq r3, #0x00000000 83 strne r5, [r3] 84 85 pop {r4-r5} /* stack is 8 byte aligned */ 86 RET 87END(copystr) 88 89#define SAVE_REGS push {r3-r6} 90#define RESTORE_REGS pop {r3-r6} 91 92/* 93 * r0 - user space address 94 * r1 - kernel space address 95 * r2 - maxlens 96 * r3 - lencopied 97 * 98 * Copy string from user space to kernel space 99 */ 100ENTRY(copyinstr) 101 SAVE_REGS 102 103 teq r2, #0x00000000 104 mov r6, #0x00000000 105 moveq r0, #ENAMETOOLONG 106 beq 2f 107 108 GET_CURPCB(r4) 109 110#ifdef DIAGNOSTIC 111 teq r4, #0x00000000 112 beq .Lcopystrpcbfault 113#endif 114 115 adr r5, .Lcopystrfault 116 str r5, [r4, #PCB_ONFAULT] 117 1181: ldrbt r5, [r0], #0x0001 119 add r6, r6, #0x00000001 120 teq r5, #0x00000000 121 strb r5, [r1], #0x0001 122 teqne r6, r2 123 bne 1b 124 125 mov r0, #0x00000000 126 str r0, [r4, #PCB_ONFAULT] 127 128 teq r5, #0x00000000 129 moveq r0, #0x00000000 130 movne r0, #ENAMETOOLONG 131 1322: teq r3, #0x00000000 133 strne r6, [r3] 134 135 RESTORE_REGS 136 RET 137END(copyinstr) 138 139/* 140 * r0 - kernel space address 141 * r1 - user space address 142 * r2 - maxlens 143 * r3 - lencopied 144 * 145 * Copy string from kernel space to user space 146 */ 147ENTRY(copyoutstr) 148 SAVE_REGS 149 150 teq r2, #0x00000000 151 mov r6, #0x00000000 152 moveq r0, #ENAMETOOLONG 153 beq 2f 154 155 GET_CURPCB(r4) 156 157#ifdef DIAGNOSTIC 158 teq r4, #0x00000000 159 beq .Lcopystrpcbfault 160#endif 161 162 adr r5, .Lcopystrfault 163 str r5, [r4, #PCB_ONFAULT] 164 1651: ldrb r5, [r0], #0x0001 166 add r6, r6, #0x00000001 167 teq r5, #0x00000000 168 strbt r5, [r1], #0x0001 169 teqne r6, r2 170 bne 1b 171 172 mov r0, #0x00000000 173 str r0, [r4, #PCB_ONFAULT] 174 175 teq r5, #0x00000000 176 moveq r0, #0x00000000 177 movne r0, #ENAMETOOLONG 178 1792: teq r3, #0x00000000 180 strne r6, [r3] 181 182 RESTORE_REGS 183 RET 184 185/* A fault occurred during the copy */ 186.Lcopystrfault: 187 mov r1, #0x00000000 188 str r1, [r4, #PCB_ONFAULT] 189 RESTORE_REGS 190 RET 191 192#ifdef DIAGNOSTIC 193.Lcopystrpcbfault: 194 mov r2, r1 195 mov r1, r0 196 adr r0, .Lcopystrpcbfaulttext 197 bic sp, sp, #7 /* align stack to 8 bytes */ 198 b _C_LABEL(panic) 199 200.Lcopystrpcbfaulttext: 201 .asciz "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n" 202 .align 0 203#endif 204END(copyoutstr) 205