4 #include <linux/linkage.h>
5 #include <linux/kernel.h>
6 #include <asm/segment.h>
12 * switch_to(n) should switch tasks to task ptr, first checking that
13 * ptr isn't the current task, in which case it does nothing. This
14 * also clears the TS-flag if the task we switched to has used the
15 * math co-processor latest.
18 * switch_to() saves the extra registers, that are not saved
19 * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
20 * a0-a1. Some of these are used by schedule() and its predecessors
21 * and so we might get see unexpected behaviors when a task returns
22 * with unexpected register values.
24 * syscall stores these registers itself and none of them are used
25 * by syscall after the function in the syscall has been called.
27 * Beware that resume now expects *next to be in d1 and the offset of
28 * tss to be in a1. This saves a few instructions as we no longer have
29 * to push them onto the stack and read them back right after.
31 * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
33 * Changed 96/09/19 by Andreas Schwab
34 * pass prev in a0, next in a1
36 asmlinkage void resume(void);
37 #define switch_to(prev,next,last) do { \
38 register void *_prev __asm__ ("a0") = (prev); \
39 register void *_next __asm__ ("a1") = (next); \
40 register void *_last __asm__ ("d1"); \
41 __asm__ __volatile__("jbsr resume" \
42 : "=a" (_prev), "=a" (_next), "=d" (_last) \
43 : "0" (_prev), "1" (_next) \
44 : "d0", "d2", "d3", "d4", "d5"); \
49 /* interrupt control.. */
51 #define local_irq_enable() asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory")
53 #include <linux/hardirq.h>
54 #define local_irq_enable() ({ \
55 if (MACH_IS_Q40 || !hardirq_count()) \
56 asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory"); \
59 #define local_irq_disable() asm volatile ("oriw #0x0700,%%sr": : : "memory")
60 #define local_save_flags(x) asm volatile ("movew %%sr,%0":"=d" (x) : : "memory")
61 #define local_irq_restore(x) asm volatile ("movew %0,%%sr": :"d" (x) : "memory")
63 static inline int irqs_disabled(void)
66 local_save_flags(flags);
67 return flags & ~ALLOWINT;
70 /* For spinlocks etc */
71 #define local_irq_save(x) ({ local_save_flags(x); local_irq_disable(); })
74 * Force strict CPU ordering.
75 * Not really required on m68k...
77 #define nop() do { asm volatile ("nop"); barrier(); } while (0)
78 #define mb() barrier()
79 #define rmb() barrier()
80 #define wmb() barrier()
81 #define read_barrier_depends() do { } while(0)
82 #define set_mb(var, value) do { xchg(&var, value); } while (0)
83 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
85 #define smp_mb() barrier()
86 #define smp_rmb() barrier()
87 #define smp_wmb() barrier()
88 #define smp_read_barrier_depends() do { } while(0)
91 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
92 #define tas(ptr) (xchg((ptr),1))
94 struct __xchg_dummy { unsigned long a[100]; };
95 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
97 #ifndef CONFIG_RMW_INSNS
98 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
100 unsigned long flags, tmp;
102 local_irq_save(flags);
124 local_irq_restore(flags);
128 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
137 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
145 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
153 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
161 * Atomic compare and exchange. Compare OLD with MEM, if identical,
162 * store NEW in MEM. Return the initial value in MEM. Success is
163 * indicated by comparing RETURN with OLD.
165 #ifdef CONFIG_RMW_INSNS
166 #define __HAVE_ARCH_CMPXCHG 1
168 static inline unsigned long __cmpxchg(volatile void *p, unsigned long old,
169 unsigned long new, int size)
173 __asm__ __volatile__ ("casb %0,%2,%1"
174 : "=d" (old), "=m" (*(char *)p)
175 : "d" (new), "0" (old), "m" (*(char *)p));
178 __asm__ __volatile__ ("casw %0,%2,%1"
179 : "=d" (old), "=m" (*(short *)p)
180 : "d" (new), "0" (old), "m" (*(short *)p));
183 __asm__ __volatile__ ("casl %0,%2,%1"
184 : "=d" (old), "=m" (*(int *)p)
185 : "d" (new), "0" (old), "m" (*(int *)p));
191 #define cmpxchg(ptr,o,n)\
192 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
193 (unsigned long)(n),sizeof(*(ptr))))
196 #define arch_align_stack(x) (x)
198 #endif /* __KERNEL__ */
200 #endif /* _M68K_SYSTEM_H */