blob: b0d88535084613bb58d61f56698220d6ab5ea595 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/assembly.h>
37#include <asm/errno.h>
Helge Deller0b3d6432007-01-28 14:52:57 +010038#include <linux/linkage.h>
Helge Dellerbd3bb8c2008-05-02 22:02:48 +020039#include <linux/init.h>
40
41 __HEAD
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 /*
44 * get_sr gets the appropriate space value into
45 * sr1 for kernel/user space access, depending
46 * on the flag stored in the task structure.
47 */
48
49 .macro get_sr
50 mfctl %cr30,%r1
51 ldw TI_SEGMENT(%r1),%r22
52 mfsp %sr3,%r1
53 or,<> %r22,%r0,%r0
54 copy %r0,%r1
55 mtsp %r1,%sr1
56 .endm
57
58 .macro fixup_branch lbl
59 ldil L%\lbl, %r1
60 ldo R%\lbl(%r1), %r1
61 bv %r0(%r1)
62 .endm
63
64 /*
65 * long lstrncpy_from_user(char *dst, const char *src, long n)
66 *
67 * Returns -EFAULT if exception before terminator,
68 * N if the entire buffer filled,
69 * otherwise strlen (i.e. excludes zero byte)
70 */
71
Helge Deller0b3d6432007-01-28 14:52:57 +010072ENTRY(lstrncpy_from_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .proc
74 .callinfo NO_CALLS
75 .entry
76 comib,= 0,%r24,$lsfu_done
77 copy %r24,%r23
78 get_sr
791: ldbs,ma 1(%sr1,%r25),%r1
80$lsfu_loop:
81 stbs,ma %r1,1(%r26)
82 comib,=,n 0,%r1,$lsfu_done
83 addib,<>,n -1,%r24,$lsfu_loop
842: ldbs,ma 1(%sr1,%r25),%r1
85$lsfu_done:
86 sub %r23,%r24,%r28
87$lsfu_exit:
88 bv %r0(%r2)
89 nop
90 .exit
Helge Deller0b3d6432007-01-28 14:52:57 +010091ENDPROC(lstrncpy_from_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 .section .fixup,"ax"
943: fixup_branch $lsfu_exit
95 ldi -EFAULT,%r28
96 .previous
97
98 .section __ex_table,"aw"
Helge Deller0b3d6432007-01-28 14:52:57 +010099 ASM_ULONG_INSN 1b,3b
100 ASM_ULONG_INSN 2b,3b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 .previous
102
103 .procend
104
105 /*
106 * unsigned long lclear_user(void *to, unsigned long n)
107 *
108 * Returns 0 for success.
109 * otherwise, returns number of bytes not transferred.
110 */
111
Helge Deller0b3d6432007-01-28 14:52:57 +0100112ENTRY(lclear_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .proc
114 .callinfo NO_CALLS
115 .entry
116 comib,=,n 0,%r25,$lclu_done
117 get_sr
118$lclu_loop:
119 addib,<> -1,%r25,$lclu_loop
1201: stbs,ma %r0,1(%sr1,%r26)
121
122$lclu_done:
123 bv %r0(%r2)
124 copy %r25,%r28
125 .exit
Helge Deller0b3d6432007-01-28 14:52:57 +0100126ENDPROC(lclear_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 .section .fixup,"ax"
1292: fixup_branch $lclu_done
130 ldo 1(%r25),%r25
131 .previous
132
133 .section __ex_table,"aw"
Helge Deller0b3d6432007-01-28 14:52:57 +0100134 ASM_ULONG_INSN 1b,2b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 .previous
136
137 .procend
138
139 /*
140 * long lstrnlen_user(char *s, long n)
141 *
142 * Returns 0 if exception before zero byte or reaching N,
143 * N+1 if N would be exceeded,
144 * else strlen + 1 (i.e. includes zero byte).
145 */
146
Helge Deller0b3d6432007-01-28 14:52:57 +0100147ENTRY(lstrnlen_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 .proc
149 .callinfo NO_CALLS
150 .entry
151 comib,= 0,%r25,$lslen_nzero
152 copy %r26,%r24
153 get_sr
1541: ldbs,ma 1(%sr1,%r26),%r1
155$lslen_loop:
156 comib,=,n 0,%r1,$lslen_done
157 addib,<> -1,%r25,$lslen_loop
1582: ldbs,ma 1(%sr1,%r26),%r1
159$lslen_done:
160 bv %r0(%r2)
161 sub %r26,%r24,%r28
162 .exit
163
164$lslen_nzero:
165 b $lslen_done
166 ldo 1(%r26),%r26 /* special case for N == 0 */
Helge Deller0b3d6432007-01-28 14:52:57 +0100167ENDPROC(lstrnlen_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 .section .fixup,"ax"
1703: fixup_branch $lslen_done
171 copy %r24,%r26 /* reset r26 so 0 is returned on fault */
172 .previous
173
174 .section __ex_table,"aw"
Helge Deller0b3d6432007-01-28 14:52:57 +0100175 ASM_ULONG_INSN 1b,3b
176 ASM_ULONG_INSN 2b,3b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 .previous
178
179 .procend
180
181 .end