1 #ifndef __M68K_UACCESS_H
2 #define __M68K_UACCESS_H
5 * User space memory access functions
7 #include <linux/compiler.h>
8 #include <linux/errno.h>
9 #include <linux/types.h>
10 #include <linux/sched.h>
11 #include <asm/segment.h>
14 #define VERIFY_WRITE 1
16 /* We let the MMU do all checking */
17 #define access_ok(type,addr,size) 1
20 * The exception table consists of pairs of addresses: the first is the
21 * address of an instruction that is allowed to fault, and the second is
22 * the address at which the program should continue. No registers are
23 * modified, so it is entirely up to the continuation code to figure out
26 * All the routines below use bits of fixup code that are out of line
27 * with the main instruction path. This means when everything is well,
28 * we don't even have to jump over them. Further, they do not intrude
29 * on our cache or tlb entries.
32 struct exception_table_entry
34 unsigned long insn
, fixup
;
37 extern int __put_user_bad(void);
38 extern int __get_user_bad(void);
40 #define __put_user_asm(res, x, ptr, bwl, reg, err) \
42 "1: moves."#bwl" %2,%1\n" \
44 " .section .fixup,\"ax\"\n" \
46 "10: moveq.l %3,%0\n" \
50 " .section __ex_table,\"a\"\n" \
55 : "+d" (res), "=m" (*(ptr)) \
56 : #reg (x), "i" (err))
59 * These are the main single-value transfer routines. They automatically
60 * use the right size if we just have the right pointer type.
63 #define __put_user(x, ptr) \
65 typeof(*(ptr)) __pu_val = (x); \
67 __chk_user_ptr(ptr); \
68 switch (sizeof (*(ptr))) { \
70 __put_user_asm(__pu_err, __pu_val, ptr, b, d, -EFAULT); \
73 __put_user_asm(__pu_err, __pu_val, ptr, w, d, -EFAULT); \
76 __put_user_asm(__pu_err, __pu_val, ptr, l, r, -EFAULT); \
80 const void __user *__pu_ptr = (ptr); \
82 "1: moves.l %2,(%1)+\n" \
83 "2: moves.l %R2,(%1)\n" \
85 " .section .fixup,\"ax\"\n" \
91 " .section __ex_table,\"a\"\n" \
97 : "+d" (__pu_err), "+a" (__pu_ptr) \
98 : "r" (__pu_val), "i" (-EFAULT) \
103 __pu_err = __put_user_bad(); \
108 #define put_user(x, ptr) __put_user(x, ptr)
111 #define __get_user_asm(res, x, ptr, type, bwl, reg, err) ({ \
114 "1: moves."#bwl" %2,%1\n" \
116 " .section .fixup,\"ax\"\n" \
118 "10: move.l %3,%0\n" \
119 " sub."#bwl" %1,%1\n" \
123 " .section __ex_table,\"a\"\n" \
127 : "+d" (res), "=&" #reg (__gu_val) \
128 : "m" (*(ptr)), "i" (err)); \
129 (x) = (typeof(*(ptr)))(unsigned long)__gu_val; \
132 #define __get_user(x, ptr) \
135 __chk_user_ptr(ptr); \
136 switch (sizeof(*(ptr))) { \
138 __get_user_asm(__gu_err, x, ptr, u8, b, d, -EFAULT); \
141 __get_user_asm(__gu_err, x, ptr, u16, w, d, -EFAULT); \
144 __get_user_asm(__gu_err, x, ptr, u32, l, r, -EFAULT); \
146 /* case 8: disabled because gcc-4.1 has a broken typeof \
148 const void *__gu_ptr = (ptr); \
151 "1: moves.l (%2)+,%1\n" \
152 "2: moves.l (%2),%R1\n" \
154 " .section .fixup,\"ax\"\n" \
156 "10: move.l %3,%0\n" \
162 " .section __ex_table,\"a\"\n" \
167 : "+d" (__gu_err), "=&r" (__gu_val), \
171 (x) = (typeof(*(ptr)))__gu_val; \
175 __gu_err = __get_user_bad(); \
180 #define get_user(x, ptr) __get_user(x, ptr)
182 unsigned long __generic_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
183 unsigned long __generic_copy_to_user(void __user
*to
, const void *from
, unsigned long n
);
185 #define __constant_copy_from_user_asm(res, to, from, tmp, n, s1, s2, s3)\
187 "1: moves."#s1" (%2)+,%3\n" \
188 " move."#s1" %3,(%1)+\n" \
189 "2: moves."#s2" (%2)+,%3\n" \
190 " move."#s2" %3,(%1)+\n" \
191 " .ifnc \""#s3"\",\"\"\n" \
192 "3: moves."#s3" (%2)+,%3\n" \
193 " move."#s3" %3,(%1)+\n" \
196 " .section __ex_table,\"a\"\n" \
200 " .ifnc \""#s3"\",\"\"\n" \
205 " .section .fixup,\"ax\"\n" \
207 "10: clr."#s1" (%1)+\n" \
208 "20: clr."#s2" (%1)+\n" \
209 " .ifnc \""#s3"\",\"\"\n" \
210 "30: clr."#s3" (%1)+\n" \
212 " moveq.l #"#n",%0\n" \
215 : "+d" (res), "+&a" (to), "+a" (from), "=&d" (tmp) \
218 static __always_inline
unsigned long
219 __constant_copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
221 unsigned long res
= 0, tmp
;
225 __get_user_asm(res
, *(u8
*)to
, (u8 __user
*)from
, u8
, b
, d
, 1);
228 __get_user_asm(res
, *(u16
*)to
, (u16 __user
*)from
, u16
, w
, d
, 2);
231 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 3, w
, b
,);
234 __get_user_asm(res
, *(u32
*)to
, (u32 __user
*)from
, u32
, l
, r
, 4);
237 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 5, l
, b
,);
240 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 6, l
, w
,);
243 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 7, l
, w
, b
);
246 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 8, l
, l
,);
249 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 9, l
, l
, b
);
252 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 10, l
, l
, w
);
255 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 12, l
, l
, l
);
258 /* we limit the inlined version to 3 moves */
259 return __generic_copy_from_user(to
, from
, n
);
265 #define __constant_copy_to_user_asm(res, to, from, tmp, n, s1, s2, s3) \
267 " move."#s1" (%2)+,%3\n" \
268 "11: moves."#s1" %3,(%1)+\n" \
269 "12: move."#s2" (%2)+,%3\n" \
270 "21: moves."#s2" %3,(%1)+\n" \
272 " .ifnc \""#s3"\",\"\"\n" \
273 " move."#s3" (%2)+,%3\n" \
274 "31: moves."#s3" %3,(%1)+\n" \
279 " .section __ex_table,\"a\"\n" \
285 " .ifnc \""#s3"\",\"\"\n" \
291 " .section .fixup,\"ax\"\n" \
293 "5: moveq.l #"#n",%0\n" \
296 : "+d" (res), "+a" (to), "+a" (from), "=&d" (tmp) \
299 static __always_inline
unsigned long
300 __constant_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
302 unsigned long res
= 0, tmp
;
306 __put_user_asm(res
, *(u8
*)from
, (u8 __user
*)to
, b
, d
, 1);
309 __put_user_asm(res
, *(u16
*)from
, (u16 __user
*)to
, w
, d
, 2);
312 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 3, w
, b
,);
315 __put_user_asm(res
, *(u32
*)from
, (u32 __user
*)to
, l
, r
, 4);
318 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 5, l
, b
,);
321 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 6, l
, w
,);
324 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 7, l
, w
, b
);
327 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 8, l
, l
,);
330 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 9, l
, l
, b
);
333 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 10, l
, l
, w
);
336 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 12, l
, l
, l
);
339 /* limit the inlined version to 3 moves */
340 return __generic_copy_to_user(to
, from
, n
);
346 #define __copy_from_user(to, from, n) \
347 (__builtin_constant_p(n) ? \
348 __constant_copy_from_user(to, from, n) : \
349 __generic_copy_from_user(to, from, n))
351 #define __copy_to_user(to, from, n) \
352 (__builtin_constant_p(n) ? \
353 __constant_copy_to_user(to, from, n) : \
354 __generic_copy_to_user(to, from, n))
356 #define __copy_to_user_inatomic __copy_to_user
357 #define __copy_from_user_inatomic __copy_from_user
359 #define copy_from_user(to, from, n) __copy_from_user(to, from, n)
360 #define copy_to_user(to, from, n) __copy_to_user(to, from, n)
362 long strncpy_from_user(char *dst
, const char __user
*src
, long count
);
363 long strnlen_user(const char __user
*src
, long n
);
364 unsigned long clear_user(void __user
*to
, unsigned long n
);
366 #define strlen_user(str) strnlen_user(str, 32767)
368 #endif /* _M68K_UACCESS_H */