2 * Authors: Bjorn Wesen (bjornw@axis.com)
3 * Hans-Peter Nilsson (hp@axis.com)
6 #ifndef _CRIS_ARCH_UACCESS_H
7 #define _CRIS_ARCH_UACCESS_H
10 * We don't tell gcc that we are accessing memory, but this is OK
11 * because we do not write to any memory gcc knows about, so there
12 * are no aliasing issues.
14 * Note that PC at a fault is the address *after* the faulting
17 #define __put_user_asm(x, addr, err, op) \
18 __asm__ __volatile__( \
21 " .section .fixup,\"ax\"\n" \
25 " .section __ex_table,\"a\"\n" \
29 : "r" (x), "r" (addr), "g" (-EFAULT), "0" (err))
31 #define __put_user_asm_64(x, addr, err) \
32 __asm__ __volatile__( \
33 " move.d %M1,[%2]\n" \
34 "2: move.d %H1,[%2+4]\n" \
36 " .section .fixup,\"ax\"\n" \
40 " .section __ex_table,\"a\"\n" \
45 : "r" (x), "r" (addr), "g" (-EFAULT), "0" (err))
47 /* See comment before __put_user_asm. */
49 #define __get_user_asm(x, addr, err, op) \
50 __asm__ __volatile__( \
53 " .section .fixup,\"ax\"\n" \
58 " .section __ex_table,\"a\"\n" \
61 : "=r" (err), "=r" (x) \
62 : "r" (addr), "g" (-EFAULT), "0" (err))
64 #define __get_user_asm_64(x, addr, err) \
65 __asm__ __volatile__( \
66 " move.d [%2],%M1\n" \
67 "2: move.d [%2+4],%H1\n" \
69 " .section .fixup,\"ax\"\n" \
74 " .section __ex_table,\"a\"\n" \
78 : "=r" (err), "=r" (x) \
79 : "r" (addr), "g" (-EFAULT), "0" (err))
82 * Copy a null terminated string from userspace.
85 * -EFAULT for an exception
86 * count if we hit the buffer limit
87 * bytes copied if we hit a null byte
88 * (without the null byte)
91 __do_strncpy_from_user(char *dst
, const char *src
, long count
)
99 * Currently, in 2.4.0-test9, most ports use a simple byte-copy loop.
102 * This code is deduced from:
107 * while ((*dst++ = (tmp2 = *src++)) != 0
111 * res = count - tmp1;
116 __asm__
__volatile__ (
118 " move.b [%2+],$r9\n"
120 " move.b $r9,[%1+]\n"
124 " move.b [%2+],$r9\n"
129 " .section .fixup,\"ax\"\n"
133 /* There's one address for a fault at the first move, and
134 two possible PC values for a fault at the second move,
135 being a delay-slot filler. However, the branch-target
136 for the second move is the same as the first address.
137 Just so you don't get confused... */
139 " .section __ex_table,\"a\"\n"
143 : "=r" (res
), "=r" (dst
), "=r" (src
), "=r" (count
)
144 : "3" (count
), "1" (dst
), "2" (src
), "g" (-EFAULT
)
150 /* A few copy asms to build up the more complex ones from.
152 Note again, a post-increment is performed regardless of whether a bus
153 fault occurred in that instruction, and PC for a faulted insn is the
154 address *after* the insn. */
156 #define __asm_copy_user_cont(to, from, ret, COPY, FIXUP, TENTRY) \
157 __asm__ __volatile__ ( \
160 " .section .fixup,\"ax\"\n" \
164 " .section __ex_table,\"a\"\n" \
167 : "=r" (to), "=r" (from), "=r" (ret) \
168 : "0" (to), "1" (from), "2" (ret) \
171 #define __asm_copy_from_user_1(to, from, ret) \
172 __asm_copy_user_cont(to, from, ret, \
173 " move.b [%1+],$r9\n" \
174 "2: move.b $r9,[%0+]\n", \
176 " clear.b [%0+]\n", \
179 #define __asm_copy_from_user_2x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
180 __asm_copy_user_cont(to, from, ret, \
181 " move.w [%1+],$r9\n" \
182 "2: move.w $r9,[%0+]\n" COPY, \
184 " clear.w [%0+]\n" FIXUP, \
185 " .dword 2b,3b\n" TENTRY)
187 #define __asm_copy_from_user_2(to, from, ret) \
188 __asm_copy_from_user_2x_cont(to, from, ret, "", "", "")
190 #define __asm_copy_from_user_3(to, from, ret) \
191 __asm_copy_from_user_2x_cont(to, from, ret, \
192 " move.b [%1+],$r9\n" \
193 "4: move.b $r9,[%0+]\n", \
195 " clear.b [%0+]\n", \
198 #define __asm_copy_from_user_4x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
199 __asm_copy_user_cont(to, from, ret, \
200 " move.d [%1+],$r9\n" \
201 "2: move.d $r9,[%0+]\n" COPY, \
203 " clear.d [%0+]\n" FIXUP, \
204 " .dword 2b,3b\n" TENTRY)
206 #define __asm_copy_from_user_4(to, from, ret) \
207 __asm_copy_from_user_4x_cont(to, from, ret, "", "", "")
209 #define __asm_copy_from_user_5(to, from, ret) \
210 __asm_copy_from_user_4x_cont(to, from, ret, \
211 " move.b [%1+],$r9\n" \
212 "4: move.b $r9,[%0+]\n", \
214 " clear.b [%0+]\n", \
217 #define __asm_copy_from_user_6x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
218 __asm_copy_from_user_4x_cont(to, from, ret, \
219 " move.w [%1+],$r9\n" \
220 "4: move.w $r9,[%0+]\n" COPY, \
222 " clear.w [%0+]\n" FIXUP, \
223 " .dword 4b,5b\n" TENTRY)
225 #define __asm_copy_from_user_6(to, from, ret) \
226 __asm_copy_from_user_6x_cont(to, from, ret, "", "", "")
228 #define __asm_copy_from_user_7(to, from, ret) \
229 __asm_copy_from_user_6x_cont(to, from, ret, \
230 " move.b [%1+],$r9\n" \
231 "6: move.b $r9,[%0+]\n", \
233 " clear.b [%0+]\n", \
236 #define __asm_copy_from_user_8x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
237 __asm_copy_from_user_4x_cont(to, from, ret, \
238 " move.d [%1+],$r9\n" \
239 "4: move.d $r9,[%0+]\n" COPY, \
241 " clear.d [%0+]\n" FIXUP, \
242 " .dword 4b,5b\n" TENTRY)
244 #define __asm_copy_from_user_8(to, from, ret) \
245 __asm_copy_from_user_8x_cont(to, from, ret, "", "", "")
247 #define __asm_copy_from_user_9(to, from, ret) \
248 __asm_copy_from_user_8x_cont(to, from, ret, \
249 " move.b [%1+],$r9\n" \
250 "6: move.b $r9,[%0+]\n", \
252 " clear.b [%0+]\n", \
255 #define __asm_copy_from_user_10x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
256 __asm_copy_from_user_8x_cont(to, from, ret, \
257 " move.w [%1+],$r9\n" \
258 "6: move.w $r9,[%0+]\n" COPY, \
260 " clear.w [%0+]\n" FIXUP, \
261 " .dword 6b,7b\n" TENTRY)
263 #define __asm_copy_from_user_10(to, from, ret) \
264 __asm_copy_from_user_10x_cont(to, from, ret, "", "", "")
266 #define __asm_copy_from_user_11(to, from, ret) \
267 __asm_copy_from_user_10x_cont(to, from, ret, \
268 " move.b [%1+],$r9\n" \
269 "8: move.b $r9,[%0+]\n", \
271 " clear.b [%0+]\n", \
274 #define __asm_copy_from_user_12x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
275 __asm_copy_from_user_8x_cont(to, from, ret, \
276 " move.d [%1+],$r9\n" \
277 "6: move.d $r9,[%0+]\n" COPY, \
279 " clear.d [%0+]\n" FIXUP, \
280 " .dword 6b,7b\n" TENTRY)
282 #define __asm_copy_from_user_12(to, from, ret) \
283 __asm_copy_from_user_12x_cont(to, from, ret, "", "", "")
285 #define __asm_copy_from_user_13(to, from, ret) \
286 __asm_copy_from_user_12x_cont(to, from, ret, \
287 " move.b [%1+],$r9\n" \
288 "8: move.b $r9,[%0+]\n", \
290 " clear.b [%0+]\n", \
293 #define __asm_copy_from_user_14x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
294 __asm_copy_from_user_12x_cont(to, from, ret, \
295 " move.w [%1+],$r9\n" \
296 "8: move.w $r9,[%0+]\n" COPY, \
298 " clear.w [%0+]\n" FIXUP, \
299 " .dword 8b,9b\n" TENTRY)
301 #define __asm_copy_from_user_14(to, from, ret) \
302 __asm_copy_from_user_14x_cont(to, from, ret, "", "", "")
304 #define __asm_copy_from_user_15(to, from, ret) \
305 __asm_copy_from_user_14x_cont(to, from, ret, \
306 " move.b [%1+],$r9\n" \
307 "10: move.b $r9,[%0+]\n", \
309 " clear.b [%0+]\n", \
312 #define __asm_copy_from_user_16x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
313 __asm_copy_from_user_12x_cont(to, from, ret, \
314 " move.d [%1+],$r9\n" \
315 "8: move.d $r9,[%0+]\n" COPY, \
317 " clear.d [%0+]\n" FIXUP, \
318 " .dword 8b,9b\n" TENTRY)
320 #define __asm_copy_from_user_16(to, from, ret) \
321 __asm_copy_from_user_16x_cont(to, from, ret, "", "", "")
323 #define __asm_copy_from_user_20x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
324 __asm_copy_from_user_16x_cont(to, from, ret, \
325 " move.d [%1+],$r9\n" \
326 "10: move.d $r9,[%0+]\n" COPY, \
328 " clear.d [%0+]\n" FIXUP, \
329 " .dword 10b,11b\n" TENTRY)
331 #define __asm_copy_from_user_20(to, from, ret) \
332 __asm_copy_from_user_20x_cont(to, from, ret, "", "", "")
334 #define __asm_copy_from_user_24x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
335 __asm_copy_from_user_20x_cont(to, from, ret, \
336 " move.d [%1+],$r9\n" \
337 "12: move.d $r9,[%0+]\n" COPY, \
339 " clear.d [%0+]\n" FIXUP, \
340 " .dword 12b,13b\n" TENTRY)
342 #define __asm_copy_from_user_24(to, from, ret) \
343 __asm_copy_from_user_24x_cont(to, from, ret, "", "", "")
345 /* And now, the to-user ones. */
347 #define __asm_copy_to_user_1(to, from, ret) \
348 __asm_copy_user_cont(to, from, ret, \
349 " move.b [%1+],$r9\n" \
350 " move.b $r9,[%0+]\n2:\n", \
354 #define __asm_copy_to_user_2x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
355 __asm_copy_user_cont(to, from, ret, \
356 " move.w [%1+],$r9\n" \
357 " move.w $r9,[%0+]\n2:\n" COPY, \
358 "3: addq 2,%2\n" FIXUP, \
359 " .dword 2b,3b\n" TENTRY)
361 #define __asm_copy_to_user_2(to, from, ret) \
362 __asm_copy_to_user_2x_cont(to, from, ret, "", "", "")
364 #define __asm_copy_to_user_3(to, from, ret) \
365 __asm_copy_to_user_2x_cont(to, from, ret, \
366 " move.b [%1+],$r9\n" \
367 " move.b $r9,[%0+]\n4:\n", \
371 #define __asm_copy_to_user_4x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
372 __asm_copy_user_cont(to, from, ret, \
373 " move.d [%1+],$r9\n" \
374 " move.d $r9,[%0+]\n2:\n" COPY, \
375 "3: addq 4,%2\n" FIXUP, \
376 " .dword 2b,3b\n" TENTRY)
378 #define __asm_copy_to_user_4(to, from, ret) \
379 __asm_copy_to_user_4x_cont(to, from, ret, "", "", "")
381 #define __asm_copy_to_user_5(to, from, ret) \
382 __asm_copy_to_user_4x_cont(to, from, ret, \
383 " move.b [%1+],$r9\n" \
384 " move.b $r9,[%0+]\n4:\n", \
388 #define __asm_copy_to_user_6x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
389 __asm_copy_to_user_4x_cont(to, from, ret, \
390 " move.w [%1+],$r9\n" \
391 " move.w $r9,[%0+]\n4:\n" COPY, \
392 "5: addq 2,%2\n" FIXUP, \
393 " .dword 4b,5b\n" TENTRY)
395 #define __asm_copy_to_user_6(to, from, ret) \
396 __asm_copy_to_user_6x_cont(to, from, ret, "", "", "")
398 #define __asm_copy_to_user_7(to, from, ret) \
399 __asm_copy_to_user_6x_cont(to, from, ret, \
400 " move.b [%1+],$r9\n" \
401 " move.b $r9,[%0+]\n6:\n", \
405 #define __asm_copy_to_user_8x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
406 __asm_copy_to_user_4x_cont(to, from, ret, \
407 " move.d [%1+],$r9\n" \
408 " move.d $r9,[%0+]\n4:\n" COPY, \
409 "5: addq 4,%2\n" FIXUP, \
410 " .dword 4b,5b\n" TENTRY)
412 #define __asm_copy_to_user_8(to, from, ret) \
413 __asm_copy_to_user_8x_cont(to, from, ret, "", "", "")
415 #define __asm_copy_to_user_9(to, from, ret) \
416 __asm_copy_to_user_8x_cont(to, from, ret, \
417 " move.b [%1+],$r9\n" \
418 " move.b $r9,[%0+]\n6:\n", \
422 #define __asm_copy_to_user_10x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
423 __asm_copy_to_user_8x_cont(to, from, ret, \
424 " move.w [%1+],$r9\n" \
425 " move.w $r9,[%0+]\n6:\n" COPY, \
426 "7: addq 2,%2\n" FIXUP, \
427 " .dword 6b,7b\n" TENTRY)
429 #define __asm_copy_to_user_10(to, from, ret) \
430 __asm_copy_to_user_10x_cont(to, from, ret, "", "", "")
432 #define __asm_copy_to_user_11(to, from, ret) \
433 __asm_copy_to_user_10x_cont(to, from, ret, \
434 " move.b [%1+],$r9\n" \
435 " move.b $r9,[%0+]\n8:\n", \
439 #define __asm_copy_to_user_12x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
440 __asm_copy_to_user_8x_cont(to, from, ret, \
441 " move.d [%1+],$r9\n" \
442 " move.d $r9,[%0+]\n6:\n" COPY, \
443 "7: addq 4,%2\n" FIXUP, \
444 " .dword 6b,7b\n" TENTRY)
446 #define __asm_copy_to_user_12(to, from, ret) \
447 __asm_copy_to_user_12x_cont(to, from, ret, "", "", "")
449 #define __asm_copy_to_user_13(to, from, ret) \
450 __asm_copy_to_user_12x_cont(to, from, ret, \
451 " move.b [%1+],$r9\n" \
452 " move.b $r9,[%0+]\n8:\n", \
456 #define __asm_copy_to_user_14x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
457 __asm_copy_to_user_12x_cont(to, from, ret, \
458 " move.w [%1+],$r9\n" \
459 " move.w $r9,[%0+]\n8:\n" COPY, \
460 "9: addq 2,%2\n" FIXUP, \
461 " .dword 8b,9b\n" TENTRY)
463 #define __asm_copy_to_user_14(to, from, ret) \
464 __asm_copy_to_user_14x_cont(to, from, ret, "", "", "")
466 #define __asm_copy_to_user_15(to, from, ret) \
467 __asm_copy_to_user_14x_cont(to, from, ret, \
468 " move.b [%1+],$r9\n" \
469 " move.b $r9,[%0+]\n10:\n", \
473 #define __asm_copy_to_user_16x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
474 __asm_copy_to_user_12x_cont(to, from, ret, \
475 " move.d [%1+],$r9\n" \
476 " move.d $r9,[%0+]\n8:\n" COPY, \
477 "9: addq 4,%2\n" FIXUP, \
478 " .dword 8b,9b\n" TENTRY)
480 #define __asm_copy_to_user_16(to, from, ret) \
481 __asm_copy_to_user_16x_cont(to, from, ret, "", "", "")
483 #define __asm_copy_to_user_20x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
484 __asm_copy_to_user_16x_cont(to, from, ret, \
485 " move.d [%1+],$r9\n" \
486 " move.d $r9,[%0+]\n10:\n" COPY, \
487 "11: addq 4,%2\n" FIXUP, \
488 " .dword 10b,11b\n" TENTRY)
490 #define __asm_copy_to_user_20(to, from, ret) \
491 __asm_copy_to_user_20x_cont(to, from, ret, "", "", "")
493 #define __asm_copy_to_user_24x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
494 __asm_copy_to_user_20x_cont(to, from, ret, \
495 " move.d [%1+],$r9\n" \
496 " move.d $r9,[%0+]\n12:\n" COPY, \
497 "13: addq 4,%2\n" FIXUP, \
498 " .dword 12b,13b\n" TENTRY)
500 #define __asm_copy_to_user_24(to, from, ret) \
501 __asm_copy_to_user_24x_cont(to, from, ret, "", "", "")
503 /* Define a few clearing asms with exception handlers. */
505 /* This frame-asm is like the __asm_copy_user_cont one, but has one less
508 #define __asm_clear(to, ret, CLEAR, FIXUP, TENTRY) \
509 __asm__ __volatile__ ( \
512 " .section .fixup,\"ax\"\n" \
516 " .section __ex_table,\"a\"\n" \
519 : "=r" (to), "=r" (ret) \
520 : "0" (to), "1" (ret) \
523 #define __asm_clear_1(to, ret) \
524 __asm_clear(to, ret, \
525 " clear.b [%0+]\n2:\n", \
529 #define __asm_clear_2(to, ret) \
530 __asm_clear(to, ret, \
531 " clear.w [%0+]\n2:\n", \
535 #define __asm_clear_3(to, ret) \
536 __asm_clear(to, ret, \
538 "2: clear.b [%0+]\n3:\n", \
544 #define __asm_clear_4x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
545 __asm_clear(to, ret, \
546 " clear.d [%0+]\n2:\n" CLEAR, \
547 "3: addq 4,%1\n" FIXUP, \
548 " .dword 2b,3b\n" TENTRY)
550 #define __asm_clear_4(to, ret) \
551 __asm_clear_4x_cont(to, ret, "", "", "")
553 #define __asm_clear_8x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
554 __asm_clear_4x_cont(to, ret, \
555 " clear.d [%0+]\n4:\n" CLEAR, \
556 "5: addq 4,%1\n" FIXUP, \
557 " .dword 4b,5b\n" TENTRY)
559 #define __asm_clear_8(to, ret) \
560 __asm_clear_8x_cont(to, ret, "", "", "")
562 #define __asm_clear_12x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
563 __asm_clear_8x_cont(to, ret, \
564 " clear.d [%0+]\n6:\n" CLEAR, \
565 "7: addq 4,%1\n" FIXUP, \
566 " .dword 6b,7b\n" TENTRY)
568 #define __asm_clear_12(to, ret) \
569 __asm_clear_12x_cont(to, ret, "", "", "")
571 #define __asm_clear_16x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
572 __asm_clear_12x_cont(to, ret, \
573 " clear.d [%0+]\n8:\n" CLEAR, \
574 "9: addq 4,%1\n" FIXUP, \
575 " .dword 8b,9b\n" TENTRY)
577 #define __asm_clear_16(to, ret) \
578 __asm_clear_16x_cont(to, ret, "", "", "")
580 #define __asm_clear_20x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
581 __asm_clear_16x_cont(to, ret, \
582 " clear.d [%0+]\n10:\n" CLEAR, \
583 "11: addq 4,%1\n" FIXUP, \
584 " .dword 10b,11b\n" TENTRY)
586 #define __asm_clear_20(to, ret) \
587 __asm_clear_20x_cont(to, ret, "", "", "")
589 #define __asm_clear_24x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
590 __asm_clear_20x_cont(to, ret, \
591 " clear.d [%0+]\n12:\n" CLEAR, \
592 "13: addq 4,%1\n" FIXUP, \
593 " .dword 12b,13b\n" TENTRY)
595 #define __asm_clear_24(to, ret) \
596 __asm_clear_24x_cont(to, ret, "", "", "")
599 * Return the size of a string (including the ending 0)
601 * Return length of string in userspace including terminating 0
602 * or 0 for error. Return a value greater than N if too long.
606 strnlen_user(const char *s
, long n
)
610 if (!access_ok(VERIFY_READ
, s
, 0))
614 * This code is deduced from:
617 * while (tmp1-- > 0 && *s++)
625 __asm__
__volatile__ (
638 " .section .fixup,\"ax\"\n"
643 /* There's one address for a fault at the first move, and
644 two possible PC values for a fault at the second move,
645 being a delay-slot filler. However, the branch-target
646 for the second move is the same as the first address.
647 Just so you don't get confused... */
649 " .section __ex_table,\"a\"\n"
653 : "=r" (res
), "=r" (tmp1
)