2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
14 * Do memcpy(), but trap and return "n" when a load or store faults.
16 * Note: this idiom only works when memcpy() compiles to a leaf function.
17 * If "sp" is updated during memcpy, the "jrp lr" will be incorrect.
19 * Also note that we are capturing "n" from the containing scope here.
22 #define _ST(p, inst, v) \
24 asm("1: " #inst " %0, %1;" \
25 ".pushsection .coldtext.memcpy,\"ax\";" \
26 "2: { move r0, %2; jrp lr };" \
27 ".section __ex_table,\"a\";" \
30 : "=m" (*(p)) : "r" (v), "r" (n)); \
33 #define _LD(p, inst) \
36 asm("1: " #inst " %0, %1;" \
37 ".pushsection .coldtext.memcpy,\"ax\";" \
38 "2: { move r0, %2; jrp lr };" \
39 ".section __ex_table,\"a\";" \
42 : "=r" (__v) : "m" (*(p)), "r" (n)); \
46 #define USERCOPY_FUNC __copy_to_user_inatomic
47 #define ST1(p, v) _ST((p), st1, (v))
48 #define ST2(p, v) _ST((p), st2, (v))
49 #define ST4(p, v) _ST((p), st4, (v))
50 #define ST8(p, v) _ST((p), st, (v))
55 #include "memcpy_64.c"
57 #define USERCOPY_FUNC __copy_from_user_inatomic
62 #define LD1(p) _LD((p), ld1u)
63 #define LD2(p) _LD((p), ld2u)
64 #define LD4(p) _LD((p), ld4u)
65 #define LD8(p) _LD((p), ld)
66 #include "memcpy_64.c"
68 #define USERCOPY_FUNC __copy_in_user_inatomic
69 #define ST1(p, v) _ST((p), st1, (v))
70 #define ST2(p, v) _ST((p), st2, (v))
71 #define ST4(p, v) _ST((p), st4, (v))
72 #define ST8(p, v) _ST((p), st, (v))
73 #define LD1(p) _LD((p), ld1u)
74 #define LD2(p) _LD((p), ld2u)
75 #define LD4(p) _LD((p), ld4u)
76 #define LD8(p) _LD((p), ld)
77 #include "memcpy_64.c"
79 unsigned long __copy_from_user_zeroing(void *to
, const void __user
*from
,
82 unsigned long rc
= __copy_from_user_inatomic(to
, from
, n
);
84 memset(to
+ n
- rc
, 0, rc
);