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 <asm/segment.h>
13 #define VERIFY_WRITE 1
15 /* We let the MMU do all checking */
16 #define access_ok(type,addr,size) 1
19 * The exception table consists of pairs of addresses: the first is the
20 * address of an instruction that is allowed to fault, and the second is
21 * the address at which the program should continue. No registers are
22 * modified, so it is entirely up to the continuation code to figure out
25 * All the routines below use bits of fixup code that are out of line
26 * with the main instruction path. This means when everything is well,
27 * we don't even have to jump over them. Further, they do not intrude
28 * on our cache or tlb entries.
31 struct exception_table_entry
33 unsigned long insn, fixup;
36 extern int __put_user_bad(void);
37 extern int __get_user_bad(void);
39 #define __put_user_asm(res, x, ptr, bwl, reg, err) \
41 "1: moves."#bwl" %2,%1\n" \
43 " .section .fixup,\"ax\"\n" \
45 "10: moveq.l %3,%0\n" \
49 " .section __ex_table,\"a\"\n" \
54 : "+d" (res), "=m" (*(ptr)) \
55 : #reg (x), "i" (err))
58 * These are the main single-value transfer routines. They automatically
59 * use the right size if we just have the right pointer type.
62 #define __put_user(x, ptr) \
64 typeof(*(ptr)) __pu_val = (x); \
66 __chk_user_ptr(ptr); \
67 switch (sizeof (*(ptr))) { \
69 __put_user_asm(__pu_err, __pu_val, ptr, b, d, -EFAULT); \
72 __put_user_asm(__pu_err, __pu_val, ptr, w, d, -EFAULT); \
75 __put_user_asm(__pu_err, __pu_val, ptr, l, r, -EFAULT); \
79 const void *__pu_ptr = (ptr); \
81 "1: moves.l %2,(%1)+\n" \
82 "2: moves.l %R2,(%1)\n" \
84 " .section .fixup,\"ax\"\n" \
90 " .section __ex_table,\"a\"\n" \
96 : "+d" (__pu_err), "+a" (__pu_ptr) \
97 : "r" (__pu_val), "i" (-EFAULT) \
102 __pu_err = __put_user_bad(); \
107 #define put_user(x, ptr) __put_user(x, ptr)
110 #define __get_user_asm(res, x, ptr, type, bwl, reg, err) ({ \
113 "1: moves."#bwl" %2,%1\n" \
115 " .section .fixup,\"ax\"\n" \
117 "10: move.l %3,%0\n" \
118 " sub."#bwl" %1,%1\n" \
122 " .section __ex_table,\"a\"\n" \
126 : "+d" (res), "=&" #reg (__gu_val) \
127 : "m" (*(ptr)), "i" (err)); \
128 (x) = (typeof(*(ptr)))(long)__gu_val; \
131 #define __get_user(x, ptr) \
134 __chk_user_ptr(ptr); \
135 switch (sizeof(*(ptr))) { \
137 __get_user_asm(__gu_err, x, ptr, u8, b, d, -EFAULT); \
140 __get_user_asm(__gu_err, x, ptr, u16, w, d, -EFAULT); \
143 __get_user_asm(__gu_err, x, ptr, u32, l, r, -EFAULT); \
145 /* case 8: disabled because gcc-4.1 has a broken typeof \
147 const void *__gu_ptr = (ptr); \
150 "1: moves.l (%2)+,%1\n" \
151 "2: moves.l (%2),%R1\n" \
153 " .section .fixup,\"ax\"\n" \
155 "10: move.l %3,%0\n" \
161 " .section __ex_table,\"a\"\n" \
166 : "+d" (__gu_err), "=&r" (__gu_val), \
170 (x) = (typeof(*(ptr)))__gu_val; \
174 __gu_err = __get_user_bad(); \
179 #define get_user(x, ptr) __get_user(x, ptr)
181 unsigned long __generic_copy_from_user(void *to, const void __user *from, unsigned long n);
182 unsigned long __generic_copy_to_user(void __user *to, const void *from, unsigned long n);
184 static __always_inline unsigned long
185 __constant_copy_from_user(void *to, const void __user *from, unsigned long n)
187 unsigned long res = 0, tmp;
189 /* limit the inlined version to 3 moves */
190 if (n == 11 || n > 12)
191 return __generic_copy_from_user(to, from, n);
195 __get_user_asm(res, *(u8 *)to, (u8 *)from, u8, b, d, 1);
198 __get_user_asm(res, *(u16 *)to, (u16 *)from, u16, w, d, 2);
201 __get_user_asm(res, *(u32 *)to, (u32 *)from, u32, l, r, 4);
206 " .ifndef .Lfrom_user\n"
207 " .set .Lfrom_user,1\n"
208 " .macro copy_from_user to,from,tmp\n"
210 "1: moves.l (\\from)+,\\tmp\n"
211 " move.l \\tmp,(\\to)+\n"
212 " .set .Lcnt,.Lcnt-4\n"
213 " .elseif .Lcnt & 2\n"
214 "1: moves.w (\\from)+,\\tmp\n"
215 " move.w \\tmp,(\\to)+\n"
216 " .set .Lcnt,.Lcnt-2\n"
217 " .elseif .Lcnt & 1\n"
218 "1: moves.b (\\from)+,\\tmp\n"
219 " move.b \\tmp,(\\to)+\n"
220 " .set .Lcnt,.Lcnt-1\n"
225 " .section __ex_table,\"a\"\n"
233 " copy_from_user %1,%2,%3\n"
234 " copy_from_user %1,%2,%3\n"
235 " copy_from_user %1,%2,%3\n"
237 " .section .fixup,\"ax\"\n"
252 : "+r" (res), "+a" (to), "+a" (from), "=&d" (tmp)
259 static __always_inline unsigned long
260 __constant_copy_to_user(void __user *to, const void *from, unsigned long n)
262 unsigned long res = 0, tmp;
264 /* limit the inlined version to 3 moves */
265 if (n == 11 || n > 12)
266 return __generic_copy_to_user(to, from, n);
270 __put_user_asm(res, *(u8 *)from, (u8 *)to, b, d, 1);
273 __put_user_asm(res, *(u16 *)from, (u16 *)to, w, d, 2);
276 __put_user_asm(res, *(u32 *)from, (u32 *)to, l, r, 4);
281 " .ifndef .Lto_user\n"
282 " .set .Lto_user,1\n"
283 " .macro copy_to_user to,from,tmp\n"
285 " move.l (\\from)+,\\tmp\n"
286 "11: moves.l \\tmp,(\\to)+\n"
287 "12: .set .Lcnt,.Lcnt-4\n"
288 " .elseif .Lcnt & 2\n"
289 " move.w (\\from)+,\\tmp\n"
290 "11: moves.w \\tmp,(\\to)+\n"
291 "12: .set .Lcnt,.Lcnt-2\n"
292 " .elseif .Lcnt & 1\n"
293 " move.b (\\from)+,\\tmp\n"
294 "11: moves.b \\tmp,(\\to)+\n"
295 "12: .set .Lcnt,.Lcnt-1\n"
300 " .section __ex_table,\"a\"\n"
309 " copy_to_user %1,%2,%3\n"
310 " copy_to_user %1,%2,%3\n"
311 " copy_to_user %1,%2,%3\n"
313 " .section .fixup,\"ax\"\n"
318 : "+r" (res), "+a" (to), "+a" (from), "=&d" (tmp)
325 #define __copy_from_user(to, from, n) \
326 (__builtin_constant_p(n) ? \
327 __constant_copy_from_user(to, from, n) : \
328 __generic_copy_from_user(to, from, n))
330 #define __copy_to_user(to, from, n) \
331 (__builtin_constant_p(n) ? \
332 __constant_copy_to_user(to, from, n) : \
333 __generic_copy_to_user(to, from, n))
335 #define __copy_to_user_inatomic __copy_to_user
336 #define __copy_from_user_inatomic __copy_from_user
338 #define copy_from_user(to, from, n) __copy_from_user(to, from, n)
339 #define copy_to_user(to, from, n) __copy_to_user(to, from, n)
341 long strncpy_from_user(char *dst, const char __user *src, long count);
342 long strnlen_user(const char __user *src, long n);
343 unsigned long clear_user(void __user *to, unsigned long n);
345 #define strlen_user(str) strnlen_user(str, 32767)
347 #endif /* _M68K_UACCESS_H */