ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / parisc / lib / lusercopy.S
1 /*
2  *    User Space Access Routines
3  *
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>
8  *
9  *
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)
13  *    any later version.
14  *
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.
19  *
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
23  */
24
25 /*
26  * These routines still have plenty of room for optimization
27  * (word & doubleword load/store, dual issue, store hints, etc.).
28  */
29
30 /*
31  * The following routines assume that space register 3 (sr3) contains
32  * the space id associated with the current users address space.
33  */
34
35
36         .text
37         
38 #include <asm/assembly.h>
39 #include <asm/errno.h>
40
41         /*
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.
45          */
46
47         .macro  get_sr
48         mfctl       %cr30,%r1
49         ldw         TI_SEGMENT(%r1),%r22
50         mfsp        %sr3,%r1
51         or,<>       %r22,%r0,%r0
52         copy        %r0,%r1
53         mtsp        %r1,%sr1
54         .endm
55
56         /*
57          * unsigned long
58          * lcopy_to_user(void *to, const void *from, unsigned long n)
59          *
60          * Returns 0 for success.
61          * otherwise, returns number of bytes not transferred.
62          */
63
64         .export lcopy_to_user,code
65 lcopy_to_user:
66         .proc
67         .callinfo NO_CALLS
68         .entry
69         comib,=,n   0,%r24,$lctu_done
70         get_sr
71 $lctu_loop:
72         ldbs,ma     1(%r25),%r1
73         addib,<>    -1,%r24,$lctu_loop
74 1:      stbs,ma     %r1,1(%sr1,%r26)
75 $lctu_done:
76         bv          %r0(%r2)
77         copy        %r24,%r28
78         .exit
79
80 2:      b $lctu_done
81         ldo         1(%r24),%r24
82
83         .section __ex_table,"a"
84 #ifdef __LP64__
85         .dword      1b,(2b-1b)
86 #else
87         .word       1b,(2b-1b)
88 #endif
89         .previous
90
91         .procend
92
93         /*
94          * unsigned long
95          * lcopy_from_user(void *to, const void *from, unsigned long n)
96          *
97          * Returns 0 for success.
98          * otherwise, returns number of bytes not transferred.
99          *
100          * NOTE: This routine will also zero any bytes in the
101          *       destination that were not copied due to a fault.
102          *
103          */
104
105         .export lcopy_from_user,code
106 lcopy_from_user:
107         .proc
108         .callinfo NO_CALLS
109         .entry
110         comib,=,n   0,%r24,$lcfu_done
111         get_sr
112 $lcfu_loop:
113 1:      ldbs,ma     1(%sr1,%r25),%r1
114         addib,<>    -1,%r24,$lcfu_loop
115         stbs,ma     %r1,1(%r26)
116 $lcfu_done:
117         bv          %r0(%r2)
118         copy        %r24,%r28
119         .exit
120
121 2:      copy        %r24,%r23
122 $lcfu_zero_loop:
123         addib,<>    -1,%r23,$lcfu_zero_loop
124         stbs,ma     %r0,1(%r26)
125         b           $lcfu_done
126         nop
127
128         .section __ex_table,"a"
129 #ifdef __LP64__
130         .dword      1b,(2b-1b)
131 #else
132         .word       1b,(2b-1b)
133 #endif
134         .previous
135
136         .procend
137
138         /*
139          * unsigned long
140          * lcopy_in_user(void *to, const void *from, unsigned long n)
141          *
142          * Returns 0 for success.
143          * otherwise, returns number of bytes not transferred.
144          */
145
146         .export lcopy_in_user,code
147 lcopy_in_user:
148         .proc
149         .callinfo NO_CALLS
150         .entry
151         comib,=,n   0,%r24,$lciu_done
152         get_sr
153 $lciu_loop:
154         ldbs,ma     1(%sr1,%r25),%r1
155         addib,<>    -1,%r24,$lciu_loop
156 1:      stbs,ma     %r1,1(%sr1,%r26)
157 $lciu_done:
158         bv          %r0(%r2)
159         copy        %r24,%r28
160         .exit
161
162 2:      b $lciu_done
163         ldo         1(%r24),%r24
164
165         .section __ex_table,"a"
166 #ifdef __LP64__
167         .dword      1b,(2b-1b)
168 #else
169         .word       1b,(2b-1b)
170 #endif
171         .previous
172
173         .procend
174
175         /*
176          * long lstrncpy_from_user(char *dst, const char *src, long n)
177          *
178          * Returns -EFAULT if exception before terminator,
179          *         N if the entire buffer filled,
180          *         otherwise strlen (i.e. excludes zero byte)
181          */
182
183         .export lstrncpy_from_user,code
184 lstrncpy_from_user:
185         .proc
186         .callinfo NO_CALLS
187         .entry
188         comib,=     0,%r24,$lsfu_done
189         copy        %r24,%r23
190         get_sr
191 1:      ldbs,ma     1(%sr1,%r25),%r1
192 $lsfu_loop:
193         stbs,ma     %r1,1(%r26)
194         comib,=,n   0,%r1,$lsfu_done
195         addib,<>,n  -1,%r24,$lsfu_loop
196 2:      ldbs,ma     1(%sr1,%r25),%r1
197 $lsfu_done:
198         sub         %r23,%r24,%r28
199 $lsfu_exit:
200         bv          %r0(%r2)
201         nop
202         .exit
203
204 3:      b           $lsfu_exit
205         ldi         -EFAULT,%r28
206
207         .section __ex_table,"a"
208 #ifdef __LP64__
209         .dword      1b,(3b-1b)
210         .dword      2b,(3b-2b)
211 #else
212         .word       1b,(3b-1b)
213         .word       2b,(3b-2b)
214 #endif
215         .previous
216
217         .procend
218
219         /*
220          * unsigned long lclear_user(void *to, unsigned long n)
221          *
222          * Returns 0 for success.
223          * otherwise, returns number of bytes not transferred.
224          */
225
226         .export lclear_user,code
227 lclear_user:
228         .proc
229         .callinfo NO_CALLS
230         .entry
231         comib,=,n   0,%r25,$lclu_done
232         get_sr
233 $lclu_loop:
234         addib,<>    -1,%r25,$lclu_loop
235 1:      stbs,ma     %r0,1(%sr1,%r26)
236
237 $lclu_done:
238         bv          %r0(%r2)
239         copy        %r25,%r28
240         .exit
241
242 2:      b $lclu_done
243         ldo        1(%r25),%r25
244
245         .section __ex_table,"a"
246 #ifdef __LP64__
247         .dword      1b,(2b-1b)
248 #else
249         .word       1b,(2b-1b)
250 #endif
251         .previous
252
253         .procend
254
255         /*
256          * long lstrnlen_user(char *s, long n)
257          *
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).
261          */
262
263         .export lstrnlen_user,code
264 lstrnlen_user:
265         .proc
266         .callinfo NO_CALLS
267         .entry
268         comib,=     0,%r25,$lslen_nzero
269         copy        %r26,%r24
270         get_sr
271 1:      ldbs,ma     1(%sr1,%r26),%r1
272 $lslen_loop:
273         comib,=,n   0,%r1,$lslen_done
274         addib,<>    -1,%r25,$lslen_loop
275 2:      ldbs,ma     1(%sr1,%r26),%r1
276 $lslen_done:
277         bv          %r0(%r2)
278         sub         %r26,%r24,%r28
279         .exit
280
281 $lslen_nzero:
282         b           $lslen_done
283         ldo         1(%r26),%r26 /* special case for N == 0 */
284
285 3:      b           $lslen_done
286         copy        %r24,%r26    /* reset r26 so 0 is returned on fault */
287
288         .section __ex_table,"a"
289 #ifdef __LP64__
290         .dword      1b,(3b-1b)
291         .dword      2b,(3b-2b)
292 #else
293         .word       1b,(3b-1b)
294         .word       2b,(3b-2b)
295 #endif
296         .previous
297
298         .procend
299
300         .end