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#include "assym.inc" 42#include <machine/asm.h> 43#include <machine/armreg.h> 44#include <sys/errno.h> 45 46 .text 47 .align 2 48 49#define GET_PCB(tmp) \ 50 mrc p15, 0, tmp, c13, c0, 4; \ 51 add tmp, tmp, #(TD_PCB) 52 53#define SAVE_REGS stmfd sp!, {r4-r6} 54#define RESTORE_REGS ldmfd sp!, {r4-r6} 55 56/* 57 * r0 - user space address 58 * r1 - kernel space address 59 * r2 - maxlens 60 * r3 - lencopied 61 * 62 * Copy string from user space to kernel space 63 */ 64ENTRY(copyinstr) 65 SAVE_REGS 66 67 teq r2, #0x00000000 68 mov r6, #0x00000000 69 moveq r0, #ENAMETOOLONG 70 beq 2f 71 72 ldr r12, =VM_MAXUSER_ADDRESS 73 74 GET_PCB(r4) 75 ldr r4, [r4] 76 77#ifdef DIAGNOSTIC 78 teq r4, #0x00000000 79 beq .Lcopystrpcbfault 80#endif 81 82 adr r5, .Lcopystrfault 83 str r5, [r4, #PCB_ONFAULT] 84 851: 86 cmp r0, r12 87 bcs .Lcopystrfault 88 ldrbt r5, [r0], #0x0001 89 add r6, r6, #0x00000001 90 teq r5, #0x00000000 91 strb r5, [r1], #0x0001 92 teqne r6, r2 93 bne 1b 94 95 mov r0, #0x00000000 96 str r0, [r4, #PCB_ONFAULT] 97 98 teq r5, #0x00000000 99 moveq r0, #0x00000000 100 movne r0, #ENAMETOOLONG 101 1022: teq r3, #0x00000000 103 strne r6, [r3] 104 105 RESTORE_REGS 106 RET 107END(copyinstr) 108 109/* A fault occurred during the copy */ 110.Lcopystrfault: 111 mov r1, #0x00000000 112 str r1, [r4, #PCB_ONFAULT] 113 mov r0, #EFAULT 114 RESTORE_REGS 115 RET 116 117#ifdef DIAGNOSTIC 118.Lcopystrpcbfault: 119 mov r2, r1 120 mov r1, r0 121 adr r0, Lcopystrpcbfaulttext 122 bic sp, sp, #7 /* align stack to 8 bytes */ 123 b _C_LABEL(panic) 124 125Lcopystrpcbfaulttext: 126 .asciz "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n" 127 .align 2 128#endif 129