MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / include / asm-nios2nommu / uaccess.h
blob0ef6734924a466213e1cc5014f13bf297344f9a9
1 #ifndef __NIOS2NOMMU_UACCESS_H
2 #define __NIOS2NOMMU_UACCESS_H
4 /*--------------------------------------------------------------------
6 * asm-nios2nommu/uaccess.h
8 * User space memory access functions
10 * Derived from various works, Alpha, ix86, M68K, Sparc, ...et al
12 * Copyright (C) 2004 Microtronix Datacom Ltd
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
25 * Ported from asm-m68knommu/uaccess.h --wentao
26 * Jan/20/2004 dgt NiosII
28 ---------------------------------------------------------------------*/
31 #include <linux/sched.h>
32 #include <linux/mm.h>
33 #include <asm/segment.h>
34 #include <asm/nios.h>
36 #define VERIFY_READ 0
37 #define VERIFY_WRITE 1
39 #define access_ok(type,addr,size) _access_ok((unsigned long)(addr),(size))
41 static inline int _access_ok(unsigned long addr, unsigned long size)
43 return (((unsigned long)addr < (unsigned long)nasys_program_mem_end) &&
44 (((unsigned long)addr >= (unsigned long)nasys_program_mem)));
47 extern inline int verify_area(int type, const void * addr, unsigned long size)
49 return access_ok(type,addr,size)?0:-EFAULT;
53 * The exception table consists of pairs of addresses: the first is the
54 * address of an instruction that is allowed to fault, and the second is
55 * the address at which the program should continue. No registers are
56 * modified, so it is entirely up to the continuation code to figure out
57 * what to do.
59 * All the routines below use bits of fixup code that are out of line
60 * with the main instruction path. This means when everything is well,
61 * we don't even have to jump over them. Further, they do not intrude
62 * on our cache or tlb entries.
65 #define ARCH_HAS_SEARCH_EXTABLE
66 //;dgt2;tmp;
68 struct exception_table_entry
70 unsigned long insn, fixup;
73 /* Returns 0 if exception not found and fixup otherwise. */
74 extern unsigned long search_exception_table(unsigned long);
78 * These are the main single-value transfer routines. They automatically
79 * use the right size if we just have the right pointer type.
82 #define put_user(x, ptr) \
83 ({ \
84 int __pu_err = 0; \
85 typeof(*(ptr)) __pu_val = (x); \
86 switch (sizeof (*(ptr))) { \
87 case 1: \
88 case 2: \
89 case 4: \
90 case 8: \
91 memcpy(ptr, &__pu_val, sizeof (*(ptr))); \
92 break; \
93 default: \
94 __pu_err = __put_user_bad(); \
95 break; \
96 } \
97 __pu_err; \
99 #define __put_user(x, ptr) put_user(x, ptr)
101 extern int __put_user_bad(void);
104 * Tell gcc we read from memory instead of writing: this is because
105 * we do not write to any memory gcc knows about, so there are no
106 * aliasing issues.
109 #define __ptr(x) ((unsigned long *)(x))
111 #define get_user(x, ptr) \
112 ({ \
113 int __gu_err = 0; \
114 typeof(*(ptr)) __gu_val = 0; \
115 switch (sizeof(*(ptr))) { \
116 case 1: \
117 case 2: \
118 case 4: \
119 case 8: \
120 memcpy(&__gu_val, ptr, sizeof (*(ptr))); \
121 break; \
122 default: \
123 __gu_val = 0; \
124 __gu_err = __get_user_bad(); \
125 break; \
127 (x) = __gu_val; \
128 __gu_err; \
130 #define __get_user(x, ptr) get_user(x, ptr)
132 extern int __get_user_bad(void);
134 #define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
135 #define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
137 #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
138 #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
139 #define __copy_to_user_inatomic __copy_to_user
140 #define __copy_from_user_inatomic __copy_from_user
142 #define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; })
144 #define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; })
147 * Copy a null terminated string from userspace.
150 static inline long
151 strncpy_from_user(char *dst, const char *src, long count)
153 char *tmp;
154 strncpy(dst, src, count);
155 for (tmp = dst; *tmp && count > 0; tmp++, count--)
157 return(tmp - dst); /* DAVIDM should we count a NUL ? check getname */
161 * Return the size of a string (including the ending 0)
163 * Return 0 on exception, a value greater than N if too long
165 static inline long strnlen_user(const char *src, long n)
167 return(strlen(src) + 1); /* DAVIDM make safer */
170 #define strlen_user(str) strnlen_user(str, 32767)
173 * Zero Userspace
176 static inline unsigned long
177 clear_user(void *to, unsigned long n)
179 memset(to, 0, n);
180 return(0);
183 #endif /* _NIOS2NOMMU_UACCESS_H */