2 * Copyright (C) 1994 - 1999 by Ralf Baechle
3 * Copyright (C) 1996 by Paul M. Antoine
4 * Copyright (C) 1994 - 1999 by Ralf Baechle
6 * Changed set_except_vector declaration to allow return of previous
7 * vector address value - necessary for "borrowing" vectors.
9 * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
10 * Copyright (C) 2000 MIPS Technologies, Inc.
12 * SPDX-License-Identifier: GPL-2.0
17 #include <asm/sgidefs.h>
18 #include <asm/ptrace.h>
20 #include <linux/kernel.h>
23 static __inline__ void
41 * For cli() we have to insert nops to make shure that the new value
42 * has actually arrived in the status register before the end of this
44 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
47 static __inline__ void
68 #define __save_flags(x) \
69 __asm__ __volatile__( \
76 #define __save_and_cli(x) \
77 __asm__ __volatile__( \
84 ".set\tnoreorder\n\t" \
94 #define __restore_flags(flags) \
96 unsigned long __tmp1; \
98 __asm__ __volatile__( \
99 ".set\tnoreorder\t\t\t# __restore_flags\n\t" \
101 "mfc0\t$1, $12\n\t" \
106 "mtc0\t%0, $12\n\t" \
119 extern void __global_sti(void);
120 extern void __global_cli(void);
121 extern unsigned long __global_save_flags(void);
122 extern void __global_restore_flags(unsigned long);
123 # define sti() __global_sti()
124 # define cli() __global_cli()
125 # define save_flags(x) do { x = __global_save_flags(); } while (0)
126 # define restore_flags(x) __global_restore_flags(x)
127 # define save_and_cli(x) do { save_flags(x); cli(); } while(0)
129 #else /* Single processor */
131 # define sti() __sti()
132 # define cli() __cli()
133 # define save_flags(x) __save_flags(x)
134 # define save_and_cli(x) __save_and_cli(x)
135 # define restore_flags(x) __restore_flags(x)
139 /* For spinlocks etc */
140 #define local_irq_save(x) __save_and_cli(x);
141 #define local_irq_restore(x) __restore_flags(x);
142 #define local_irq_disable() __cli();
143 #define local_irq_enable() __sti();
146 * These are probably defined overly paranoid ...
148 #ifdef CONFIG_CPU_HAS_WB
150 #include <asm/wbflush.h>
151 #define rmb() do { } while(0)
152 #define wmb() wbflush()
153 #define mb() wbflush()
155 #else /* CONFIG_CPU_HAS_WB */
158 __asm__ __volatile__( \
159 "# prevent instructions being moved around\n\t" \
160 ".set\tnoreorder\n\t" \
161 "# 8 nops to fool the R4400 pipeline\n\t" \
162 "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \
170 #endif /* CONFIG_CPU_HAS_WB */
173 #define smp_mb() mb()
174 #define smp_rmb() rmb()
175 #define smp_wmb() wmb()
177 #define smp_mb() barrier()
178 #define smp_rmb() barrier()
179 #define smp_wmb() barrier()
182 #define set_mb(var, value) \
183 do { var = value; mb(); } while (0)
185 #define set_wmb(var, value) \
186 do { var = value; wmb(); } while (0)
188 #if !defined (_LANGUAGE_ASSEMBLY)
190 * switch_to(n) should switch tasks to task nr n, first
191 * checking that n isn't the current task, in which case it does nothing.
194 extern asmlinkage void *resume(void *last, void *next);
196 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
198 #define prepare_to_switch() do { } while(0)
199 #define switch_to(prev,next,last) \
201 (last) = resume(prev, next); \
205 * For 32 and 64 bit operands we can take advantage of ll and sc.
206 * FIXME: This doesn't work for R3000 machines.
208 static __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val)
210 #ifdef CONFIG_CPU_HAS_LLSC
213 __asm__ __volatile__(
214 ".set\tnoreorder\t\t\t# xchg_u32\n\t"
217 "1:\tmove\t$1, %2\n\t"
223 : "=r" (val), "=o" (*m), "=r" (dummy)
224 : "o" (*m), "2" (val)
229 unsigned long flags, retval;
235 restore_flags(flags);
237 #endif /* Processor-dependent optimization */
240 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
241 #define tas(ptr) (xchg((ptr),1))
243 static __inline__ unsigned long
244 __xchg(unsigned long x, volatile void * ptr, int size)
248 return xchg_u32(ptr, x);
253 extern void *set_except_vector(int n, void *addr);
255 extern void __die(const char *, struct pt_regs *, const char *where,
256 unsigned long line) __attribute__((noreturn));
257 extern void __die_if_kernel(const char *, struct pt_regs *, const char *where,
260 #define die(msg, regs) \
261 __die(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
262 #define die_if_kernel(msg, regs) \
263 __die_if_kernel(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
265 #endif /* _ASM_SYSTEM_H */