1/*
2 * Copyright (C) 2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2009 PetaLogix
4 * Copyright (C) 2007 LynuxWorks, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License.  See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/errno.h>
12#include <linux/linkage.h>
13
14/*
15 * int __strncpy_user(char *to, char *from, int len);
16 *
17 * Returns:
18 *  -EFAULT  for an exception
19 *  len      if we hit the buffer limit
20 *  bytes copied
21 */
22
23	.text
24.globl __strncpy_user;
25.align 4;
26__strncpy_user:
27
28	/*
29	 * r5 - to
30	 * r6 - from
31	 * r7 - len
32	 * r3 - temp count
33	 * r4 - temp val
34	 */
35	addik	r3,r7,0		/* temp_count = len */
36	beqi	r3,3f
371:
38	lbu	r4,r6,r0
39	sb	r4,r5,r0
40
41	addik	r3,r3,-1
42	beqi	r3,2f		/* break on len */
43
44	addik	r5,r5,1
45	bneid	r4,1b
46	addik	r6,r6,1		/* delay slot */
47	addik	r3,r3,1		/* undo "temp_count--" */
482:
49	rsubk	r3,r3,r7	/* temp_count = len - temp_count */
503:
51	rtsd	r15,8
52	nop
53
54
55	.section	.fixup, "ax"
56	.align	2
574:
58	brid	3b
59	addik	r3,r0, -EFAULT
60
61	.section	__ex_table, "a"
62	.word	1b,4b
63
64/*
65 * int __strnlen_user(char __user *str, int maxlen);
66 *
67 * Returns:
68 *  0 on error
69 *  maxlen + 1  if no NUL byte found within maxlen bytes
70 *  size of the string (including NUL byte)
71 */
72
73	.text
74.globl __strnlen_user;
75.align 4;
76__strnlen_user:
77	addik	r3,r6,0
78	beqi	r3,3f
791:
80	lbu	r4,r5,r0
81	beqid	r4,2f		/* break on NUL */
82	addik	r3,r3,-1	/* delay slot */
83
84	bneid	r3,1b
85	addik	r5,r5,1		/* delay slot */
86
87	addik	r3,r3,-1	/* for break on len */
882:
89	rsubk	r3,r3,r6
903:
91	rtsd	r15,8
92	nop
93
94
95	.section	.fixup,"ax"
964:
97	brid	3b
98	addk	r3,r0,r0
99
100	.section	__ex_table,"a"
101	.word	1b,4b
102
103/*
104 * int __copy_tofrom_user(char *to, char *from, int len)
105 * Return:
106 *   0 on success
107 *   number of not copied bytes on error
108 */
109	.text
110.globl __copy_tofrom_user;
111.align 4;
112__copy_tofrom_user:
113	/*
114	 * r5 - to
115	 * r6 - from
116	 * r7, r3 - count
117	 * r4 - tempval
118	 */
119	addik	r3,r7,0
120	beqi	r3,3f
1211:
122	lbu	r4,r6,r0
123	addik	r6,r6,1
1242:
125	sb	r4,r5,r0
126	addik	r3,r3,-1
127	bneid	r3,1b
128	addik	r5,r5,1		/* delay slot */
1293:
130	rtsd	r15,8
131	nop
132
133
134	.section	__ex_table,"a"
135	.word	1b,3b,2b,3b
136