blob: c0de7ee35ab7aa5ba80c393f4a2588102d01e2a1 [file] [log] [blame]
Paul Mundt02f7e622008-06-03 18:48:54 +09001/*
Paul Mundt9b01bd92007-11-10 19:55:50 +09002 * User space memory access functions
3 *
4 * Copyright (C) 1999, 2002 Niibe Yutaka
Paul Mundt02f7e622008-06-03 18:48:54 +09005 * Copyright (C) 2003 - 2008 Paul Mundt
Paul Mundt9b01bd92007-11-10 19:55:50 +09006 *
7 * Based on:
8 * MIPS implementation version 1.15 by
9 * Copyright (C) 1996, 1997, 1998 by Ralf Baechle
10 * and i386 version.
11 */
Magnus Damm1e6760c2008-02-07 19:50:52 +090012#ifndef __ASM_SH_UACCESS_32_H
13#define __ASM_SH_UACCESS_32_H
Paul Mundt9b01bd92007-11-10 19:55:50 +090014
Paul Mundt9b01bd92007-11-10 19:55:50 +090015#define __get_user_size(x,ptr,size,retval) \
16do { \
17 retval = 0; \
Paul Mundt9b01bd92007-11-10 19:55:50 +090018 switch (size) { \
19 case 1: \
20 __get_user_asm(x, ptr, retval, "b"); \
21 break; \
22 case 2: \
23 __get_user_asm(x, ptr, retval, "w"); \
24 break; \
25 case 4: \
26 __get_user_asm(x, ptr, retval, "l"); \
27 break; \
28 default: \
29 __get_user_unknown(); \
30 break; \
31 } \
32} while (0)
33
Paul Mundt42fd3b12008-06-03 20:05:39 +090034#ifdef CONFIG_MMU
Paul Mundt9b01bd92007-11-10 19:55:50 +090035#define __get_user_asm(x, addr, err, insn) \
36({ \
37__asm__ __volatile__( \
38 "1:\n\t" \
39 "mov." insn " %2, %1\n\t" \
Paul Mundt9b01bd92007-11-10 19:55:50 +090040 "2:\n" \
41 ".section .fixup,\"ax\"\n" \
42 "3:\n\t" \
43 "mov #0, %1\n\t" \
44 "mov.l 4f, %0\n\t" \
45 "jmp @%0\n\t" \
Stuart Menefy0fb19dc2007-11-30 18:16:23 +090046 " mov %3, %0\n\t" \
47 ".balign 4\n" \
Paul Mundt9b01bd92007-11-10 19:55:50 +090048 "4: .long 2b\n\t" \
49 ".previous\n" \
50 ".section __ex_table,\"a\"\n\t" \
51 ".long 1b, 3b\n\t" \
52 ".previous" \
53 :"=&r" (err), "=&r" (x) \
Stuart Menefy0fb19dc2007-11-30 18:16:23 +090054 :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); })
Paul Mundt42fd3b12008-06-03 20:05:39 +090055#else
56#define __get_user_asm(x, addr, err, insn) \
57do { \
58 __asm__ __volatile__ ( \
59 "mov." insn " %1, %0\n\t" \
60 : "=&r" (x) \
61 : "m" (__m(addr)) \
62 ); \
63} while (0)
64#endif /* CONFIG_MMU */
Paul Mundt9b01bd92007-11-10 19:55:50 +090065
66extern void __get_user_unknown(void);
67
68#define __put_user_size(x,ptr,size,retval) \
69do { \
70 retval = 0; \
Paul Mundt9b01bd92007-11-10 19:55:50 +090071 switch (size) { \
72 case 1: \
73 __put_user_asm(x, ptr, retval, "b"); \
74 break; \
75 case 2: \
76 __put_user_asm(x, ptr, retval, "w"); \
77 break; \
78 case 4: \
OGAWA Hirofumi6de9c642008-07-29 09:16:33 +090079 __put_user_asm(x, ptr, retval, "l"); \
Paul Mundt9b01bd92007-11-10 19:55:50 +090080 break; \
81 case 8: \
82 __put_user_u64(x, ptr, retval); \
83 break; \
84 default: \
85 __put_user_unknown(); \
86 } \
87} while (0)
88
Paul Mundt42fd3b12008-06-03 20:05:39 +090089#ifdef CONFIG_MMU
90#define __put_user_asm(x, addr, err, insn) \
91do { \
92 __asm__ __volatile__ ( \
93 "1:\n\t" \
94 "mov." insn " %1, %2\n\t" \
95 "2:\n" \
96 ".section .fixup,\"ax\"\n" \
97 "3:\n\t" \
98 "mov.l 4f, %0\n\t" \
99 "jmp @%0\n\t" \
100 " mov %3, %0\n\t" \
101 ".balign 4\n" \
102 "4: .long 2b\n\t" \
103 ".previous\n" \
104 ".section __ex_table,\"a\"\n\t" \
105 ".long 1b, 3b\n\t" \
106 ".previous" \
107 : "=&r" (err) \
108 : "r" (x), "m" (__m(addr)), "i" (-EFAULT), \
109 "0" (err) \
110 : "memory" \
111 ); \
112} while (0)
113#else
114#define __put_user_asm(x, addr, err, insn) \
115do { \
116 __asm__ __volatile__ ( \
117 "mov." insn " %0, %1\n\t" \
118 : /* no outputs */ \
119 : "r" (x), "m" (__m(addr)) \
120 : "memory" \
121 ); \
122} while (0)
123#endif /* CONFIG_MMU */
Paul Mundt9b01bd92007-11-10 19:55:50 +0900124
Stuart Menefy0fb19dc2007-11-30 18:16:23 +0900125#if defined(CONFIG_CPU_LITTLE_ENDIAN)
Paul Mundt9b01bd92007-11-10 19:55:50 +0900126#define __put_user_u64(val,addr,retval) \
127({ \
128__asm__ __volatile__( \
129 "1:\n\t" \
130 "mov.l %R1,%2\n\t" \
131 "mov.l %S1,%T2\n\t" \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900132 "2:\n" \
133 ".section .fixup,\"ax\"\n" \
134 "3:\n\t" \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900135 "mov.l 4f,%0\n\t" \
136 "jmp @%0\n\t" \
Stuart Menefy0fb19dc2007-11-30 18:16:23 +0900137 " mov %3,%0\n\t" \
138 ".balign 4\n" \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900139 "4: .long 2b\n\t" \
140 ".previous\n" \
141 ".section __ex_table,\"a\"\n\t" \
142 ".long 1b, 3b\n\t" \
143 ".previous" \
144 : "=r" (retval) \
Stuart Menefy0fb19dc2007-11-30 18:16:23 +0900145 : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900146 : "memory"); })
147#else
148#define __put_user_u64(val,addr,retval) \
149({ \
150__asm__ __volatile__( \
151 "1:\n\t" \
152 "mov.l %S1,%2\n\t" \
153 "mov.l %R1,%T2\n\t" \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900154 "2:\n" \
155 ".section .fixup,\"ax\"\n" \
156 "3:\n\t" \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900157 "mov.l 4f,%0\n\t" \
158 "jmp @%0\n\t" \
Stuart Menefy0fb19dc2007-11-30 18:16:23 +0900159 " mov %3,%0\n\t" \
160 ".balign 4\n" \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900161 "4: .long 2b\n\t" \
162 ".previous\n" \
163 ".section __ex_table,\"a\"\n\t" \
164 ".long 1b, 3b\n\t" \
165 ".previous" \
166 : "=r" (retval) \
Stuart Menefy0fb19dc2007-11-30 18:16:23 +0900167 : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \
Paul Mundt9b01bd92007-11-10 19:55:50 +0900168 : "memory"); })
169#endif
170
171extern void __put_user_unknown(void);
172
Magnus Damm1e6760c2008-02-07 19:50:52 +0900173#endif /* __ASM_SH_UACCESS_32_H */