2 * User Space Access Routines
4 * Copyright (C) 2000-2002 Hewlett-Packard (John Marvin)
5 * Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>
6 * Copyright (C) 2001 Matthieu Delahaye <delahaym at esiee.fr>
7 * Copyright (C) 2003 Randolph Chung <tausq with parisc-linux.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * These routines still have plenty of room for optimization
27 * (word & doubleword load/store, dual issue, store hints, etc.).
31 * The following routines assume that space register 3 (sr3) contains
32 * the space id associated with the current users address space.
38 #include <asm/assembly.h>
39 #include <asm/errno.h>
42 * get_sr gets the appropriate space value into
43 * sr1 for kernel/user space access, depending
44 * on the flag stored in the task structure.
49 ldw TI_SEGMENT(%r1),%r22
58 * lcopy_to_user(void *to, const void *from, unsigned long n)
60 * Returns 0 for success.
61 * otherwise, returns number of bytes not transferred.
64 .export lcopy_to_user,code
69 comib,=,n 0,%r24,$lctu_done
73 addib,<> -1,%r24,$lctu_loop
74 1: stbs,ma %r1,1(%sr1,%r26)
83 .section __ex_table,"a"
95 * lcopy_from_user(void *to, const void *from, unsigned long n)
97 * Returns 0 for success.
98 * otherwise, returns number of bytes not transferred.
100 * NOTE: This routine will also zero any bytes in the
101 * destination that were not copied due to a fault.
105 .export lcopy_from_user,code
110 comib,=,n 0,%r24,$lcfu_done
113 1: ldbs,ma 1(%sr1,%r25),%r1
114 addib,<> -1,%r24,$lcfu_loop
123 addib,<> -1,%r23,$lcfu_zero_loop
128 .section __ex_table,"a"
140 * lcopy_in_user(void *to, const void *from, unsigned long n)
142 * Returns 0 for success.
143 * otherwise, returns number of bytes not transferred.
146 .export lcopy_in_user,code
151 comib,=,n 0,%r24,$lciu_done
154 ldbs,ma 1(%sr1,%r25),%r1
155 addib,<> -1,%r24,$lciu_loop
156 1: stbs,ma %r1,1(%sr1,%r26)
165 .section __ex_table,"a"
176 * long lstrncpy_from_user(char *dst, const char *src, long n)
178 * Returns -EFAULT if exception before terminator,
179 * N if the entire buffer filled,
180 * otherwise strlen (i.e. excludes zero byte)
183 .export lstrncpy_from_user,code
188 comib,= 0,%r24,$lsfu_done
191 1: ldbs,ma 1(%sr1,%r25),%r1
194 comib,=,n 0,%r1,$lsfu_done
195 addib,<>,n -1,%r24,$lsfu_loop
196 2: ldbs,ma 1(%sr1,%r25),%r1
207 .section __ex_table,"a"
220 * unsigned long lclear_user(void *to, unsigned long n)
222 * Returns 0 for success.
223 * otherwise, returns number of bytes not transferred.
226 .export lclear_user,code
231 comib,=,n 0,%r25,$lclu_done
234 addib,<> -1,%r25,$lclu_loop
235 1: stbs,ma %r0,1(%sr1,%r26)
245 .section __ex_table,"a"
256 * long lstrnlen_user(char *s, long n)
258 * Returns 0 if exception before zero byte or reaching N,
259 * N+1 if N would be exceeded,
260 * else strlen + 1 (i.e. includes zero byte).
263 .export lstrnlen_user,code
268 comib,= 0,%r25,$lslen_nzero
271 1: ldbs,ma 1(%sr1,%r26),%r1
273 comib,=,n 0,%r1,$lslen_done
274 addib,<> -1,%r25,$lslen_loop
275 2: ldbs,ma 1(%sr1,%r26),%r1
283 ldo 1(%r26),%r26 /* special case for N == 0 */
286 copy %r24,%r26 /* reset r26 so 0 is returned on fault */
288 .section __ex_table,"a"