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>
28 ".macro\tlocal_irq_enable\n\t"
39 static inline void local_irq_enable(void)
49 * For cli() we have to insert nops to make sure that the new value
50 * has actually arrived in the status register before the end of this
52 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
56 ".macro\tlocal_irq_disable\n\t"
64 "sll\t$0, $0, 1\t\t\t# nop\n\t"
65 "sll\t$0, $0, 1\t\t\t# nop\n\t"
66 "sll\t$0, $0, 1\t\t\t# nop\n\t"
70 static inline void local_irq_disable(void)
80 ".macro\tlocal_save_flags flags\n\t"
83 "mfc0\t\\flags, $12\n\t"
87 #define local_save_flags(x) \
88 __asm__ __volatile__( \
89 "local_save_flags %0" \
93 ".macro\tlocal_irq_save result\n\t"
97 "mfc0\t\\result, $12\n\t"
98 "ori\t$1, \\result, 1\n\t"
100 ".set\tnoreorder\n\t"
102 "sll\t$0, $0, 1\t\t\t# nop\n\t"
103 "sll\t$0, $0, 1\t\t\t# nop\n\t"
104 "sll\t$0, $0, 1\t\t\t# nop\n\t"
108 #define local_irq_save(x) \
109 __asm__ __volatile__( \
110 "local_irq_save\t%0" \
115 __asm__(".macro\tlocal_irq_restore flags\n\t"
116 ".set\tnoreorder\n\t"
119 "andi\t\\flags, 1\n\t"
122 "or\t\\flags, $1\n\t"
123 "mtc0\t\\flags, $12\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"
126 "sll\t$0, $0, 1\t\t\t# nop\n\t"
131 #define local_irq_restore(flags) \
133 unsigned long __tmp1; \
135 __asm__ __volatile__( \
136 "local_irq_restore\t%0" \
142 #define irqs_disabled() \
144 unsigned long flags; \
145 local_save_flags(flags); \
150 * read_barrier_depends - Flush all pending reads that subsequents reads
153 * No data-dependent reads from memory-like regions are ever reordered
154 * over this barrier. All reads preceding this primitive are guaranteed
155 * to access memory (but not necessarily other CPUs' caches) before any
156 * reads following this primitive that depend on the data return by
157 * any of the preceding reads. This primitive is much lighter weight than
158 * rmb() on most CPUs, and is never heavier weight than is
161 * These ordering constraints are respected by both the local CPU
164 * Ordering is not guaranteed by anything other than these primitives,
165 * not even by data dependencies. See the documentation for
166 * memory_barrier() for examples and URLs to more information.
168 * For example, the following code would force ordering (the initial
169 * value of "a" is zero, "b" is one, and "p" is "&a"):
177 * read_barrier_depends();
181 * because the read of "*q" depends on the read of "p" and these
182 * two reads are separated by a read_barrier_depends(). However,
183 * the following code, with the same initial values for "a" and "b":
191 * read_barrier_depends();
195 * does not enforce ordering, since there is no data dependency between
196 * the read of "a" and the read of "b". Therefore, on some CPUs, such
197 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
198 * in cases like thiswhere there are no data dependencies.
201 #define read_barrier_depends() do { } while(0)
203 #ifdef CONFIG_CPU_HAS_SYNC
205 __asm__ __volatile__( \
207 ".set noreorder\n\t" \
215 #define __sync() do { } while(0)
218 #define __fast_iob() \
219 __asm__ __volatile__( \
221 ".set noreorder\n\t" \
226 : "m" (*(int *)KSEG1) \
229 #define fast_wmb() __sync()
230 #define fast_rmb() __sync()
231 #define fast_mb() __sync()
238 #ifdef CONFIG_CPU_HAS_WB
240 #include <asm/wbflush.h>
242 #define wmb() fast_wmb()
243 #define rmb() fast_rmb()
244 #define mb() wbflush();
245 #define iob() wbflush();
247 #else /* !CONFIG_CPU_HAS_WB */
249 #define wmb() fast_wmb()
250 #define rmb() fast_rmb()
251 #define mb() fast_mb()
252 #define iob() fast_iob()
254 #endif /* !CONFIG_CPU_HAS_WB */
257 #define smp_mb() mb()
258 #define smp_rmb() rmb()
259 #define smp_wmb() wmb()
260 #define smp_read_barrier_depends() read_barrier_depends()
262 #define smp_mb() barrier()
263 #define smp_rmb() barrier()
264 #define smp_wmb() barrier()
265 #define smp_read_barrier_depends() do { } while(0)
268 #define set_mb(var, value) \
269 do { var = value; mb(); } while (0)
271 #define set_wmb(var, value) \
272 do { var = value; wmb(); } while (0)
275 * switch_to(n) should switch tasks to task nr n, first
276 * checking that n isn't the current task, in which case it does nothing.
278 extern asmlinkage
void *resume(void *last
, void *next
, void *next_ti
);
282 #define switch_to(prev,next,last) \
284 (last) = resume(prev, next, next->thread_info); \
288 * For 32 and 64 bit operands we can take advantage of ll and sc.
289 * FIXME: This doesn't work for R3000 machines.
291 static __inline__
unsigned long xchg_u32(volatile int * m
, unsigned long val
)
293 #ifdef CONFIG_CPU_HAS_LLSC
296 __asm__
__volatile__(
297 ".set\tpush\t\t\t\t# xchg_u32\n\t"
298 ".set\tnoreorder\n\t"
301 "1:\tmove\t%2, %z4\n\t"
307 : "=&r" (val
), "=m" (*m
), "=&r" (dummy
)
308 : "R" (*m
), "Jr" (val
)
313 unsigned long flags
, retval
;
315 local_irq_save(flags
);
318 local_irq_restore(flags
); /* implies memory barrier */
320 #endif /* Processor-dependent optimization */
323 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
324 #define tas(ptr) (xchg((ptr),1))
326 static __inline__
unsigned long
327 __xchg(unsigned long x
, volatile void * ptr
, int size
)
331 return xchg_u32(ptr
, x
);
336 extern void *set_except_vector(int n
, void *addr
);
337 extern void per_cpu_trap_init(void);
339 extern void __die(const char *, struct pt_regs
*, const char *file
,
340 const char *func
, unsigned long line
) __attribute__((noreturn
));
341 extern void __die_if_kernel(const char *, struct pt_regs
*, const char *file
,
342 const char *func
, unsigned long line
);
344 #define die(msg, regs) \
345 __die(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
346 #define die_if_kernel(msg, regs) \
347 __die_if_kernel(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
349 extern int serial_console
;
350 extern int stop_a_enabled
;
352 static __inline__
int con_is_present(void)
354 return serial_console
? 0 : 1;
357 #endif /* _ASM_SYSTEM_H */