1 #ifndef _ASM_M32R_SYSTEM_H
2 #define _ASM_M32R_SYSTEM_H
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
9 * Copyright (C) 2001 Hiroyuki Kondo, Hirokazu Takata, and Hitoshi Yamamoto
10 * Copyright (C) 2004, 2006 Hirokazu Takata <takata at linux-m32r.org>
13 #include <linux/compiler.h>
14 #include <asm/assembler.h>
19 * switch_to(prev, next) should switch from task `prev' to `next'
20 * `prev' will never be the same as `next'.
22 * `next' and `prev' should be struct task_struct, but it isn't always defined
25 #if defined(CONFIG_FRAME_POINTER) || \
26 !defined(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER)
27 #define M32R_PUSH_FP " push fp\n"
28 #define M32R_POP_FP " pop fp\n"
30 #define M32R_PUSH_FP ""
31 #define M32R_POP_FP ""
34 #define switch_to(prev, next, last) do { \
35 __asm__ __volatile__ ( \
36 " seth lr, #high(1f) \n" \
37 " or3 lr, lr, #low(1f) \n" \
38 " st lr, @%4 ; store old LR \n" \
39 " ld lr, @%5 ; load new LR \n" \
41 " st sp, @%2 ; store old SP \n" \
42 " ld sp, @%3 ; load new SP \n" \
43 " push %1 ; store `prev' on new stack \n" \
47 " pop %0 ; restore `__last' from new stack \n" \
51 "r" (&(prev->thread.sp)), "r" (&(next->thread.sp)), \
52 "r" (&(prev->thread.lr)), "r" (&(next->thread.lr)) \
57 /* Interrupt Control */
58 #if !defined(CONFIG_CHIP_M32102) && !defined(CONFIG_CHIP_M32104)
59 #define local_irq_enable() \
60 __asm__ __volatile__ ("setpsw #0x40 -> nop": : :"memory")
61 #define local_irq_disable() \
62 __asm__ __volatile__ ("clrpsw #0x40 -> nop": : :"memory")
63 #else /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
64 static inline void local_irq_enable(void)
69 "or3 %0, %0, #0x0040; \n\t"
71 : "=&r" (tmpreg
) : : "cbit", "memory");
74 static inline void local_irq_disable(void)
76 unsigned long tmpreg0
, tmpreg1
;
78 "ld24 %0, #0 ; Use 32-bit insn. \n\t"
79 "mvfc %1, psw ; No interrupt can be accepted here. \n\t"
81 "and3 %0, %1, #0xffbf \n\t"
83 : "=&r" (tmpreg0
), "=&r" (tmpreg1
) : : "cbit", "memory");
85 #endif /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
87 #define local_save_flags(x) \
88 __asm__ __volatile__("mvfc %0,psw" : "=r"(x) : /* no input */)
90 #define local_irq_restore(x) \
91 __asm__ __volatile__("mvtc %0,psw" : /* no outputs */ \
92 : "r" (x) : "cbit", "memory")
94 #if !(defined(CONFIG_CHIP_M32102) || defined(CONFIG_CHIP_M32104))
95 #define local_irq_save(x) \
96 __asm__ __volatile__( \
97 "mvfc %0, psw; \n\t" \
98 "clrpsw #0x40 -> nop; \n\t" \
99 : "=r" (x) : /* no input */ : "memory")
100 #else /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
101 #define local_irq_save(x) \
103 unsigned long tmpreg; \
104 __asm__ __volatile__( \
106 "mvfc %0, psw \n\t" \
107 "mvtc %1, psw \n\t" \
108 "and3 %1, %0, #0xffbf \n\t" \
109 "mvtc %1, psw \n\t" \
110 : "=r" (x), "=&r" (tmpreg) \
111 : : "cbit", "memory"); \
113 #endif /* CONFIG_CHIP_M32102 || CONFIG_CHIP_M32104 */
115 #define irqs_disabled() \
117 unsigned long flags; \
118 local_save_flags(flags); \
122 #define nop() __asm__ __volatile__ ("nop" : : )
124 #define xchg(ptr,x) \
125 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
128 extern void __xchg_called_with_bad_pointer(void);
131 #ifdef CONFIG_CHIP_M32700_TS1
132 #define DCACHE_CLEAR(reg0, reg1, addr) \
133 "seth "reg1", #high(dcache_dummy); \n\t" \
134 "or3 "reg1", "reg1", #low(dcache_dummy); \n\t" \
135 "lock "reg0", @"reg1"; \n\t" \
136 "add3 "reg0", "addr", #0x1000; \n\t" \
137 "ld "reg0", @"reg0"; \n\t" \
138 "add3 "reg0", "addr", #0x2000; \n\t" \
139 "ld "reg0", @"reg0"; \n\t" \
140 "unlock "reg0", @"reg1"; \n\t"
141 /* FIXME: This workaround code cannot handle kernel modules
142 * correctly under SMP environment.
144 #else /* CONFIG_CHIP_M32700_TS1 */
145 #define DCACHE_CLEAR(reg0, reg1, addr)
146 #endif /* CONFIG_CHIP_M32700_TS1 */
148 static __always_inline
unsigned long
149 __xchg(unsigned long x
, volatile void * ptr
, int size
)
152 unsigned long tmp
= 0;
154 local_irq_save(flags
);
159 __asm__
__volatile__ (
162 : "=&r" (tmp
) : "r" (x
), "r" (ptr
) : "memory");
165 __asm__
__volatile__ (
168 : "=&r" (tmp
) : "r" (x
), "r" (ptr
) : "memory");
171 __asm__
__volatile__ (
174 : "=&r" (tmp
) : "r" (x
), "r" (ptr
) : "memory");
176 #else /* CONFIG_SMP */
178 __asm__
__volatile__ (
179 DCACHE_CLEAR("%0", "r4", "%2")
181 "unlock %1, @%2; \n\t"
182 : "=&r" (tmp
) : "r" (x
), "r" (ptr
)
184 #ifdef CONFIG_CHIP_M32700_TS1
186 #endif /* CONFIG_CHIP_M32700_TS1 */
190 __xchg_called_with_bad_pointer();
191 #endif /* CONFIG_SMP */
194 local_irq_restore(flags
);
199 #define __HAVE_ARCH_CMPXCHG 1
201 static inline unsigned long
202 __cmpxchg_u32(volatile unsigned int *p
, unsigned int old
, unsigned int new)
207 local_irq_save(flags
);
208 __asm__
__volatile__ (
209 DCACHE_CLEAR("%0", "r4", "%1")
210 M32R_LOCK
" %0, @%1; \n"
211 " bne %0, %2, 1f; \n"
212 M32R_UNLOCK
" %3, @%1; \n"
216 M32R_UNLOCK
" %0, @%1; \n"
220 : "r" (p
), "r" (old
), "r" (new)
222 #ifdef CONFIG_CHIP_M32700_TS1
224 #endif /* CONFIG_CHIP_M32700_TS1 */
226 local_irq_restore(flags
);
231 /* This function doesn't exist, so you'll get a linker error
232 if something tries to do an invalid cmpxchg(). */
233 extern void __cmpxchg_called_with_bad_pointer(void);
235 static inline unsigned long
236 __cmpxchg(volatile void *ptr
, unsigned long old
, unsigned long new, int size
)
240 return __cmpxchg_u32(ptr
, old
, new);
241 #if 0 /* we don't have __cmpxchg_u64 */
243 return __cmpxchg_u64(ptr
, old
, new);
246 __cmpxchg_called_with_bad_pointer();
250 #define cmpxchg(ptr,o,n) \
252 __typeof__(*(ptr)) _o_ = (o); \
253 __typeof__(*(ptr)) _n_ = (n); \
254 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
255 (unsigned long)_n_, sizeof(*(ptr))); \
258 #endif /* __KERNEL__ */
263 * mb() prevents loads and stores being reordered across this point.
264 * rmb() prevents loads being reordered across this point.
265 * wmb() prevents stores being reordered across this point.
267 #define mb() barrier()
272 * read_barrier_depends - Flush all pending reads that subsequents reads
275 * No data-dependent reads from memory-like regions are ever reordered
276 * over this barrier. All reads preceding this primitive are guaranteed
277 * to access memory (but not necessarily other CPUs' caches) before any
278 * reads following this primitive that depend on the data return by
279 * any of the preceding reads. This primitive is much lighter weight than
280 * rmb() on most CPUs, and is never heavier weight than is
283 * These ordering constraints are respected by both the local CPU
286 * Ordering is not guaranteed by anything other than these primitives,
287 * not even by data dependencies. See the documentation for
288 * memory_barrier() for examples and URLs to more information.
290 * For example, the following code would force ordering (the initial
291 * value of "a" is zero, "b" is one, and "p" is "&a"):
299 * read_barrier_depends();
304 * because the read of "*q" depends on the read of "p" and these
305 * two reads are separated by a read_barrier_depends(). However,
306 * the following code, with the same initial values for "a" and "b":
314 * read_barrier_depends();
318 * does not enforce ordering, since there is no data dependency between
319 * the read of "a" and the read of "b". Therefore, on some CPUs, such
320 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
321 * in cases like this where there are no data dependencies.
324 #define read_barrier_depends() do { } while (0)
327 #define smp_mb() mb()
328 #define smp_rmb() rmb()
329 #define smp_wmb() wmb()
330 #define smp_read_barrier_depends() read_barrier_depends()
331 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
333 #define smp_mb() barrier()
334 #define smp_rmb() barrier()
335 #define smp_wmb() barrier()
336 #define smp_read_barrier_depends() do { } while (0)
337 #define set_mb(var, value) do { var = value; barrier(); } while (0)
340 #define arch_align_stack(x) (x)
342 #endif /* _ASM_M32R_SYSTEM_H */