microblaze_mmu_v2: Update exception handling - MMU exception
[linux-2.6-block.git] / arch / microblaze / include / asm / uaccess.h
CommitLineData
2660663f
MS
1/*
2 * Copyright (C) 2006 Atmark Techno, Inc.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
8
9#ifndef _ASM_MICROBLAZE_UACCESS_H
10#define _ASM_MICROBLAZE_UACCESS_H
11
12#ifdef __KERNEL__
13#ifndef __ASSEMBLY__
14
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/sched.h> /* RLIMIT_FSIZE */
18#include <linux/mm.h>
19
20#include <asm/mmu.h>
21#include <asm/page.h>
22#include <asm/pgtable.h>
23#include <asm/segment.h>
24#include <linux/string.h>
25
26#define VERIFY_READ 0
27#define VERIFY_WRITE 1
28
29extern int ___range_ok(unsigned long addr, unsigned long size);
30
31#define __range_ok(addr, size) \
32 ___range_ok((unsigned long)(addr), (unsigned long)(size))
33
34#define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0)
35#define __access_ok(add, size) (__range_ok((addr), (size)) == 0)
36
838d2406
AB
37/* Undefined function to trigger linker error */
38extern int bad_user_access_length(void);
39
2660663f
MS
40/* FIXME this is function for optimalization -> memcpy */
41#define __get_user(var, ptr) \
42 ({ \
43 int __gu_err = 0; \
44 switch (sizeof(*(ptr))) { \
45 case 1: \
46 case 2: \
47 case 4: \
48 (var) = *(ptr); \
49 break; \
50 case 8: \
51 memcpy((void *) &(var), (ptr), 8); \
52 break; \
53 default: \
54 (var) = 0; \
55 __gu_err = __get_user_bad(); \
56 break; \
57 } \
58 __gu_err; \
59 })
60
61#define __get_user_bad() (bad_user_access_length(), (-EFAULT))
62
63#define __put_user(var, ptr) \
64 ({ \
65 int __pu_err = 0; \
66 switch (sizeof(*(ptr))) { \
67 case 1: \
68 case 2: \
69 case 4: \
70 *(ptr) = (var); \
71 break; \
72 case 8: { \
73 typeof(*(ptr)) __pu_val = var; \
74 memcpy(ptr, &__pu_val, sizeof(__pu_val));\
75 } \
76 break; \
77 default: \
78 __pu_err = __put_user_bad(); \
79 break; \
80 } \
81 __pu_err; \
82 })
83
84#define __put_user_bad() (bad_user_access_length(), (-EFAULT))
85
86#define put_user(x, ptr) __put_user(x, ptr)
87#define get_user(x, ptr) __get_user(x, ptr)
88
89#define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
90#define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
91
92#define __copy_to_user(to, from, n) (copy_to_user(to, from, n))
93#define __copy_from_user(to, from, n) (copy_from_user(to, from, n))
94#define __copy_to_user_inatomic(to, from, n) (__copy_to_user(to, from, n))
95#define __copy_from_user_inatomic(to, from, n) (__copy_from_user(to, from, n))
96
97#define __clear_user(addr, n) (memset((void *)addr, 0, n), 0)
98
99static inline unsigned long clear_user(void *addr, unsigned long size)
100{
101 if (access_ok(VERIFY_WRITE, addr, size))
102 size = __clear_user(addr, size);
103 return size;
104}
105
106/* Returns 0 if exception not found and fixup otherwise. */
107extern unsigned long search_exception_table(unsigned long);
108
109
110extern long strncpy_from_user(char *dst, const char __user *src, long count);
111extern long strnlen_user(const char __user *src, long count);
112extern long __strncpy_from_user(char *dst, const char __user *src, long count);
113
114/*
115 * The exception table consists of pairs of addresses: the first is the
116 * address of an instruction that is allowed to fault, and the second is
117 * the address at which the program should continue. No registers are
118 * modified, so it is entirely up to the continuation code to figure out
119 * what to do.
120 *
121 * All the routines below use bits of fixup code that are out of line
122 * with the main instruction path. This means when everything is well,
123 * we don't even have to jump over them. Further, they do not intrude
124 * on our cache or tlb entries.
125 */
126struct exception_table_entry {
127 unsigned long insn, fixup;
128};
129
130#endif /* __ASSEMBLY__ */
131#endif /* __KERNEL__ */
132
133#endif /* _ASM_MICROBLAZE_UACCESS_H */