1 #ifndef __PARISC_UACCESS_H
2 #define __PARISC_UACCESS_H
3
4 /*
5 * User space memory access functions
6 */
7 #include <linux/sched.h>
8 #include <asm/page.h>
9 #include <asm/system.h>
10 #include <asm/cache.h>
11
12 #define VERIFY_READ 0
13 #define VERIFY_WRITE 1
14
15 #define KERNEL_DS ((mm_segment_t){0})
16 #define USER_DS ((mm_segment_t){1})
17
18 #define segment_eq(a,b) ((a).seg == (b).seg)
19
20 #define get_ds() (KERNEL_DS)
21 #define get_fs() (current->addr_limit)
22 #define set_fs(x) (current->addr_limit = (x))
23
24 /*
25 * Note that since kernel addresses are in a separate address space on
26 * parisc, we don't need to do anything for access_ok() or verify_area().
27 * We just let the page fault handler do the right thing. This also means
28 * that put_user is the same as __put_user, etc.
29 */
30
31 #define access_ok(type,addr,size) (1)
32 #define verify_area(type,addr,size) (0)
33
34 #define put_user __put_user
35 #define get_user __get_user
36
37 #if BITS_PER_LONG == 32
38 #define LDD_KERNEL(ptr) BUG()
39 #define LDD_USER(ptr) BUG()
40 #define STD_KERNEL(x, ptr) __put_kernel_asm64(x,ptr)
41 #define STD_USER(x, ptr) __put_user_asm64(x,ptr)
42 #else
43 #define LDD_KERNEL(ptr) __get_kernel_asm("ldd",ptr)
44 #define LDD_USER(ptr) __get_user_asm("ldd",ptr)
45 #define STD_KERNEL(x, ptr) __put_kernel_asm("std",x,ptr)
46 #define STD_USER(x, ptr) __put_user_asm("std",x,ptr)
47 #endif
48
49 /*
50 * The exception table contains two values: the first is an address
51 * for an instruction that is allowed to fault, and the second is
52 * the number of bytes to skip if a fault occurs. We also support in
53 * two bit flags: 0x2 tells the exception handler to clear register
54 * r9 and 0x1 tells the exception handler to put -EFAULT in r8.
55 * This allows us to handle the simple cases for put_user and
56 * get_user without having to have .fixup sections.
57 */
58
59 struct exception_table_entry {
60 unsigned long addr; /* address of insn that is allowed to fault. */
61 long skip; /* pcoq skip | r9 clear flag | r8 -EFAULT flag */
62 };
63
64 extern const struct exception_table_entry
65 *search_exception_table(unsigned long addr);
66
67 #define __get_user(x,ptr) \
68 ({ \
69 register long __gu_err __asm__ ("r8") = 0; \
70 register long __gu_val __asm__ ("r9") = 0; \
71 \
72 if (segment_eq(get_fs(),KERNEL_DS)) { \
73 switch (sizeof(*(ptr))) { \
74 case 1: __get_kernel_asm("ldb",ptr); break; \
75 case 2: __get_kernel_asm("ldh",ptr); break; \
76 case 4: __get_kernel_asm("ldw",ptr); break; \
77 case 8: LDD_KERNEL(ptr); break; \
78 default: BUG(); break; \
79 } \
80 } \
81 else { \
82 switch (sizeof(*(ptr))) { \
83 case 1: __get_user_asm("ldb",ptr); break; \
84 case 2: __get_user_asm("ldh",ptr); break; \
85 case 4: __get_user_asm("ldw",ptr); break; \
86 case 8: LDD_USER(ptr); break; \
87 default: BUG(); break; \
88 } \
89 } \
90 \
91 (x) = (__typeof__(*(ptr))) __gu_val; \
92 __gu_err; \
93 })
94
95 #ifdef __LP64__
96 #define __get_kernel_asm(ldx,ptr) \
97 __asm__("\n1:\t" ldx "\t0(%2),%0\n" \
98 "2:\n" \
99 "\t.section __ex_table,\"a\"\n" \
100 "\t.dword\t1b\n" \
101 "\t.dword\t(2b-1b)+3\n" \
102 "\t.previous" \
103 : "=r"(__gu_val), "=r"(__gu_err) \
104 : "r"(ptr), "1"(__gu_err));
105
106 #define __get_user_asm(ldx,ptr) \
107 __asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n" \
108 "2:\n" \
109 "\t.section __ex_table,\"a\"\n" \
110 "\t.dword\t1b\n" \
111 "\t.dword\t(2b-1b)+3\n" \
112 "\t.previous" \
113 : "=r"(__gu_val), "=r"(__gu_err) \
114 : "r"(ptr), "1"(__gu_err));
115 #else
116 #define __get_kernel_asm(ldx,ptr) \
117 __asm__("\n1:\t" ldx "\t0(%2),%0\n" \
118 "2:\n" \
119 "\t.section __ex_table,\"a\"\n" \
120 "\t.word\t1b\n" \
121 "\t.word\t(2b-1b)+3\n" \
122 "\t.previous" \
123 : "=r"(__gu_val), "=r"(__gu_err) \
124 : "r"(ptr), "1"(__gu_err));
125
126 #define __get_user_asm(ldx,ptr) \
127 __asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n" \
128 "2:\n" \
129 "\t.section __ex_table,\"a\"\n" \
130 "\t.word\t1b\n" \
131 "\t.word\t(2b-1b)+3\n" \
132 "\t.previous" \
133 : "=r"(__gu_val), "=r"(__gu_err) \
134 : "r"(ptr), "1"(__gu_err));
135 #endif
136
137 #define __put_user(x,ptr) \
138 ({ \
139 register long __pu_err __asm__ ("r8") = 0; \
140 \
141 if (segment_eq(get_fs(),KERNEL_DS)) { \
142 switch (sizeof(*(ptr))) { \
143 case 1: __put_kernel_asm("stb",x,ptr); break; \
144 case 2: __put_kernel_asm("sth",x,ptr); break; \
145 case 4: __put_kernel_asm("stw",x,ptr); break; \
146 case 8: STD_KERNEL(x,ptr); break; \
147 default: BUG(); break; \
148 } \
149 } \
150 else { \
151 switch (sizeof(*(ptr))) { \
152 case 1: __put_user_asm("stb",x,ptr); break; \
153 case 2: __put_user_asm("sth",x,ptr); break; \
154 case 4: __put_user_asm("stw",x,ptr); break; \
155 case 8: STD_USER(x,ptr); break; \
156 default: BUG(); break; \
157 } \
158 } \
159 \
160 __pu_err; \
161 })
162
163 /*
164 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
165 * instead of writing. This is because they do not write to any memory
166 * gcc knows about, so there are no aliasing issues.
167 */
168
169 #ifdef __LP64__
170 #define __put_kernel_asm(stx,x,ptr) \
171 __asm__ __volatile__ ( \
172 "\n1:\t" stx "\t%2,0(%1)\n" \
173 "2:\n" \
174 "\t.section __ex_table,\"a\"\n" \
175 "\t.dword\t1b\n" \
176 "\t.dword\t(2b-1b)+1\n" \
177 "\t.previous" \
178 : "=r"(__pu_err) \
179 : "r"(ptr), "r"(x), "0"(__pu_err))
180
181 #define __put_user_asm(stx,x,ptr) \
182 __asm__ __volatile__ ( \
183 "\n1:\t" stx "\t%2,0(%%sr3,%1)\n" \
184 "2:\n" \
185 "\t.section __ex_table,\"a\"\n" \
186 "\t.dword\t1b\n" \
187 "\t.dword\t(2b-1b)+1\n" \
188 "\t.previous" \
189 : "=r"(__pu_err) \
190 : "r"(ptr), "r"(x), "0"(__pu_err))
191 #else
192 #define __put_kernel_asm(stx,x,ptr) \
193 __asm__ __volatile__ ( \
194 "\n1:\t" stx "\t%2,0(%1)\n" \
195 "2:\n" \
196 "\t.section __ex_table,\"a\"\n" \
197 "\t.word\t1b\n" \
198 "\t.word\t(2b-1b)+1\n" \
199 "\t.previous" \
200 : "=r"(__pu_err) \
201 : "r"(ptr), "r"(x), "0"(__pu_err))
202
203 #define __put_user_asm(stx,x,ptr) \
204 __asm__ __volatile__ ( \
205 "\n1:\t" stx "\t%2,0(%%sr3,%1)\n" \
206 "2:\n" \
207 "\t.section __ex_table,\"a\"\n" \
208 "\t.word\t1b\n" \
209 "\t.word\t(2b-1b)+1\n" \
210 "\t.previous" \
211 : "=r"(__pu_err) \
212 : "r"(ptr), "r"(x), "0"(__pu_err))
213
__put_kernel_asm64(u64 x,void * ptr)214 static inline void __put_kernel_asm64(u64 x, void *ptr)
215 {
216 u32 hi = x>>32;
217 u32 lo = x&0xffffffff;
218 __asm__ __volatile__ (
219 "\n1:\tstw %1,0(%0)\n"
220 "\n2:\tstw %2,4(%0)\n"
221 "3:\n"
222 "\t.section __ex_table,\"a\"\n"
223 "\t.word\t1b\n"
224 "\t.word\t(3b-1b)+1\n"
225 "\t.word\t2b\n"
226 "\t.word\t(3b-2b)+1\n"
227 "\t.previous"
228 : : "r"(ptr), "r"(hi), "r"(lo));
229
230 }
231
__put_user_asm64(u64 x,void * ptr)232 static inline void __put_user_asm64(u64 x, void *ptr)
233 {
234 u32 hi = x>>32;
235 u32 lo = x&0xffffffff;
236 __asm__ __volatile__ (
237 "\n1:\tstw %1,0(%%sr3,%0)\n"
238 "\n2:\tstw %2,4(%%sr3,%0)\n"
239 "3:\n"
240 "\t.section __ex_table,\"a\"\n"
241 "\t.word\t1b\n"
242 "\t.word\t(3b-1b)+1\n"
243 "\t.word\t2b\n"
244 "\t.word\t(3b-2b)+1\n"
245 "\t.previous"
246 : : "r"(ptr), "r"(hi), "r"(lo));
247
248 }
249
250 #endif
251
252
253 /*
254 * Complex access routines -- external declarations
255 */
256
257 extern unsigned long lcopy_to_user(void *, const void *, unsigned long);
258 extern unsigned long lcopy_from_user(void *, const void *, unsigned long);
259 extern long lstrncpy_from_user(char *, const char *, long);
260 extern unsigned lclear_user(void *,unsigned long);
261 extern long lstrnlen_user(const char *,long);
262
263 /*
264 * Complex access routines -- macros
265 */
266
267 #define strncpy_from_user lstrncpy_from_user
268 #define strnlen_user lstrnlen_user
269 #define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
270 #define clear_user lclear_user
271 #define __clear_user lclear_user
272
273 #define copy_from_user lcopy_from_user
274 #define __copy_from_user lcopy_from_user
275 #define copy_to_user lcopy_to_user
276 #define __copy_to_user lcopy_to_user
277
278 #endif /* __PARISC_UACCESS_H */
279