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>
33 #include <asm/segment.h>
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
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
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) \
85 typeof(*(ptr)) __pu_val = (x); \
86 switch (sizeof (*(ptr))) { \
91 memcpy(ptr, &__pu_val, sizeof (*(ptr))); \
94 __pu_err = __put_user_bad(); \
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
109 #define __ptr(x) ((unsigned long *)(x))
111 #define get_user(x, ptr) \
114 typeof(*(ptr)) __gu_val = 0; \
115 switch (sizeof(*(ptr))) { \
120 memcpy(&__gu_val, ptr, sizeof (*(ptr))); \
124 __gu_err = __get_user_bad(); \
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.
151 strncpy_from_user(char *dst
, const char *src
, long count
)
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)
176 static inline unsigned long
177 clear_user(void *to
, unsigned long n
)
183 #endif /* _NIOS2NOMMU_UACCESS_H */