diff options
author | Michal Simek <monstr@monstr.eu> | 2009-05-26 10:30:23 -0400 |
---|---|---|
committer | Michal Simek <monstr@monstr.eu> | 2009-05-26 10:45:20 -0400 |
commit | 0d6de9532663a4120ce35f507f16b72df382e360 (patch) | |
tree | 67e0f2f4f7abd401cff056f43afefd4ccf314a67 /arch/microblaze | |
parent | 7db29dde731db02143418cfa008b7b77ccb2fa57 (diff) |
microblaze_mmu_v2: uaccess MMU update
Signed-off-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'arch/microblaze')
-rw-r--r-- | arch/microblaze/include/asm/uaccess.h | 298 | ||||
-rw-r--r-- | arch/microblaze/lib/uaccess_old.S | 135 |
2 files changed, 381 insertions, 52 deletions
diff --git a/arch/microblaze/include/asm/uaccess.h b/arch/microblaze/include/asm/uaccess.h index a4e171d49d15..65adad61e7e9 100644 --- a/arch/microblaze/include/asm/uaccess.h +++ b/arch/microblaze/include/asm/uaccess.h | |||
@@ -1,4 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> | ||
3 | * Copyright (C) 2008-2009 PetaLogix | ||
2 | * Copyright (C) 2006 Atmark Techno, Inc. | 4 | * Copyright (C) 2006 Atmark Techno, Inc. |
3 | * | 5 | * |
4 | * This file is subject to the terms and conditions of the GNU General Public | 6 | * This file is subject to the terms and conditions of the GNU General Public |
@@ -26,6 +28,10 @@ | |||
26 | #define VERIFY_READ 0 | 28 | #define VERIFY_READ 0 |
27 | #define VERIFY_WRITE 1 | 29 | #define VERIFY_WRITE 1 |
28 | 30 | ||
31 | #define __clear_user(addr, n) (memset((void *)(addr), 0, (n)), 0) | ||
32 | |||
33 | #ifndef CONFIG_MMU | ||
34 | |||
29 | extern int ___range_ok(unsigned long addr, unsigned long size); | 35 | extern int ___range_ok(unsigned long addr, unsigned long size); |
30 | 36 | ||
31 | #define __range_ok(addr, size) \ | 37 | #define __range_ok(addr, size) \ |
@@ -38,63 +44,64 @@ extern int ___range_ok(unsigned long addr, unsigned long size); | |||
38 | extern int bad_user_access_length(void); | 44 | extern int bad_user_access_length(void); |
39 | 45 | ||
40 | /* FIXME this is function for optimalization -> memcpy */ | 46 | /* FIXME this is function for optimalization -> memcpy */ |
41 | #define __get_user(var, ptr) \ | 47 | #define __get_user(var, ptr) \ |
42 | ({ \ | 48 | ({ \ |
43 | int __gu_err = 0; \ | 49 | int __gu_err = 0; \ |
44 | switch (sizeof(*(ptr))) { \ | 50 | switch (sizeof(*(ptr))) { \ |
45 | case 1: \ | 51 | case 1: \ |
46 | case 2: \ | 52 | case 2: \ |
47 | case 4: \ | 53 | case 4: \ |
48 | (var) = *(ptr); \ | 54 | (var) = *(ptr); \ |
49 | break; \ | 55 | break; \ |
50 | case 8: \ | 56 | case 8: \ |
51 | memcpy((void *) &(var), (ptr), 8); \ | 57 | memcpy((void *) &(var), (ptr), 8); \ |
52 | break; \ | 58 | break; \ |
53 | default: \ | 59 | default: \ |
54 | (var) = 0; \ | 60 | (var) = 0; \ |
55 | __gu_err = __get_user_bad(); \ | 61 | __gu_err = __get_user_bad(); \ |
56 | break; \ | 62 | break; \ |
57 | } \ | 63 | } \ |
58 | __gu_err; \ | 64 | __gu_err; \ |
59 | }) | 65 | }) |
60 | 66 | ||
61 | #define __get_user_bad() (bad_user_access_length(), (-EFAULT)) | 67 | #define __get_user_bad() (bad_user_access_length(), (-EFAULT)) |
62 | 68 | ||
69 | /* FIXME is not there defined __pu_val */ | ||
63 | #define __put_user(var, ptr) \ | 70 | #define __put_user(var, ptr) \ |
64 | ({ \ | 71 | ({ \ |
65 | int __pu_err = 0; \ | 72 | int __pu_err = 0; \ |
66 | switch (sizeof(*(ptr))) { \ | 73 | switch (sizeof(*(ptr))) { \ |
67 | case 1: \ | 74 | case 1: \ |
68 | case 2: \ | 75 | case 2: \ |
69 | case 4: \ | 76 | case 4: \ |
70 | *(ptr) = (var); \ | 77 | *(ptr) = (var); \ |
71 | break; \ | 78 | break; \ |
72 | case 8: { \ | 79 | case 8: { \ |
73 | typeof(*(ptr)) __pu_val = var; \ | 80 | typeof(*(ptr)) __pu_val = (var); \ |
74 | memcpy(ptr, &__pu_val, sizeof(__pu_val));\ | 81 | memcpy(ptr, &__pu_val, sizeof(__pu_val)); \ |
75 | } \ | 82 | } \ |
76 | break; \ | 83 | break; \ |
77 | default: \ | 84 | default: \ |
78 | __pu_err = __put_user_bad(); \ | 85 | __pu_err = __put_user_bad(); \ |
79 | break; \ | 86 | break; \ |
80 | } \ | 87 | } \ |
81 | __pu_err; \ | 88 | __pu_err; \ |
82 | }) | 89 | }) |
83 | 90 | ||
84 | #define __put_user_bad() (bad_user_access_length(), (-EFAULT)) | 91 | #define __put_user_bad() (bad_user_access_length(), (-EFAULT)) |
85 | 92 | ||
86 | #define put_user(x, ptr) __put_user(x, ptr) | 93 | #define put_user(x, ptr) __put_user((x), (ptr)) |
87 | #define get_user(x, ptr) __get_user(x, ptr) | 94 | #define get_user(x, ptr) __get_user((x), (ptr)) |
88 | |||
89 | #define copy_to_user(to, from, n) (memcpy(to, from, n), 0) | ||
90 | #define copy_from_user(to, from, n) (memcpy(to, from, n), 0) | ||
91 | 95 | ||
92 | #define __copy_to_user(to, from, n) (copy_to_user(to, from, n)) | 96 | #define copy_to_user(to, from, n) (memcpy((to), (from), (n)), 0) |
93 | #define __copy_from_user(to, from, n) (copy_from_user(to, from, n)) | 97 | #define copy_from_user(to, from, n) (memcpy((to), (from), (n)), 0) |
94 | #define __copy_to_user_inatomic(to, from, n) (__copy_to_user(to, from, n)) | ||
95 | #define __copy_from_user_inatomic(to, from, n) (__copy_from_user(to, from, n)) | ||
96 | 98 | ||
97 | #define __clear_user(addr, n) (memset((void *)addr, 0, n), 0) | 99 | #define __copy_to_user(to, from, n) (copy_to_user((to), (from), (n))) |
100 | #define __copy_from_user(to, from, n) (copy_from_user((to), (from), (n))) | ||
101 | #define __copy_to_user_inatomic(to, from, n) \ | ||
102 | (__copy_to_user((to), (from), (n))) | ||
103 | #define __copy_from_user_inatomic(to, from, n) \ | ||
104 | (__copy_from_user((to), (from), (n))) | ||
98 | 105 | ||
99 | static inline unsigned long clear_user(void *addr, unsigned long size) | 106 | static inline unsigned long clear_user(void *addr, unsigned long size) |
100 | { | 107 | { |
@@ -103,13 +110,200 @@ static inline unsigned long clear_user(void *addr, unsigned long size) | |||
103 | return size; | 110 | return size; |
104 | } | 111 | } |
105 | 112 | ||
106 | /* Returns 0 if exception not found and fixup otherwise. */ | 113 | /* Returns 0 if exception not found and fixup otherwise. */ |
107 | extern unsigned long search_exception_table(unsigned long); | 114 | extern unsigned long search_exception_table(unsigned long); |
108 | 115 | ||
116 | extern long strncpy_from_user(char *dst, const char *src, long count); | ||
117 | extern long strnlen_user(const char *src, long count); | ||
118 | |||
119 | #else /* CONFIG_MMU */ | ||
120 | |||
121 | /* | ||
122 | * Address is valid if: | ||
123 | * - "addr", "addr + size" and "size" are all below the limit | ||
124 | */ | ||
125 | #define access_ok(type, addr, size) \ | ||
126 | (get_fs().seg > (((unsigned long)(addr)) | \ | ||
127 | (size) | ((unsigned long)(addr) + (size)))) | ||
128 | |||
129 | /* || printk("access_ok failed for %s at 0x%08lx (size %d), seg 0x%08x\n", | ||
130 | type?"WRITE":"READ",addr,size,get_fs().seg)) */ | ||
131 | |||
132 | /* | ||
133 | * All the __XXX versions macros/functions below do not perform | ||
134 | * access checking. It is assumed that the necessary checks have been | ||
135 | * already performed before the finction (macro) is called. | ||
136 | */ | ||
137 | |||
138 | #define get_user(x, ptr) \ | ||
139 | ({ \ | ||
140 | access_ok(VERIFY_READ, (ptr), sizeof(*(ptr))) \ | ||
141 | ? __get_user((x), (ptr)) : -EFAULT; \ | ||
142 | }) | ||
143 | |||
144 | #define put_user(x, ptr) \ | ||
145 | ({ \ | ||
146 | access_ok(VERIFY_WRITE, (ptr), sizeof(*(ptr))) \ | ||
147 | ? __put_user((x), (ptr)) : -EFAULT; \ | ||
148 | }) | ||
149 | |||
150 | #define __get_user(x, ptr) \ | ||
151 | ({ \ | ||
152 | unsigned long __gu_val; \ | ||
153 | /*unsigned long __gu_ptr = (unsigned long)(ptr);*/ \ | ||
154 | long __gu_err; \ | ||
155 | switch (sizeof(*(ptr))) { \ | ||
156 | case 1: \ | ||
157 | __get_user_asm("lbu", (ptr), __gu_val, __gu_err); \ | ||
158 | break; \ | ||
159 | case 2: \ | ||
160 | __get_user_asm("lhu", (ptr), __gu_val, __gu_err); \ | ||
161 | break; \ | ||
162 | case 4: \ | ||
163 | __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ | ||
164 | break; \ | ||
165 | default: \ | ||
166 | __gu_val = 0; __gu_err = -EINVAL; \ | ||
167 | } \ | ||
168 | x = (__typeof__(*(ptr))) __gu_val; \ | ||
169 | __gu_err; \ | ||
170 | }) | ||
171 | |||
172 | #define __get_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ | ||
173 | ({ \ | ||
174 | __asm__ __volatile__ ( \ | ||
175 | "1:" insn " %1, %2, r0; \ | ||
176 | addk %0, r0, r0; \ | ||
177 | 2: \ | ||
178 | .section .fixup,\"ax\"; \ | ||
179 | 3: brid 2b; \ | ||
180 | addik %0, r0, %3; \ | ||
181 | .previous; \ | ||
182 | .section __ex_table,\"a\"; \ | ||
183 | .word 1b,3b; \ | ||
184 | .previous;" \ | ||
185 | : "=r"(__gu_err), "=r"(__gu_val) \ | ||
186 | : "r"(__gu_ptr), "i"(-EFAULT) \ | ||
187 | ); \ | ||
188 | }) | ||
189 | |||
190 | #define __put_user(x, ptr) \ | ||
191 | ({ \ | ||
192 | __typeof__(*(ptr)) __gu_val = x; \ | ||
193 | long __gu_err = 0; \ | ||
194 | switch (sizeof(__gu_val)) { \ | ||
195 | case 1: \ | ||
196 | __put_user_asm("sb", (ptr), __gu_val, __gu_err); \ | ||
197 | break; \ | ||
198 | case 2: \ | ||
199 | __put_user_asm("sh", (ptr), __gu_val, __gu_err); \ | ||
200 | break; \ | ||
201 | case 4: \ | ||
202 | __put_user_asm("sw", (ptr), __gu_val, __gu_err); \ | ||
203 | break; \ | ||
204 | case 8: \ | ||
205 | __put_user_asm_8((ptr), __gu_val, __gu_err); \ | ||
206 | break; \ | ||
207 | default: \ | ||
208 | __gu_err = -EINVAL; \ | ||
209 | } \ | ||
210 | __gu_err; \ | ||
211 | }) | ||
212 | |||
213 | #define __put_user_asm_8(__gu_ptr, __gu_val, __gu_err) \ | ||
214 | ({ \ | ||
215 | __asm__ __volatile__ (" lwi %0, %1, 0; \ | ||
216 | 1: swi %0, %2, 0; \ | ||
217 | lwi %0, %1, 4; \ | ||
218 | 2: swi %0, %2, 4; \ | ||
219 | addk %0,r0,r0; \ | ||
220 | 3: \ | ||
221 | .section .fixup,\"ax\"; \ | ||
222 | 4: brid 3b; \ | ||
223 | addik %0, r0, %3; \ | ||
224 | .previous; \ | ||
225 | .section __ex_table,\"a\"; \ | ||
226 | .word 1b,4b,2b,4b; \ | ||
227 | .previous;" \ | ||
228 | : "=&r"(__gu_err) \ | ||
229 | : "r"(&__gu_val), \ | ||
230 | "r"(__gu_ptr), "i"(-EFAULT) \ | ||
231 | ); \ | ||
232 | }) | ||
233 | |||
234 | #define __put_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ | ||
235 | ({ \ | ||
236 | __asm__ __volatile__ ( \ | ||
237 | "1:" insn " %1, %2, r0; \ | ||
238 | addk %0, r0, r0; \ | ||
239 | 2: \ | ||
240 | .section .fixup,\"ax\"; \ | ||
241 | 3: brid 2b; \ | ||
242 | addik %0, r0, %3; \ | ||
243 | .previous; \ | ||
244 | .section __ex_table,\"a\"; \ | ||
245 | .word 1b,3b; \ | ||
246 | .previous;" \ | ||
247 | : "=r"(__gu_err) \ | ||
248 | : "r"(__gu_val), "r"(__gu_ptr), "i"(-EFAULT) \ | ||
249 | ); \ | ||
250 | }) | ||
251 | |||
252 | /* | ||
253 | * Return: number of not copied bytes, i.e. 0 if OK or non-zero if fail. | ||
254 | */ | ||
255 | static inline int clear_user(char *to, int size) | ||
256 | { | ||
257 | if (size && access_ok(VERIFY_WRITE, to, size)) { | ||
258 | __asm__ __volatile__ (" \ | ||
259 | 1: \ | ||
260 | sb r0, %2, r0; \ | ||
261 | addik %0, %0, -1; \ | ||
262 | bneid %0, 1b; \ | ||
263 | addik %2, %2, 1; \ | ||
264 | 2: \ | ||
265 | .section __ex_table,\"a\"; \ | ||
266 | .word 1b,2b; \ | ||
267 | .section .text;" \ | ||
268 | : "=r"(size) \ | ||
269 | : "0"(size), "r"(to) | ||
270 | ); | ||
271 | } | ||
272 | return size; | ||
273 | } | ||
274 | |||
275 | extern unsigned long __copy_tofrom_user(void __user *to, | ||
276 | const void __user *from, unsigned long size); | ||
277 | |||
278 | #define copy_to_user(to, from, n) \ | ||
279 | (access_ok(VERIFY_WRITE, (to), (n)) ? \ | ||
280 | __copy_tofrom_user((void __user *)(to), \ | ||
281 | (__force const void __user *)(from), (n)) \ | ||
282 | : -EFAULT) | ||
283 | |||
284 | #define __copy_to_user(to, from, n) copy_to_user((to), (from), (n)) | ||
285 | #define __copy_to_user_inatomic(to, from, n) copy_to_user((to), (from), (n)) | ||
286 | |||
287 | #define copy_from_user(to, from, n) \ | ||
288 | (access_ok(VERIFY_READ, (from), (n)) ? \ | ||
289 | __copy_tofrom_user((__force void __user *)(to), \ | ||
290 | (void __user *)(from), (n)) \ | ||
291 | : -EFAULT) | ||
292 | |||
293 | #define __copy_from_user(to, from, n) copy_from_user((to), (from), (n)) | ||
294 | #define __copy_from_user_inatomic(to, from, n) \ | ||
295 | copy_from_user((to), (from), (n)) | ||
296 | |||
297 | extern int __strncpy_user(char *to, const char __user *from, int len); | ||
298 | extern int __strnlen_user(const char __user *sstr, int len); | ||
299 | |||
300 | #define strncpy_from_user(to, from, len) \ | ||
301 | (access_ok(VERIFY_READ, from, 1) ? \ | ||
302 | __strncpy_user(to, from, len) : -EFAULT) | ||
303 | #define strnlen_user(str, len) \ | ||
304 | (access_ok(VERIFY_READ, str, 1) ? __strnlen_user(str, len) : 0) | ||
109 | 305 | ||
110 | extern long strncpy_from_user(char *dst, const char __user *src, long count); | 306 | #endif /* CONFIG_MMU */ |
111 | extern long strnlen_user(const char __user *src, long count); | ||
112 | extern long __strncpy_from_user(char *dst, const char __user *src, long count); | ||
113 | 307 | ||
114 | /* | 308 | /* |
115 | * The exception table consists of pairs of addresses: the first is the | 309 | * The exception table consists of pairs of addresses: the first is the |
diff --git a/arch/microblaze/lib/uaccess_old.S b/arch/microblaze/lib/uaccess_old.S new file mode 100644 index 000000000000..67f991c14b8a --- /dev/null +++ b/arch/microblaze/lib/uaccess_old.S | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009 Michal Simek <monstr@monstr.eu> | ||
3 | * Copyright (C) 2009 PetaLogix | ||
4 | * Copyright (C) 2007 LynuxWorks, Inc. | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file "COPYING" in the main directory of this archive | ||
8 | * for more details. | ||
9 | */ | ||
10 | |||
11 | #include <linux/errno.h> | ||
12 | #include <linux/linkage.h> | ||
13 | |||
14 | /* | ||
15 | * int __strncpy_user(char *to, char *from, int len); | ||
16 | * | ||
17 | * Returns: | ||
18 | * -EFAULT for an exception | ||
19 | * len if we hit the buffer limit | ||
20 | * bytes copied | ||
21 | */ | ||
22 | |||
23 | .text | ||
24 | .globl __strncpy_user; | ||
25 | .align 4; | ||
26 | __strncpy_user: | ||
27 | |||
28 | /* | ||
29 | * r5 - to | ||
30 | * r6 - from | ||
31 | * r7 - len | ||
32 | * r3 - temp count | ||
33 | * r4 - temp val | ||
34 | */ | ||
35 | addik r3,r7,0 /* temp_count = len */ | ||
36 | beqi r3,3f | ||
37 | 1: | ||
38 | lbu r4,r6,r0 | ||
39 | sb r4,r5,r0 | ||
40 | |||
41 | addik r3,r3,-1 | ||
42 | beqi r3,2f /* break on len */ | ||
43 | |||
44 | addik r5,r5,1 | ||
45 | bneid r4,1b | ||
46 | addik r6,r6,1 /* delay slot */ | ||
47 | addik r3,r3,1 /* undo "temp_count--" */ | ||
48 | 2: | ||
49 | rsubk r3,r3,r7 /* temp_count = len - temp_count */ | ||
50 | 3: | ||
51 | rtsd r15,8 | ||
52 | nop | ||
53 | |||
54 | |||
55 | .section .fixup, "ax" | ||
56 | .align 2 | ||
57 | 4: | ||
58 | brid 3b | ||
59 | addik r3,r0, -EFAULT | ||
60 | |||
61 | .section __ex_table, "a" | ||
62 | .word 1b,4b | ||
63 | |||
64 | /* | ||
65 | * int __strnlen_user(char __user *str, int maxlen); | ||
66 | * | ||
67 | * Returns: | ||
68 | * 0 on error | ||
69 | * maxlen + 1 if no NUL byte found within maxlen bytes | ||
70 | * size of the string (including NUL byte) | ||
71 | */ | ||
72 | |||
73 | .text | ||
74 | .globl __strnlen_user; | ||
75 | .align 4; | ||
76 | __strnlen_user: | ||
77 | addik r3,r6,0 | ||
78 | beqi r3,3f | ||
79 | 1: | ||
80 | lbu r4,r5,r0 | ||
81 | beqid r4,2f /* break on NUL */ | ||
82 | addik r3,r3,-1 /* delay slot */ | ||
83 | |||
84 | bneid r3,1b | ||
85 | addik r5,r5,1 /* delay slot */ | ||
86 | |||
87 | addik r3,r3,-1 /* for break on len */ | ||
88 | 2: | ||
89 | rsubk r3,r3,r6 | ||
90 | 3: | ||
91 | rtsd r15,8 | ||
92 | nop | ||
93 | |||
94 | |||
95 | .section .fixup,"ax" | ||
96 | 4: | ||
97 | brid 3b | ||
98 | addk r3,r0,r0 | ||
99 | |||
100 | .section __ex_table,"a" | ||
101 | .word 1b,4b | ||
102 | |||
103 | /* | ||
104 | * int __copy_tofrom_user(char *to, char *from, int len) | ||
105 | * Return: | ||
106 | * 0 on success | ||
107 | * number of not copied bytes on error | ||
108 | */ | ||
109 | .text | ||
110 | .globl __copy_tofrom_user; | ||
111 | .align 4; | ||
112 | __copy_tofrom_user: | ||
113 | /* | ||
114 | * r5 - to | ||
115 | * r6 - from | ||
116 | * r7, r3 - count | ||
117 | * r4 - tempval | ||
118 | */ | ||
119 | addik r3,r7,0 | ||
120 | beqi r3,3f | ||
121 | 1: | ||
122 | lbu r4,r6,r0 | ||
123 | addik r6,r6,1 | ||
124 | 2: | ||
125 | sb r4,r5,r0 | ||
126 | addik r3,r3,-1 | ||
127 | bneid r3,1b | ||
128 | addik r5,r5,1 /* delay slot */ | ||
129 | 3: | ||
130 | rtsd r15,8 | ||
131 | nop | ||
132 | |||
133 | |||
134 | .section __ex_table,"a" | ||
135 | .word 1b,3b,2b,3b | ||