allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / include / asm-sparc / system.h
blob8b4e23b3bb38477557905b504d8e3ba5dfde0fc8
1 /* $Id: system.h,v 1.86 2001/10/30 04:57:10 davem Exp $ */
3 #ifndef __SPARC_SYSTEM_H
4 #define __SPARC_SYSTEM_H
6 #include <linux/kernel.h>
7 #include <linux/threads.h> /* NR_CPUS */
8 #include <linux/thread_info.h>
10 #include <asm/page.h>
11 #include <asm/psr.h>
12 #include <asm/ptrace.h>
13 #include <asm/btfixup.h>
14 #include <asm/smp.h>
16 #ifndef __ASSEMBLY__
19 * Sparc (general) CPU types
21 enum sparc_cpu {
22 sun4 = 0x00,
23 sun4c = 0x01,
24 sun4m = 0x02,
25 sun4d = 0x03,
26 sun4e = 0x04,
27 sun4u = 0x05, /* V8 ploos ploos */
28 sun_unknown = 0x06,
29 ap1000 = 0x07, /* almost a sun4m */
32 /* Really, userland should not be looking at any of this... */
33 #ifdef __KERNEL__
35 extern enum sparc_cpu sparc_cpu_model;
37 #ifndef CONFIG_SUN4
38 #define ARCH_SUN4C_SUN4 (sparc_cpu_model==sun4c)
39 #define ARCH_SUN4 0
40 #else
41 #define ARCH_SUN4C_SUN4 1
42 #define ARCH_SUN4 1
43 #endif
45 #define SUN4M_NCPUS 4 /* Architectural limit of sun4m. */
47 extern struct thread_info *current_set[NR_CPUS];
49 extern unsigned long empty_bad_page;
50 extern unsigned long empty_bad_page_table;
51 extern unsigned long empty_zero_page;
53 extern void sun_do_break(void);
54 extern int serial_console;
55 extern int stop_a_enabled;
57 static __inline__ int con_is_present(void)
59 return serial_console ? 0 : 1;
62 /* When a context switch happens we must flush all user windows so that
63 * the windows of the current process are flushed onto its stack. This
64 * way the windows are all clean for the next process and the stack
65 * frames are up to date.
67 extern void flush_user_windows(void);
68 extern void kill_user_windows(void);
69 extern void synchronize_user_stack(void);
70 extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
71 void *fpqueue, unsigned long *fpqdepth);
73 #ifdef CONFIG_SMP
74 #define SWITCH_ENTER(prv) \
75 do { \
76 if (test_tsk_thread_flag(prv, TIF_USEDFPU)) { \
77 put_psr(get_psr() | PSR_EF); \
78 fpsave(&(prv)->thread.float_regs[0], &(prv)->thread.fsr, \
79 &(prv)->thread.fpqueue[0], &(prv)->thread.fpqdepth); \
80 clear_tsk_thread_flag(prv, TIF_USEDFPU); \
81 (prv)->thread.kregs->psr &= ~PSR_EF; \
82 } \
83 } while(0)
85 #define SWITCH_DO_LAZY_FPU(next) /* */
86 #else
87 #define SWITCH_ENTER(prv) /* */
88 #define SWITCH_DO_LAZY_FPU(nxt) \
89 do { \
90 if (last_task_used_math != (nxt)) \
91 (nxt)->thread.kregs->psr&=~PSR_EF; \
92 } while(0)
93 #endif
96 * Flush windows so that the VM switch which follows
97 * would not pull the stack from under us.
99 * SWITCH_ENTER and SWITH_DO_LAZY_FPU do not work yet (e.g. SMP does not work)
100 * XXX WTF is the above comment? Found in late teen 2.4.x.
102 #define prepare_arch_switch(next) do { \
103 __asm__ __volatile__( \
104 ".globl\tflush_patch_switch\nflush_patch_switch:\n\t" \
105 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
106 "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
107 "save %sp, -0x40, %sp\n\t" \
108 "restore; restore; restore; restore; restore; restore; restore"); \
109 } while(0)
111 /* Much care has gone into this code, do not touch it.
113 * We need to loadup regs l0/l1 for the newly forked child
114 * case because the trap return path relies on those registers
115 * holding certain values, gcc is told that they are clobbered.
116 * Gcc needs registers for 3 values in and 1 value out, so we
117 * clobber every non-fixed-usage register besides l2/l3/o4/o5. -DaveM
119 * Hey Dave, that do not touch sign is too much of an incentive
120 * - Anton & Pete
122 #define switch_to(prev, next, last) do { \
123 SWITCH_ENTER(prev); \
124 SWITCH_DO_LAZY_FPU(next); \
125 cpu_set(smp_processor_id(), next->active_mm->cpu_vm_mask); \
126 __asm__ __volatile__( \
127 "sethi %%hi(here - 0x8), %%o7\n\t" \
128 "mov %%g6, %%g3\n\t" \
129 "or %%o7, %%lo(here - 0x8), %%o7\n\t" \
130 "rd %%psr, %%g4\n\t" \
131 "std %%sp, [%%g6 + %4]\n\t" \
132 "rd %%wim, %%g5\n\t" \
133 "wr %%g4, 0x20, %%psr\n\t" \
134 "nop\n\t" \
135 "std %%g4, [%%g6 + %3]\n\t" \
136 "ldd [%2 + %3], %%g4\n\t" \
137 "mov %2, %%g6\n\t" \
138 ".globl patchme_store_new_current\n" \
139 "patchme_store_new_current:\n\t" \
140 "st %2, [%1]\n\t" \
141 "wr %%g4, 0x20, %%psr\n\t" \
142 "nop\n\t" \
143 "nop\n\t" \
144 "nop\n\t" /* LEON needs all 3 nops: load to %sp depends on CWP. */ \
145 "ldd [%%g6 + %4], %%sp\n\t" \
146 "wr %%g5, 0x0, %%wim\n\t" \
147 "ldd [%%sp + 0x00], %%l0\n\t" \
148 "ldd [%%sp + 0x38], %%i6\n\t" \
149 "wr %%g4, 0x0, %%psr\n\t" \
150 "nop\n\t" \
151 "nop\n\t" \
152 "jmpl %%o7 + 0x8, %%g0\n\t" \
153 " ld [%%g3 + %5], %0\n\t" \
154 "here:\n" \
155 : "=&r" (last) \
156 : "r" (&(current_set[hard_smp_processor_id()])), \
157 "r" (task_thread_info(next)), \
158 "i" (TI_KPSR), \
159 "i" (TI_KSP), \
160 "i" (TI_TASK) \
161 : "g1", "g2", "g3", "g4", "g5", "g7", \
162 "l0", "l1", "l3", "l4", "l5", "l6", "l7", \
163 "i0", "i1", "i2", "i3", "i4", "i5", \
164 "o0", "o1", "o2", "o3", "o7"); \
165 } while(0)
168 * On SMP systems, when the scheduler does migration-cost autodetection,
169 * it needs a way to flush as much of the CPU's caches as possible.
171 * TODO: fill this in!
173 static inline void sched_cacheflush(void)
178 * Changing the IRQ level on the Sparc.
180 extern void local_irq_restore(unsigned long);
181 extern unsigned long __local_irq_save(void);
182 extern void local_irq_enable(void);
184 static inline unsigned long getipl(void)
186 unsigned long retval;
188 __asm__ __volatile__("rd %%psr, %0" : "=r" (retval));
189 return retval;
192 #define local_save_flags(flags) ((flags) = getipl())
193 #define local_irq_save(flags) ((flags) = __local_irq_save())
194 #define local_irq_disable() ((void) __local_irq_save())
195 #define irqs_disabled() ((getipl() & PSR_PIL) != 0)
197 /* XXX Change this if we ever use a PSO mode kernel. */
198 #define mb() __asm__ __volatile__ ("" : : : "memory")
199 #define rmb() mb()
200 #define wmb() mb()
201 #define read_barrier_depends() do { } while(0)
202 #define set_mb(__var, __value) do { __var = __value; mb(); } while(0)
203 #define smp_mb() __asm__ __volatile__("":::"memory")
204 #define smp_rmb() __asm__ __volatile__("":::"memory")
205 #define smp_wmb() __asm__ __volatile__("":::"memory")
206 #define smp_read_barrier_depends() do { } while(0)
208 #define nop() __asm__ __volatile__ ("nop")
210 /* This has special calling conventions */
211 #ifndef CONFIG_SMP
212 BTFIXUPDEF_CALL(void, ___xchg32, void)
213 #endif
215 static inline unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val)
217 #ifdef CONFIG_SMP
218 __asm__ __volatile__("swap [%2], %0"
219 : "=&r" (val)
220 : "0" (val), "r" (m)
221 : "memory");
222 return val;
223 #else
224 register unsigned long *ptr asm("g1");
225 register unsigned long ret asm("g2");
227 ptr = (unsigned long *) m;
228 ret = val;
230 /* Note: this is magic and the nop there is
231 really needed. */
232 __asm__ __volatile__(
233 "mov %%o7, %%g4\n\t"
234 "call ___f____xchg32\n\t"
235 " nop\n\t"
236 : "=&r" (ret)
237 : "0" (ret), "r" (ptr)
238 : "g3", "g4", "g7", "memory", "cc");
240 return ret;
241 #endif
244 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
246 extern void __xchg_called_with_bad_pointer(void);
248 static __inline__ unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
250 switch (size) {
251 case 4:
252 return xchg_u32(ptr, x);
254 __xchg_called_with_bad_pointer();
255 return x;
258 extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
260 #endif /* __KERNEL__ */
262 #endif /* __ASSEMBLY__ */
264 #define arch_align_stack(x) (x)
266 #endif /* !(__SPARC_SYSTEM_H) */