x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / arch / mn10300 / lib / usercopy.c
blobce8899e5e171370ebc88c08a91727ef9232febf9
1 /* MN10300 Userspace accessor functions
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/uaccess.h>
14 unsigned long
15 __generic_copy_to_user(void *to, const void *from, unsigned long n)
17 if (access_ok(VERIFY_WRITE, to, n))
18 __copy_user(to, from, n);
19 return n;
22 unsigned long
23 __generic_copy_from_user(void *to, const void *from, unsigned long n)
25 if (access_ok(VERIFY_READ, from, n))
26 __copy_user_zeroing(to, from, n);
27 else
28 memset(to, 0, n);
29 return n;
33 * Copy a null terminated string from userspace.
35 #define __do_strncpy_from_user(dst, src, count, res) \
36 do { \
37 int w; \
38 asm volatile( \
39 " mov %1,%0\n" \
40 " cmp 0,%1\n" \
41 " beq 2f\n" \
42 "0:\n" \
43 " movbu (%5),%2\n" \
44 "1:\n" \
45 " movbu %2,(%6)\n" \
46 " inc %5\n" \
47 " inc %6\n" \
48 " cmp 0,%2\n" \
49 " beq 2f\n" \
50 " add -1,%1\n" \
51 " bne 0b\n" \
52 "2:\n" \
53 " sub %1,%0\n" \
54 "3:\n" \
55 " .section .fixup,\"ax\"\n" \
56 "4:\n" \
57 " mov %3,%0\n" \
58 " jmp 3b\n" \
59 " .previous\n" \
60 " .section __ex_table,\"a\"\n" \
61 " .balign 4\n" \
62 " .long 0b,4b\n" \
63 " .long 1b,4b\n" \
64 " .previous" \
65 :"=&r"(res), "=r"(count), "=&r"(w) \
66 :"i"(-EFAULT), "1"(count), "a"(src), "a"(dst) \
67 : "memory", "cc"); \
68 } while (0)
70 long
71 __strncpy_from_user(char *dst, const char *src, long count)
73 long res;
74 __do_strncpy_from_user(dst, src, count, res);
75 return res;
78 long
79 strncpy_from_user(char *dst, const char *src, long count)
81 long res = -EFAULT;
82 if (access_ok(VERIFY_READ, src, 1))
83 __do_strncpy_from_user(dst, src, count, res);
84 return res;
89 * Clear a userspace memory
91 #define __do_clear_user(addr, size) \
92 do { \
93 int w; \
94 asm volatile( \
95 " cmp 0,%0\n" \
96 " beq 1f\n" \
97 " clr %1\n" \
98 "0: movbu %1,(%3,%2)\n" \
99 " inc %3\n" \
100 " cmp %0,%3\n" \
101 " bne 0b\n" \
102 "1:\n" \
103 " sub %3,%0\n" \
104 "2:\n" \
105 ".section .fixup,\"ax\"\n" \
106 "3: jmp 2b\n" \
107 ".previous\n" \
108 ".section __ex_table,\"a\"\n" \
109 " .balign 4\n" \
110 " .long 0b,3b\n" \
111 ".previous\n" \
112 : "+r"(size), "=&r"(w) \
113 : "a"(addr), "d"(0) \
114 : "memory", "cc"); \
115 } while (0)
117 unsigned long
118 __clear_user(void *to, unsigned long n)
120 __do_clear_user(to, n);
121 return n;
124 unsigned long
125 clear_user(void *to, unsigned long n)
127 if (access_ok(VERIFY_WRITE, to, n))
128 __do_clear_user(to, n);
129 return n;
133 * Return the size of a string (including the ending 0)
135 * Return 0 on exception, a value greater than N if too long
137 long strnlen_user(const char *s, long n)
139 unsigned long res, w;
141 if (!__addr_ok(s))
142 return 0;
144 if (n < 0 || n + (u_long) s > current_thread_info()->addr_limit.seg)
145 n = current_thread_info()->addr_limit.seg - (u_long)s;
147 asm volatile(
148 "0: cmp %4,%0\n"
149 " beq 2f\n"
150 "1: movbu (%0,%3),%1\n"
151 " inc %0\n"
152 " cmp 0,%1\n"
153 " beq 3f\n"
154 " bra 0b\n"
155 "2: clr %0\n"
156 "3:\n"
157 ".section .fixup,\"ax\"\n"
158 "4: jmp 2b\n"
159 ".previous\n"
160 ".section __ex_table,\"a\"\n"
161 " .balign 4\n"
162 " .long 1b,4b\n"
163 ".previous\n"
164 :"=d"(res), "=&r"(w)
165 :"0"(0), "a"(s), "r"(n)
166 : "memory", "cc");
167 return res;