1#ifndef _ASM_UACCESS_H
2#define _ASM_UACCESS_H
3
4
5
6
7
8#ifdef __KERNEL__
9#include <linux/errno.h>
10#include <linux/compiler.h>
11#include <linux/string.h>
12#include <linux/thread_info.h>
13#include <asm/asi.h>
14#include <asm/spitfire.h>
15#include <asm-generic/uaccess-unaligned.h>
16#endif
17
18#ifndef __ASSEMBLY__
19
20#include <asm/processor.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#define KERNEL_DS ((mm_segment_t) { ASI_P })
36#define USER_DS ((mm_segment_t) { ASI_AIUS })
37
38#define VERIFY_READ 0
39#define VERIFY_WRITE 1
40
41#define get_fs() ((mm_segment_t){(current_thread_info()->current_ds)})
42#define get_ds() (KERNEL_DS)
43
44#define segment_eq(a,b) ((a).seg == (b).seg)
45
46#define set_fs(val) \
47do { \
48 current_thread_info()->current_ds =(val).seg; \
49 __asm__ __volatile__ ("wr %%g0, %0, %%asi" : : "r" ((val).seg)); \
50} while(0)
51
52static inline int __access_ok(const void __user * addr, unsigned long size)
53{
54 return 1;
55}
56
57static inline int access_ok(int type, const void __user * addr, unsigned long size)
58{
59 return 1;
60}
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75struct exception_table_entry {
76 unsigned int insn, fixup;
77};
78
79void __ret_efault(void);
80void __retl_efault(void);
81
82
83
84
85
86
87
88
89
90
91#define put_user(x,ptr) ({ \
92unsigned long __pu_addr = (unsigned long)(ptr); \
93__chk_user_ptr(ptr); \
94__put_user_nocheck((__typeof__(*(ptr)))(x),__pu_addr,sizeof(*(ptr))); })
95
96#define get_user(x,ptr) ({ \
97unsigned long __gu_addr = (unsigned long)(ptr); \
98__chk_user_ptr(ptr); \
99__get_user_nocheck((x),__gu_addr,sizeof(*(ptr)),__typeof__(*(ptr))); })
100
101#define __put_user(x,ptr) put_user(x,ptr)
102#define __get_user(x,ptr) get_user(x,ptr)
103
104struct __large_struct { unsigned long buf[100]; };
105#define __m(x) ((struct __large_struct *)(x))
106
107#define __put_user_nocheck(data,addr,size) ({ \
108register int __pu_ret; \
109switch (size) { \
110case 1: __put_user_asm(data,b,addr,__pu_ret); break; \
111case 2: __put_user_asm(data,h,addr,__pu_ret); break; \
112case 4: __put_user_asm(data,w,addr,__pu_ret); break; \
113case 8: __put_user_asm(data,x,addr,__pu_ret); break; \
114default: __pu_ret = __put_user_bad(); break; \
115} __pu_ret; })
116
117#define __put_user_asm(x,size,addr,ret) \
118__asm__ __volatile__( \
119 "/* Put user asm, inline. */\n" \
120"1:\t" "st"#size "a %1, [%2] %%asi\n\t" \
121 "clr %0\n" \
122"2:\n\n\t" \
123 ".section .fixup,#alloc,#execinstr\n\t" \
124 ".align 4\n" \
125"3:\n\t" \
126 "sethi %%hi(2b), %0\n\t" \
127 "jmpl %0 + %%lo(2b), %%g0\n\t" \
128 " mov %3, %0\n\n\t" \
129 ".previous\n\t" \
130 ".section __ex_table,\"a\"\n\t" \
131 ".align 4\n\t" \
132 ".word 1b, 3b\n\t" \
133 ".previous\n\n\t" \
134 : "=r" (ret) : "r" (x), "r" (__m(addr)), \
135 "i" (-EFAULT))
136
137int __put_user_bad(void);
138
139#define __get_user_nocheck(data,addr,size,type) ({ \
140register int __gu_ret; \
141register unsigned long __gu_val; \
142switch (size) { \
143case 1: __get_user_asm(__gu_val,ub,addr,__gu_ret); break; \
144case 2: __get_user_asm(__gu_val,uh,addr,__gu_ret); break; \
145case 4: __get_user_asm(__gu_val,uw,addr,__gu_ret); break; \
146case 8: __get_user_asm(__gu_val,x,addr,__gu_ret); break; \
147default: __gu_val = 0; __gu_ret = __get_user_bad(); break; \
148} data = (type) __gu_val; __gu_ret; })
149
150#define __get_user_nocheck_ret(data,addr,size,type,retval) ({ \
151register unsigned long __gu_val __asm__ ("l1"); \
152switch (size) { \
153case 1: __get_user_asm_ret(__gu_val,ub,addr,retval); break; \
154case 2: __get_user_asm_ret(__gu_val,uh,addr,retval); break; \
155case 4: __get_user_asm_ret(__gu_val,uw,addr,retval); break; \
156case 8: __get_user_asm_ret(__gu_val,x,addr,retval); break; \
157default: if (__get_user_bad()) return retval; \
158} data = (type) __gu_val; })
159
160#define __get_user_asm(x,size,addr,ret) \
161__asm__ __volatile__( \
162 "/* Get user asm, inline. */\n" \
163"1:\t" "ld"#size "a [%2] %%asi, %1\n\t" \
164 "clr %0\n" \
165"2:\n\n\t" \
166 ".section .fixup,#alloc,#execinstr\n\t" \
167 ".align 4\n" \
168"3:\n\t" \
169 "sethi %%hi(2b), %0\n\t" \
170 "clr %1\n\t" \
171 "jmpl %0 + %%lo(2b), %%g0\n\t" \
172 " mov %3, %0\n\n\t" \
173 ".previous\n\t" \
174 ".section __ex_table,\"a\"\n\t" \
175 ".align 4\n\t" \
176 ".word 1b, 3b\n\n\t" \
177 ".previous\n\t" \
178 : "=r" (ret), "=r" (x) : "r" (__m(addr)), \
179 "i" (-EFAULT))
180
181#define __get_user_asm_ret(x,size,addr,retval) \
182if (__builtin_constant_p(retval) && retval == -EFAULT) \
183__asm__ __volatile__( \
184 "/* Get user asm ret, inline. */\n" \
185"1:\t" "ld"#size "a [%1] %%asi, %0\n\n\t" \
186 ".section __ex_table,\"a\"\n\t" \
187 ".align 4\n\t" \
188 ".word 1b,__ret_efault\n\n\t" \
189 ".previous\n\t" \
190 : "=r" (x) : "r" (__m(addr))); \
191else \
192__asm__ __volatile__( \
193 "/* Get user asm ret, inline. */\n" \
194"1:\t" "ld"#size "a [%1] %%asi, %0\n\n\t" \
195 ".section .fixup,#alloc,#execinstr\n\t" \
196 ".align 4\n" \
197"3:\n\t" \
198 "ret\n\t" \
199 " restore %%g0, %2, %%o0\n\n\t" \
200 ".previous\n\t" \
201 ".section __ex_table,\"a\"\n\t" \
202 ".align 4\n\t" \
203 ".word 1b, 3b\n\n\t" \
204 ".previous\n\t" \
205 : "=r" (x) : "r" (__m(addr)), "i" (retval))
206
207int __get_user_bad(void);
208
209unsigned long __must_check ___copy_from_user(void *to,
210 const void __user *from,
211 unsigned long size);
212unsigned long copy_from_user_fixup(void *to, const void __user *from,
213 unsigned long size);
214static inline unsigned long __must_check
215copy_from_user(void *to, const void __user *from, unsigned long size)
216{
217 unsigned long ret = ___copy_from_user(to, from, size);
218
219 if (unlikely(ret))
220 ret = copy_from_user_fixup(to, from, size);
221
222 return ret;
223}
224#define __copy_from_user copy_from_user
225
226unsigned long __must_check ___copy_to_user(void __user *to,
227 const void *from,
228 unsigned long size);
229unsigned long copy_to_user_fixup(void __user *to, const void *from,
230 unsigned long size);
231static inline unsigned long __must_check
232copy_to_user(void __user *to, const void *from, unsigned long size)
233{
234 unsigned long ret = ___copy_to_user(to, from, size);
235
236 if (unlikely(ret))
237 ret = copy_to_user_fixup(to, from, size);
238 return ret;
239}
240#define __copy_to_user copy_to_user
241
242unsigned long __must_check ___copy_in_user(void __user *to,
243 const void __user *from,
244 unsigned long size);
245unsigned long copy_in_user_fixup(void __user *to, void __user *from,
246 unsigned long size);
247static inline unsigned long __must_check
248copy_in_user(void __user *to, void __user *from, unsigned long size)
249{
250 unsigned long ret = ___copy_in_user(to, from, size);
251
252 if (unlikely(ret))
253 ret = copy_in_user_fixup(to, from, size);
254 return ret;
255}
256#define __copy_in_user copy_in_user
257
258unsigned long __must_check __clear_user(void __user *, unsigned long);
259
260#define clear_user __clear_user
261
262__must_check long strlen_user(const char __user *str);
263__must_check long strnlen_user(const char __user *str, long n);
264
265#define __copy_to_user_inatomic __copy_to_user
266#define __copy_from_user_inatomic __copy_from_user
267
268struct pt_regs;
269unsigned long compute_effective_address(struct pt_regs *,
270 unsigned int insn,
271 unsigned int rd);
272
273#endif
274
275#endif
276