ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-sparc64 / ttable.h
1 /* $Id: ttable.h,v 1.18 2002/02/09 19:49:32 davem Exp $ */
2 #ifndef _SPARC64_TTABLE_H
3 #define _SPARC64_TTABLE_H
4
5 #include <linux/config.h>
6 #include <asm/utrap.h>
7
8 #ifdef __ASSEMBLY__
9 #include <asm/thread_info.h>
10 #endif
11
12 #define BOOT_KERNEL b sparc64_boot; nop; nop; nop; nop; nop; nop; nop;
13
14 /* We need a "cleaned" instruction... */
15 #define CLEAN_WINDOW                                                    \
16         rdpr    %cleanwin, %l0;         add     %l0, 1, %l0;            \
17         wrpr    %l0, 0x0, %cleanwin;                                    \
18         clr     %o0;    clr     %o1;    clr     %o2;    clr     %o3;    \
19         clr     %o4;    clr     %o5;    clr     %o6;    clr     %o7;    \
20         clr     %l0;    clr     %l1;    clr     %l2;    clr     %l3;    \
21         clr     %l4;    clr     %l5;    clr     %l6;    clr     %l7;    \
22         retry;                                                          \
23         nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
24
25 #define TRAP(routine)                                   \
26         sethi   %hi(109f), %g7;                         \
27         ba,pt   %xcc, etrap;                            \
28 109:     or     %g7, %lo(109b), %g7;                    \
29         call    routine;                                \
30          add    %sp, PTREGS_OFF, %o0;                   \
31         ba,pt   %xcc, rtrap;                            \
32          clr    %l6;                                    \
33         nop;
34
35 #define TRAP_7INSNS(routine)                            \
36         sethi   %hi(109f), %g7;                         \
37         ba,pt   %xcc, etrap;                            \
38 109:     or     %g7, %lo(109b), %g7;                    \
39         call    routine;                                \
40          add    %sp, PTREGS_OFF, %o0;                   \
41         ba,pt   %xcc, rtrap;                            \
42          clr    %l6;
43
44 #define TRAP_SAVEFPU(routine)                           \
45         sethi   %hi(109f), %g7;                         \
46         ba,pt   %xcc, do_fptrap;                        \
47 109:     or     %g7, %lo(109b), %g7;                    \
48         call    routine;                                \
49          add    %sp, PTREGS_OFF, %o0;                   \
50         ba,pt   %xcc, rtrap;                            \
51          clr    %l6;                                    \
52         nop;
53
54 #define TRAP_NOSAVE(routine)                            \
55         ba,pt   %xcc, routine;                          \
56          nop;                                           \
57         nop; nop; nop; nop; nop; nop;
58         
59 #define TRAP_NOSAVE_7INSNS(routine)                     \
60         ba,pt   %xcc, routine;                          \
61          nop;                                           \
62         nop; nop; nop; nop; nop;
63         
64 #define TRAPTL1(routine)                                \
65         sethi   %hi(109f), %g7;                         \
66         ba,pt   %xcc, etraptl1;                         \
67 109:     or     %g7, %lo(109b), %g7;                    \
68         call    routine;                                \
69          add    %sp, PTREGS_OFF, %o0;                   \
70         ba,pt   %xcc, rtrap;                            \
71          clr    %l6;                                    \
72         nop;
73         
74 #define TRAP_ARG(routine, arg)                          \
75         sethi   %hi(109f), %g7;                         \
76         ba,pt   %xcc, etrap;                            \
77 109:     or     %g7, %lo(109b), %g7;                    \
78         add     %sp, PTREGS_OFF, %o0;                   \
79         call    routine;                                \
80          mov    arg, %o1;                               \
81         ba,pt   %xcc, rtrap;                            \
82          clr    %l6;
83         
84 #define TRAPTL1_ARG(routine, arg)                       \
85         sethi   %hi(109f), %g7;                         \
86         ba,pt   %xcc, etraptl1;                         \
87 109:     or     %g7, %lo(109b), %g7;                    \
88         add     %sp, PTREGS_OFF, %o0;                   \
89         call    routine;                                \
90          mov    arg, %o1;                               \
91         ba,pt   %xcc, rtrap;                            \
92          clr    %l6;
93         
94 #define SYSCALL_TRAP(routine, systbl)                   \
95         sethi   %hi(109f), %g7;                         \
96         ba,pt   %xcc, scetrap;                          \
97 109:     or     %g7, %lo(109b), %g7;                    \
98         sethi   %hi(systbl), %l7;                       \
99         ba,pt   %xcc, routine;                          \
100          or     %l7, %lo(systbl), %l7;                  \
101         nop; nop;
102         
103 #define INDIRECT_SOLARIS_SYSCALL(num)                   \
104         sethi   %hi(109f), %g7;                         \
105         ba,pt   %xcc, etrap;                            \
106 109:     or     %g7, %lo(109b), %g7;                    \
107         ba,pt   %xcc, tl0_solaris + 0xc;                \
108          mov    num, %g1;                               \
109         nop;nop;nop;
110         
111 #define TRAP_UTRAP(handler,lvl)                         \
112         ldx     [%g6 + TI_UTRAPS], %g1;                 \
113         sethi   %hi(109f), %g7;                         \
114         brz,pn  %g1, utrap;                             \
115          or     %g7, %lo(109f), %g7;                    \
116         ba,pt   %xcc, utrap;                            \
117 109:     ldx    [%g1 + handler*8], %g1;                 \
118         ba,pt   %xcc, utrap_ill;                        \
119          mov    lvl, %o1;
120
121 #ifdef CONFIG_SUNOS_EMUL
122 #define SUNOS_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall32, sunos_sys_table)
123 #else
124 #define SUNOS_SYSCALL_TRAP TRAP(sunos_syscall)
125 #endif
126 #define LINUX_32BIT_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall32, sys_call_table32)
127 #define LINUX_64BIT_SYSCALL_TRAP SYSCALL_TRAP(linux_sparc_syscall, sys_call_table64)
128 #define GETCC_TRAP TRAP(getcc)
129 #define SETCC_TRAP TRAP(setcc)
130 #ifdef CONFIG_SOLARIS_EMUL
131 #define SOLARIS_SYSCALL_TRAP TRAP(solaris_sparc_syscall)
132 #else
133 #define SOLARIS_SYSCALL_TRAP TRAP(solaris_syscall)
134 #endif
135 /* FIXME: Write these actually */       
136 #define NETBSD_SYSCALL_TRAP TRAP(netbsd_syscall)
137 #define BREAKPOINT_TRAP TRAP(breakpoint_trap)
138
139 #define TRAP_IRQ(routine, level)                        \
140         rdpr    %pil, %g2;                              \
141         wrpr    %g0, 15, %pil;                          \
142         b,pt    %xcc, etrap_irq;                        \
143          rd     %pc, %g7;                               \
144         mov     level, %o0;                             \
145         call    routine;                                \
146          add    %sp, PTREGS_OFF, %o1;                   \
147         ba,a,pt %xcc, rtrap_irq;
148         
149 #define TICK_SMP_IRQ                                    \
150         rdpr    %pil, %g2;                              \
151         wrpr    %g0, 15, %pil;                          \
152         sethi   %hi(109f), %g7;                         \
153         b,pt    %xcc, etrap_irq;                        \
154 109:     or     %g7, %lo(109b), %g7;                    \
155         call    smp_percpu_timer_interrupt;             \
156          add    %sp, PTREGS_OFF, %o0;                   \
157         ba,a,pt %xcc, rtrap_irq;
158
159 #define TRAP_IVEC TRAP_NOSAVE(do_ivec)
160
161 #define BTRAP(lvl) TRAP_ARG(bad_trap, lvl)
162
163 #define BTRAPTL1(lvl) TRAPTL1_ARG(bad_trap_tl1, lvl)
164
165 #define FLUSH_WINDOW_TRAP                                               \
166         ba,pt   %xcc, etrap;                                            \
167          rd     %pc, %g7;                                               \
168         flushw;                                                         \
169         ldx     [%sp + PTREGS_OFF + PT_V9_TNPC], %l1;                   \
170         add     %l1, 4, %l2;                                            \
171         stx     %l1, [%sp + PTREGS_OFF + PT_V9_TPC];                    \
172         ba,pt   %xcc, rtrap_clr_l6;                                     \
173          stx    %l2, [%sp + PTREGS_OFF + PT_V9_TNPC];
174                 
175 /* Before touching these macros, you owe it to yourself to go and
176  * see how arch/sparc64/kernel/winfixup.S works... -DaveM
177  *
178  * For the user cases we used to use the %asi register, but
179  * it turns out that the "wr xxx, %asi" costs ~5 cycles, so
180  * now we use immediate ASI loads and stores instead.  Kudos
181  * to Greg Onufer for pointing out this performance anomaly.
182  *
183  * Further note that we cannot use the g2, g4, g5, and g7 alternate
184  * globals in the spill routines, check out the save instruction in
185  * arch/sparc64/kernel/etrap.S to see what I mean about g2, and
186  * g4/g5 are the globals which are preserved by etrap processing
187  * for the caller of it.  The g7 register is the return pc for
188  * etrap.  Finally, g6 is the current thread register so we cannot
189  * us it in the spill handlers either.  Most of these rules do not
190  * apply to fill processing, only g6 is not usable.
191  */
192
193 /* Normal kernel spill */
194 #define SPILL_0_NORMAL                                  \
195         stx     %l0, [%sp + STACK_BIAS + 0x00];         \
196         stx     %l1, [%sp + STACK_BIAS + 0x08];         \
197         stx     %l2, [%sp + STACK_BIAS + 0x10];         \
198         stx     %l3, [%sp + STACK_BIAS + 0x18];         \
199         stx     %l4, [%sp + STACK_BIAS + 0x20];         \
200         stx     %l5, [%sp + STACK_BIAS + 0x28];         \
201         stx     %l6, [%sp + STACK_BIAS + 0x30];         \
202         stx     %l7, [%sp + STACK_BIAS + 0x38];         \
203         stx     %i0, [%sp + STACK_BIAS + 0x40];         \
204         stx     %i1, [%sp + STACK_BIAS + 0x48];         \
205         stx     %i2, [%sp + STACK_BIAS + 0x50];         \
206         stx     %i3, [%sp + STACK_BIAS + 0x58];         \
207         stx     %i4, [%sp + STACK_BIAS + 0x60];         \
208         stx     %i5, [%sp + STACK_BIAS + 0x68];         \
209         stx     %i6, [%sp + STACK_BIAS + 0x70];         \
210         stx     %i7, [%sp + STACK_BIAS + 0x78];         \
211         saved; retry; nop; nop; nop; nop; nop; nop;     \
212         nop; nop; nop; nop; nop; nop; nop; nop;
213
214 /* Normal 64bit spill */
215 #define SPILL_1_GENERIC(ASI)                            \
216         add     %sp, STACK_BIAS + 0x00, %g1;            \
217         stxa    %l0, [%g1 + %g0] ASI;                   \
218         mov     0x08, %g3;                              \
219         stxa    %l1, [%g1 + %g3] ASI;                   \
220         add     %g1, 0x10, %g1;                         \
221         stxa    %l2, [%g1 + %g0] ASI;                   \
222         stxa    %l3, [%g1 + %g3] ASI;                   \
223         add     %g1, 0x10, %g1;                         \
224         stxa    %l4, [%g1 + %g0] ASI;                   \
225         stxa    %l5, [%g1 + %g3] ASI;                   \
226         add     %g1, 0x10, %g1;                         \
227         stxa    %l6, [%g1 + %g0] ASI;                   \
228         stxa    %l7, [%g1 + %g3] ASI;                   \
229         add     %g1, 0x10, %g1;                         \
230         stxa    %i0, [%g1 + %g0] ASI;                   \
231         stxa    %i1, [%g1 + %g3] ASI;                   \
232         add     %g1, 0x10, %g1;                         \
233         stxa    %i2, [%g1 + %g0] ASI;                   \
234         stxa    %i3, [%g1 + %g3] ASI;                   \
235         add     %g1, 0x10, %g1;                         \
236         stxa    %i4, [%g1 + %g0] ASI;                   \
237         stxa    %i5, [%g1 + %g3] ASI;                   \
238         add     %g1, 0x10, %g1;                         \
239         stxa    %i6, [%g1 + %g0] ASI;                   \
240         stxa    %i7, [%g1 + %g3] ASI;                   \
241         saved;                                          \
242         retry; nop; nop;                                \
243         b,a,pt  %xcc, spill_fixup_dax;                  \
244         b,a,pt  %xcc, spill_fixup_mna;                  \
245         b,a,pt  %xcc, spill_fixup;
246
247 /* Normal 32bit spill */
248 #define SPILL_2_GENERIC(ASI)                            \
249         srl     %sp, 0, %sp;                            \
250         stwa    %l0, [%sp + %g0] ASI;                   \
251         mov     0x04, %g3;                              \
252         stwa    %l1, [%sp + %g3] ASI;                   \
253         add     %sp, 0x08, %g1;                         \
254         stwa    %l2, [%g1 + %g0] ASI;                   \
255         stwa    %l3, [%g1 + %g3] ASI;                   \
256         add     %g1, 0x08, %g1;                         \
257         stwa    %l4, [%g1 + %g0] ASI;                   \
258         stwa    %l5, [%g1 + %g3] ASI;                   \
259         add     %g1, 0x08, %g1;                         \
260         stwa    %l6, [%g1 + %g0] ASI;                   \
261         stwa    %l7, [%g1 + %g3] ASI;                   \
262         add     %g1, 0x08, %g1;                         \
263         stwa    %i0, [%g1 + %g0] ASI;                   \
264         stwa    %i1, [%g1 + %g3] ASI;                   \
265         add     %g1, 0x08, %g1;                         \
266         stwa    %i2, [%g1 + %g0] ASI;                   \
267         stwa    %i3, [%g1 + %g3] ASI;                   \
268         add     %g1, 0x08, %g1;                         \
269         stwa    %i4, [%g1 + %g0] ASI;                   \
270         stwa    %i5, [%g1 + %g3] ASI;                   \
271         add     %g1, 0x08, %g1;                         \
272         stwa    %i6, [%g1 + %g0] ASI;                   \
273         stwa    %i7, [%g1 + %g3] ASI;                   \
274         saved;                                          \
275         retry; nop; nop;                                \
276         b,a,pt  %xcc, spill_fixup_dax;                  \
277         b,a,pt  %xcc, spill_fixup_mna;                  \
278         b,a,pt  %xcc, spill_fixup;
279
280 #define SPILL_1_NORMAL SPILL_1_GENERIC(ASI_AIUP)
281 #define SPILL_2_NORMAL SPILL_2_GENERIC(ASI_AIUP)
282 #define SPILL_3_NORMAL SPILL_0_NORMAL
283 #define SPILL_4_NORMAL SPILL_0_NORMAL
284 #define SPILL_5_NORMAL SPILL_0_NORMAL
285 #define SPILL_6_NORMAL SPILL_0_NORMAL
286 #define SPILL_7_NORMAL SPILL_0_NORMAL
287
288 #define SPILL_0_OTHER SPILL_0_NORMAL
289 #define SPILL_1_OTHER SPILL_1_GENERIC(ASI_AIUS)
290 #define SPILL_2_OTHER SPILL_2_GENERIC(ASI_AIUS)
291 #define SPILL_3_OTHER SPILL_3_NORMAL
292 #define SPILL_4_OTHER SPILL_4_NORMAL
293 #define SPILL_5_OTHER SPILL_5_NORMAL
294 #define SPILL_6_OTHER SPILL_6_NORMAL
295 #define SPILL_7_OTHER SPILL_7_NORMAL
296
297 /* Normal kernel fill */
298 #define FILL_0_NORMAL                                   \
299         ldx     [%sp + STACK_BIAS + 0x00], %l0;         \
300         ldx     [%sp + STACK_BIAS + 0x08], %l1;         \
301         ldx     [%sp + STACK_BIAS + 0x10], %l2;         \
302         ldx     [%sp + STACK_BIAS + 0x18], %l3;         \
303         ldx     [%sp + STACK_BIAS + 0x20], %l4;         \
304         ldx     [%sp + STACK_BIAS + 0x28], %l5;         \
305         ldx     [%sp + STACK_BIAS + 0x30], %l6;         \
306         ldx     [%sp + STACK_BIAS + 0x38], %l7;         \
307         ldx     [%sp + STACK_BIAS + 0x40], %i0;         \
308         ldx     [%sp + STACK_BIAS + 0x48], %i1;         \
309         ldx     [%sp + STACK_BIAS + 0x50], %i2;         \
310         ldx     [%sp + STACK_BIAS + 0x58], %i3;         \
311         ldx     [%sp + STACK_BIAS + 0x60], %i4;         \
312         ldx     [%sp + STACK_BIAS + 0x68], %i5;         \
313         ldx     [%sp + STACK_BIAS + 0x70], %i6;         \
314         ldx     [%sp + STACK_BIAS + 0x78], %i7;         \
315         restored; retry; nop; nop; nop; nop; nop; nop;  \
316         nop; nop; nop; nop; nop; nop; nop; nop;
317
318 /* Normal 64bit fill */
319 #define FILL_1_GENERIC(ASI)                             \
320         add     %sp, STACK_BIAS + 0x00, %g1;            \
321         ldxa    [%g1 + %g0] ASI, %l0;                   \
322         mov     0x08, %g2;                              \
323         mov     0x10, %g3;                              \
324         ldxa    [%g1 + %g2] ASI, %l1;                   \
325         mov     0x18, %g5;                              \
326         ldxa    [%g1 + %g3] ASI, %l2;                   \
327         ldxa    [%g1 + %g5] ASI, %l3;                   \
328         add     %g1, 0x20, %g1;                         \
329         ldxa    [%g1 + %g0] ASI, %l4;                   \
330         ldxa    [%g1 + %g2] ASI, %l5;                   \
331         ldxa    [%g1 + %g3] ASI, %l6;                   \
332         ldxa    [%g1 + %g5] ASI, %l7;                   \
333         add     %g1, 0x20, %g1;                         \
334         ldxa    [%g1 + %g0] ASI, %i0;                   \
335         ldxa    [%g1 + %g2] ASI, %i1;                   \
336         ldxa    [%g1 + %g3] ASI, %i2;                   \
337         ldxa    [%g1 + %g5] ASI, %i3;                   \
338         add     %g1, 0x20, %g1;                         \
339         ldxa    [%g1 + %g0] ASI, %i4;                   \
340         ldxa    [%g1 + %g2] ASI, %i5;                   \
341         ldxa    [%g1 + %g3] ASI, %i6;                   \
342         ldxa    [%g1 + %g5] ASI, %i7;                   \
343         restored;                                       \
344         retry; nop; nop; nop; nop;                      \
345         b,a,pt  %xcc, fill_fixup_dax;                   \
346         b,a,pt  %xcc, fill_fixup_mna;                   \
347         b,a,pt  %xcc, fill_fixup;
348
349 /* Normal 32bit fill */
350 #define FILL_2_GENERIC(ASI)                             \
351         srl     %sp, 0, %sp;                            \
352         lduwa   [%sp + %g0] ASI, %l0;                   \
353         mov     0x04, %g2;                              \
354         mov     0x08, %g3;                              \
355         lduwa   [%sp + %g2] ASI, %l1;                   \
356         mov     0x0c, %g5;                              \
357         lduwa   [%sp + %g3] ASI, %l2;                   \
358         lduwa   [%sp + %g5] ASI, %l3;                   \
359         add     %sp, 0x10, %g1;                         \
360         lduwa   [%g1 + %g0] ASI, %l4;                   \
361         lduwa   [%g1 + %g2] ASI, %l5;                   \
362         lduwa   [%g1 + %g3] ASI, %l6;                   \
363         lduwa   [%g1 + %g5] ASI, %l7;                   \
364         add     %g1, 0x10, %g1;                         \
365         lduwa   [%g1 + %g0] ASI, %i0;                   \
366         lduwa   [%g1 + %g2] ASI, %i1;                   \
367         lduwa   [%g1 + %g3] ASI, %i2;                   \
368         lduwa   [%g1 + %g5] ASI, %i3;                   \
369         add     %g1, 0x10, %g1;                         \
370         lduwa   [%g1 + %g0] ASI, %i4;                   \
371         lduwa   [%g1 + %g2] ASI, %i5;                   \
372         lduwa   [%g1 + %g3] ASI, %i6;                   \
373         lduwa   [%g1 + %g5] ASI, %i7;                   \
374         restored;                                       \
375         retry; nop; nop; nop; nop;                      \
376         b,a,pt  %xcc, fill_fixup_dax;                   \
377         b,a,pt  %xcc, fill_fixup_mna;                   \
378         b,a,pt  %xcc, fill_fixup;
379
380 #define FILL_1_NORMAL FILL_1_GENERIC(ASI_AIUP)
381 #define FILL_2_NORMAL FILL_2_GENERIC(ASI_AIUP)
382 #define FILL_3_NORMAL FILL_0_NORMAL
383 #define FILL_4_NORMAL FILL_0_NORMAL
384 #define FILL_5_NORMAL FILL_0_NORMAL
385 #define FILL_6_NORMAL FILL_0_NORMAL
386 #define FILL_7_NORMAL FILL_0_NORMAL
387
388 #define FILL_0_OTHER FILL_0_NORMAL
389 #define FILL_1_OTHER FILL_1_GENERIC(ASI_AIUS)
390 #define FILL_2_OTHER FILL_2_GENERIC(ASI_AIUS)
391 #define FILL_3_OTHER FILL_3_NORMAL
392 #define FILL_4_OTHER FILL_4_NORMAL
393 #define FILL_5_OTHER FILL_5_NORMAL
394 #define FILL_6_OTHER FILL_6_NORMAL
395 #define FILL_7_OTHER FILL_7_NORMAL
396
397 #endif /* !(_SPARC64_TTABLE_H) */