OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [include/] [asm-or32/] [uaccess.h] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 xianfeng
#ifndef _OR32_UACCESS_H
2
#define _OR32_UACCESS_H
3
 
4
/*
5
 * User space memory access functions
6
 */
7
#include <linux/errno.h>
8
#include <linux/thread_info.h>
9
#include <linux/prefetch.h>
10
#include <linux/string.h>
11
#include <asm/page.h>
12
#include <asm/thread_info.h>
13
 
14
#define VERIFY_READ     0
15
#define VERIFY_WRITE    1
16
 
17
/*
18
 * The fs value determines whether argument validity checking should be
19
 * performed or not.  If get_fs() == USER_DS, checking is performed, with
20
 * get_fs() == KERNEL_DS, checking is bypassed.
21
 *
22
 * For historical reasons, these macros are grossly misnamed.
23
 */
24
 
25
#define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
26
 
27
/* addr_limit is the maximum accessible address for the task. we misuse
28
 * the KERNEL_DS and USER_DS values to both assign and compare the
29
 * addr_limit values through the equally misnamed get/set_fs macros.
30
 * (see above)
31
 */
32
 
33
#define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFFUL)
34
#define USER_DS         MAKE_MM_SEG(PAGE_OFFSET)
35
 
36
#define get_ds()        (KERNEL_DS)
37
#define get_fs()        (current_thread_info()->addr_limit)
38
#define set_fs(x)       (current_thread_info()->addr_limit = (x))
39
 
40
#define segment_eq(a,b) ((a).seg == (b).seg)
41
 
42
#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
43
#define __user_ok(addr,size) (((size) <= TASK_SIZE)&&((addr) <= TASK_SIZE-(size)))
44
#define __access_ok(addr,size) (__kernel_ok || __user_ok((addr),(size)))
45
#define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
46
 
47
extern inline int verify_area(int type, const void * addr, unsigned long size)
48
{
49
        return access_ok(type,addr,size) ? 0 : -EFAULT;
50
}
51
 
52
 
53
/*
54
 * The exception table consists of pairs of addresses: the first is the
55
 * address of an instruction that is allowed to fault, and the second is
56
 * the address at which the program should continue.  No registers are
57
 * modified, so it is entirely up to the continuation code to figure out
58
 * what to do.
59
 *
60
 * All the routines below use bits of fixup code that are out of line
61
 * with the main instruction path.  This means when everything is well,
62
 * we don't even have to jump over them.  Further, they do not intrude
63
 * on our cache or tlb entries.
64
 */
65
 
66
struct exception_table_entry
67
{
68
        unsigned long insn, fixup;
69
};
70
 
71
/* Returns 0 if exception not found and fixup otherwise.  */
72
extern unsigned long search_exception_table(unsigned long);
73
extern void sort_exception_table(void);
74
 
75
/*
76
 * These are the main single-value transfer routines.  They automatically
77
 * use the right size if we just have the right pointer type.
78
 *
79
 * This gets kind of ugly. We want to return _two_ values in "get_user()"
80
 * and yet we don't want to do any pointers, because that is too much
81
 * of a performance impact. Thus we have a few rather ugly macros here,
82
 * and hide all the uglyness from the user.
83
 *
84
 * The "__xxx" versions of the user access functions are versions that
85
 * do not verify the address space, that must have been done previously
86
 * with a separate "access_ok()" call (this is used when we do multiple
87
 * accesses to the same area of user memory).
88
 *
89
 * As we use the same address space for kernel and user data on the
90
 * PowerPC, we can just do these as direct assignments.  (Of course, the
91
 * exception handling means that it's no longer "just"...)
92
 */
93
#define get_user(x,ptr) \
94
  __get_user_check((x),(ptr),sizeof(*(ptr)))
95
#define put_user(x,ptr) \
96
  __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
97
 
98
#define __get_user(x,ptr) \
99
  __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
100
#define __put_user(x,ptr) \
101
  __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
102
 
103
extern long __put_user_bad(void);
104
 
105
#define __put_user_nocheck(x,ptr,size)                  \
106
({                                                      \
107
        long __pu_err;                                  \
108
        __put_user_size((x),(ptr),(size),__pu_err);     \
109
        __pu_err;                                       \
110
})
111
 
112
#define __put_user_check(x,ptr,size)                            \
113
({                                                              \
114
        long __pu_err = -EFAULT;                                \
115
        __typeof__(*(ptr)) *__pu_addr = (ptr);                  \
116
        if (access_ok(VERIFY_WRITE,__pu_addr,size))             \
117
                __put_user_size((x),__pu_addr,(size),__pu_err); \
118
        __pu_err;                                               \
119
})
120
 
