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