1 /* $Id: system.h,v 1.5 2000/01/27 07:48:08 kanoj Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 by Ralf Baechle
8 * Modified further for R[236]000 by Paul M. Antoine, 1996
9 * Copyright (C) 1999 Silicon Graphics
14 #include <linux/config.h>
16 #include <asm/sgidefs.h>
17 #include <linux/kernel.h>
19 extern __inline__
void
37 * For cli() we have to insert nops to make shure that the new value
38 * has actually arrived in the status register before the end of this
40 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
43 extern __inline__
void
63 #define __save_flags(x) \
64 __asm__ __volatile__( \
65 ".set\tnoreorder\n\t" \
72 #define __save_and_cli(x) \
73 __asm__ __volatile__( \
74 ".set\tnoreorder\n\t" \
89 extern void __inline__
90 __restore_flags(int flags
)
107 : "$8", "$9", "memory");
112 extern void __global_cli(void);
113 extern void __global_sti(void);
114 extern unsigned long __global_save_flags(void);
115 extern void __global_restore_flags(unsigned long);
116 #define cli() __global_cli()
117 #define sti() __global_sti()
118 #define save_flags(x) ((x)=__global_save_flags())
119 #define restore_flags(x) __global_restore_flags(x)
120 #define save_and_cli(x) do { save_flags(x); cli(); } while(0)
124 #define cli() __cli()
125 #define sti() __sti()
126 #define save_flags(x) __save_flags(x)
127 #define restore_flags(x) __restore_flags(x)
128 #define save_and_cli(x) __save_and_cli(x)
130 #endif /* CONFIG_SMP */
132 /* For spinlocks etc */
133 #define local_irq_save(x) __save_and_cli(x);
134 #define local_irq_restore(x) __restore_flags(x);
135 #define local_irq_disable() __cli();
136 #define local_irq_enable() __sti();
139 * These are probably defined overly paranoid ...
142 __asm__ __volatile__( \
143 "# prevent instructions being moved around\n\t" \
144 ".set\tnoreorder\n\t" \
145 "# 8 nops to fool the R4400 pipeline\n\t" \
146 "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \
154 #define set_mb(var, value) \
155 do { var = value; mb(); } while (0)
157 #define set_wmb(var, value) \
158 do { var = value; wmb(); } while (0)
160 #if !defined (_LANGUAGE_ASSEMBLY)
162 * switch_to(n) should switch tasks to task nr n, first
163 * checking that n isn't the current task, in which case it does nothing.
165 extern asmlinkage
void *resume(void *last
, void *next
);
166 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
168 #define prepare_to_switch() do { } while(0)
170 extern asmlinkage
void lazy_fpu_switch(void *, void *);
171 extern asmlinkage
void init_fpu(void);
172 extern asmlinkage
void save_fp(void *);
175 #define SWITCH_DO_LAZY_FPU \
176 if (prev->flags & PF_USEDFPU) { \
177 lazy_fpu_switch(prev, 0); \
178 set_cp0_status(ST0_CU1, ~ST0_CU1); \
179 prev->flags &= ~PF_USEDFPU; \
181 #else /* CONFIG_SMP */
182 #define SWITCH_DO_LAZY_FPU do { } while(0)
183 #endif /* CONFIG_SMP */
185 #define switch_to(prev,next,last) \
187 SWITCH_DO_LAZY_FPU; \
188 (last) = resume(prev, next); \
191 extern __inline__
unsigned long xchg_u32(volatile int * m
, unsigned long val
)
195 __asm__
__volatile__(
196 ".set\tnoreorder\n\t"
199 "1:\tmove\t$1,%2\n\t"
205 : "=r" (val
), "=r" (m
), "=r" (dummy
)
213 * Only used for 64 bit kernel.
215 extern __inline__
unsigned long xchg_u64(volatile long * m
, unsigned long val
)
219 __asm__
__volatile__(
220 ".set\tnoreorder\n\t"
223 "1:\tmove\t$1,%2\n\t"
229 : "=r" (val
), "=r" (m
), "=r" (dummy
)
236 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
237 #define tas(ptr) (xchg((ptr),1))
239 /* This function doesn't exist, so you'll get a linker error if something
240 tries to do an invalid xchg(). */
241 extern void __xchg_called_with_bad_pointer(void);
243 static __inline__
unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
247 return xchg_u32(ptr
, x
);
249 return xchg_u64(ptr
, x
);
251 __xchg_called_with_bad_pointer();
255 extern void set_except_vector(int n
, void *addr
);
257 #endif /* _ASM_SYSTEM_H */