1 #ifndef __ASM_SH_SYSTEM_H
2 #define __ASM_SH_SYSTEM_H
5 * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
6 * Copyright (C) 2002 Paul Mundt
9 #include <linux/irqflags.h>
10 #include <linux/compiler.h>
11 #include <asm/types.h>
14 * switch_to() should switch tasks to task nr n, first
17 #define switch_to(prev, next, last) do { \
18 struct task_struct *__last; \
19 register unsigned long *__ts1 __asm__ ("r1") = &prev->thread.sp; \
20 register unsigned long *__ts2 __asm__ ("r2") = &prev->thread.pc; \
21 register unsigned long *__ts4 __asm__ ("r4") = (unsigned long *)prev; \
22 register unsigned long *__ts5 __asm__ ("r5") = (unsigned long *)next; \
23 register unsigned long *__ts6 __asm__ ("r6") = &next->thread.sp; \
24 register unsigned long __ts7 __asm__ ("r7") = next->thread.pc; \
25 __asm__ __volatile__ (".balign 4\n\t" \
26 "stc.l gbr, @-r15\n\t" \
27 "sts.l pr, @-r15\n\t" \
28 "mov.l r8, @-r15\n\t" \
29 "mov.l r9, @-r15\n\t" \
30 "mov.l r10, @-r15\n\t" \
31 "mov.l r11, @-r15\n\t" \
32 "mov.l r12, @-r15\n\t" \
33 "mov.l r13, @-r15\n\t" \
34 "mov.l r14, @-r15\n\t" \
35 "mov.l r15, @r1 ! save SP\n\t" \
36 "mov.l @r6, r15 ! change to new stack\n\t" \
38 "mov.l %0, @r2 ! save PC\n\t" \
40 "jmp @%0 ! call __switch_to\n\t" \
41 " lds r7, pr ! with return to new PC\n\t" \
44 ".long __switch_to\n" \
46 "mov.l @r15+, r14\n\t" \
47 "mov.l @r15+, r13\n\t" \
48 "mov.l @r15+, r12\n\t" \
49 "mov.l @r15+, r11\n\t" \
50 "mov.l @r15+, r10\n\t" \
51 "mov.l @r15+, r9\n\t" \
52 "mov.l @r15+, r8\n\t" \
53 "lds.l @r15+, pr\n\t" \
54 "ldc.l @r15+, gbr\n\t" \
56 : "r" (__ts1), "r" (__ts2), "r" (__ts4), \
57 "r" (__ts5), "r" (__ts6), "r" (__ts7) \
63 * On SMP systems, when the scheduler does migration-cost autodetection,
64 * it needs a way to flush as much of the CPU's caches as possible.
68 static inline void sched_cacheflush(void)
72 #ifdef CONFIG_CPU_SH4A
75 unsigned long __addr; \
76 __addr = 0xa8000000; \
77 __asm__ __volatile__( \
80 : "m" (__m(__addr))); \
84 static inline unsigned long tas(volatile int *m
)
88 __asm__
__volatile__ ("tas.b @%1\n\t"
90 : "=r" (retval
): "r" (m
): "t", "memory");
95 * A brief note on ctrl_barrier(), the control register write barrier.
97 * Legacy SH cores typically require a sequence of 8 nops after
98 * modification of a control register in order for the changes to take
99 * effect. On newer cores (like the sh4a and sh5) this is accomplished
102 * Also note that on sh4a in the icbi case we can forego a synco for the
103 * write barrier, as it's not necessary for control registers.
105 * Historically we have only done this type of barrier for the MMUCR, but
106 * it's also necessary for the CCR, so we make it generic here instead.
108 #ifdef CONFIG_CPU_SH4A
109 #define mb() __asm__ __volatile__ ("synco": : :"memory")
111 #define wmb() __asm__ __volatile__ ("synco": : :"memory")
112 #define ctrl_barrier() __icbi()
113 #define read_barrier_depends() do { } while(0)
115 #define mb() __asm__ __volatile__ ("": : :"memory")
117 #define wmb() __asm__ __volatile__ ("": : :"memory")
118 #define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
119 #define read_barrier_depends() do { } while(0)
123 #define smp_mb() mb()
124 #define smp_rmb() rmb()
125 #define smp_wmb() wmb()
126 #define smp_read_barrier_depends() read_barrier_depends()
128 #define smp_mb() barrier()
129 #define smp_rmb() barrier()
130 #define smp_wmb() barrier()
131 #define smp_read_barrier_depends() do { } while(0)
134 #define set_mb(var, value) do { xchg(&var, value); } while (0)
138 * When handling TLB or caches, we need to do it from P2 area.
140 #define jump_to_P2() \
142 unsigned long __dummy; \
143 __asm__ __volatile__( \
152 : "r" (0x20000000)); \
158 #define back_to_P1() \
160 unsigned long __dummy; \
162 __asm__ __volatile__( \
169 : "=&r" (__dummy)); \
172 static inline unsigned long xchg_u32(volatile u32
*m
, unsigned long val
)
174 unsigned long flags
, retval
;
176 local_irq_save(flags
);
179 local_irq_restore(flags
);
183 static inline unsigned long xchg_u8(volatile u8
*m
, unsigned long val
)
185 unsigned long flags
, retval
;
187 local_irq_save(flags
);
190 local_irq_restore(flags
);
194 extern void __xchg_called_with_bad_pointer(void);
196 #define __xchg(ptr, x, size) \
198 unsigned long __xchg__res; \
199 volatile void *__xchg_ptr = (ptr); \
202 __xchg__res = xchg_u32(__xchg_ptr, x); \
205 __xchg__res = xchg_u8(__xchg_ptr, x); \
208 __xchg_called_with_bad_pointer(); \
216 #define xchg(ptr,x) \
217 ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
219 static inline unsigned long __cmpxchg_u32(volatile int * m
, unsigned long old
,
225 local_irq_save(flags
);
229 local_irq_restore(flags
); /* implies memory barrier */
233 /* This function doesn't exist, so you'll get a linker error
234 * if something tries to do an invalid cmpxchg(). */
235 extern void __cmpxchg_called_with_bad_pointer(void);
237 #define __HAVE_ARCH_CMPXCHG 1
239 static inline unsigned long __cmpxchg(volatile void * ptr
, unsigned long old
,
240 unsigned long new, int size
)
244 return __cmpxchg_u32(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 extern void *set_exception_table_vec(unsigned int vec
, void *handler
);
260 static inline void *set_exception_table_evt(unsigned int evt
, void *handler
)
262 return set_exception_table_vec(evt
>> 5, handler
);
266 * disable hlt during certain critical i/o operations
268 #define HAVE_DISABLE_HLT
269 void disable_hlt(void);
270 void enable_hlt(void);
272 #define arch_align_stack(x) (x)