1 /* $Id: system.h,v 1.75 1999/09/01 08:06:08 davem Exp $ */
2 #include <linux/config.h>
4 #ifndef __SPARC_SYSTEM_H
5 #define __SPARC_SYSTEM_H
7 #include <linux/kernel.h>
9 #include <asm/segment.h>
13 #include <asm/oplib.h>
15 #include <asm/ptrace.h>
16 #include <asm/btfixup.h>
18 #define EMPTY_PGT (&empty_bad_page)
19 #define EMPTY_PGE (&empty_bad_page_table)
20 #endif /* __KERNEL__ */
25 * Sparc (general) CPU types
33 sun4u
= 0x05, /* V8 ploos ploos */
35 ap1000
= 0x07, /* almost a sun4m */
38 /* Really, userland should not be looking at any of this... */
41 extern enum sparc_cpu sparc_cpu_model
;
44 #define ARCH_SUN4C_SUN4 (sparc_cpu_model==sun4c)
47 #define ARCH_SUN4C_SUN4 1
51 #define SUN4M_NCPUS 4 /* Architectural limit of sun4m. */
53 extern unsigned long empty_bad_page
;
54 extern unsigned long empty_bad_page_table
;
55 extern unsigned long empty_zero_page
;
57 extern struct linux_romvec
*romvec
;
58 #define halt() romvec->pv_halt()
60 /* When a context switch happens we must flush all user windows so that
61 * the windows of the current process are flushed onto its stack. This
62 * way the windows are all clean for the next process and the stack
63 * frames are up to date.
65 extern void flush_user_windows(void);
66 extern void kill_user_windows(void);
67 extern void synchronize_user_stack(void);
68 extern void fpsave(unsigned long *fpregs
, unsigned long *fsr
,
69 void *fpqueue
, unsigned long *fpqdepth
);
72 #define SWITCH_ENTER \
73 if(prev->flags & PF_USEDFPU) { \
74 put_psr(get_psr() | PSR_EF); \
75 fpsave(&prev->tss.float_regs[0], &prev->tss.fsr, \
76 &prev->tss.fpqueue[0], &prev->tss.fpqdepth); \
77 prev->flags &= ~PF_USEDFPU; \
78 prev->tss.kregs->psr &= ~PSR_EF; \
81 #define SWITCH_DO_LAZY_FPU
84 #define SWITCH_DO_LAZY_FPU if(last_task_used_math != next) next->tss.kregs->psr&=~PSR_EF;
87 /* Much care has gone into this code, do not touch it.
89 * We need to loadup regs l0/l1 for the newly forked child
90 * case because the trap return path relies on those registers
91 * holding certain values, gcc is told that they are clobbered.
92 * Gcc needs registers for 3 values in and 1 value out, so we
93 * clobber every non-fixed-usage register besides l2/l3/o4/o5. -DaveM
95 #define switch_to(prev, next, last) do { \
97 register unsigned long task_pc asm("o7"); \
98 extern struct task_struct *current_set[NR_CPUS]; \
101 __asm__ __volatile__( \
102 ".globl\tflush_patch_switch\nflush_patch_switch:\n\t" \
103 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
104 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
105 "save %sp, -0x40, %sp\n\t" \
106 "restore; restore; restore; restore; restore; restore; restore"); \
107 if(!(next->tss.flags & SPARC_FLAG_KTHREAD) && \
108 !(next->flags & PF_EXITING)) \
109 switch_to_context(next); \
110 next->mm->cpu_vm_mask |= (1 << smp_processor_id()); \
111 task_pc = ((unsigned long) &&here) - 0x8; \
112 __asm__ __volatile__( \
113 "mov %%g6, %%g3\n\t" \
114 "rd %%psr, %%g4\n\t" \
115 "std %%sp, [%%g6 + %4]\n\t" \
116 "rd %%wim, %%g5\n\t" \
117 "wr %%g4, 0x20, %%psr\n\t" \
119 "std %%g4, [%%g6 + %3]\n\t" \
120 "ldd [%2 + %3], %%g4\n\t" \
122 ".globl patchme_store_new_current\n" \
123 "patchme_store_new_current:\n\t" \
125 "wr %%g4, 0x20, %%psr\n\t" \
128 "ldd [%%g6 + %4], %%sp\n\t" \
129 "wr %%g5, 0x0, %%wim\n\t" \
130 "ldd [%%sp + 0x00], %%l0\n\t" \
131 "ldd [%%sp + 0x38], %%i6\n\t" \
132 "wr %%g4, 0x0, %%psr\n\t" \
135 "jmpl %%o7 + 0x8, %%g0\n\t" \
136 " mov %%g3, %0\n\t" \
138 : "r" (&(current_set[hard_smp_processor_id()])), "r" (next), \
139 "i" ((const unsigned long)(&((struct task_struct *)0)->tss.kpsr)), \
140 "i" ((const unsigned long)(&((struct task_struct *)0)->tss.ksp)), \
142 : "g1", "g2", "g3", "g4", "g5", "g7", "l0", "l1", \
143 "l4", "l5", "l6", "l7", "i0", "i1", "i2", "i3", "i4", "i5", "o0", "o1", "o2", \
147 /* Changing the IRQ level on the Sparc. We now avoid writing the psr
150 extern __inline__
void setipl(unsigned long __orig_psr
)
152 __asm__
__volatile__("
160 extern __inline__
void __cli(void)
164 __asm__
__volatile__("
166 nop; nop; nop; /* Sun4m + Cypress + SMP bug */
175 extern __inline__
void __sti(void)
179 __asm__
__volatile__("
181 nop; nop; nop; /* Sun4m + Cypress + SMP bug */
190 extern __inline__
unsigned long getipl(void)
192 unsigned long retval
;
194 __asm__
__volatile__("rd %%psr, %0" : "=r" (retval
));
198 extern __inline__
unsigned long swap_pil(unsigned long __new_psr
)
200 unsigned long retval
;
202 __asm__
__volatile__("
204 nop; nop; nop; /* Sun4m + Cypress + SMP bug */
207 xorcc %%g1, %%g2, %%g0
214 : "r" (__new_psr
), "i" (PSR_PIL
)
215 : "g1", "g2", "memory", "cc");
220 extern __inline__
unsigned long read_psr_and_cli(void)
222 unsigned long retval
;
224 __asm__
__volatile__("
226 nop; nop; nop; /* Sun4m + Cypress + SMP bug */
237 #define __save_flags(flags) ((flags) = getipl())
238 #define __save_and_cli(flags) ((flags) = read_psr_and_cli())
239 #define __restore_flags(flags) setipl((flags))
243 /* This goes away after lockups have been found... */
244 #ifndef DEBUG_IRQLOCK
245 #define DEBUG_IRQLOCK
248 extern unsigned char global_irq_holder
;
250 #define save_and_cli(flags) do { save_flags(flags); cli(); } while(0)
253 extern void __global_cli(void);
254 extern void __global_sti(void);
255 extern unsigned long __global_save_flags(void);
256 extern void __global_restore_flags(unsigned long flags
);
257 #define cli() __global_cli()
258 #define sti() __global_sti()
259 #define save_flags(flags) ((flags)=__global_save_flags())
260 #define restore_flags(flags) __global_restore_flags(flags)
263 #error For combined sun4[md] smp, we need to get rid of the rdtbr.
265 /* Visit arch/sparc/lib/irqlock.S for all the fun details... */
266 #define cli() __asm__ __volatile__("mov %%o7, %%g4\n\t" \
267 "call ___f_global_cli\n\t" \
268 " rd %%tbr, %%g7" : : \
269 : "g1", "g2", "g3", "g4", "g5", "g7", \
273 do { register unsigned long bits asm("g7"); \
275 __asm__ __volatile__("mov %%o7, %%g4\n\t" \
276 "call ___f_global_sti\n\t" \
280 : "g1", "g2", "g3", "g4", "g5", \
284 #define restore_flags(flags) \
285 do { register unsigned long bits asm("g7"); \
287 __asm__ __volatile__("mov %%o7, %%g4\n\t" \
288 "call ___f_global_restore_flags\n\t" \
289 " andcc %%g7, 0x1, %%g0" \
292 : "g1", "g2", "g3", "g4", "g5", \
296 #endif /* DEBUG_IRQLOCK */
300 #define cli() __cli()
301 #define sti() __sti()
302 #define save_flags(x) __save_flags(x)
303 #define restore_flags(x) __restore_flags(x)
304 #define save_and_cli(x) __save_and_cli(x)
308 /* XXX Change this if we ever use a PSO mode kernel. */
309 #define mb() __asm__ __volatile__ ("" : : : "memory")
312 #define set_mb(__var, __value) do { __var = __value; mb(); } while(0)
313 #define set_rmb(__var, __value) set_mb(__var, __value)
314 #define set_wmb(__var, __value) set_mb(__var, __value)
316 #define nop() __asm__ __volatile__ ("nop");
318 /* This has special calling conventions */
320 BTFIXUPDEF_CALL(void, ___xchg32
, void)
323 extern __inline__
unsigned long xchg_u32(__volatile__
unsigned long *m
, unsigned long val
)
326 __asm__
__volatile__("swap [%2], %0"
328 : "0" (val
), "r" (m
));
331 register unsigned long *ptr
asm("g1");
332 register unsigned long ret
asm("g2");
334 ptr
= (unsigned long *) m
;
337 /* Note: this is magic and the nop there is
339 __asm__
__volatile__("
344 : "0" (ret
), "r" (ptr
)
345 : "g3", "g4", "g7", "memory", "cc");
351 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
352 #define tas(ptr) (xchg((ptr),1))
354 extern void __xchg_called_with_bad_pointer(void);
356 static __inline__
unsigned long __xchg(unsigned long x
, __volatile__
void * ptr
, int size
)
360 return xchg_u32(ptr
, x
);
362 __xchg_called_with_bad_pointer();
366 extern void die_if_kernel(char *str
, struct pt_regs
*regs
) __attribute__ ((noreturn
));
368 #endif /* __KERNEL__ */
370 #endif /* __ASSEMBLY__ */
372 #endif /* !(__SPARC_SYSTEM_H) */