summaryrefslogtreecommitdiff
path: root/arch/csky/include/asm/uaccess.h
blob: 2e927c21d8a1088eab960f9eeb6bdef43f7316e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __ASM_CSKY_UACCESS_H
#define __ASM_CSKY_UACCESS_H

/*
 * __put_user_fn
 */
extern int __put_user_bad(void);

#define __put_user_asm_b(x, ptr, err)			\
do {							\
	int errcode;					\
	__asm__ __volatile__(				\
	"1:     stb   %1, (%2,0)	\n"		\
	"       br    3f		\n"		\
	"2:     mov   %0, %3		\n"		\
	"       br    3f		\n"		\
	".section __ex_table, \"a\"	\n"		\
	".align   2			\n"		\
	".long    1b,2b			\n"		\
	".previous			\n"		\
	"3:				\n"		\
	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
	: "memory");					\
} while (0)

#define __put_user_asm_h(x, ptr, err)			\
do {							\
	int errcode;					\
	__asm__ __volatile__(				\
	"1:     sth   %1, (%2,0)	\n"		\
	"       br    3f		\n"		\
	"2:     mov   %0, %3		\n"		\
	"       br    3f		\n"		\
	".section __ex_table, \"a\"	\n"		\
	".align   2			\n"		\
	".long    1b,2b			\n"		\
	".previous			\n"		\
	"3:				\n"		\
	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
	: "memory");					\
} while (0)

#define __put_user_asm_w(x, ptr, err)			\
do {							\
	int errcode;					\
	__asm__ __volatile__(				\
	"1:     stw   %1, (%2,0)	\n"		\
	"       br    3f		\n"		\
	"2:     mov   %0, %3		\n"		\
	"       br    3f		\n"		\
	".section __ex_table,\"a\"	\n"		\
	".align   2			\n"		\
	".long    1b, 2b		\n"		\
	".previous			\n"		\
	"3:				\n"		\
	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
	: "memory");					\
} while (0)

#define __put_user_asm_64(x, ptr, err)			\
do {							\
	int tmp;					\
	int errcode;					\
							\
	__asm__ __volatile__(				\
	"     ldw     %3, (%1, 0)     \n"		\
	"1:   stw     %3, (%2, 0)     \n"		\
	"     ldw     %3, (%1, 4)     \n"		\
	"2:   stw     %3, (%2, 4)     \n"		\
	"     br      4f              \n"		\
	"3:   mov     %0, %4          \n"		\
	"     br      4f              \n"		\
	".section __ex_table, \"a\"   \n"		\
	".align   2                   \n"		\
	".long    1b, 3b              \n"		\
	".long    2b, 3b              \n"		\
	".previous                    \n"		\
	"4:                           \n"		\
	: "=r"(err), "=r"(x), "=r"(ptr),		\
	  "=r"(tmp), "=r"(errcode)			\
	: "0"(err), "1"(x), "2"(ptr), "3"(0),		\
	  "4"(-EFAULT)					\
	: "memory");					\
} while (0)

static inline int __put_user_fn(size_t size, void __user *ptr, void *x)
{
	int retval = 0;
	u32 tmp;

	switch (size) {
	case 1:
		tmp = *(u8 *)x;
		__put_user_asm_b(tmp, ptr, retval);
		break;
	case 2:
		tmp = *(u16 *)x;
		__put_user_asm_h(tmp, ptr, retval);
		break;
	case 4:
		tmp = *(u32 *)x;
		__put_user_asm_w(tmp, ptr, retval);
		break;
	case 8:
		__put_user_asm_64(x, (u64 *)ptr, retval);
		break;
	}

	return retval;
}
#define __put_user_fn __put_user_fn

/*
 * __get_user_fn
 */
extern int __get_user_bad(void);

#define __get_user_asm_common(x, ptr, ins, err)		\
do {							\
	int errcode;					\
	__asm__ __volatile__(				\
	"1:   " ins " %1, (%4, 0)	\n"		\
	"       br    3f		\n"		\
	"2:     mov   %0, %2		\n"		\
	"       movi  %1, 0		\n"		\
	"       br    3f		\n"		\
	".section __ex_table,\"a\"      \n"		\
	".align   2			\n"		\
	".long    1b, 2b		\n"		\
	".previous			\n"		\
	"3:				\n" 		\
	: "=r"(err), "=r"(x), "=r"(errcode)		\
	: "0"(0), "r"(ptr), "2"(-EFAULT)		\
	: "memory");					\
} while (0)

#define __get_user_asm_64(x, ptr, err)			\
do {							\
	int tmp;					\
	int errcode;					\
							\
	__asm__ __volatile__(				\
	"1:   ldw     %3, (%2, 0)     \n"		\
	"     stw     %3, (%1, 0)     \n"		\
	"2:   ldw     %3, (%2, 4)     \n"		\
	"     stw     %3, (%1, 4)     \n"		\
	"     br      4f              \n"		\
	"3:   mov     %0, %4          \n"		\
	"     br      4f              \n"		\
	".section __ex_table, \"a\"   \n"		\
	".align   2                   \n"		\
	".long    1b, 3b              \n"		\
	".long    2b, 3b              \n"		\
	".previous                    \n"		\
	"4:                           \n"		\
	: "=r"(err), "=r"(x), "=r"(ptr),		\
	  "=r"(tmp), "=r"(errcode)			\
	: "0"(err), "1"(x), "2"(ptr), "3"(0),		\
	  "4"(-EFAULT)					\
	: "memory");					\
} while (0)

static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
{
	int retval;
	u32 tmp;

	switch (size) {
	case 1:
		__get_user_asm_common(tmp, ptr, "ldb", retval);
		*(u8 *)x = (u8)tmp;
		break;
	case 2:
		__get_user_asm_common(tmp, ptr, "ldh", retval);
		*(u16 *)x = (u16)tmp;
		break;
	case 4:
		__get_user_asm_common(tmp, ptr, "ldw", retval);
		*(u32 *)x = (u32)tmp;
		break;
	case 8:
		__get_user_asm_64(x, ptr, retval);
		break;
	}

	return retval;
}
#define __get_user_fn __get_user_fn

unsigned long raw_copy_from_user(void *to, const void *from, unsigned long n);
unsigned long raw_copy_to_user(void *to, const void *from, unsigned long n);

unsigned long __clear_user(void __user *to, unsigned long n);
#define __clear_user __clear_user

#include <asm-generic/uaccess.h>

#endif /* __ASM_CSKY_UACCESS_H */