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>
21 #include <asm/ptrace.h>
23 #include <linux/kernel.h>
26 extern __inline__ void
44 * For cli() we have to insert nops to make shure 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
50 extern __inline__ void
71 #define __save_flags(x) \
72 __asm__ __volatile__( \
79 #define __save_and_cli(x) \
80 __asm__ __volatile__( \
87 ".set\tnoreorder\n\t" \
97 #define __restore_flags(flags) \
99 unsigned long __tmp1; \
101 __asm__ __volatile__( \
102 ".set\tnoreorder\t\t\t# __restore_flags\n\t" \
104 "mfc0\t$1, $12\n\t" \
109 "mtc0\t%0, $12\n\t" \
122 extern void __global_sti(void);
123 extern void __global_cli(void);
124 extern unsigned long __global_save_flags(void);
125 extern void __global_restore_flags(unsigned long);
126 # define sti() __global_sti()
127 # define cli() __global_cli()
128 # define save_flags(x) do { x = __global_save_flags(); } while (0)
129 # define restore_flags(x) __global_restore_flags(x)
130 # define save_and_cli(x) do { save_flags(x); cli(); } while(0)
132 #else /* Single processor */
134 # define sti() __sti()
135 # define cli() __cli()
136 # define save_flags(x) __save_flags(x)
137 # define save_and_cli(x) __save_and_cli(x)
138 # define restore_flags(x) __restore_flags(x)
142 /* For spinlocks etc */
143 #define local_irq_save(x) __save_and_cli(x);
144 #define local_irq_restore(x) __restore_flags(x);
145 #define local_irq_disable() __cli();
146 #define local_irq_enable() __sti();
149 * These are probably defined overly paranoid ...
151 #ifdef CONFIG_CPU_HAS_WB
153 #include <asm/wbflush.h>
154 #define rmb() do { } while(0)
155 #define wmb() wbflush()
156 #define mb() wbflush()
158 #else /* CONFIG_CPU_HAS_WB */
161 __asm__ __volatile__( \
162 "# prevent instructions being moved around\n\t" \
163 ".set\tnoreorder\n\t" \
164 "# 8 nops to fool the R4400 pipeline\n\t" \
165 "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \
173 #endif /* CONFIG_CPU_HAS_WB */
176 #define smp_mb() mb()
177 #define smp_rmb() rmb()
178 #define smp_wmb() wmb()
180 #define smp_mb() barrier()
181 #define smp_rmb() barrier()
182 #define smp_wmb() barrier()
185 #define set_mb(var, value) \
186 do { var = value; mb(); } while (0)
188 #define set_wmb(var, value) \
189 do { var = value; wmb(); } while (0)
191 #if !defined (_LANGUAGE_ASSEMBLY)
193 * switch_to(n) should switch tasks to task nr n, first
194 * checking that n isn't the current task, in which case it does nothing.
197 extern asmlinkage void *resume(void *last, void *next);
199 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
201 #define prepare_to_switch() do { } while(0)
202 #define switch_to(prev,next,last) \
204 (last) = resume(prev, next); \
208 * For 32 and 64 bit operands we can take advantage of ll and sc.
209 * FIXME: This doesn't work for R3000 machines.
211 extern __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val)
213 #ifdef CONFIG_CPU_HAS_LLSC
216 __asm__ __volatile__(
217 ".set\tnoreorder\t\t\t# xchg_u32\n\t"
220 "1:\tmove\t$1, %2\n\t"
226 : "=r" (val), "=o" (*m), "=r" (dummy)
227 : "o" (*m), "2" (val)
232 unsigned long flags, retval;
238 restore_flags(flags);
240 #endif /* Processor-dependent optimization */
243 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
244 #define tas(ptr) (xchg((ptr),1))
246 static __inline__ unsigned long
247 __xchg(unsigned long x, volatile void * ptr, int size)
251 return xchg_u32(ptr, x);
256 extern void *set_except_vector(int n, void *addr);
258 extern void __die(const char *, struct pt_regs *, const char *where,
259 unsigned long line) __attribute__((noreturn));
260 extern void __die_if_kernel(const char *, struct pt_regs *, const char *where,
263 #define die(msg, regs) \
264 __die(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
265 #define die_if_kernel(msg, regs) \
266 __die_if_kernel(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
268 #endif /* _ASM_SYSTEM_H */