This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-m32r / uaccess.h
1 #ifndef _ASM_M32R_UACCESS_H
2 #define _ASM_M32R_UACCESS_H
3
4 /*
5  *  linux/include/asm-m32r/uaccess.h
6  *
7  *  M32R version.
8  *    Copyright (C) 2004  Hirokazu Takata <takata at linux-m32r.org>
9  */
10
11 #undef UACCESS_DEBUG
12
13 #ifdef UACCESS_DEBUG
14 #define UAPRINTK(args...) printk(args)
15 #else
16 #define UAPRINTK(args...)
17 #endif /* UACCESS_DEBUG */
18
19 /*
20  * User space memory access functions
21  */
22 #include <linux/config.h>
23 #include <linux/errno.h>
24 #include <linux/thread_info.h>
25 #include <asm/page.h>
26
27 #define VERIFY_READ 0
28 #define VERIFY_WRITE 1
29
30 /*
31  * The fs value determines whether argument validity checking should be
32  * performed or not.  If get_fs() == USER_DS, checking is performed, with
33  * get_fs() == KERNEL_DS, checking is bypassed.
34  *
35  * For historical reasons, these macros are grossly misnamed.
36  */
37
38 #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
39
40 #ifdef CONFIG_MMU
41 #define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFF)
42 #define USER_DS         MAKE_MM_SEG(PAGE_OFFSET)
43 #else
44 #define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFF)
45 #define USER_DS         MAKE_MM_SEG(0xFFFFFFFF)
46 #endif /* CONFIG_MMU */
47
48 #define get_ds()        (KERNEL_DS)
49 #ifdef CONFIG_MMU
50 #define get_fs()        (current_thread_info()->addr_limit)
51 #define set_fs(x)       (current_thread_info()->addr_limit = (x))
52 #else
53 static inline mm_segment_t get_fs(void)
54 {
55   return USER_DS;
56 }
57
58 static inline void set_fs(mm_segment_t s)
59 {
60 }
61 #endif /* CONFIG_MMU */
62
63 #define segment_eq(a,b) ((a).seg == (b).seg)
64
65 #define __addr_ok(addr) \
66         ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
67
68 /*
69  * Test whether a block of memory is a valid user space address.
70  * Returns 0 if the range is valid, nonzero otherwise.
71  *
72  * This is equivalent to the following test:
73  * (u33)addr + (u33)size >= (u33)current->addr_limit.seg
74  *
75  * This needs 33-bit arithmetic. We have a carry...
76  */
77 #define __range_ok(addr,size) ({                                        \
78         unsigned long flag, sum;                                        \
79         __chk_user_ptr(addr);                                           \
80         asm (                                                           \
81                 "       cmpu    %1, %1    ; clear cbit\n"               \
82                 "       addx    %1, %3    ; set cbit if overflow\n"     \
83                 "       subx    %0, %0\n"                               \
84                 "       cmpu    %4, %1\n"                               \
85                 "       subx    %0, %5\n"                               \
86                 : "=&r"(flag), "=r"(sum)                                \
87                 : "1"(addr), "r"((int)(size)),                          \
88                   "r"(current_thread_info()->addr_limit.seg), "r"(0)    \
89                 : "cbit" );                                             \
90         flag; })
91
92 /**
93  * access_ok: - Checks if a user space pointer is valid
94  * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE.  Note that
95  *        %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
96  *        to write to a block, it is always safe to read from it.
97  * @addr: User space pointer to start of block to check
98  * @size: Size of block to check
99  *
100  * Context: User context only.  This function may sleep.
101  *
102  * Checks if a pointer to a block of memory in user space is valid.
103  *
104  * Returns true (nonzero) if the memory block may be valid, false (zero)
105  * if it is definitely invalid.
106  *
107  * Note that, depending on architecture, this function probably just
108  * checks that the pointer is in the user space range - after calling
109  * this function, memory access functions may still return -EFAULT.
110  */
111 #ifdef CONFIG_MMU
112 #define access_ok(type,addr,size) (likely(__range_ok(addr,size) == 0))
113 #else
114 static inline int access_ok(int type, const void *addr, unsigned long size)
115 {
116   extern unsigned long memory_start, memory_end;
117   unsigned long val = (unsigned long)addr;
118
119   return ((val >= memory_start) && ((val + size) < memory_end));
120 }
121 #endif /* CONFIG_MMU */
122
123 /**
124  * verify_area: - Obsolete, use access_ok()
125  * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE
126  * @addr: User space pointer to start of block to check
127  * @size: Size of block to check
128  *
129  * Context: User context only.  This function may sleep.
130  *
131  * This function has been replaced by access_ok().
132  *
133  * Checks if a pointer to a block of memory in user space is valid.
134  *
135  * Returns zero if the memory block may be valid, -EFAULT
136  * if it is definitely invalid.
137  *
138  * See access_ok() for more details.
139  */
140 static inline int verify_area(int type, const void __user *addr,
141                               unsigned long size)
142 {
143         return access_ok(type, addr, size) ? 0 : -EFAULT;
144 }
145
146
147 /*
148  * The exception table consists of pairs of addresses: the first is the
149  * address of an instruction that is allowed to fault, and the second is
150  * the address at which the program should continue.  No registers are
151  * modified, so it is entirely up to the continuation code to figure out
152  * what to do.
153  *
154  * All the routines below use bits of fixup code that are out of line
155  * with the main instruction path.  This means when everything is well,
156  * we don't even have to jump over them.  Further, they do not intrude
157  * on our cache or tlb entries.
158  */
159
160 struct exception_table_entry
161 {
162         unsigned long insn, fixup;
163 };
164
165 extern int fixup_exception(struct pt_regs *regs);
166
167 /*
168  * These are the main single-value transfer routines.  They automatically
169  * use the right size if we just have the right pointer type.
170  *
171  * This gets kind of ugly. We want to return _two_ values in "get_user()"
172  * and yet we don't want to do any pointers, because that is too much
173  * of a performance impact. Thus we have a few rather ugly macros here,
174  * and hide all the uglyness from the user.
175  *
176  * The "__xxx" versions of the user access functions are versions that
177  * do not verify the address space, that must have been done previously
178  * with a separate "access_ok()" call (this is used when we do multiple
179  * accesses to the same area of user memory).
180  */
181
182 extern void __get_user_1(void);
183 extern void __get_user_2(void);
184 extern void __get_user_4(void);
185
186 #ifndef MODULE
187 #define __get_user_x(size,ret,x,ptr)                                    \
188         __asm__ __volatile__(                                           \
189                 "       mv      r0, %0\n"                               \
190                 "       mv      r1, %1\n"                               \
191                 "       bl __get_user_" #size "\n"                      \
192                 "       mv      %0, r0\n"                               \
193                 "       mv      %1, r1\n"                               \
194                 : "=r"(ret), "=r"(x)                                    \
195                 : "0"(ptr)                                              \
196                 : "r0", "r1", "r14" )
197 #else /* MODULE */
198 /*
199  * Use "jl" instead of "bl" for MODULE
200  */
201 #define __get_user_x(size,ret,x,ptr)                                    \
202         __asm__ __volatile__(                                           \
203                 "       mv      r0, %0\n"                               \
204                 "       mv      r1, %1\n"                               \
205                 "       seth    lr, #high(__get_user_" #size ")\n"      \
206                 "       or3     lr, lr, #low(__get_user_" #size ")\n"   \
207                 "       jl      lr\n"                                   \
208                 "       mv      %0, r0\n"                               \
209                 "       mv      %1, r1\n"                               \
210                 : "=r"(ret), "=r"(x)                                    \
211                 : "0"(ptr)                                              \
212                 : "r0", "r1", "r14" )
213 #endif
214
215 /* Careful: we have to cast the result to the type of the pointer for sign
216    reasons */
217 /**
218  * get_user: - Get a simple variable from user space.
219  * @x:   Variable to store result.
220  * @ptr: Source address, in user space.
221  *
222  * Context: User context only.  This function may sleep.
223  *
224  * This macro copies a single simple variable from user space to kernel
225  * space.  It supports simple types like char and int, but not larger
226  * data types like structures or arrays.
227  *
228  * @ptr must have pointer-to-simple-variable type, and the result of
229  * dereferencing @ptr must be assignable to @x without a cast.
230  *
231  * Returns zero on success, or -EFAULT on error.
232  * On error, the variable @x is set to zero.
233  */
234 #define get_user(x,ptr)                                                 \
235 ({      int __ret_gu,__val_gu;                                          \
236         __chk_user_ptr(ptr);                                            \
237         switch(sizeof (*(ptr))) {                                       \
238         case 1:  __get_user_x(1,__ret_gu,__val_gu,ptr); break;          \
239         case 2:  __get_user_x(2,__ret_gu,__val_gu,ptr); break;          \
240         case 4:  __get_user_x(4,__ret_gu,__val_gu,ptr); break;          \
241         default: __get_user_x(X,__ret_gu,__val_gu,ptr); break;          \
242         }                                                               \
243         (x) = (__typeof__(*(ptr)))__val_gu;                             \
244         __ret_gu;                                                       \
245 })
246
247 extern void __put_user_bad(void);
248
249 /**
250  * put_user: - Write a simple value into user space.
251  * @x:   Value to copy to user space.
252  * @ptr: Destination address, in user space.
253  *
254  * Context: User context only.  This function may sleep.
255  *
256  * This macro copies a single simple value from kernel space to user
257  * space.  It supports simple types like char and int, but not larger
258  * data types like structures or arrays.
259  *
260  * @ptr must have pointer-to-simple-variable type, and @x must be assignable
261  * to the result of dereferencing @ptr.
262  *
263  * Returns zero on success, or -EFAULT on error.
264  */
265 #define put_user(x,ptr)                                                 \
266   __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
267
268
269 /**
270  * __get_user: - Get a simple variable from user space, with less checking.
271  * @x:   Variable to store result.
272  * @ptr: Source address, in user space.
273  *
274  * Context: User context only.  This function may sleep.
275  *
276  * This macro copies a single simple variable from user space to kernel
277  * space.  It supports simple types like char and int, but not larger
278  * data types like structures or arrays.
279  *
280  * @ptr must have pointer-to-simple-variable type, and the result of
281  * dereferencing @ptr must be assignable to @x without a cast.
282  *
283  * Caller must check the pointer with access_ok() before calling this
284  * function.
285  *
286  * Returns zero on success, or -EFAULT on error.
287  * On error, the variable @x is set to zero.
288  */
289 #define __get_user(x,ptr) \
290   __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
291
292
293 /**
294  * __put_user: - Write a simple value into user space, with less checking.
295  * @x:   Value to copy to user space.
296  * @ptr: Destination address, in user space.
297  *
298  * Context: User context only.  This function may sleep.
299  *
300  * This macro copies a single simple value from kernel space to user
301  * space.  It supports simple types like char and int, but not larger
302  * data types like structures or arrays.
303  *
304  * @ptr must have pointer-to-simple-variable type, and @x must be assignable
305  * to the result of dereferencing @ptr.
306  *
307  * Caller must check the pointer with access_ok() before calling this
308  * function.
309  *
310  * Returns zero on success, or -EFAULT on error.
311  */
312 #define __put_user(x,ptr) \
313   __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
314
315 #define __put_user_nocheck(x,ptr,size)                                  \
316 ({                                                                      \
317         long __pu_err;                                                  \
318         __put_user_size((x),(ptr),(size),__pu_err);                     \
319         __pu_err;                                                       \
320 })
321
322
323 #define __put_user_check(x,ptr,size)                                    \
324 ({                                                                      \
325         long __pu_err = -EFAULT;                                        \
326         __typeof__(*(ptr)) __user *__pu_addr = (ptr);                   \
327         might_sleep();                                                  \
328         if (access_ok(VERIFY_WRITE,__pu_addr,size))                     \
329                 __put_user_size((x),__pu_addr,(size),__pu_err);         \
330         __pu_err;                                                       \
331 })
332
333 #if defined(__LITTLE_ENDIAN__)
334 #define __put_user_u64(x, addr, err)                                    \
335         __asm__ __volatile__(                                           \
336                 "       .fillinsn\n"                                    \
337                 "1:     st %L1,@%2\n"                                    \
338                 "       .fillinsn\n"                                    \
339                 "2:     st %H1,@(4,%2)\n"                                \
340                 "       .fillinsn\n"                                    \
341                 "3:\n"                                                  \
342                 ".section .fixup,\"ax\"\n"                              \
343                 "       .balign 4\n"                                    \
344                 "4:     ldi %0,%3\n"                                    \
345                 "       seth r14,#high(3b)\n"                           \
346                 "       or3 r14,r14,#low(3b)\n"                         \
347                 "       jmp r14\n"                                      \
348                 ".previous\n"                                           \
349                 ".section __ex_table,\"a\"\n"                           \
350                 "       .balign 4\n"                                    \
351                 "       .long 1b,4b\n"                                  \
352                 "       .long 2b,4b\n"                                  \
353                 ".previous"                                             \
354                 : "=r"(err)                                             \
355                 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err)             \
356                 : "r14", "memory")
357
358 #elif defined(__BIG_ENDIAN__)
359 #define __put_user_u64(x, addr, err)                                    \
360         __asm__ __volatile__(                                           \
361                 "       .fillinsn\n"                                    \
362                 "1:     st %H1,@%2\n"                                   \
363                 "       .fillinsn\n"                                    \
364                 "2:     st %L1,@(4,%2)\n"                               \
365                 "       .fillinsn\n"                                    \
366                 "3:\n"                                                  \
367                 ".section .fixup,\"ax\"\n"                              \
368                 "       .balign 4\n"                                    \
369                 "4:     ldi %0,%3\n"                                    \
370                 "       seth r14,#high(3b)\n"                           \
371                 "       or3 r14,r14,#low(3b)\n"                         \
372                 "       jmp r14\n"                                      \
373                 ".previous\n"                                           \
374                 ".section __ex_table,\"a\"\n"                           \
375                 "       .balign 4\n"                                    \
376                 "       .long 1b,4b\n"                                  \
377                 "       .long 2b,4b\n"                                  \
378                 ".previous"                                             \
379                 : "=r"(err)                                             \
380                 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err)             \
381                 : "r14", "memory")
382 #else
383 #error no endian defined
384 #endif
385
386 #define __put_user_size(x,ptr,size,retval)                              \
387 do {                                                                    \
388         retval = 0;                                                     \
389         __chk_user_ptr(ptr);                                            \
390         switch (size) {                                                 \
391           case 1: __put_user_asm(x,ptr,retval,"b"); break;              \
392           case 2: __put_user_asm(x,ptr,retval,"h"); break;              \
393           case 4: __put_user_asm(x,ptr,retval,""); break;               \
394           case 8: __put_user_u64((__typeof__(*ptr))(x),ptr,retval); break;\
395           default: __put_user_bad();                                    \
396         }                                                               \
397 } while (0)
398
399 struct __large_struct { unsigned long buf[100]; };
400 #define __m(x) (*(struct __large_struct *)(x))
401
402 /*
403  * Tell gcc we read from memory instead of writing: this is because
404  * we do not write to any memory gcc knows about, so there are no
405  * aliasing issues.
406  */
407 #define __put_user_asm(x, addr, err, itype)                             \
408         __asm__ __volatile__(                                           \
409                 "       .fillinsn\n"                                    \
410                 "1:     st"itype" %1,@%2\n"                             \
411                 "       .fillinsn\n"                                    \
412                 "2:\n"                                                  \
413                 ".section .fixup,\"ax\"\n"                              \
414                 "       .balign 4\n"                                    \
415                 "3:     ldi %0,%3\n"                                    \
416                 "       seth r14,#high(2b)\n"                           \
417                 "       or3 r14,r14,#low(2b)\n"                         \
418                 "       jmp r14\n"                                      \
419                 ".previous\n"                                           \
420                 ".section __ex_table,\"a\"\n"                           \
421                 "       .balign 4\n"                                    \
422                 "       .long 1b,3b\n"                                  \
423                 ".previous"                                             \
424                 : "=r"(err)                                             \
425                 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err)             \
426                 : "r14", "memory")
427
428 #define __get_user_nocheck(x,ptr,size)                                  \
429 ({                                                                      \
430         long __gu_err, __gu_val;                                        \
431         __get_user_size(__gu_val,(ptr),(size),__gu_err);                \
432         (x) = (__typeof__(*(ptr)))__gu_val;                             \
433         __gu_err;                                                       \
434 })
435
436 extern long __get_user_bad(void);
437
438 #define __get_user_size(x,ptr,size,retval)                              \
439 do {                                                                    \
440         retval = 0;                                                     \
441         __chk_user_ptr(ptr);                                            \
442         switch (size) {                                                 \
443           case 1: __get_user_asm(x,ptr,retval,"ub"); break;             \
444           case 2: __get_user_asm(x,ptr,retval,"uh"); break;             \
445           case 4: __get_user_asm(x,ptr,retval,""); break;               \
446           default: (x) = __get_user_bad();                              \
447         }                                                               \
448 } while (0)
449
450 #define __get_user_asm(x, addr, err, itype)                             \
451         __asm__ __volatile__(                                           \
452                 "       .fillinsn\n"                                    \
453                 "1:     ld"itype" %1,@%2\n"                             \
454                 "       .fillinsn\n"                                    \
455                 "2:\n"                                                  \
456                 ".section .fixup,\"ax\"\n"                              \
457                 "       .balign 4\n"                                    \
458                 "3:     ldi %0,%3\n"                                    \
459                 "       seth r14,#high(2b)\n"                           \
460                 "       or3 r14,r14,#low(2b)\n"                         \
461                 "       jmp r14\n"                                      \
462                 ".previous\n"                                           \
463                 ".section __ex_table,\"a\"\n"                           \
464                 "       .balign 4\n"                                    \
465                 "       .long 1b,3b\n"                                  \
466                 ".previous"                                             \
467                 : "=r"(err), "=&r"(x)                                   \
468                 : "r"(addr), "i"(-EFAULT), "0"(err)                     \
469                 : "r14", "memory")
470
471 /*
472  * Here we special-case 1, 2 and 4-byte copy_*_user invocations.  On a fault
473  * we return the initial request size (1, 2 or 4), as copy_*_user should do.
474  * If a store crosses a page boundary and gets a fault, the m32r will not write
475  * anything, so this is accurate.
476  */
477
478
479 /*
480  * Copy To/From Userspace
481  */
482
483 /* Generic arbitrary sized copy.  */
484 /* Return the number of bytes NOT copied.  */
485 #define __copy_user(to,from,size)                                       \
486 do {                                                                    \
487         unsigned long __dst, __src, __c;                                \
488         __asm__ __volatile__ (                                          \
489                 "       mv      r14, %0\n"                              \
490                 "       or      r14, %1\n"                              \
491                 "       beq     %0, %1, 9f\n"                           \
492                 "       beqz    %2, 9f\n"                               \
493                 "       and3    r14, r14, #3\n"                         \
494                 "       bnez    r14, 2f\n"                              \
495                 "       and3    %2, %2, #3\n"                           \
496                 "       beqz    %3, 2f\n"                               \
497                 "       addi    %0, #-4         ; word_copy \n"         \
498                 "       .fillinsn\n"                                    \
499                 "0:     ld      r14, @%1+\n"                            \
500                 "       addi    %3, #-1\n"                              \
501                 "       .fillinsn\n"                                    \
502                 "1:     st      r14, @+%0\n"                            \
503                 "       bnez    %3, 0b\n"                               \
504                 "       beqz    %2, 9f\n"                               \
505                 "       addi    %0, #4\n"                               \
506                 "       .fillinsn\n"                                    \
507                 "2:     ldb     r14, @%1        ; byte_copy \n"         \
508                 "       .fillinsn\n"                                    \
509                 "3:     stb     r14, @%0\n"                             \
510                 "       addi    %1, #1\n"                               \
511                 "       addi    %2, #-1\n"                              \
512                 "       addi    %0, #1\n"                               \
513                 "       bnez    %2, 2b\n"                               \
514                 "       .fillinsn\n"                                    \
515                 "9:\n"                                                  \
516                 ".section .fixup,\"ax\"\n"                              \
517                 "       .balign 4\n"                                    \
518                 "5:     addi    %3, #1\n"                               \
519                 "       addi    %1, #-4\n"                              \
520                 "       .fillinsn\n"                                    \
521                 "6:     slli    %3, #2\n"                               \
522                 "       add     %2, %3\n"                               \
523                 "       addi    %0, #4\n"                               \
524                 "       .fillinsn\n"                                    \
525                 "7:     seth    r14, #high(9b)\n"                       \
526                 "       or3     r14, r14, #low(9b)\n"                   \
527                 "       jmp     r14\n"                                  \
528                 ".previous\n"                                           \
529                 ".section __ex_table,\"a\"\n"                           \
530                 "       .balign 4\n"                                    \
531                 "       .long 0b,6b\n"                                  \
532                 "       .long 1b,5b\n"                                  \
533                 "       .long 2b,9b\n"                                  \
534                 "       .long 3b,9b\n"                                  \
535                 ".previous\n"                                           \
536                 : "=&r"(__dst), "=&r"(__src), "=&r"(size), "=&r"(__c)   \
537                 : "0"(to), "1"(from), "2"(size), "3"(size / 4)          \
538                 : "r14", "memory");                                     \
539 } while (0)
540
541 #define __copy_user_zeroing(to,from,size)                               \
542 do {                                                                    \
543         unsigned long __dst, __src, __c;                                \
544         __asm__ __volatile__ (                                          \
545                 "       mv      r14, %0\n"                              \
546                 "       or      r14, %1\n"                              \
547                 "       beq     %0, %1, 9f\n"                           \
548                 "       beqz    %2, 9f\n"                               \
549                 "       and3    r14, r14, #3\n"                         \
550                 "       bnez    r14, 2f\n"                              \
551                 "       and3    %2, %2, #3\n"                           \
552                 "       beqz    %3, 2f\n"                               \
553                 "       addi    %0, #-4         ; word_copy \n"         \
554                 "       .fillinsn\n"                                    \
555                 "0:     ld      r14, @%1+\n"                            \
556                 "       addi    %3, #-1\n"                              \
557                 "       .fillinsn\n"                                    \
558                 "1:     st      r14, @+%0\n"                            \
559                 "       bnez    %3, 0b\n"                               \
560                 "       beqz    %2, 9f\n"                               \
561                 "       addi    %0, #4\n"                               \
562                 "       .fillinsn\n"                                    \
563                 "2:     ldb     r14, @%1        ; byte_copy \n"         \
564                 "       .fillinsn\n"                                    \
565                 "3:     stb     r14, @%0\n"                             \
566                 "       addi    %1, #1\n"                               \
567                 "       addi    %2, #-1\n"                              \
568                 "       addi    %0, #1\n"                               \
569                 "       bnez    %2, 2b\n"                               \
570                 "       .fillinsn\n"                                    \
571                 "9:\n"                                                  \
572                 ".section .fixup,\"ax\"\n"                              \
573                 "       .balign 4\n"                                    \
574                 "5:     addi    %3, #1\n"                               \
575                 "       addi    %1, #-4\n"                              \
576                 "       .fillinsn\n"                                    \
577                 "6:     slli    %3, #2\n"                               \
578                 "       add     %2, %3\n"                               \
579                 "       addi    %0, #4\n"                               \
580                 "       .fillinsn\n"                                    \
581                 "7:     ldi     r14, #0         ; store zero \n"        \
582                 "       .fillinsn\n"                                    \
583                 "8:     addi    %2, #-1\n"                              \
584                 "       stb     r14, @%0        ; ACE? \n"              \
585                 "       addi    %0, #1\n"                               \
586                 "       bnez    %2, 8b\n"                               \
587                 "       seth    r14, #high(9b)\n"                       \
588                 "       or3     r14, r14, #low(9b)\n"                   \
589                 "       jmp     r14\n"                                  \
590                 ".previous\n"                                           \
591                 ".section __ex_table,\"a\"\n"                           \
592                 "       .balign 4\n"                                    \
593                 "       .long 0b,6b\n"                                  \
594                 "       .long 1b,5b\n"                                  \
595                 "       .long 2b,7b\n"                                  \
596                 "       .long 3b,7b\n"                                  \
597                 ".previous\n"                                           \
598                 : "=&r"(__dst), "=&r"(__src), "=&r"(size), "=&r"(__c)   \
599                 : "0"(to), "1"(from), "2"(size), "3"(size / 4)          \
600                 : "r14", "memory");                                     \
601 } while (0)
602
603
604 /* We let the __ versions of copy_from/to_user inline, because they're often
605  * used in fast paths and have only a small space overhead.
606  */
607 static inline unsigned long __generic_copy_from_user_nocheck(void *to,
608         const void __user *from, unsigned long n)
609 {
610         __copy_user_zeroing(to,from,n);
611         return n;
612 }
613
614 static inline unsigned long __generic_copy_to_user_nocheck(void __user *to,
615         const void *from, unsigned long n)
616 {
617         __copy_user(to,from,n);
618         return n;
619 }
620
621 unsigned long __generic_copy_to_user(void *, const void *, unsigned long);
622 unsigned long __generic_copy_from_user(void *, const void *, unsigned long);
623
624 /**
625  * __copy_to_user: - Copy a block of data into user space, with less checking.
626  * @to:   Destination address, in user space.
627  * @from: Source address, in kernel space.
628  * @n:    Number of bytes to copy.
629  *
630  * Context: User context only.  This function may sleep.
631  *
632  * Copy data from kernel space to user space.  Caller must check
633  * the specified block with access_ok() before calling this function.
634  *
635  * Returns number of bytes that could not be copied.
636  * On success, this will be zero.
637  */
638 #define __copy_to_user(to,from,n)                       \
639         __generic_copy_to_user_nocheck((to),(from),(n))
640
641 #define __copy_to_user_inatomic __copy_to_user
642 #define __copy_from_user_inatomic __copy_from_user
643
644 /**
645  * copy_to_user: - Copy a block of data into user space.
646  * @to:   Destination address, in user space.
647  * @from: Source address, in kernel space.
648  * @n:    Number of bytes to copy.
649  *
650  * Context: User context only.  This function may sleep.
651  *
652  * Copy data from kernel space to user space.
653  *
654  * Returns number of bytes that could not be copied.
655  * On success, this will be zero.
656  */
657 #define copy_to_user(to,from,n)                         \
658 ({                                                      \
659         might_sleep();                                  \
660         __generic_copy_to_user((to),(from),(n));        \
661 })
662
663 /**
664  * __copy_from_user: - Copy a block of data from user space, with less checking. * @to:   Destination address, in kernel space.
665  * @from: Source address, in user space.
666  * @n:    Number of bytes to copy.
667  *
668  * Context: User context only.  This function may sleep.
669  *
670  * Copy data from user space to kernel space.  Caller must check
671  * the specified block with access_ok() before calling this function.
672  *
673  * Returns number of bytes that could not be copied.
674  * On success, this will be zero.
675  *
676  * If some data could not be copied, this function will pad the copied
677  * data to the requested size using zero bytes.
678  */
679 #define __copy_from_user(to,from,n)                     \
680         __generic_copy_from_user_nocheck((to),(from),(n))
681
682 /**
683  * copy_from_user: - Copy a block of data from user space.
684  * @to:   Destination address, in kernel space.
685  * @from: Source address, in user space.
686  * @n:    Number of bytes to copy.
687  *
688  * Context: User context only.  This function may sleep.
689  *
690  * Copy data from user space to kernel space.
691  *
692  * Returns number of bytes that could not be copied.
693  * On success, this will be zero.
694  *
695  * If some data could not be copied, this function will pad the copied
696  * data to the requested size using zero bytes.
697  */
698 #define copy_from_user(to,from,n)                       \
699 ({                                                      \
700         might_sleep();                                  \
701 __generic_copy_from_user((to),(from),(n));      \
702 })
703
704 long __must_check strncpy_from_user(char *dst, const char __user *src,
705                                 long count);
706 long __must_check __strncpy_from_user(char *dst,
707                                 const char __user *src, long count);
708
709 /**
710  * __clear_user: - Zero a block of memory in user space, with less checking.
711  * @to:   Destination address, in user space.
712  * @n:    Number of bytes to zero.
713  *
714  * Zero a block of memory in user space.  Caller must check
715  * the specified block with access_ok() before calling this function.
716  *
717  * Returns number of bytes that could not be cleared.
718  * On success, this will be zero.
719  */
720 unsigned long __clear_user(void __user *mem, unsigned long len);
721
722 /**
723  * clear_user: - Zero a block of memory in user space.
724  * @to:   Destination address, in user space.
725  * @n:    Number of bytes to zero.
726  *
727  * Zero a block of memory in user space.  Caller must check
728  * the specified block with access_ok() before calling this function.
729  *
730  * Returns number of bytes that could not be cleared.
731  * On success, this will be zero.
732  */
733 unsigned long clear_user(void __user *mem, unsigned long len);
734
735 /**
736  * strlen_user: - Get the size of a string in user space.
737  * @str: The string to measure.
738  *
739  * Context: User context only.  This function may sleep.
740  *
741  * Get the size of a NUL-terminated string in user space.
742  *
743  * Returns the size of the string INCLUDING the terminating NUL.
744  * On exception, returns 0.
745  *
746  * If there is a limit on the length of a valid string, you may wish to
747  * consider using strnlen_user() instead.
748  */
749 #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
750 long strnlen_user(const char __user *str, long n);
751
752 #endif /* _ASM_M32R_UACCESS_H */