2 * arch/s390/lib/uaccess_std.c
4 * Standard user space access functions based on mvcp/mvcs and doing
5 * interesting things in the secondary space mode.
7 * Copyright (C) IBM Corp. 2006
8 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
9 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
12 #include <linux/errno.h>
14 #include <asm/uaccess.h>
15 #include <asm/futex.h>
31 size_t copy_from_user_std(size_t size, const void __user *ptr, void *x)
33 unsigned long tmp1, tmp2;
37 "0: mvcp 0(%0,%2),0(%1),%3\n"
42 "2: mvcp 0(%0,%2),0(%1),%3\n"
45 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
47 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
49 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
51 "4: mvcp 0(%4,%2),0(%1),%3\n"
56 EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b)
57 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
62 size_t copy_from_user_std_small(size_t size, const void __user *ptr, void *x)
64 unsigned long tmp1, tmp2;
68 "0: mvcp 0(%0,%2),0(%1),%3\n"
71 "1: la %4,255(%1)\n" /* %4 = ptr + 255 */
73 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
75 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
77 "2: mvcp 0(%4,%2),0(%1),%3\n"
80 EX_TABLE(0b,1b) EX_TABLE(2b,3b)
81 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
86 size_t copy_to_user_std(size_t size, void __user *ptr, const void *x)
88 unsigned long tmp1, tmp2;
92 "0: mvcs 0(%0,%1),0(%2),%3\n"
97 "2: mvcs 0(%0,%1),0(%2),%3\n"
100 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
102 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
104 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
106 "4: mvcs 0(%4,%1),0(%2),%3\n"
111 EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b)
112 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
117 size_t copy_to_user_std_small(size_t size, void __user *ptr, const void *x)
119 unsigned long tmp1, tmp2;
123 "0: mvcs 0(%0,%1),0(%2),%3\n"
126 "1: la %4,255(%1)\n" /* ptr + 255 */
128 " nr %4,%3\n" /* (ptr + 255) & -4096UL */
130 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
132 "2: mvcs 0(%4,%1),0(%2),%3\n"
135 EX_TABLE(0b,1b) EX_TABLE(2b,3b)
136 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
141 size_t copy_in_user_std(size_t size, void __user *to, const void __user *from)
151 "1: mvc 0(1,%1),0(%2)\n"
157 "2: mvc 0(256,%1),0(%2)\n"
162 "4: ex %0,1b-0b(%3)\n"
166 EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
167 : "+a" (size), "+a" (to), "+a" (from), "=a" (tmp1)
172 size_t clear_user_std(size_t size, void __user *to)
174 unsigned long tmp1, tmp2;
181 " xc 0(1,%1),0(%1)\n"
183 " la %2,255(%1)\n" /* %2 = ptr + 255 */
185 " sll %2,12\n" /* %2 = (ptr + 255) & -4096 */
187 " "CLR" %0,%2\n" /* clear crosses next page boundary? */
194 "2: xc 0(256,%1),0(%1)\n"
202 EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
203 : "+a" (size), "+a" (to), "=a" (tmp1), "=a" (tmp2)
208 size_t strnlen_user_std(size_t size, const char __user *src)
210 register unsigned long reg0 asm("0") = 0UL;
211 unsigned long tmp1, tmp2;
220 " la %0,1(%3)\n" /* strnlen_user results includes \0 */
224 : "+a" (size), "+a" (src), "=a" (tmp1), "=a" (tmp2)
225 : "d" (reg0) : "cc", "memory");
229 size_t strncpy_from_user_std(size_t size, const char __user *src, char *dst)
231 register unsigned long reg0 asm("0") = 0UL;
232 unsigned long tmp1, tmp2;
242 " jh 1f\n" /* found \0 in string ? */
243 " "AHI" %4,1\n" /* include \0 in copy */
244 "1:"SLR" %0,%1\n" /* %0 = return length (without \0) */
245 " "SLR" %4,%1\n" /* %4 = copy length (including \0) */
246 "2: mvcp 0(%4,%2),0(%1),%5\n"
251 "4: mvcp 0(%4,%2),0(%1),%5\n"
257 EX_TABLE(0b,7b) EX_TABLE(2b,8b) EX_TABLE(4b,8b)
258 : "+a" (size), "+a" (src), "+d" (dst), "=a" (tmp1), "=a" (tmp2)
259 : "d" (reg0), "K" (-EFAULT) : "cc", "memory");
263 #define __futex_atomic_op(insn, ret, oldval, newval, uaddr, oparg) \
268 "2: cs %1,%2,0(%6)\n" \
272 EX_TABLE(0b,4b) EX_TABLE(2b,4b) EX_TABLE(3b,4b) \
273 : "=d" (ret), "=&d" (oldval), "=&d" (newval), \
275 : "0" (-EFAULT), "d" (oparg), "a" (uaddr), \
276 "m" (*uaddr) : "cc");
278 int futex_atomic_op(int op, int __user *uaddr, int oparg, int *old)
280 int oldval = 0, newval, ret;
286 __futex_atomic_op("lr %2,%5\n",
287 ret, oldval, newval, uaddr, oparg);
290 __futex_atomic_op("lr %2,%1\nar %2,%5\n",
291 ret, oldval, newval, uaddr, oparg);
294 __futex_atomic_op("lr %2,%1\nor %2,%5\n",
295 ret, oldval, newval, uaddr, oparg);
298 __futex_atomic_op("lr %2,%1\nnr %2,%5\n",
299 ret, oldval, newval, uaddr, oparg);
302 __futex_atomic_op("lr %2,%1\nxr %2,%5\n",
303 ret, oldval, newval, uaddr, oparg);
313 int futex_atomic_cmpxchg(int __user *uaddr, int oldval, int newval)
323 : "=d" (ret), "+d" (oldval), "=m" (*uaddr)
324 : "0" (-EFAULT), "d" (newval), "a" (uaddr), "m" (*uaddr)
329 struct uaccess_ops uaccess_std = {
330 .copy_from_user = copy_from_user_std,
331 .copy_from_user_small = copy_from_user_std_small,
332 .copy_to_user = copy_to_user_std,
333 .copy_to_user_small = copy_to_user_std_small,
334 .copy_in_user = copy_in_user_std,
335 .clear_user = clear_user_std,
336 .strnlen_user = strnlen_user_std,
337 .strncpy_from_user = strncpy_from_user_std,
338 .futex_atomic_op = futex_atomic_op,
339 .futex_atomic_cmpxchg = futex_atomic_cmpxchg,