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 - 1999 by Ralf Baechle
7 * Copyright (C) 1996 by Paul M. Antoine
8 * Copyright (C) 1994 - 1999 by Ralf Baechle
10 * Changed set_except_vector declaration to allow return of previous
11 * vector address value - necessary for "borrowing" vectors.
13 * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
14 * Copyright (C) 2000 MIPS Technologies, Inc.
19 #include <linux/config.h>
20 #include <asm/sgidefs.h>
22 #include <linux/kernel.h>
24 #include <asm/addrspace.h>
25 #include <asm/ptrace.h>
39 extern __inline__ void
50 * For cli() we have to insert nops to make sure that the new value
51 * has actually arrived in the status register before the end of this
53 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
65 "sll\t$0, $0, 1\t\t\t# nop\n\t"
66 "sll\t$0, $0, 1\t\t\t# nop\n\t"
67 "sll\t$0, $0, 1\t\t\t# nop\n\t"
71 extern __inline__ void
82 ".macro\t__save_flags flags\n\t"
85 "mfc0\t\\flags, $12\n\t"
89 #define __save_flags(x) \
90 __asm__ __volatile__( \
95 ".macro\t__save_and_cli result\n\t"
99 "mfc0\t\\result, $12\n\t"
100 "ori\t$1, \\result, 1\n\t"
102 ".set\tnoreorder\n\t"
104 "sll\t$0, $0, 1\t\t\t# nop\n\t"
105 "sll\t$0, $0, 1\t\t\t# nop\n\t"
106 "sll\t$0, $0, 1\t\t\t# nop\n\t"
110 #define __save_and_cli(x) \
111 __asm__ __volatile__( \
112 "__save_and_cli\t%0" \
117 #define __save_and_sti(x) do { __save_flags(x); __sti(); } while(0);
119 __asm__(".macro\t__restore_flags flags\n\t"
120 ".set\tnoreorder\n\t"
123 "andi\t\\flags, 1\n\t"
126 "or\t\\flags, $1\n\t"
127 "mtc0\t\\flags, $12\n\t"
128 "sll\t$0, $0, 1\t\t\t# nop\n\t"
129 "sll\t$0, $0, 1\t\t\t# nop\n\t"
130 "sll\t$0, $0, 1\t\t\t# nop\n\t"
135 #define __restore_flags(flags) \
137 unsigned long __tmp1; \
139 __asm__ __volatile__( \
140 "__restore_flags\t%0" \
148 extern void __global_sti(void);
149 extern void __global_cli(void);
150 extern unsigned long __global_save_flags(void);
151 extern void __global_restore_flags(unsigned long);
152 # define sti() __global_sti()
153 # define cli() __global_cli()
154 # define save_flags(x) do { x = __global_save_flags(); } while (0)
155 # define restore_flags(x) __global_restore_flags(x)
156 # define save_and_cli(x) do { save_flags(x); cli(); } while(0)
157 # define save_and_sti(x) do { save_flags(x); sti(); } while(0)
159 #else /* Single processor */
161 # define sti() __sti()
162 # define cli() __cli()
163 # define save_flags(x) __save_flags(x)
164 # define save_and_cli(x) __save_and_cli(x)
165 # define restore_flags(x) __restore_flags(x)
166 # define save_and_sti(x) __save_and_sti(x)
170 /* For spinlocks etc */
171 #define local_irq_save(x) __save_and_cli(x)
172 #define local_irq_set(x) __save_and_sti(x)
173 #define local_irq_restore(x) __restore_flags(x)
174 #define local_irq_disable() __cli()
175 #define local_irq_enable() __sti()
177 #ifdef CONFIG_CPU_HAS_SYNC
179 __asm__ __volatile__( \
181 ".set noreorder\n\t" \
189 #define __sync() do { } while(0)
192 #define __fast_iob() \
193 __asm__ __volatile__( \
195 ".set noreorder\n\t" \
200 : "m" (*(int *)KSEG1) \
203 #define fast_wmb() __sync()
204 #define fast_rmb() __sync()
205 #define fast_mb() __sync()
212 #ifdef CONFIG_CPU_HAS_WB
214 #include <asm/wbflush.h>
216 #define wmb() fast_wmb()
217 #define rmb() fast_rmb()
218 #define mb() wbflush();
219 #define iob() wbflush();
221 #else /* !CONFIG_CPU_HAS_WB */
223 #define wmb() fast_wmb()
224 #define rmb() fast_rmb()
225 #define mb() fast_mb()
226 #define iob() fast_iob()
228 #endif /* !CONFIG_CPU_HAS_WB */
231 #define smp_mb() mb()
232 #define smp_rmb() rmb()
233 #define smp_wmb() wmb()
235 #define smp_mb() barrier()
236 #define smp_rmb() barrier()
237 #define smp_wmb() barrier()
240 #define set_mb(var, value) \
241 do { var = value; mb(); } while (0)
243 #define set_wmb(var, value) \
244 do { var = value; wmb(); } while (0)
248 * switch_to(n) should switch tasks to task nr n, first
249 * checking that n isn't the current task, in which case it does nothing.
251 extern asmlinkage void *resume(void *last, void *next);
252 #endif /* !__ASSEMBLY__ */
254 #define prepare_to_switch() do { } while(0)
258 extern asmlinkage void lazy_fpu_switch(void *);
259 extern asmlinkage void init_fpu(void);
260 extern asmlinkage void save_fp(struct task_struct *);
261 extern asmlinkage void restore_fp(struct task_struct *);
263 #define switch_to(prev,next,last) \
265 (last) = resume(prev, next); \
269 * For 32 and 64 bit operands we can take advantage of ll and sc.
270 * FIXME: This doesn't work for R3000 machines.
272 extern __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val)
274 #ifdef CONFIG_CPU_HAS_LLSC
277 __asm__ __volatile__(
278 ".set\tpush\t\t\t\t# xchg_u32\n\t"
279 ".set\tnoreorder\n\t"
282 "1:\tmove\t%2, %z4\n\t"
288 : "=&r" (val), "=m" (*m), "=&r" (dummy)
289 : "R" (*m), "Jr" (val)
294 unsigned long flags, retval;
300 restore_flags(flags); /* implies memory barrier */
302 #endif /* Processor-dependent optimization */
305 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
306 #define tas(ptr) (xchg((ptr),1))
308 static __inline__ unsigned long
309 __xchg(unsigned long x, volatile void * ptr, int size)
313 return xchg_u32(ptr, x);
318 extern void *set_except_vector(int n, void *addr);
320 extern void __die(const char *, struct pt_regs *, const char *file,
321 const char *func, unsigned long line) __attribute__((noreturn));
322 extern void __die_if_kernel(const char *, struct pt_regs *, const char *file,
323 const char *func, unsigned long line);
325 #define die(msg, regs) \
326 __die(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
327 #define die_if_kernel(msg, regs) \
328 __die_if_kernel(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
330 #endif /* _ASM_SYSTEM_H */