blob: 5baca16993d08f512c2a1956a21755fd55521a94 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
12
13#include <asm/asm.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010014#include <asm/asmmacro.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/cacheops.h>
Ralf Baechle192ef362006-07-07 14:07:18 +010016#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#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
23#define PANIC_PIC(msg) \
24 .set push; \
25 .set reorder; \
26 PTR_LA a0,8f; \
27 .set noat; \
28 PTR_LA AT, panic; \
29 jr AT; \
309: b 9b; \
31 .set pop; \
32 TEXT(msg)
33
34 __INIT
35
36NESTED(except_vec0_generic, 0, sp)
37 PANIC_PIC("Exception vector 0 called")
38 END(except_vec0_generic)
39
40NESTED(except_vec1_generic, 0, sp)
41 PANIC_PIC("Exception vector 1 called")
42 END(except_vec1_generic)
43
44/*
45 * General exception vector for all other CPUs.
46 *
47 * Be careful when changing this, it has to be at most 128 bytes
48 * to fit into space reserved for the exception handler.
49 */
50NESTED(except_vec3_generic, 0, sp)
51 .set push
52 .set noat
53#if R5432_CP0_INTERRUPT_WAR
54 mfc0 k0, CP0_INDEX
55#endif
56 mfc0 k1, CP0_CAUSE
57 andi k1, k1, 0x7c
Ralf Baechle875d43e2005-09-03 15:56:16 -070058#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 dsll k1, k1, 1
60#endif
61 PTR_L k0, exception_handlers(k1)
62 jr k0
63 .set pop
64 END(except_vec3_generic)
65
66/*
67 * General exception handler for CPUs with virtual coherency exception.
68 *
69 * Be careful when changing this, it has to be at most 256 (as a special
70 * exception) bytes to fit into space reserved for the exception handler.
71 */
72NESTED(except_vec3_r4000, 0, sp)
73 .set push
74 .set mips3
75 .set noat
76 mfc0 k1, CP0_CAUSE
77 li k0, 31<<2
78 andi k1, k1, 0x7c
79 .set push
80 .set noreorder
81 .set nomacro
82 beq k1, k0, handle_vced
83 li k0, 14<<2
84 beq k1, k0, handle_vcei
Ralf Baechle875d43e2005-09-03 15:56:16 -070085#ifdef CONFIG_64BIT
Thiemo Seufer69903d62004-12-08 10:32:45 +000086 dsll k1, k1, 1
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#endif
88 .set pop
89 PTR_L k0, exception_handlers(k1)
90 jr k0
91
92 /*
93 * Big shit, we now may have two dirty primary cache lines for the same
Thiemo Seufer69903d62004-12-08 10:32:45 +000094 * physical address. We can safely invalidate the line pointed to by
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 * c0_badvaddr because after return from this exception handler the
96 * load / store will be re-executed.
97 */
98handle_vced:
Thiemo Seufer69903d62004-12-08 10:32:45 +000099 MFC0 k0, CP0_BADVADDR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 li k1, -4 # Is this ...
101 and k0, k1 # ... really needed?
102 mtc0 zero, CP0_TAGLO
Thiemo Seufer69903d62004-12-08 10:32:45 +0000103 cache Index_Store_Tag_D, (k0)
104 cache Hit_Writeback_Inv_SD, (k0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#ifdef CONFIG_PROC_FS
106 PTR_LA k0, vced_count
107 lw k1, (k0)
108 addiu k1, 1
109 sw k1, (k0)
110#endif
111 eret
112
113handle_vcei:
114 MFC0 k0, CP0_BADVADDR
115 cache Hit_Writeback_Inv_SD, (k0) # also cleans pi
116#ifdef CONFIG_PROC_FS
117 PTR_LA k0, vcei_count
118 lw k1, (k0)
119 addiu k1, 1
120 sw k1, (k0)
121#endif
122 eret
123 .set pop
124 END(except_vec3_r4000)
125
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100126 __FINIT
127
128 .align 5
129NESTED(handle_int, PT_SIZE, sp)
130 SAVE_ALL
131 CLI
Ralf Baechle192ef362006-07-07 14:07:18 +0100132 TRACE_IRQS_OFF
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100133
Ralf Baechle937a8012006-10-07 19:44:33 +0100134 LONG_L s0, TI_REGS($28)
135 LONG_S sp, TI_REGS($28)
Atsushi Nemotof431baa2006-10-09 01:24:23 +0900136 PTR_LA ra, ret_from_irq
137 j plat_irq_dispatch
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100138 END(handle_int)
139
140 __INIT
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/*
143 * Special interrupt vector for MIPS64 ISA & embedded MIPS processors.
144 * This is a dedicated interrupt exception vector which reduces the
145 * interrupt processing overhead. The jump instruction will be replaced
146 * at the initialization time.
147 *
148 * Be careful when changing this, it has to be at most 128 bytes
149 * to fit into space reserved for the exception handler.
150 */
151NESTED(except_vec4, 0, sp)
1521: j 1b /* Dummy, will be replaced */
153 END(except_vec4)
154
155/*
156 * EJTAG debug exception handler.
157 * The EJTAG debug exception entry point is 0xbfc00480, which
158 * normally is in the boot PROM, so the boot PROM must do a
159 * unconditional jump to this vector.
160 */
161NESTED(except_vec_ejtag_debug, 0, sp)
162 j ejtag_debug_handler
163 END(except_vec_ejtag_debug)
164
165 __FINIT
166
167/*
Ralf Baechlee01402b2005-07-14 15:57:16 +0000168 * Vectored interrupt handler.
169 * This prototype is copied to ebase + n*IntCtl.VS and patched
170 * to invoke the handler
171 */
172NESTED(except_vec_vi, 0, sp)
173 SAVE_SOME
174 SAVE_AT
175 .set push
176 .set noreorder
Ralf Baechle41c594a2006-04-05 09:45:45 +0100177#ifdef CONFIG_MIPS_MT_SMTC
178 /*
179 * To keep from blindly blocking *all* interrupts
180 * during service by SMTC kernel, we also want to
181 * pass the IM value to be cleared.
182 */
183EXPORT(except_vec_vi_mori)
184 ori a0, $0, 0
185#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechlee01402b2005-07-14 15:57:16 +0000186EXPORT(except_vec_vi_lui)
187 lui v0, 0 /* Patched */
188 j except_vec_vi_handler
189EXPORT(except_vec_vi_ori)
190 ori v0, 0 /* Patched */
191 .set pop
192 END(except_vec_vi)
193EXPORT(except_vec_vi_end)
194
195/*
196 * Common Vectored Interrupt code
197 * Complete the register saves and invoke the handler which is passed in $v0
198 */
199NESTED(except_vec_vi_handler, 0, sp)
200 SAVE_TEMP
201 SAVE_STATIC
Ralf Baechle41c594a2006-04-05 09:45:45 +0100202#ifdef CONFIG_MIPS_MT_SMTC
203 /*
204 * SMTC has an interesting problem that interrupts are level-triggered,
205 * and the CLI macro will clear EXL, potentially causing a duplicate
206 * interrupt service invocation. So we need to clear the associated
207 * IM bit of Status prior to doing CLI, and restore it after the
208 * service routine has been invoked - we must assume that the
209 * service routine will have cleared the state, and any active
210 * level represents a new or otherwised unserviced event...
211 */
212 mfc0 t1, CP0_STATUS
213 and t0, a0, t1
214 mfc0 t2, CP0_TCCONTEXT
215 or t0, t0, t2
216 mtc0 t0, CP0_TCCONTEXT
217 xor t1, t1, t0
218 mtc0 t1, CP0_STATUS
Ralf Baechle4277ff52006-06-03 22:40:15 +0100219 _ehb
Ralf Baechle41c594a2006-04-05 09:45:45 +0100220#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechlee01402b2005-07-14 15:57:16 +0000221 CLI
Ralf Baechle192ef362006-07-07 14:07:18 +0100222 TRACE_IRQS_OFF
Ralf Baechle937a8012006-10-07 19:44:33 +0100223
224 LONG_L s0, TI_REGS($28)
225 LONG_S sp, TI_REGS($28)
Atsushi Nemoto23126692006-09-28 19:15:33 +0900226 PTR_LA ra, ret_from_irq
Atsushi Nemotof431baa2006-10-09 01:24:23 +0900227 jr v0
Ralf Baechlee01402b2005-07-14 15:57:16 +0000228 END(except_vec_vi_handler)
229
230/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 * EJTAG debug exception handler.
232 */
233NESTED(ejtag_debug_handler, PT_SIZE, sp)
234 .set push
235 .set noat
236 MTC0 k0, CP0_DESAVE
237 mfc0 k0, CP0_DEBUG
238
239 sll k0, k0, 30 # Check for SDBBP.
240 bgez k0, ejtag_return
241
242 PTR_LA k0, ejtag_debug_buffer
243 LONG_S k1, 0(k0)
244 SAVE_ALL
245 move a0, sp
246 jal ejtag_exception_handler
247 RESTORE_ALL
248 PTR_LA k0, ejtag_debug_buffer
249 LONG_L k1, 0(k0)
250
251ejtag_return:
252 MFC0 k0, CP0_DESAVE
253 .set mips32
254 deret
255 .set pop
256 END(ejtag_debug_handler)
257
258/*
259 * This buffer is reserved for the use of the EJTAG debug
260 * handler.
261 */
262 .data
263EXPORT(ejtag_debug_buffer)
264 .fill LONGSIZE
265 .previous
266
267 __INIT
268
269/*
270 * NMI debug exception handler for MIPS reference boards.
271 * The NMI debug exception entry point is 0xbfc00000, which
272 * normally is in the boot PROM, so the boot PROM must do a
273 * unconditional jump to this vector.
274 */
275NESTED(except_vec_nmi, 0, sp)
276 j nmi_handler
277 END(except_vec_nmi)
278
279 __FINIT
280
281NESTED(nmi_handler, PT_SIZE, sp)
282 .set push
283 .set noat
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 SAVE_ALL
285 move a0, sp
286 jal nmi_exception_handler
287 RESTORE_ALL
Ralf Baechle4f0638b2006-01-09 20:09:36 +0000288 .set mips3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 eret
290 .set pop
291 END(nmi_handler)
292
293 .macro __build_clear_none
294 .endm
295
296 .macro __build_clear_sti
Ralf Baechle192ef362006-07-07 14:07:18 +0100297 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 STI
299 .endm
300
301 .macro __build_clear_cli
302 CLI
Ralf Baechle192ef362006-07-07 14:07:18 +0100303 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 .endm
305
306 .macro __build_clear_fpe
307 cfc1 a1, fcr31
308 li a2, ~(0x3f << 12)
309 and a2, a1
310 ctc1 a2, fcr31
Ralf Baechle192ef362006-07-07 14:07:18 +0100311 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 STI
313 .endm
314
315 .macro __build_clear_ade
316 MFC0 t0, CP0_BADVADDR
317 PTR_S t0, PT_BVADDR(sp)
318 KMODE
319 .endm
320
321 .macro __BUILD_silent exception
322 .endm
323
324 /* Gas tries to parse the PRINT argument as a string containing
325 string escapes and emits bogus warnings if it believes to
326 recognize an unknown escape code. So make the arguments
327 start with an n and gas will believe \n is ok ... */
328 .macro __BUILD_verbose nexception
329 LONG_L a1, PT_EPC(sp)
Yoichi Yuasa766160c2005-09-03 15:56:22 -0700330#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 PRINT("Got \nexception at %08lx\012")
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700332#endif
Yoichi Yuasa766160c2005-09-03 15:56:22 -0700333#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 PRINT("Got \nexception at %016lx\012")
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700335#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 .endm
337
338 .macro __BUILD_count exception
339 LONG_L t0,exception_count_\exception
340 LONG_ADDIU t0, 1
341 LONG_S t0,exception_count_\exception
342 .comm exception_count\exception, 8, 8
343 .endm
344
345 .macro __BUILD_HANDLER exception handler clear verbose ext
346 .align 5
347 NESTED(handle_\exception, PT_SIZE, sp)
348 .set noat
349 SAVE_ALL
350 FEXPORT(handle_\exception\ext)
351 __BUILD_clear_\clear
352 .set at
353 __BUILD_\verbose \exception
354 move a0, sp
Atsushi Nemoto23126692006-09-28 19:15:33 +0900355 PTR_LA ra, ret_from_exception
356 j do_\handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 END(handle_\exception)
358 .endm
359
360 .macro BUILD_HANDLER exception handler clear verbose
361 __BUILD_HANDLER \exception \handler \clear \verbose _int
362 .endm
363
364 BUILD_HANDLER adel ade ade silent /* #4 */
365 BUILD_HANDLER ades ade ade silent /* #5 */
366 BUILD_HANDLER ibe be cli silent /* #6 */
367 BUILD_HANDLER dbe be cli silent /* #7 */
368 BUILD_HANDLER bp bp sti silent /* #9 */
369 BUILD_HANDLER ri ri sti silent /* #10 */
370 BUILD_HANDLER cpu cpu sti silent /* #11 */
371 BUILD_HANDLER ov ov sti silent /* #12 */
372 BUILD_HANDLER tr tr sti silent /* #13 */
373 BUILD_HANDLER fpe fpe fpe silent /* #15 */
374 BUILD_HANDLER mdmx mdmx sti silent /* #22 */
375 BUILD_HANDLER watch watch sti verbose /* #23 */
376 BUILD_HANDLER mcheck mcheck cli verbose /* #24 */
Chris Dearmane35a5e32006-06-30 14:19:45 +0100377 BUILD_HANDLER mt mt sti silent /* #25 */
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000378 BUILD_HANDLER dsp dsp sti silent /* #26 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 BUILD_HANDLER reserved reserved sti verbose /* others */
380
Ralf Baechle875d43e2005-09-03 15:56:16 -0700381#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/* A temporary overflow handler used by check_daddi(). */
383
384 __INIT
385
386 BUILD_HANDLER daddi_ov daddi_ov none silent /* #12 */
387#endif