RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / mips / kernel / genex.S
blob8ed25cbf217618dddb99850ceea342f1723320c8
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
7  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8  * Copyright (C) 2001 MIPS Technologies, Inc.
9  * Copyright (C) 2002 Maciej W. Rozycki
10  */
11 #include <linux/init.h>
13 #include <asm/asm.h>
14 #include <asm/asmmacro.h>
15 #include <asm/cacheops.h>
16 #include <asm/irqflags.h>
17 #include <asm/regdef.h>
18 #include <asm/fpregdef.h>
19 #include <asm/mipsregs.h>
20 #include <asm/stackframe.h>
21 #include <asm/war.h>
22 #include <asm/page.h>
23 #include <asm/thread_info.h>
25 #define PANIC_PIC(msg)                                  \
26                 .set push;                              \
27                 .set    reorder;                        \
28                 PTR_LA  a0,8f;                          \
29                 .set    noat;                           \
30                 PTR_LA  AT, panic;                      \
31                 jr      AT;                             \
32 9:              b       9b;                             \
33                 .set    pop;                            \
34                 TEXT(msg)
36         __INIT
38 NESTED(except_vec0_generic, 0, sp)
39         PANIC_PIC("Exception vector 0 called")
40         END(except_vec0_generic)
42 NESTED(except_vec1_generic, 0, sp)
43         PANIC_PIC("Exception vector 1 called")
44         END(except_vec1_generic)
47  * General exception vector for all other CPUs.
48  *
49  * Be careful when changing this, it has to be at most 128 bytes
50  * to fit into space reserved for the exception handler.
51  */
52 NESTED(except_vec3_generic, 0, sp)
53         .set    push
54         .set    noat
55 #ifdef CONFIG_BCM47XX
56         nop
57         nop
58 #endif
59 #if R5432_CP0_INTERRUPT_WAR
60         mfc0    k0, CP0_INDEX
61 #endif
62 #ifdef CONFIG_BCM47XX
63         nop
64         nop
65 #endif          
66         mfc0    k1, CP0_CAUSE
67         andi    k1, k1, 0x7c
68 #ifdef CONFIG_64BIT
69         dsll    k1, k1, 1
70 #endif
71         PTR_L   k0, exception_handlers(k1)
72         jr      k0
73         .set    pop
74         END(except_vec3_generic)
77  * General exception handler for CPUs with virtual coherency exception.
78  *
79  * Be careful when changing this, it has to be at most 256 (as a special
80  * exception) bytes to fit into space reserved for the exception handler.
81  */
82 NESTED(except_vec3_r4000, 0, sp)
83         .set    push
84         .set    mips3
85         .set    noat
86         mfc0    k1, CP0_CAUSE
87         li      k0, 31<<2
88         andi    k1, k1, 0x7c
89         .set    push
90         .set    noreorder
91         .set    nomacro
92         beq     k1, k0, handle_vced
93          li     k0, 14<<2
94         beq     k1, k0, handle_vcei
95 #ifdef CONFIG_64BIT
96          dsll   k1, k1, 1
97 #endif
98         .set    pop
99         PTR_L   k0, exception_handlers(k1)
100         jr      k0
102         /*
103          * Big shit, we now may have two dirty primary cache lines for the same
104          * physical address.  We can safely invalidate the line pointed to by
105          * c0_badvaddr because after return from this exception handler the
106          * load / store will be re-executed.
107          */
108 handle_vced:
109         MFC0    k0, CP0_BADVADDR
110         li      k1, -4                                  # Is this ...
111         and     k0, k1                                  # ... really needed?
112         mtc0    zero, CP0_TAGLO
113         cache   Index_Store_Tag_D, (k0)
114         cache   Hit_Writeback_Inv_SD, (k0)
115 #ifdef CONFIG_PROC_FS
116         PTR_LA  k0, vced_count
117         lw      k1, (k0)
118         addiu   k1, 1
119         sw      k1, (k0)
120 #endif
121         eret
123 handle_vcei:
124         MFC0    k0, CP0_BADVADDR
125         cache   Hit_Writeback_Inv_SD, (k0)              # also cleans pi
126 #ifdef CONFIG_PROC_FS
127         PTR_LA  k0, vcei_count
128         lw      k1, (k0)
129         addiu   k1, 1
130         sw      k1, (k0)
131 #endif
132         eret
133         .set    pop
134         END(except_vec3_r4000)
136         __FINIT
138         .align  5       /* 32 byte rollback region */
139 LEAF(r4k_wait)
140         .set    push
141         .set    noreorder
142         /* start of rollback region */
143         LONG_L  t0, TI_FLAGS($28)
144         nop
145         andi    t0, _TIF_NEED_RESCHED
146         bnez    t0, 1f
147          nop
148         nop
149         nop
150         .set    mips3
151         wait
152         /* end of rollback region (the region size must be power of two) */
153         .set    pop
155         jr      ra
156         END(r4k_wait)
158         .macro  BUILD_ROLLBACK_PROLOGUE handler
159         FEXPORT(rollback_\handler)
160         .set    push
161         .set    noat
162         MFC0    k0, CP0_EPC
163         PTR_LA  k1, r4k_wait
164         ori     k0, 0x1f        /* 32 byte rollback region */
165         xori    k0, 0x1f
166         bne     k0, k1, 9f
167         MTC0    k0, CP0_EPC
169         .set pop
170         .endm
172         .align  5
173 BUILD_ROLLBACK_PROLOGUE handle_int
174 NESTED(handle_int, PT_SIZE, sp)
175 #ifdef CONFIG_TRACE_IRQFLAGS
176         /*
177          * Check to see if the interrupted code has just disabled
178          * interrupts and ignore this interrupt for now if so.
179          *
180          * local_irq_disable() disables interrupts and then calls
181          * trace_hardirqs_off() to track the state. If an interrupt is taken
182          * after interrupts are disabled but before the state is updated
183          * it will appear to restore_all that it is incorrectly returning with
184          * interrupts disabled
185          */
186         .set    push
187         .set    noat
188         mfc0    k0, CP0_STATUS
189 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
190         and     k0, ST0_IEP
191         bnez    k0, 1f
193         mfc0    k0, CP0_EPC
194         .set    noreorder
195         j       k0
196         rfe
197 #else
198         and     k0, ST0_IE
199         bnez    k0, 1f
201         eret
202 #endif
204         .set pop
205 #endif
206         SAVE_ALL
207         CLI
208         TRACE_IRQS_OFF
210         LONG_L  s0, TI_REGS($28)
211         LONG_S  sp, TI_REGS($28)
212         PTR_LA  ra, ret_from_irq
213         j       plat_irq_dispatch
214         END(handle_int)
216         __INIT
219  * Special interrupt vector for MIPS64 ISA & embedded MIPS processors.
220  * This is a dedicated interrupt exception vector which reduces the
221  * interrupt processing overhead.  The jump instruction will be replaced
222  * at the initialization time.
224  * Be careful when changing this, it has to be at most 128 bytes
225  * to fit into space reserved for the exception handler.
226  */
227 NESTED(except_vec4, 0, sp)
228 1:      j       1b                      /* Dummy, will be replaced */
229         END(except_vec4)
232  * EJTAG debug exception handler.
233  * The EJTAG debug exception entry point is 0xbfc00480, which
234  * normally is in the boot PROM, so the boot PROM must do a
235  * unconditional jump to this vector.
236  */
237 NESTED(except_vec_ejtag_debug, 0, sp)
238         j       ejtag_debug_handler
239         END(except_vec_ejtag_debug)
241         __FINIT
244  * Vectored interrupt handler.
245  * This prototype is copied to ebase + n*IntCtl.VS and patched
246  * to invoke the handler
247  */
248 BUILD_ROLLBACK_PROLOGUE except_vec_vi
249 NESTED(except_vec_vi, 0, sp)
250         SAVE_SOME
251         SAVE_AT
252         .set    push
253         .set    noreorder
254 #ifdef CONFIG_MIPS_MT_SMTC
255         /*
256          * To keep from blindly blocking *all* interrupts
257          * during service by SMTC kernel, we also want to
258          * pass the IM value to be cleared.
259          */
260 FEXPORT(except_vec_vi_mori)
261         ori     a0, $0, 0
262 #endif /* CONFIG_MIPS_MT_SMTC */
263 FEXPORT(except_vec_vi_lui)
264         lui     v0, 0           /* Patched */
265         j       except_vec_vi_handler
266 FEXPORT(except_vec_vi_ori)
267          ori    v0, 0           /* Patched */
268         .set    pop
269         END(except_vec_vi)
270 EXPORT(except_vec_vi_end)
273  * Common Vectored Interrupt code
274  * Complete the register saves and invoke the handler which is passed in $v0
275  */
276 NESTED(except_vec_vi_handler, 0, sp)
277         SAVE_TEMP
278         SAVE_STATIC
279 #ifdef CONFIG_MIPS_MT_SMTC
280         /*
281          * SMTC has an interesting problem that interrupts are level-triggered,
282          * and the CLI macro will clear EXL, potentially causing a duplicate
283          * interrupt service invocation. So we need to clear the associated
284          * IM bit of Status prior to doing CLI, and restore it after the
285          * service routine has been invoked - we must assume that the
286          * service routine will have cleared the state, and any active
287          * level represents a new or otherwised unserviced event...
288          */
289         mfc0    t1, CP0_STATUS
290         and     t0, a0, t1
291 #ifdef CONFIG_MIPS_MT_SMTC_IM_BACKSTOP
292         mfc0    t2, CP0_TCCONTEXT
293         or      t0, t0, t2
294         mtc0    t0, CP0_TCCONTEXT
295 #endif /* CONFIG_MIPS_MT_SMTC_IM_BACKSTOP */
296         xor     t1, t1, t0
297         mtc0    t1, CP0_STATUS
298         _ehb
299 #endif /* CONFIG_MIPS_MT_SMTC */
300         CLI
301 #ifdef CONFIG_TRACE_IRQFLAGS
302         move    s0, v0
303 #ifdef CONFIG_MIPS_MT_SMTC
304         move    s1, a0
305 #endif
306         TRACE_IRQS_OFF
307 #ifdef CONFIG_MIPS_MT_SMTC
308         move    a0, s1
309 #endif
310         move    v0, s0
311 #endif
313         LONG_L  s0, TI_REGS($28)
314         LONG_S  sp, TI_REGS($28)
315         PTR_LA  ra, ret_from_irq
316         jr      v0
317         END(except_vec_vi_handler)
320  * EJTAG debug exception handler.
321  */
322 NESTED(ejtag_debug_handler, PT_SIZE, sp)
323         .set    push
324         .set    noat
325         MTC0    k0, CP0_DESAVE
326         mfc0    k0, CP0_DEBUG
328         sll     k0, k0, 30      # Check for SDBBP.
329         bgez    k0, ejtag_return
331         PTR_LA  k0, ejtag_debug_buffer
332         LONG_S  k1, 0(k0)
333         SAVE_ALL
334         move    a0, sp
335         jal     ejtag_exception_handler
336         RESTORE_ALL
337         PTR_LA  k0, ejtag_debug_buffer
338         LONG_L  k1, 0(k0)
340 ejtag_return:
341         MFC0    k0, CP0_DESAVE
342         .set    mips32
343         deret
344         .set pop
345         END(ejtag_debug_handler)
348  * This buffer is reserved for the use of the EJTAG debug
349  * handler.
350  */
351         .data
352 EXPORT(ejtag_debug_buffer)
353         .fill   LONGSIZE
354         .previous
356         __INIT
359  * NMI debug exception handler for MIPS reference boards.
360  * The NMI debug exception entry point is 0xbfc00000, which
361  * normally is in the boot PROM, so the boot PROM must do a
362  * unconditional jump to this vector.
363  */
364 NESTED(except_vec_nmi, 0, sp)
365         j       nmi_handler
366         END(except_vec_nmi)
368         __FINIT
370 NESTED(nmi_handler, PT_SIZE, sp)
371         .set    push
372         .set    noat
373         SAVE_ALL
374         move    a0, sp
375         jal     nmi_exception_handler
376         RESTORE_ALL
377         .set    mips3
378         eret
379         .set    pop
380         END(nmi_handler)
382         .macro  __build_clear_none
383         .endm
385         .macro  __build_clear_sti
386         TRACE_IRQS_ON
387         STI
388         .endm
390         .macro  __build_clear_cli
391         CLI
392         TRACE_IRQS_OFF
393         .endm
395         .macro  __build_clear_fpe
396         cfc1    a1, fcr31
397         li      a2, ~(0x3f << 12)
398         and     a2, a1
399         ctc1    a2, fcr31
400         TRACE_IRQS_ON
401         STI
402         .endm
404         .macro  __build_clear_ade
405         MFC0    t0, CP0_BADVADDR
406         PTR_S   t0, PT_BVADDR(sp)
407         KMODE
408         .endm
410         .macro  __BUILD_silent exception
411         .endm
413         /* Gas tries to parse the PRINT argument as a string containing
414            string escapes and emits bogus warnings if it believes to
415            recognize an unknown escape code.  So make the arguments
416            start with an n and gas will believe \n is ok ...  */
417         .macro  __BUILD_verbose nexception
418         LONG_L  a1, PT_EPC(sp)
419 #ifdef CONFIG_32BIT
420         PRINT("Got \nexception at %08lx\012")
421 #endif
422 #ifdef CONFIG_64BIT
423         PRINT("Got \nexception at %016lx\012")
424 #endif
425         .endm
427         .macro  __BUILD_count exception
428         LONG_L  t0,exception_count_\exception
429         LONG_ADDIU t0, 1
430         LONG_S  t0,exception_count_\exception
431         .comm   exception_count\exception, 8, 8
432         .endm
434         .macro  __BUILD_HANDLER exception handler clear verbose ext
435         .align  5
436         NESTED(handle_\exception, PT_SIZE, sp)
437         .set    noat
438         SAVE_ALL
439         FEXPORT(handle_\exception\ext)
440         __BUILD_clear_\clear
441         .set    at
442         __BUILD_\verbose \exception
443         move    a0, sp
444         PTR_LA  ra, ret_from_exception
445         j       do_\handler
446         END(handle_\exception)
447         .endm
449         .macro  BUILD_HANDLER exception handler clear verbose
450         __BUILD_HANDLER \exception \handler \clear \verbose _int
451         .endm
453         BUILD_HANDLER adel ade ade silent               /* #4  */
454         BUILD_HANDLER ades ade ade silent               /* #5  */
455         BUILD_HANDLER ibe be cli silent                 /* #6  */
456         BUILD_HANDLER dbe be cli silent                 /* #7  */
457         BUILD_HANDLER bp bp sti silent                  /* #9  */
458         BUILD_HANDLER ri ri sti silent                  /* #10 */
459         BUILD_HANDLER cpu cpu sti silent                /* #11 */
460         BUILD_HANDLER ov ov sti silent                  /* #12 */
461         BUILD_HANDLER tr tr sti silent                  /* #13 */
462         BUILD_HANDLER fpe fpe fpe silent                /* #15 */
463         BUILD_HANDLER mdmx mdmx sti silent              /* #22 */
464         BUILD_HANDLER watch watch sti verbose           /* #23 */
465         BUILD_HANDLER mcheck mcheck cli verbose         /* #24 */
466         BUILD_HANDLER mt mt sti silent                  /* #25 */
467         BUILD_HANDLER dsp dsp sti silent                /* #26 */
468         BUILD_HANDLER reserved reserved sti verbose     /* others */
470         .align  5
471         LEAF(handle_ri_rdhwr_vivt)
472 #ifdef CONFIG_MIPS_MT_SMTC
473         PANIC_PIC("handle_ri_rdhwr_vivt called")
474 #else
475         .set    push
476         .set    noat
477         .set    noreorder
478         /* check if TLB contains a entry for EPC */
479         MFC0    k1, CP0_ENTRYHI
480         andi    k1, 0xff        /* ASID_MASK */
481         MFC0    k0, CP0_EPC
482         PTR_SRL k0, PAGE_SHIFT + 1
483         PTR_SLL k0, PAGE_SHIFT + 1
484         or      k1, k0
485         MTC0    k1, CP0_ENTRYHI
486         mtc0_tlbw_hazard
487         tlbp
488         tlb_probe_hazard
489         mfc0    k1, CP0_INDEX
490         .set    pop
491         bltz    k1, handle_ri   /* slow path */
492         /* fall thru */
493 #endif
494         END(handle_ri_rdhwr_vivt)
496         LEAF(handle_ri_rdhwr)
497         .set    push
498         .set    noat
499         .set    noreorder
500         /* 0x7c03e83b: rdhwr v1,$29 */
501         MFC0    k1, CP0_EPC
502         lui     k0, 0x7c03
503         lw      k1, (k1)
504         ori     k0, 0xe83b
505         .set    reorder
506         bne     k0, k1, handle_ri       /* if not ours */
507         /* The insn is rdhwr.  No need to check CAUSE.BD here. */
508         get_saved_sp    /* k1 := current_thread_info */
509         .set    noreorder
510         MFC0    k0, CP0_EPC
511 #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
512         ori     k1, _THREAD_MASK
513         xori    k1, _THREAD_MASK
514         LONG_L  v1, TI_TP_VALUE(k1)
515         LONG_ADDIU      k0, 4
516         jr      k0
517          rfe
518 #else
519         LONG_ADDIU      k0, 4           /* stall on $k0 */
520         MTC0    k0, CP0_EPC
521         /* I hope three instructions between MTC0 and ERET are enough... */
522         ori     k1, _THREAD_MASK
523         xori    k1, _THREAD_MASK
524         LONG_L  v1, TI_TP_VALUE(k1)
525         .set    mips3
526         eret
527         .set    mips0
528 #endif
529         .set    pop
530         END(handle_ri_rdhwr)
532 #ifdef CONFIG_64BIT
533 /* A temporary overflow handler used by check_daddi(). */
535         __INIT
537         BUILD_HANDLER  daddi_ov daddi_ov none silent    /* #12 */
538 #endif