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 #define __constant_copy_from_user_asm(res, to, from, tmp, n, s1, s2, s3)\
186 "1: moves."#s1" (%2)+,%3\n" \
187 " move."#s1" %3,(%1)+\n" \
188 "2: moves."#s2" (%2)+,%3\n" \
189 " move."#s2" %3,(%1)+\n" \
190 " .ifnc \""#s3"\",\"\"\n" \
191 "3: moves."#s3" (%2)+,%3\n" \
192 " move."#s3" %3,(%1)+\n" \
195 " .section __ex_table,\"a\"\n" \
199 " .ifnc \""#s3"\",\"\"\n" \
204 " .section .fixup,\"ax\"\n" \
206 "10: clr."#s1" (%1)+\n" \
207 "20: clr."#s2" (%1)+\n" \
208 " .ifnc \""#s3"\",\"\"\n" \
209 "30: clr."#s3" (%1)+\n" \
211 " moveq.l #"#n",%0\n" \
214 : "+d" (res), "+&a" (to), "+a" (from), "=&d" (tmp) \
217 static __always_inline
unsigned long
218 __constant_copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
220 unsigned long res
= 0, tmp
;
224 __get_user_asm(res
, *(u8
*)to
, (u8
*)from
, u8
, b
, d
, 1);
227 __get_user_asm(res
, *(u16
*)to
, (u16
*)from
, u16
, w
, d
, 2);
230 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 3, w
, b
,);
233 __get_user_asm(res
, *(u32
*)to
, (u32
*)from
, u32
, l
, r
, 4);
236 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 5, l
, b
,);
239 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 6, l
, w
,);
242 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 7, l
, w
, b
);
245 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 8, l
, l
,);
248 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 9, l
, l
, b
);
251 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 10, l
, l
, w
);
254 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 12, l
, l
, l
);
257 /* we limit the inlined version to 3 moves */
258 return __generic_copy_from_user(to
, from
, n
);
264 #define __constant_copy_to_user_asm(res, to, from, tmp, n, s1, s2, s3) \
266 " move."#s1" (%2)+,%3\n" \
267 "11: moves."#s1" %3,(%1)+\n" \
268 "12: move."#s2" (%2)+,%3\n" \
269 "21: moves."#s2" %3,(%1)+\n" \
271 " .ifnc \""#s3"\",\"\"\n" \
272 " move."#s3" (%2)+,%3\n" \
273 "31: moves."#s3" %3,(%1)+\n" \
278 " .section __ex_table,\"a\"\n" \
284 " .ifnc \""#s3"\",\"\"\n" \
290 " .section .fixup,\"ax\"\n" \
292 "5: moveq.l #"#n",%0\n" \
295 : "+d" (res), "+a" (to), "+a" (from), "=&d" (tmp) \
298 static __always_inline
unsigned long
299 __constant_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
301 unsigned long res
= 0, tmp
;
305 __put_user_asm(res
, *(u8
*)from
, (u8
*)to
, b
, d
, 1);
308 __put_user_asm(res
, *(u16
*)from
, (u16
*)to
, w
, d
, 2);
311 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 3, w
, b
,);
314 __put_user_asm(res
, *(u32
*)from
, (u32
*)to
, l
, r
, 4);
317 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 5, l
, b
,);
320 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 6, l
, w
,);
323 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 7, l
, w
, b
);
326 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 8, l
, l
,);
329 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 9, l
, l
, b
);
332 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 10, l
, l
, w
);
335 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 12, l
, l
, l
);
338 /* limit the inlined version to 3 moves */
339 return __generic_copy_to_user(to
, from
, n
);
345 #define __copy_from_user(to, from, n) \
346 (__builtin_constant_p(n) ? \
347 __constant_copy_from_user(to, from, n) : \
348 __generic_copy_from_user(to, from, n))
350 #define __copy_to_user(to, from, n) \
351 (__builtin_constant_p(n) ? \
352 __constant_copy_to_user(to, from, n) : \
353 __generic_copy_to_user(to, from, n))
355 #define __copy_to_user_inatomic __copy_to_user
356 #define __copy_from_user_inatomic __copy_from_user
358 #define copy_from_user(to, from, n) __copy_from_user(to, from, n)
359 #define copy_to_user(to, from, n) __copy_to_user(to, from, n)
361 long strncpy_from_user(char *dst
, const char __user
*src
, long count
);
362 long strnlen_user(const char __user
*src
, long n
);
363 unsigned long clear_user(void __user
*to
, unsigned long n
);
365 #define strlen_user(str) strnlen_user(str, 32767)
367 #endif /* _M68K_UACCESS_H */