121
#define __put_user_size(x,ptr,size,retval)                      \
122
do {                                                            \
123
        retval = 0;                                              \
124
        switch (size) {                                         \
125
          case 1: __put_user_asm(x,ptr,retval,"l.sb"); break;   \
126
          case 2: __put_user_asm(x,ptr,retval,"l.sh"); break;   \
127
          case 4: __put_user_asm(x,ptr,retval,"l.sw"); break;   \
128
          case 8: __put_user_asm2(x,ptr,retval); break;         \
129
          default: __put_user_bad();                            \
130
        }                                                       \
131
} while (0)
132
 
133
struct __large_struct { unsigned long buf[100]; };
134
#define __m(x) (*(struct __large_struct *)(x))
135
 
136
/*
137
 * We don't tell gcc that we are accessing memory, but this is OK
138
 * because we do not write to any memory gcc knows about, so there
139
 * are no aliasing issues.
140
 */
141
#define __put_user_asm(x, addr, err, op)                        \
142
        __asm__ __volatile__(                                   \
143
                "1:     "op" 0(%2),%1\n"                        \
144
                "2:\n"                                          \
145
                ".section .fixup,\"ax\"\n"                      \
146
                "3:     l.addi %0,r0,%3\n"                      \
147
                "       l.j 2b\n"                               \
148
                "       l.nop \n"                               \
149
                ".previous\n"                                   \
150
                ".section __ex_table,\"a\"\n"                   \
151
                "       .align 2\n"                             \
152
                "       .long 1b,3b\n"                          \
153
                ".previous"                                     \
154
                : "=r"(err)                                     \
155
                : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
156
 
157
#define __put_user_asm2(x, addr, err)                           \
158
        __asm__ __volatile__(                                   \
159
                "1:     l.sw 0(%2),%1\n"                        \
160
                "2:     l.sw 4(%2),%H1\n"                       \
161
                "3:\n"                                          \
162
                ".section .fixup,\"ax\"\n"                      \
163
                "4:     l.addi %0,r0,%3\n"                      \
164
                "       l.j 3b\n"                               \
165
                "       l.nop \n"                               \
166
                ".previous\n"                                   \
167
                ".section __ex_table,\"a\"\n"                   \
168
                "       .align 2\n"                             \
169
                "       .long 1b,4b\n"                          \
170
                "       .long 2b,4b\n"                          \
171
                ".previous"                                     \
172
                : "=r"(err)                                     \
173
                : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
174
 
175
#define __get_user_nocheck(x,ptr,size)                          \
176
({                                                              \
177
        long __gu_err, __gu_val;                                \
178
        __get_user_size(__gu_val,(ptr),(size),__gu_err);        \
179
        (x) = (__typeof__(*(ptr)))__gu_val;                     \
180
        __gu_err;                                               \
181
})
182
 
183
#define __get_user_check(x,ptr,size)                                    \
184
({                                                                      \
185
        long __gu_err = -EFAULT, __gu_val = 0;                           \
186
        const __typeof__(*(ptr)) *__gu_addr = (ptr);                    \
187
        if (access_ok(VERIFY_READ,__gu_addr,size))                      \
188
                __get_user_size(__gu_val,__gu_addr,(size),__gu_err);    \
189
        (x) = (__typeof__(*(ptr)))__gu_val;                             \
190
        __gu_err;                                                       \
191
})
192
 
193
extern long __get_user_bad(void);
194
 
195
#define __get_user_size(x,ptr,size,retval)                      \
196
do {                                                            \
197
        retval = 0;                                              \
198
        switch (size) {                                         \
199
          case 1: __get_user_asm(x,ptr,retval,"l.lbz"); break;  \
200
          case 2: __get_user_asm(x,ptr,retval,"l.lhz"); break;  \
201
          case 4: __get_user_asm(x,ptr,retval,"l.lwz"); break;  \
202
          case 8: __get_user_asm2(x, ptr, retval);              \
203
          default: (x) = __get_user_bad();                      \
204
        }                                                       \
205
} while (0)
206
 
207
#define __get_user_asm(x, addr, err, op)                \
208
        __asm__ __volatile__(                           \
209
                "1:     "op" %1,0(%2)\n"                \
210
                "2:\n"                                  \
211
                ".section .fixup,\"ax\"\n"              \
212
                "3:     l.addi %0,r0,%3\n"              \
213
                "       l.addi %1,r0,0\n"               \
214
                "       l.j 2b\n"                       \
215
                "       l.nop \n"                       \
216
                ".previous\n"                           \
217
                ".section __ex_table,\"a\"\n"           \
218
                "       .align 2\n"                     \
219
                "       .long 1b,3b\n"                  \
220
                ".previous"                             \
221
                : "=r"(err), "=r"(x)                    \
222
                : "r"(addr), "i"(-EFAULT), "0"(err))
223
 
224
#define __get_user_asm2(x, addr, err)                   \
225
        __asm__ __volatile__(                           \
226
                "1:     l.lwz %1,0(%2)\n"               \
227
                "2:     l.lwz %H1,4(%2)\n"              \
228
                "3:\n"                                  \
229
                ".section .fixup,\"ax\"\n"              \
230
                "4:     l.addi %0,r0,%3\n"              \
231
                "       l.addi %1,r0,0\n"               \
232
                "       l.addi %H1,r0,0\n"              \
233
                "       l.j 3b\n"                       \
234
                "       l.nop \n"                       \
235
                ".previous\n"                           \
236
                ".section __ex_table,\"a\"\n"           \
237
                "       .align 2\n"                     \
238
                "       .long 1b,4b\n"                  \
239
                "       .long 2b,4b\n"                  \
240
                ".previous"                             \
241
                : "=r"(err), "=&r"(x)                   \
242
                : "r"(addr), "i"(-EFAULT), "0"(err))
243
 
244
/* more complex routines */
245
 
246
extern int __copy_tofrom_user(void *to, const void *from, unsigned long size);
247
 
248
extern inline unsigned long
249
copy_from_user(void *to, const void *from, unsigned long n)
250
{
251
        unsigned long over;
252
 
253
        if (access_ok(VERIFY_READ, from, n))
254
                return __copy_tofrom_user(to, from, n);
255
        if ((unsigned long)from < TASK_SIZE) {
256
                over = (unsigned long)from + n - TASK_SIZE;
257
                return __copy_tofrom_user(to, from, n - over) + over;
258
        }
259
        return n;
260
}
261
 
262
extern inline unsigned long
263
copy_to_user(void *to, const void *from, unsigned long n)
264
{
265
        unsigned long over;
266
 
267
        if (access_ok(VERIFY_WRITE, to, n))
268
                return __copy_tofrom_user(to, from, n);
269
        if ((unsigned long)to < TASK_SIZE) {
270
                over = (unsigned long)to + n - TASK_SIZE;
271
                return __copy_tofrom_user(to, from, n - over) + over;
272
        }
273
        return n;
274
}
275
 
276
#define __copy_from_user(to, from, size) \
277
        __copy_tofrom_user((to), (from), (size))
278
#define __copy_to_user(to, from, size) \
279
        __copy_tofrom_user((to), (from), (size))
280
#define __copy_to_user_inatomic __copy_to_user
281
#define __copy_from_user_inatomic __copy_from_user
282
 
283
extern unsigned long __clear_user(void *addr, unsigned long size);
284
 
285
extern inline unsigned long
286
clear_user(void *addr, unsigned long size)
287
{
288
 
289
        if (access_ok(VERIFY_WRITE, addr, size))
290
                return __clear_user(addr, size);
291
        if ((unsigned long)addr < TASK_SIZE) {
292
                unsigned long over = (unsigned long)addr + size - TASK_SIZE;
293
                return __clear_user(addr, size - over) + over;
294
        }
295
        return size;
296
}
297
 
298
extern int __strncpy_from_user(char *dst, const char *src, long count);
299
 
300
extern inline long
301
strncpy_from_user(char *dst, const char *src, long count)
302
{
303
        if (access_ok(VERIFY_READ, src, 1))
304
                return __strncpy_from_user(dst, src, count);
305
        return -EFAULT;
306
}
307
 
308
/*
309
 * Return the size of a string (including the ending 0)
310
 *
311
 * Return 0 for error
312
 */
313
 
314
extern int __strnlen_user(const char *str, long len, unsigned long top);
315
 
316
/*
317
 * Returns the length of the string at str (including the null byte),
318
 * or 0 if we hit a page we can't access,
319
 * or something > len if we didn't find a null byte.
320
 *
321
 * The `top' parameter to __strnlen_user is to make sure that
322
 * we can never overflow from the user area into kernel space.
323
 */
324
extern __inline__ int strnlen_user(const char *str, long len)
325
{
326
        unsigned long top = __kernel_ok? ~0UL: TASK_SIZE - 1;
327
 
328
        if ((unsigned long)str > top)
329
                return 0;
330
        return __strnlen_user(str, len, top);
331
}
332
 
333
#define strlen_user(str)        strnlen_user((str), 0x7ffffffe)
334
 
335
#endif  /* _OR32_UACCESS_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.