19 #ifndef __ASM_OPENRISC_UACCESS_H
20 #define __ASM_OPENRISC_UACCESS_H
25 #include <linux/errno.h>
27 #include <linux/prefetch.h>
28 #include <linux/string.h>
32 #define VERIFY_WRITE 1
48 #define KERNEL_DS (~0UL)
49 #define get_ds() (KERNEL_DS)
51 #define USER_DS (TASK_SIZE)
52 #define get_fs() (current_thread_info()->addr_limit)
53 #define set_fs(x) (current_thread_info()->addr_limit = (x))
55 #define segment_eq(a, b) ((a) == (b))
60 #define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs()-size))
63 #define __addr_ok(addr) ((unsigned long) addr < get_fs())
65 #define access_ok(type, addr, size) \
66 __range_ok((unsigned long)addr, (unsigned long)size)
107 #define get_user(x, ptr) \
108 __get_user_check((x), (ptr), sizeof(*(ptr)))
109 #define put_user(x, ptr) \
110 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
112 #define __get_user(x, ptr) \
113 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
114 #define __put_user(x, ptr) \
115 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
119 #define __put_user_nocheck(x, ptr, size) \
122 __put_user_size((x), (ptr), (size), __pu_err); \
126 #define __put_user_check(x, ptr, size) \
128 long __pu_err = -EFAULT; \
129 __typeof__(*(ptr)) *__pu_addr = (ptr); \
130 if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
131 __put_user_size((x), __pu_addr, (size), __pu_err); \
135 #define __put_user_size(x, ptr, size, retval) \
139 case 1: __put_user_asm(x, ptr, retval, "l.sb"); break; \
140 case 2: __put_user_asm(x, ptr, retval, "l.sh"); break; \
141 case 4: __put_user_asm(x, ptr, retval, "l.sw"); break; \
142 case 8: __put_user_asm2(x, ptr, retval); break; \
143 default: __put_user_bad(); \
148 unsigned long buf[100];
150 #define __m(x) (*(struct __large_struct *)(x))
157 #define __put_user_asm(x, addr, err, op) \
158 __asm__ __volatile__( \
159 "1: "op" 0(%2),%1\n" \
161 ".section .fixup,\"ax\"\n" \
162 "3: l.addi %0,r0,%3\n" \
166 ".section __ex_table,\"a\"\n" \
171 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
173 #define __put_user_asm2(x, addr, err) \
174 __asm__ __volatile__( \
175 "1: l.sw 0(%2),%1\n" \
176 "2: l.sw 4(%2),%H1\n" \
178 ".section .fixup,\"ax\"\n" \
179 "4: l.addi %0,r0,%3\n" \
183 ".section __ex_table,\"a\"\n" \
189 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
191 #define __get_user_nocheck(x, ptr, size) \
193 long __gu_err, __gu_val; \
194 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
195 (x) = (__typeof__(*(ptr)))__gu_val; \
199 #define __get_user_check(x, ptr, size) \
201 long __gu_err = -EFAULT, __gu_val = 0; \
202 const __typeof__(*(ptr)) * __gu_addr = (ptr); \
203 if (access_ok(VERIFY_READ, __gu_addr, size)) \
204 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
205 (x) = (__typeof__(*(ptr)))__gu_val; \
211 #define __get_user_size(x, ptr, size, retval) \
215 case 1: __get_user_asm(x, ptr, retval, "l.lbz"); break; \
216 case 2: __get_user_asm(x, ptr, retval, "l.lhz"); break; \
217 case 4: __get_user_asm(x, ptr, retval, "l.lwz"); break; \
218 case 8: __get_user_asm2(x, ptr, retval); \
219 default: (x) = __get_user_bad(); \
223 #define __get_user_asm(x, addr, err, op) \
224 __asm__ __volatile__( \
225 "1: "op" %1,0(%2)\n" \
227 ".section .fixup,\"ax\"\n" \
228 "3: l.addi %0,r0,%3\n" \
229 " l.addi %1,r0,0\n" \
233 ".section __ex_table,\"a\"\n" \
237 : "=r"(err), "=r"(x) \
238 : "r"(addr), "i"(-EFAULT), "0"(err))
240 #define __get_user_asm2(x, addr, err) \
241 __asm__ __volatile__( \
242 "1: l.lwz %1,0(%2)\n" \
243 "2: l.lwz %H1,4(%2)\n" \
245 ".section .fixup,\"ax\"\n" \
246 "4: l.addi %0,r0,%3\n" \
247 " l.addi %1,r0,0\n" \
248 " l.addi %H1,r0,0\n" \
252 ".section __ex_table,\"a\"\n" \
257 : "=r"(err), "=&r"(x) \
258 : "r"(addr), "i"(-EFAULT), "0"(err))
265 #define __copy_from_user(to, from, size) \
266 __copy_tofrom_user(to, from, size)
267 #define __copy_to_user(to, from, size) \
268 __copy_tofrom_user(to, from, size)
270 #define __copy_to_user_inatomic __copy_to_user
271 #define __copy_from_user_inatomic __copy_from_user
273 static inline unsigned long
287 static inline unsigned long
316 #define user_addr_max() \
317 (segment_eq(get_fs(), USER_DS) ? TASK_SIZE : ~0UL)