2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 by Ralf Baechle
7 * Modified further for R[236]000 by Paul M. Antoine, 1996
8 * Copyright (C) 1999 Silicon Graphics
13 #include <linux/config.h>
14 #include <asm/sgidefs.h>
16 #include <linux/kernel.h>
18 #include <asm/addrspace.h>
19 #include <asm/ptrace.h>
33 extern __inline__ void
44 * For cli() we have to insert nops to make sure that the new value
45 * has actually arrived in the status register before the end of this
47 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
60 "sll\t$0, $0, 1\t\t\t# nop\n\t"
61 "sll\t$0, $0, 1\t\t\t# nop\n\t"
62 "sll\t$0, $0, 1\t\t\t# nop\n\t"
66 extern __inline__ void
77 ".macro\t__save_flags flags\n\t"
80 "mfc0\t\\flags, $12\n\t"
84 #define __save_flags(x) \
85 __asm__ __volatile__( \
90 ".macro\t__save_and_cli result\n\t"
94 "mfc0\t\\result, $12\n\t"
95 "ori\t$1, \\result, 1\n\t"
99 "sll\t$0, $0, 1\t\t\t# nop\n\t"
100 "sll\t$0, $0, 1\t\t\t# nop\n\t"
101 "sll\t$0, $0, 1\t\t\t# nop\n\t"
105 #define __save_and_cli(x) \
106 __asm__ __volatile__( \
107 "__save_and_cli\t%0" \
112 #define __save_and_sti(x) do { __save_flags(x); __sti(); } while(0);
114 __asm__(".macro\t__restore_flags flags\n\t"
115 ".set\tnoreorder\n\t"
118 "andi\t\\flags, 1\n\t"
121 "or\t\\flags, $1\n\t"
122 "mtc0\t\\flags, $12\n\t"
123 "sll\t$0, $0, 1\t\t\t# nop\n\t"
124 "sll\t$0, $0, 1\t\t\t# nop\n\t"
125 "sll\t$0, $0, 1\t\t\t# nop\n\t"
130 #define __restore_flags(flags) \
132 unsigned long __tmp1; \
134 __asm__ __volatile__( \
135 "__restore_flags\t%0" \
143 extern void __global_cli(void);
144 extern void __global_sti(void);
145 extern unsigned long __global_save_flags(void);
146 extern void __global_restore_flags(unsigned long);
147 #define cli() __global_cli()
148 #define sti() __global_sti()
149 #define save_flags(x) ((x)=__global_save_flags())
150 #define restore_flags(x) __global_restore_flags(x)
151 #define save_and_cli(x) do { save_flags(x); cli(); } while(0)
152 #define save_and_sti(x) do { save_flags(x); sti(); } while(0)
156 #define cli() __cli()
157 #define sti() __sti()
158 #define save_flags(x) __save_flags(x)
159 #define restore_flags(x) __restore_flags(x)
160 #define save_and_cli(x) __save_and_cli(x)
161 #define save_and_sti(x) __save_and_sti(x)
163 #endif /* CONFIG_SMP */
165 /* For spinlocks etc */
166 #define local_irq_save(x) __save_and_cli(x)
167 #define local_irq_set(x) __save_and_sti(x)
168 #define local_irq_restore(x) __restore_flags(x)
169 #define local_irq_disable() __cli()
170 #define local_irq_enable() __sti()
173 __asm__ __volatile__( \
175 ".set noreorder\n\t" \
182 #define fast_wmb() __sync()
183 #define fast_rmb() __sync()
184 #define fast_mb() __sync()
188 __asm__ __volatile__( \
190 ".set noreorder\n\t" \
195 : "m" (*(int *)KSEG1) \
199 #define wmb() fast_wmb()
200 #define rmb() fast_rmb()
201 #define mb() fast_mb()
202 #define iob() fast_iob()
205 #define smp_mb() mb()
206 #define smp_rmb() rmb()
207 #define smp_wmb() wmb()
209 #define smp_mb() barrier()
210 #define smp_rmb() barrier()
211 #define smp_wmb() barrier()
214 #define set_mb(var, value) \
215 do { var = value; mb(); } while (0)
217 #define set_wmb(var, value) \
218 do { var = value; wmb(); } while (0)
221 * switch_to(n) should switch tasks to task nr n, first
222 * checking that n isn't the current task, in which case it does nothing.
224 extern asmlinkage void *resume(void *last, void *next);
226 #define prepare_to_switch() do { } while(0)
230 extern asmlinkage void lazy_fpu_switch(void *, void *);
231 extern asmlinkage void init_fpu(void);
232 extern asmlinkage void save_fp(struct task_struct *);
233 extern asmlinkage void restore_fp(struct task_struct *);
236 #define SWITCH_DO_LAZY_FPU \
237 if (prev->flags & PF_USEDFPU) { \
238 lazy_fpu_switch(prev, 0); \
239 clear_cp0_status(ST0_CU1); \
240 prev->flags &= ~PF_USEDFPU; \
242 #else /* CONFIG_SMP */
243 #define SWITCH_DO_LAZY_FPU do { } while(0)
244 #endif /* CONFIG_SMP */
246 #define switch_to(prev,next,last) \
248 SWITCH_DO_LAZY_FPU; \
249 (last) = resume(prev, next); \
252 extern __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val)
256 __asm__ __volatile__(
257 ".set\tpush\t\t\t\t# xchg_u32\n\t"
258 ".set\tnoreorder\n\t"
261 "1:\tmove\t%2, %z4\n\t"
267 : "=&r" (val), "=m" (*m), "=&r" (dummy)
268 : "R" (*m), "Jr" (val)
274 extern __inline__ unsigned long xchg_u64(volatile int * m, unsigned long val)
278 __asm__ __volatile__(
279 ".set\tpush\t\t\t\t# xchg_u64\n\t"
280 ".set\tnoreorder\n\t"
283 "1:\tmove\t%2, %z4\n\t"
289 : "=&r" (val), "=m" (*m), "=&r" (dummy)
290 : "R" (*m), "Jr" (val)
296 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
297 #define tas(ptr) (xchg((ptr),1))
300 static inline unsigned long __xchg(unsigned long x, volatile void * ptr,
305 return xchg_u32(ptr, x);
307 return xchg_u64(ptr, x);
312 extern void *set_except_vector(int n, void *addr);
314 extern void __die(const char *, struct pt_regs *, const char *file,
315 const char *func, unsigned long line) __attribute__((noreturn));
316 extern void __die_if_kernel(const char *, struct pt_regs *, const char *file,
317 const char *func, unsigned long line);
319 #define die(msg, regs) \
320 __die(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
321 #define die_if_kernel(msg, regs) \
322 __die_if_kernel(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
324 #endif /* _ASM_SYSTEM_H */