x86, apic: Fix spurious error interrupts triggering on all non-boot APs
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / mips / kernel / traps.c
blob31b204b26ba08915e647369fbe6c3c0930a7642e
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.
6 * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle
7 * Copyright (C) 1995, 1996 Paul M. Antoine
8 * Copyright (C) 1998 Ulf Carlsson
9 * Copyright (C) 1999 Silicon Graphics, Inc.
10 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
11 * Copyright (C) 2000, 01 MIPS Technologies, Inc.
12 * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
14 #include <linux/bug.h>
15 #include <linux/compiler.h>
16 #include <linux/init.h>
17 #include <linux/mm.h>
18 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/spinlock.h>
22 #include <linux/kallsyms.h>
23 #include <linux/bootmem.h>
24 #include <linux/interrupt.h>
25 #include <linux/ptrace.h>
26 #include <linux/kgdb.h>
27 #include <linux/kdebug.h>
28 #include <linux/notifier.h>
30 #include <asm/bootinfo.h>
31 #include <asm/branch.h>
32 #include <asm/break.h>
33 #include <asm/cop2.h>
34 #include <asm/cpu.h>
35 #include <asm/dsp.h>
36 #include <asm/fpu.h>
37 #include <asm/fpu_emulator.h>
38 #include <asm/mipsregs.h>
39 #include <asm/mipsmtregs.h>
40 #include <asm/module.h>
41 #include <asm/pgtable.h>
42 #include <asm/ptrace.h>
43 #include <asm/sections.h>
44 #include <asm/system.h>
45 #include <asm/tlbdebug.h>
46 #include <asm/traps.h>
47 #include <asm/uaccess.h>
48 #include <asm/watch.h>
49 #include <asm/mmu_context.h>
50 #include <asm/types.h>
51 #include <asm/stacktrace.h>
52 #include <asm/irq.h>
54 extern void check_wait(void);
55 extern asmlinkage void r4k_wait(void);
56 extern asmlinkage void rollback_handle_int(void);
57 extern asmlinkage void handle_int(void);
58 extern asmlinkage void handle_tlbm(void);
59 extern asmlinkage void handle_tlbl(void);
60 extern asmlinkage void handle_tlbs(void);
61 extern asmlinkage void handle_adel(void);
62 extern asmlinkage void handle_ades(void);
63 extern asmlinkage void handle_ibe(void);
64 extern asmlinkage void handle_dbe(void);
65 extern asmlinkage void handle_sys(void);
66 extern asmlinkage void handle_bp(void);
67 extern asmlinkage void handle_ri(void);
68 extern asmlinkage void handle_ri_rdhwr_vivt(void);
69 extern asmlinkage void handle_ri_rdhwr(void);
70 extern asmlinkage void handle_cpu(void);
71 extern asmlinkage void handle_ov(void);
72 extern asmlinkage void handle_tr(void);
73 extern asmlinkage void handle_fpe(void);
74 extern asmlinkage void handle_mdmx(void);
75 extern asmlinkage void handle_watch(void);
76 extern asmlinkage void handle_mt(void);
77 extern asmlinkage void handle_dsp(void);
78 extern asmlinkage void handle_mcheck(void);
79 extern asmlinkage void handle_reserved(void);
81 extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
82 struct mips_fpu_struct *ctx, int has_fpu);
84 void (*board_be_init)(void);
85 int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
86 void (*board_nmi_handler_setup)(void);
87 void (*board_ejtag_handler_setup)(void);
88 void (*board_bind_eic_interrupt)(int irq, int regset);
91 static void show_raw_backtrace(unsigned long reg29)
93 unsigned long *sp = (unsigned long *)(reg29 & ~3);
94 unsigned long addr;
96 printk("Call Trace:");
97 #ifdef CONFIG_KALLSYMS
98 printk("\n");
99 #endif
100 while (!kstack_end(sp)) {
101 unsigned long __user *p =
102 (unsigned long __user *)(unsigned long)sp++;
103 if (__get_user(addr, p)) {
104 printk(" (Bad stack address)");
105 break;
107 if (__kernel_text_address(addr))
108 print_ip_sym(addr);
110 printk("\n");
113 #ifdef CONFIG_KALLSYMS
114 int raw_show_trace;
115 static int __init set_raw_show_trace(char *str)
117 raw_show_trace = 1;
118 return 1;
120 __setup("raw_show_trace", set_raw_show_trace);
121 #endif
123 static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
125 unsigned long sp = regs->regs[29];
126 unsigned long ra = regs->regs[31];
127 unsigned long pc = regs->cp0_epc;
129 if (raw_show_trace || !__kernel_text_address(pc)) {
130 show_raw_backtrace(sp);
131 return;
133 printk("Call Trace:\n");
134 do {
135 print_ip_sym(pc);
136 pc = unwind_stack(task, &sp, pc, &ra);
137 } while (pc);
138 printk("\n");
142 * This routine abuses get_user()/put_user() to reference pointers
143 * with at least a bit of error checking ...
145 static void show_stacktrace(struct task_struct *task,
146 const struct pt_regs *regs)
148 const int field = 2 * sizeof(unsigned long);
149 long stackdata;
150 int i;
151 unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
153 printk("Stack :");
154 i = 0;
155 while ((unsigned long) sp & (PAGE_SIZE - 1)) {
156 if (i && ((i % (64 / field)) == 0))
157 printk("\n ");
158 if (i > 39) {
159 printk(" ...");
160 break;
163 if (__get_user(stackdata, sp++)) {
164 printk(" (Bad stack address)");
165 break;
168 printk(" %0*lx", field, stackdata);
169 i++;
171 printk("\n");
172 show_backtrace(task, regs);
175 void show_stack(struct task_struct *task, unsigned long *sp)
177 struct pt_regs regs;
178 if (sp) {
179 regs.regs[29] = (unsigned long)sp;
180 regs.regs[31] = 0;
181 regs.cp0_epc = 0;
182 } else {
183 if (task && task != current) {
184 regs.regs[29] = task->thread.reg29;
185 regs.regs[31] = 0;
186 regs.cp0_epc = task->thread.reg31;
187 } else {
188 prepare_frametrace(&regs);
191 show_stacktrace(task, &regs);
195 * The architecture-independent dump_stack generator
197 void dump_stack(void)
199 struct pt_regs regs;
201 prepare_frametrace(&regs);
202 show_backtrace(current, &regs);
205 EXPORT_SYMBOL(dump_stack);
207 static void show_code(unsigned int __user *pc)
209 long i;
210 unsigned short __user *pc16 = NULL;
212 printk("\nCode:");
214 if ((unsigned long)pc & 1)
215 pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
216 for(i = -3 ; i < 6 ; i++) {
217 unsigned int insn;
218 if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
219 printk(" (Bad address in epc)\n");
220 break;
222 printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
226 static void __show_regs(const struct pt_regs *regs)
228 const int field = 2 * sizeof(unsigned long);
229 unsigned int cause = regs->cp0_cause;
230 int i;
232 printk("Cpu %d\n", smp_processor_id());
235 * Saved main processor registers
237 for (i = 0; i < 32; ) {
238 if ((i % 4) == 0)
239 printk("$%2d :", i);
240 if (i == 0)
241 printk(" %0*lx", field, 0UL);
242 else if (i == 26 || i == 27)
243 printk(" %*s", field, "");
244 else
245 printk(" %0*lx", field, regs->regs[i]);
247 i++;
248 if ((i % 4) == 0)
249 printk("\n");
252 #ifdef CONFIG_CPU_HAS_SMARTMIPS
253 printk("Acx : %0*lx\n", field, regs->acx);
254 #endif
255 printk("Hi : %0*lx\n", field, regs->hi);
256 printk("Lo : %0*lx\n", field, regs->lo);
259 * Saved cp0 registers
261 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
262 (void *) regs->cp0_epc);
263 printk(" %s\n", print_tainted());
264 printk("ra : %0*lx %pS\n", field, regs->regs[31],
265 (void *) regs->regs[31]);
267 printk("Status: %08x ", (uint32_t) regs->cp0_status);
269 if (current_cpu_data.isa_level == MIPS_CPU_ISA_I) {
270 if (regs->cp0_status & ST0_KUO)
271 printk("KUo ");
272 if (regs->cp0_status & ST0_IEO)
273 printk("IEo ");
274 if (regs->cp0_status & ST0_KUP)
275 printk("KUp ");
276 if (regs->cp0_status & ST0_IEP)
277 printk("IEp ");
278 if (regs->cp0_status & ST0_KUC)
279 printk("KUc ");
280 if (regs->cp0_status & ST0_IEC)
281 printk("IEc ");
282 } else {
283 if (regs->cp0_status & ST0_KX)
284 printk("KX ");
285 if (regs->cp0_status & ST0_SX)
286 printk("SX ");
287 if (regs->cp0_status & ST0_UX)
288 printk("UX ");
289 switch (regs->cp0_status & ST0_KSU) {
290 case KSU_USER:
291 printk("USER ");
292 break;
293 case KSU_SUPERVISOR:
294 printk("SUPERVISOR ");
295 break;
296 case KSU_KERNEL:
297 printk("KERNEL ");
298 break;
299 default:
300 printk("BAD_MODE ");
301 break;
303 if (regs->cp0_status & ST0_ERL)
304 printk("ERL ");
305 if (regs->cp0_status & ST0_EXL)
306 printk("EXL ");
307 if (regs->cp0_status & ST0_IE)
308 printk("IE ");
310 printk("\n");
312 printk("Cause : %08x\n", cause);
314 cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
315 if (1 <= cause && cause <= 5)
316 printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
318 printk("PrId : %08x (%s)\n", read_c0_prid(),
319 cpu_name_string());
323 * FIXME: really the generic show_regs should take a const pointer argument.
325 void show_regs(struct pt_regs *regs)
327 __show_regs((struct pt_regs *)regs);
330 void show_registers(const struct pt_regs *regs)
332 const int field = 2 * sizeof(unsigned long);
334 __show_regs(regs);
335 print_modules();
336 printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
337 current->comm, current->pid, current_thread_info(), current,
338 field, current_thread_info()->tp_value);
339 if (cpu_has_userlocal) {
340 unsigned long tls;
342 tls = read_c0_userlocal();
343 if (tls != current_thread_info()->tp_value)
344 printk("*HwTLS: %0*lx\n", field, tls);
347 show_stacktrace(current, regs);
348 show_code((unsigned int __user *) regs->cp0_epc);
349 printk("\n");
352 static DEFINE_SPINLOCK(die_lock);
354 void __noreturn die(const char * str, const struct pt_regs * regs)
356 static int die_counter;
357 #ifdef CONFIG_MIPS_MT_SMTC
358 unsigned long dvpret = dvpe();
359 #endif /* CONFIG_MIPS_MT_SMTC */
361 console_verbose();
362 spin_lock_irq(&die_lock);
363 bust_spinlocks(1);
364 #ifdef CONFIG_MIPS_MT_SMTC
365 mips_mt_regdump(dvpret);
366 #endif /* CONFIG_MIPS_MT_SMTC */
367 printk("%s[#%d]:\n", str, ++die_counter);
368 show_registers(regs);
369 add_taint(TAINT_DIE);
370 spin_unlock_irq(&die_lock);
372 if (in_interrupt())
373 panic("Fatal exception in interrupt");
375 if (panic_on_oops) {
376 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
377 ssleep(5);
378 panic("Fatal exception");
381 do_exit(SIGSEGV);
384 extern struct exception_table_entry __start___dbe_table[];
385 extern struct exception_table_entry __stop___dbe_table[];
387 __asm__(
388 " .section __dbe_table, \"a\"\n"
389 " .previous \n");
391 /* Given an address, look for it in the exception tables. */
392 static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
394 const struct exception_table_entry *e;
396 e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
397 if (!e)
398 e = search_module_dbetables(addr);
399 return e;
402 asmlinkage void do_be(struct pt_regs *regs)
404 const int field = 2 * sizeof(unsigned long);
405 const struct exception_table_entry *fixup = NULL;
406 int data = regs->cp0_cause & 4;
407 int action = MIPS_BE_FATAL;
409 /* XXX For now. Fixme, this searches the wrong table ... */
410 if (data && !user_mode(regs))
411 fixup = search_dbe_tables(exception_epc(regs));
413 if (fixup)
414 action = MIPS_BE_FIXUP;
416 if (board_be_handler)
417 action = board_be_handler(regs, fixup != NULL);
419 switch (action) {
420 case MIPS_BE_DISCARD:
421 return;
422 case MIPS_BE_FIXUP:
423 if (fixup) {
424 regs->cp0_epc = fixup->nextinsn;
425 return;
427 break;
428 default:
429 break;
433 * Assume it would be too dangerous to continue ...
435 printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
436 data ? "Data" : "Instruction",
437 field, regs->cp0_epc, field, regs->regs[31]);
438 if (notify_die(DIE_OOPS, "bus error", regs, SIGBUS, 0, 0)
439 == NOTIFY_STOP)
440 return;
442 die_if_kernel("Oops", regs);
443 force_sig(SIGBUS, current);
447 * ll/sc, rdhwr, sync emulation
450 #define OPCODE 0xfc000000
451 #define BASE 0x03e00000
452 #define RT 0x001f0000
453 #define OFFSET 0x0000ffff
454 #define LL 0xc0000000
455 #define SC 0xe0000000
456 #define SPEC0 0x00000000
457 #define SPEC3 0x7c000000
458 #define RD 0x0000f800
459 #define FUNC 0x0000003f
460 #define SYNC 0x0000000f
461 #define RDHWR 0x0000003b
464 * The ll_bit is cleared by r*_switch.S
467 unsigned int ll_bit;
468 struct task_struct *ll_task;
470 static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
472 unsigned long value, __user *vaddr;
473 long offset;
476 * analyse the ll instruction that just caused a ri exception
477 * and put the referenced address to addr.
480 /* sign extend offset */
481 offset = opcode & OFFSET;
482 offset <<= 16;
483 offset >>= 16;
485 vaddr = (unsigned long __user *)
486 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
488 if ((unsigned long)vaddr & 3)
489 return SIGBUS;
490 if (get_user(value, vaddr))
491 return SIGSEGV;
493 preempt_disable();
495 if (ll_task == NULL || ll_task == current) {
496 ll_bit = 1;
497 } else {
498 ll_bit = 0;
500 ll_task = current;
502 preempt_enable();
504 regs->regs[(opcode & RT) >> 16] = value;
506 return 0;
509 static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
511 unsigned long __user *vaddr;
512 unsigned long reg;
513 long offset;
516 * analyse the sc instruction that just caused a ri exception
517 * and put the referenced address to addr.
520 /* sign extend offset */
521 offset = opcode & OFFSET;
522 offset <<= 16;
523 offset >>= 16;
525 vaddr = (unsigned long __user *)
526 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
527 reg = (opcode & RT) >> 16;
529 if ((unsigned long)vaddr & 3)
530 return SIGBUS;
532 preempt_disable();
534 if (ll_bit == 0 || ll_task != current) {
535 regs->regs[reg] = 0;
536 preempt_enable();
537 return 0;
540 preempt_enable();
542 if (put_user(regs->regs[reg], vaddr))
543 return SIGSEGV;
545 regs->regs[reg] = 1;
547 return 0;
551 * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
552 * opcodes are supposed to result in coprocessor unusable exceptions if
553 * executed on ll/sc-less processors. That's the theory. In practice a
554 * few processors such as NEC's VR4100 throw reserved instruction exceptions
555 * instead, so we're doing the emulation thing in both exception handlers.
557 static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
559 if ((opcode & OPCODE) == LL)
560 return simulate_ll(regs, opcode);
561 if ((opcode & OPCODE) == SC)
562 return simulate_sc(regs, opcode);
564 return -1; /* Must be something else ... */
568 * Simulate trapping 'rdhwr' instructions to provide user accessible
569 * registers not implemented in hardware.
571 static int simulate_rdhwr(struct pt_regs *regs, unsigned int opcode)
573 struct thread_info *ti = task_thread_info(current);
575 if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
576 int rd = (opcode & RD) >> 11;
577 int rt = (opcode & RT) >> 16;
578 switch (rd) {
579 case 0: /* CPU number */
580 regs->regs[rt] = smp_processor_id();
581 return 0;
582 case 1: /* SYNCI length */
583 regs->regs[rt] = min(current_cpu_data.dcache.linesz,
584 current_cpu_data.icache.linesz);
585 return 0;
586 case 2: /* Read count register */
587 regs->regs[rt] = read_c0_count();
588 return 0;
589 case 3: /* Count register resolution */
590 switch (current_cpu_data.cputype) {
591 case CPU_20KC:
592 case CPU_25KF:
593 regs->regs[rt] = 1;
594 break;
595 default:
596 regs->regs[rt] = 2;
598 return 0;
599 case 29:
600 regs->regs[rt] = ti->tp_value;
601 return 0;
602 default:
603 return -1;
607 /* Not ours. */
608 return -1;
611 static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
613 if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC)
614 return 0;
616 return -1; /* Must be something else ... */
619 asmlinkage void do_ov(struct pt_regs *regs)
621 siginfo_t info;
623 die_if_kernel("Integer overflow", regs);
625 info.si_code = FPE_INTOVF;
626 info.si_signo = SIGFPE;
627 info.si_errno = 0;
628 info.si_addr = (void __user *) regs->cp0_epc;
629 force_sig_info(SIGFPE, &info, current);
633 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
635 asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
637 siginfo_t info;
639 if (notify_die(DIE_FP, "FP exception", regs, SIGFPE, 0, 0)
640 == NOTIFY_STOP)
641 return;
642 die_if_kernel("FP exception in kernel code", regs);
644 if (fcr31 & FPU_CSR_UNI_X) {
645 int sig;
648 * Unimplemented operation exception. If we've got the full
649 * software emulator on-board, let's use it...
651 * Force FPU to dump state into task/thread context. We're
652 * moving a lot of data here for what is probably a single
653 * instruction, but the alternative is to pre-decode the FP
654 * register operands before invoking the emulator, which seems
655 * a bit extreme for what should be an infrequent event.
657 /* Ensure 'resume' not overwrite saved fp context again. */
658 lose_fpu(1);
660 /* Run the emulator */
661 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1);
664 * We can't allow the emulated instruction to leave any of
665 * the cause bit set in $fcr31.
667 current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
669 /* Restore the hardware register state */
670 own_fpu(1); /* Using the FPU again. */
672 /* If something went wrong, signal */
673 if (sig)
674 force_sig(sig, current);
676 return;
677 } else if (fcr31 & FPU_CSR_INV_X)
678 info.si_code = FPE_FLTINV;
679 else if (fcr31 & FPU_CSR_DIV_X)
680 info.si_code = FPE_FLTDIV;
681 else if (fcr31 & FPU_CSR_OVF_X)
682 info.si_code = FPE_FLTOVF;
683 else if (fcr31 & FPU_CSR_UDF_X)
684 info.si_code = FPE_FLTUND;
685 else if (fcr31 & FPU_CSR_INE_X)
686 info.si_code = FPE_FLTRES;
687 else
688 info.si_code = __SI_FAULT;
689 info.si_signo = SIGFPE;
690 info.si_errno = 0;
691 info.si_addr = (void __user *) regs->cp0_epc;
692 force_sig_info(SIGFPE, &info, current);
695 static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
696 const char *str)
698 siginfo_t info;
699 char b[40];
701 if (notify_die(DIE_TRAP, str, regs, code, 0, 0) == NOTIFY_STOP)
702 return;
705 * A short test says that IRIX 5.3 sends SIGTRAP for all trap
706 * insns, even for trap and break codes that indicate arithmetic
707 * failures. Weird ...
708 * But should we continue the brokenness??? --macro
710 switch (code) {
711 case BRK_OVERFLOW:
712 case BRK_DIVZERO:
713 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
714 die_if_kernel(b, regs);
715 if (code == BRK_DIVZERO)
716 info.si_code = FPE_INTDIV;
717 else
718 info.si_code = FPE_INTOVF;
719 info.si_signo = SIGFPE;
720 info.si_errno = 0;
721 info.si_addr = (void __user *) regs->cp0_epc;
722 force_sig_info(SIGFPE, &info, current);
723 break;
724 case BRK_BUG:
725 die_if_kernel("Kernel bug detected", regs);
726 force_sig(SIGTRAP, current);
727 break;
728 case BRK_MEMU:
730 * Address errors may be deliberately induced by the FPU
731 * emulator to retake control of the CPU after executing the
732 * instruction in the delay slot of an emulated branch.
734 * Terminate if exception was recognized as a delay slot return
735 * otherwise handle as normal.
737 if (do_dsemulret(regs))
738 return;
740 die_if_kernel("Math emu break/trap", regs);
741 force_sig(SIGTRAP, current);
742 break;
743 default:
744 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
745 die_if_kernel(b, regs);
746 force_sig(SIGTRAP, current);
750 asmlinkage void do_bp(struct pt_regs *regs)
752 unsigned int opcode, bcode;
754 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
755 goto out_sigsegv;
758 * There is the ancient bug in the MIPS assemblers that the break
759 * code starts left to bit 16 instead to bit 6 in the opcode.
760 * Gas is bug-compatible, but not always, grrr...
761 * We handle both cases with a simple heuristics. --macro
763 bcode = ((opcode >> 6) & ((1 << 20) - 1));
764 if (bcode >= (1 << 10))
765 bcode >>= 10;
767 do_trap_or_bp(regs, bcode, "Break");
768 return;
770 out_sigsegv:
771 force_sig(SIGSEGV, current);
774 asmlinkage void do_tr(struct pt_regs *regs)
776 unsigned int opcode, tcode = 0;
778 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
779 goto out_sigsegv;
781 /* Immediate versions don't provide a code. */
782 if (!(opcode & OPCODE))
783 tcode = ((opcode >> 6) & ((1 << 10) - 1));
785 do_trap_or_bp(regs, tcode, "Trap");
786 return;
788 out_sigsegv:
789 force_sig(SIGSEGV, current);
792 asmlinkage void do_ri(struct pt_regs *regs)
794 unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
795 unsigned long old_epc = regs->cp0_epc;
796 unsigned int opcode = 0;
797 int status = -1;
799 if (notify_die(DIE_RI, "RI Fault", regs, SIGSEGV, 0, 0)
800 == NOTIFY_STOP)
801 return;
803 die_if_kernel("Reserved instruction in kernel code", regs);
805 if (unlikely(compute_return_epc(regs) < 0))
806 return;
808 if (unlikely(get_user(opcode, epc) < 0))
809 status = SIGSEGV;
811 if (!cpu_has_llsc && status < 0)
812 status = simulate_llsc(regs, opcode);
814 if (status < 0)
815 status = simulate_rdhwr(regs, opcode);
817 if (status < 0)
818 status = simulate_sync(regs, opcode);
820 if (status < 0)
821 status = SIGILL;
823 if (unlikely(status > 0)) {
824 regs->cp0_epc = old_epc; /* Undo skip-over. */
825 force_sig(status, current);
830 * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
831 * emulated more than some threshold number of instructions, force migration to
832 * a "CPU" that has FP support.
834 static void mt_ase_fp_affinity(void)
836 #ifdef CONFIG_MIPS_MT_FPAFF
837 if (mt_fpemul_threshold > 0 &&
838 ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
840 * If there's no FPU present, or if the application has already
841 * restricted the allowed set to exclude any CPUs with FPUs,
842 * we'll skip the procedure.
844 if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
845 cpumask_t tmask;
847 current->thread.user_cpus_allowed
848 = current->cpus_allowed;
849 cpus_and(tmask, current->cpus_allowed,
850 mt_fpu_cpumask);
851 set_cpus_allowed(current, tmask);
852 set_thread_flag(TIF_FPUBOUND);
855 #endif /* CONFIG_MIPS_MT_FPAFF */
859 * No lock; only written during early bootup by CPU 0.
861 static RAW_NOTIFIER_HEAD(cu2_chain);
863 int __ref register_cu2_notifier(struct notifier_block *nb)
865 return raw_notifier_chain_register(&cu2_chain, nb);
868 int cu2_notifier_call_chain(unsigned long val, void *v)
870 return raw_notifier_call_chain(&cu2_chain, val, v);
873 static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
874 void *data)
876 struct pt_regs *regs = data;
878 switch (action) {
879 default:
880 die_if_kernel("Unhandled kernel unaligned access or invalid "
881 "instruction", regs);
882 /* Fall through */
884 case CU2_EXCEPTION:
885 force_sig(SIGILL, current);
888 return NOTIFY_OK;
891 static struct notifier_block default_cu2_notifier = {
892 .notifier_call = default_cu2_call,
893 .priority = 0x80000000, /* Run last */
896 asmlinkage void do_cpu(struct pt_regs *regs)
898 unsigned int __user *epc;
899 unsigned long old_epc;
900 unsigned int opcode;
901 unsigned int cpid;
902 int status;
903 unsigned long __maybe_unused flags;
905 die_if_kernel("do_cpu invoked from kernel context!", regs);
907 cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
909 switch (cpid) {
910 case 0:
911 epc = (unsigned int __user *)exception_epc(regs);
912 old_epc = regs->cp0_epc;
913 opcode = 0;
914 status = -1;
916 if (unlikely(compute_return_epc(regs) < 0))
917 return;
919 if (unlikely(get_user(opcode, epc) < 0))
920 status = SIGSEGV;
922 if (!cpu_has_llsc && status < 0)
923 status = simulate_llsc(regs, opcode);
925 if (status < 0)
926 status = simulate_rdhwr(regs, opcode);
928 if (status < 0)
929 status = SIGILL;
931 if (unlikely(status > 0)) {
932 regs->cp0_epc = old_epc; /* Undo skip-over. */
933 force_sig(status, current);
936 return;
938 case 1:
939 if (used_math()) /* Using the FPU again. */
940 own_fpu(1);
941 else { /* First time FPU user. */
942 init_fpu();
943 set_used_math();
946 if (!raw_cpu_has_fpu) {
947 int sig;
948 sig = fpu_emulator_cop1Handler(regs,
949 &current->thread.fpu, 0);
950 if (sig)
951 force_sig(sig, current);
952 else
953 mt_ase_fp_affinity();
956 return;
958 case 2:
959 raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
960 break;
962 case 3:
963 break;
966 force_sig(SIGILL, current);
969 asmlinkage void do_mdmx(struct pt_regs *regs)
971 force_sig(SIGILL, current);
975 * Called with interrupts disabled.
977 asmlinkage void do_watch(struct pt_regs *regs)
979 u32 cause;
982 * Clear WP (bit 22) bit of cause register so we don't loop
983 * forever.
985 cause = read_c0_cause();
986 cause &= ~(1 << 22);
987 write_c0_cause(cause);
990 * If the current thread has the watch registers loaded, save
991 * their values and send SIGTRAP. Otherwise another thread
992 * left the registers set, clear them and continue.
994 if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
995 mips_read_watch_registers();
996 local_irq_enable();
997 force_sig(SIGTRAP, current);
998 } else {
999 mips_clear_watch_registers();
1000 local_irq_enable();
1004 asmlinkage void do_mcheck(struct pt_regs *regs)
1006 const int field = 2 * sizeof(unsigned long);
1007 int multi_match = regs->cp0_status & ST0_TS;
1009 show_regs(regs);
1011 if (multi_match) {
1012 printk("Index : %0x\n", read_c0_index());
1013 printk("Pagemask: %0x\n", read_c0_pagemask());
1014 printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
1015 printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
1016 printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
1017 printk("\n");
1018 dump_tlb_all();
1021 show_code((unsigned int __user *) regs->cp0_epc);
1024 * Some chips may have other causes of machine check (e.g. SB1
1025 * graduation timer)
1027 panic("Caught Machine Check exception - %scaused by multiple "
1028 "matching entries in the TLB.",
1029 (multi_match) ? "" : "not ");
1032 asmlinkage void do_mt(struct pt_regs *regs)
1034 int subcode;
1036 subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
1037 >> VPECONTROL_EXCPT_SHIFT;
1038 switch (subcode) {
1039 case 0:
1040 printk(KERN_DEBUG "Thread Underflow\n");
1041 break;
1042 case 1:
1043 printk(KERN_DEBUG "Thread Overflow\n");
1044 break;
1045 case 2:
1046 printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
1047 break;
1048 case 3:
1049 printk(KERN_DEBUG "Gating Storage Exception\n");
1050 break;
1051 case 4:
1052 printk(KERN_DEBUG "YIELD Scheduler Exception\n");
1053 break;
1054 case 5:
1055 printk(KERN_DEBUG "Gating Storage Schedulier Exception\n");
1056 break;
1057 default:
1058 printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
1059 subcode);
1060 break;
1062 die_if_kernel("MIPS MT Thread exception in kernel", regs);
1064 force_sig(SIGILL, current);
1068 asmlinkage void do_dsp(struct pt_regs *regs)
1070 if (cpu_has_dsp)
1071 panic("Unexpected DSP exception\n");
1073 force_sig(SIGILL, current);
1076 asmlinkage void do_reserved(struct pt_regs *regs)
1079 * Game over - no way to handle this if it ever occurs. Most probably
1080 * caused by a new unknown cpu type or after another deadly
1081 * hard/software error.
1083 show_regs(regs);
1084 panic("Caught reserved exception %ld - should not happen.",
1085 (regs->cp0_cause & 0x7f) >> 2);
1088 static int __initdata l1parity = 1;
1089 static int __init nol1parity(char *s)
1091 l1parity = 0;
1092 return 1;
1094 __setup("nol1par", nol1parity);
1095 static int __initdata l2parity = 1;
1096 static int __init nol2parity(char *s)
1098 l2parity = 0;
1099 return 1;
1101 __setup("nol2par", nol2parity);
1104 * Some MIPS CPUs can enable/disable for cache parity detection, but do
1105 * it different ways.
1107 static inline void parity_protection_init(void)
1109 switch (current_cpu_type()) {
1110 case CPU_24K:
1111 case CPU_34K:
1112 case CPU_74K:
1113 case CPU_1004K:
1115 #define ERRCTL_PE 0x80000000
1116 #define ERRCTL_L2P 0x00800000
1117 unsigned long errctl;
1118 unsigned int l1parity_present, l2parity_present;
1120 errctl = read_c0_ecc();
1121 errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
1123 /* probe L1 parity support */
1124 write_c0_ecc(errctl | ERRCTL_PE);
1125 back_to_back_c0_hazard();
1126 l1parity_present = (read_c0_ecc() & ERRCTL_PE);
1128 /* probe L2 parity support */
1129 write_c0_ecc(errctl|ERRCTL_L2P);
1130 back_to_back_c0_hazard();
1131 l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
1133 if (l1parity_present && l2parity_present) {
1134 if (l1parity)
1135 errctl |= ERRCTL_PE;
1136 if (l1parity ^ l2parity)
1137 errctl |= ERRCTL_L2P;
1138 } else if (l1parity_present) {
1139 if (l1parity)
1140 errctl |= ERRCTL_PE;
1141 } else if (l2parity_present) {
1142 if (l2parity)
1143 errctl |= ERRCTL_L2P;
1144 } else {
1145 /* No parity available */
1148 printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
1150 write_c0_ecc(errctl);
1151 back_to_back_c0_hazard();
1152 errctl = read_c0_ecc();
1153 printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
1155 if (l1parity_present)
1156 printk(KERN_INFO "Cache parity protection %sabled\n",
1157 (errctl & ERRCTL_PE) ? "en" : "dis");
1159 if (l2parity_present) {
1160 if (l1parity_present && l1parity)
1161 errctl ^= ERRCTL_L2P;
1162 printk(KERN_INFO "L2 cache parity protection %sabled\n",
1163 (errctl & ERRCTL_L2P) ? "en" : "dis");
1166 break;
1168 case CPU_5KC:
1169 write_c0_ecc(0x80000000);
1170 back_to_back_c0_hazard();
1171 /* Set the PE bit (bit 31) in the c0_errctl register. */
1172 printk(KERN_INFO "Cache parity protection %sabled\n",
1173 (read_c0_ecc() & 0x80000000) ? "en" : "dis");
1174 break;
1175 case CPU_20KC:
1176 case CPU_25KF:
1177 /* Clear the DE bit (bit 16) in the c0_status register. */
1178 printk(KERN_INFO "Enable cache parity protection for "
1179 "MIPS 20KC/25KF CPUs.\n");
1180 clear_c0_status(ST0_DE);
1181 break;
1182 default:
1183 break;
1187 asmlinkage void cache_parity_error(void)
1189 const int field = 2 * sizeof(unsigned long);
1190 unsigned int reg_val;
1192 /* For the moment, report the problem and hang. */
1193 printk("Cache error exception:\n");
1194 printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1195 reg_val = read_c0_cacheerr();
1196 printk("c0_cacheerr == %08x\n", reg_val);
1198 printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1199 reg_val & (1<<30) ? "secondary" : "primary",
1200 reg_val & (1<<31) ? "data" : "insn");
1201 printk("Error bits: %s%s%s%s%s%s%s\n",
1202 reg_val & (1<<29) ? "ED " : "",
1203 reg_val & (1<<28) ? "ET " : "",
1204 reg_val & (1<<26) ? "EE " : "",
1205 reg_val & (1<<25) ? "EB " : "",
1206 reg_val & (1<<24) ? "EI " : "",
1207 reg_val & (1<<23) ? "E1 " : "",
1208 reg_val & (1<<22) ? "E0 " : "");
1209 printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1211 #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
1212 if (reg_val & (1<<22))
1213 printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
1215 if (reg_val & (1<<23))
1216 printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
1217 #endif
1219 panic("Can't handle the cache error!");
1223 * SDBBP EJTAG debug exception handler.
1224 * We skip the instruction and return to the next instruction.
1226 void ejtag_exception_handler(struct pt_regs *regs)
1228 const int field = 2 * sizeof(unsigned long);
1229 unsigned long depc, old_epc;
1230 unsigned int debug;
1232 printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
1233 depc = read_c0_depc();
1234 debug = read_c0_debug();
1235 printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
1236 if (debug & 0x80000000) {
1238 * In branch delay slot.
1239 * We cheat a little bit here and use EPC to calculate the
1240 * debug return address (DEPC). EPC is restored after the
1241 * calculation.
1243 old_epc = regs->cp0_epc;
1244 regs->cp0_epc = depc;
1245 __compute_return_epc(regs);
1246 depc = regs->cp0_epc;
1247 regs->cp0_epc = old_epc;
1248 } else
1249 depc += 4;
1250 write_c0_depc(depc);
1252 #if 0
1253 printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
1254 write_c0_debug(debug | 0x100);
1255 #endif
1259 * NMI exception handler.
1261 NORET_TYPE void ATTRIB_NORET nmi_exception_handler(struct pt_regs *regs)
1263 bust_spinlocks(1);
1264 printk("NMI taken!!!!\n");
1265 die("NMI", regs);
1268 #define VECTORSPACING 0x100 /* for EI/VI mode */
1270 unsigned long ebase;
1271 unsigned long exception_handlers[32];
1272 unsigned long vi_handlers[64];
1275 * As a side effect of the way this is implemented we're limited
1276 * to interrupt handlers in the address range from
1277 * KSEG0 <= x < KSEG0 + 256mb on the Nevada. Oh well ...
1279 void *set_except_vector(int n, void *addr)
1281 unsigned long handler = (unsigned long) addr;
1282 unsigned long old_handler = exception_handlers[n];
1284 exception_handlers[n] = handler;
1285 if (n == 0 && cpu_has_divec) {
1286 *(u32 *)(ebase + 0x200) = 0x08000000 |
1287 (0x03ffffff & (handler >> 2));
1288 local_flush_icache_range(ebase + 0x200, ebase + 0x204);
1290 return (void *)old_handler;
1293 static asmlinkage void do_default_vi(void)
1295 show_regs(get_irq_regs());
1296 panic("Caught unexpected vectored interrupt.");
1299 static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
1301 unsigned long handler;
1302 unsigned long old_handler = vi_handlers[n];
1303 int srssets = current_cpu_data.srsets;
1304 u32 *w;
1305 unsigned char *b;
1307 BUG_ON(!cpu_has_veic && !cpu_has_vint);
1309 if (addr == NULL) {
1310 handler = (unsigned long) do_default_vi;
1311 srs = 0;
1312 } else
1313 handler = (unsigned long) addr;
1314 vi_handlers[n] = (unsigned long) addr;
1316 b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
1318 if (srs >= srssets)
1319 panic("Shadow register set %d not supported", srs);
1321 if (cpu_has_veic) {
1322 if (board_bind_eic_interrupt)
1323 board_bind_eic_interrupt(n, srs);
1324 } else if (cpu_has_vint) {
1325 /* SRSMap is only defined if shadow sets are implemented */
1326 if (srssets > 1)
1327 change_c0_srsmap(0xf << n*4, srs << n*4);
1330 if (srs == 0) {
1332 * If no shadow set is selected then use the default handler
1333 * that does normal register saving and a standard interrupt exit
1336 extern char except_vec_vi, except_vec_vi_lui;
1337 extern char except_vec_vi_ori, except_vec_vi_end;
1338 extern char rollback_except_vec_vi;
1339 char *vec_start = (cpu_wait == r4k_wait) ?
1340 &rollback_except_vec_vi : &except_vec_vi;
1341 #ifdef CONFIG_MIPS_MT_SMTC
1343 * We need to provide the SMTC vectored interrupt handler
1344 * not only with the address of the handler, but with the
1345 * Status.IM bit to be masked before going there.
1347 extern char except_vec_vi_mori;
1348 const int mori_offset = &except_vec_vi_mori - vec_start;
1349 #endif /* CONFIG_MIPS_MT_SMTC */
1350 const int handler_len = &except_vec_vi_end - vec_start;
1351 const int lui_offset = &except_vec_vi_lui - vec_start;
1352 const int ori_offset = &except_vec_vi_ori - vec_start;
1354 if (handler_len > VECTORSPACING) {
1356 * Sigh... panicing won't help as the console
1357 * is probably not configured :(
1359 panic("VECTORSPACING too small");
1362 memcpy(b, vec_start, handler_len);
1363 #ifdef CONFIG_MIPS_MT_SMTC
1364 BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
1366 w = (u32 *)(b + mori_offset);
1367 *w = (*w & 0xffff0000) | (0x100 << n);
1368 #endif /* CONFIG_MIPS_MT_SMTC */
1369 w = (u32 *)(b + lui_offset);
1370 *w = (*w & 0xffff0000) | (((u32)handler >> 16) & 0xffff);
1371 w = (u32 *)(b + ori_offset);
1372 *w = (*w & 0xffff0000) | ((u32)handler & 0xffff);
1373 local_flush_icache_range((unsigned long)b,
1374 (unsigned long)(b+handler_len));
1376 else {
1378 * In other cases jump directly to the interrupt handler
1380 * It is the handlers responsibility to save registers if required
1381 * (eg hi/lo) and return from the exception using "eret"
1383 w = (u32 *)b;
1384 *w++ = 0x08000000 | (((u32)handler >> 2) & 0x03fffff); /* j handler */
1385 *w = 0;
1386 local_flush_icache_range((unsigned long)b,
1387 (unsigned long)(b+8));
1390 return (void *)old_handler;
1393 void *set_vi_handler(int n, vi_handler_t addr)
1395 return set_vi_srs_handler(n, addr, 0);
1398 extern void cpu_cache_init(void);
1399 extern void tlb_init(void);
1400 extern void flush_tlb_handlers(void);
1403 * Timer interrupt
1405 int cp0_compare_irq;
1406 int cp0_compare_irq_shift;
1409 * Performance counter IRQ or -1 if shared with timer
1411 int cp0_perfcount_irq;
1412 EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
1414 static int __cpuinitdata noulri;
1416 static int __init ulri_disable(char *s)
1418 pr_info("Disabling ulri\n");
1419 noulri = 1;
1421 return 1;
1423 __setup("noulri", ulri_disable);
1425 void __cpuinit per_cpu_trap_init(void)
1427 unsigned int cpu = smp_processor_id();
1428 unsigned int status_set = ST0_CU0;
1429 #ifdef CONFIG_MIPS_MT_SMTC
1430 int secondaryTC = 0;
1431 int bootTC = (cpu == 0);
1434 * Only do per_cpu_trap_init() for first TC of Each VPE.
1435 * Note that this hack assumes that the SMTC init code
1436 * assigns TCs consecutively and in ascending order.
1439 if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
1440 ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
1441 secondaryTC = 1;
1442 #endif /* CONFIG_MIPS_MT_SMTC */
1445 * Disable coprocessors and select 32-bit or 64-bit addressing
1446 * and the 16/32 or 32/32 FPR register model. Reset the BEV
1447 * flag that some firmware may have left set and the TS bit (for
1448 * IP27). Set XX for ISA IV code to work.
1450 #ifdef CONFIG_64BIT
1451 status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
1452 #endif
1453 if (current_cpu_data.isa_level == MIPS_CPU_ISA_IV)
1454 status_set |= ST0_XX;
1455 if (cpu_has_dsp)
1456 status_set |= ST0_MX;
1458 change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
1459 status_set);
1461 if (cpu_has_mips_r2) {
1462 unsigned int enable = 0x0000000f | cpu_hwrena_impl_bits;
1464 if (!noulri && cpu_has_userlocal)
1465 enable |= (1 << 29);
1467 write_c0_hwrena(enable);
1470 #ifdef CONFIG_MIPS_MT_SMTC
1471 if (!secondaryTC) {
1472 #endif /* CONFIG_MIPS_MT_SMTC */
1474 if (cpu_has_veic || cpu_has_vint) {
1475 unsigned long sr = set_c0_status(ST0_BEV);
1476 write_c0_ebase(ebase);
1477 write_c0_status(sr);
1478 /* Setting vector spacing enables EI/VI mode */
1479 change_c0_intctl(0x3e0, VECTORSPACING);
1481 if (cpu_has_divec) {
1482 if (cpu_has_mipsmt) {
1483 unsigned int vpflags = dvpe();
1484 set_c0_cause(CAUSEF_IV);
1485 evpe(vpflags);
1486 } else
1487 set_c0_cause(CAUSEF_IV);
1491 * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
1493 * o read IntCtl.IPTI to determine the timer interrupt
1494 * o read IntCtl.IPPCI to determine the performance counter interrupt
1496 if (cpu_has_mips_r2) {
1497 cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
1498 cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
1499 cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
1500 if (cp0_perfcount_irq == cp0_compare_irq)
1501 cp0_perfcount_irq = -1;
1502 } else {
1503 cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
1504 cp0_compare_irq_shift = cp0_compare_irq;
1505 cp0_perfcount_irq = -1;
1508 #ifdef CONFIG_MIPS_MT_SMTC
1510 #endif /* CONFIG_MIPS_MT_SMTC */
1512 cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
1513 TLBMISS_HANDLER_SETUP();
1515 atomic_inc(&init_mm.mm_count);
1516 current->active_mm = &init_mm;
1517 BUG_ON(current->mm);
1518 enter_lazy_tlb(&init_mm, current);
1520 #ifdef CONFIG_MIPS_MT_SMTC
1521 if (bootTC) {
1522 #endif /* CONFIG_MIPS_MT_SMTC */
1523 cpu_cache_init();
1524 tlb_init();
1525 #ifdef CONFIG_MIPS_MT_SMTC
1526 } else if (!secondaryTC) {
1528 * First TC in non-boot VPE must do subset of tlb_init()
1529 * for MMU countrol registers.
1531 write_c0_pagemask(PM_DEFAULT_MASK);
1532 write_c0_wired(0);
1534 #endif /* CONFIG_MIPS_MT_SMTC */
1537 /* Install CPU exception handler */
1538 void __init set_handler(unsigned long offset, void *addr, unsigned long size)
1540 memcpy((void *)(ebase + offset), addr, size);
1541 local_flush_icache_range(ebase + offset, ebase + offset + size);
1544 static char panic_null_cerr[] __cpuinitdata =
1545 "Trying to set NULL cache error exception handler";
1548 * Install uncached CPU exception handler.
1549 * This is suitable only for the cache error exception which is the only
1550 * exception handler that is being run uncached.
1552 void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
1553 unsigned long size)
1555 #ifdef CONFIG_32BIT
1556 unsigned long uncached_ebase = KSEG1ADDR(ebase);
1557 #endif
1558 #ifdef CONFIG_64BIT
1559 unsigned long uncached_ebase = TO_UNCAC(ebase);
1560 #endif
1562 if (!addr)
1563 panic(panic_null_cerr);
1565 memcpy((void *)(uncached_ebase + offset), addr, size);
1568 static int __initdata rdhwr_noopt;
1569 static int __init set_rdhwr_noopt(char *str)
1571 rdhwr_noopt = 1;
1572 return 1;
1575 __setup("rdhwr_noopt", set_rdhwr_noopt);
1577 void __init trap_init(void)
1579 extern char except_vec3_generic, except_vec3_r4000;
1580 extern char except_vec4;
1581 unsigned long i;
1582 int rollback;
1584 check_wait();
1585 rollback = (cpu_wait == r4k_wait);
1587 #if defined(CONFIG_KGDB)
1588 if (kgdb_early_setup)
1589 return; /* Already done */
1590 #endif
1592 if (cpu_has_veic || cpu_has_vint) {
1593 unsigned long size = 0x200 + VECTORSPACING*64;
1594 ebase = (unsigned long)
1595 __alloc_bootmem(size, 1 << fls(size), 0);
1596 } else {
1597 ebase = CAC_BASE;
1598 if (cpu_has_mips_r2)
1599 ebase += (read_c0_ebase() & 0x3ffff000);
1602 per_cpu_trap_init();
1605 * Copy the generic exception handlers to their final destination.
1606 * This will be overriden later as suitable for a particular
1607 * configuration.
1609 set_handler(0x180, &except_vec3_generic, 0x80);
1612 * Setup default vectors
1614 for (i = 0; i <= 31; i++)
1615 set_except_vector(i, handle_reserved);
1618 * Copy the EJTAG debug exception vector handler code to it's final
1619 * destination.
1621 if (cpu_has_ejtag && board_ejtag_handler_setup)
1622 board_ejtag_handler_setup();
1625 * Only some CPUs have the watch exceptions.
1627 if (cpu_has_watch)
1628 set_except_vector(23, handle_watch);
1631 * Initialise interrupt handlers
1633 if (cpu_has_veic || cpu_has_vint) {
1634 int nvec = cpu_has_veic ? 64 : 8;
1635 for (i = 0; i < nvec; i++)
1636 set_vi_handler(i, NULL);
1638 else if (cpu_has_divec)
1639 set_handler(0x200, &except_vec4, 0x8);
1642 * Some CPUs can enable/disable for cache parity detection, but does
1643 * it different ways.
1645 parity_protection_init();
1648 * The Data Bus Errors / Instruction Bus Errors are signaled
1649 * by external hardware. Therefore these two exceptions
1650 * may have board specific handlers.
1652 if (board_be_init)
1653 board_be_init();
1655 set_except_vector(0, rollback ? rollback_handle_int : handle_int);
1656 set_except_vector(1, handle_tlbm);
1657 set_except_vector(2, handle_tlbl);
1658 set_except_vector(3, handle_tlbs);
1660 set_except_vector(4, handle_adel);
1661 set_except_vector(5, handle_ades);
1663 set_except_vector(6, handle_ibe);
1664 set_except_vector(7, handle_dbe);
1666 set_except_vector(8, handle_sys);
1667 set_except_vector(9, handle_bp);
1668 set_except_vector(10, rdhwr_noopt ? handle_ri :
1669 (cpu_has_vtag_icache ?
1670 handle_ri_rdhwr_vivt : handle_ri_rdhwr));
1671 set_except_vector(11, handle_cpu);
1672 set_except_vector(12, handle_ov);
1673 set_except_vector(13, handle_tr);
1675 if (current_cpu_type() == CPU_R6000 ||
1676 current_cpu_type() == CPU_R6000A) {
1678 * The R6000 is the only R-series CPU that features a machine
1679 * check exception (similar to the R4000 cache error) and
1680 * unaligned ldc1/sdc1 exception. The handlers have not been
1681 * written yet. Well, anyway there is no R6000 machine on the
1682 * current list of targets for Linux/MIPS.
1683 * (Duh, crap, there is someone with a triple R6k machine)
1685 //set_except_vector(14, handle_mc);
1686 //set_except_vector(15, handle_ndc);
1690 if (board_nmi_handler_setup)
1691 board_nmi_handler_setup();
1693 if (cpu_has_fpu && !cpu_has_nofpuex)
1694 set_except_vector(15, handle_fpe);
1696 set_except_vector(22, handle_mdmx);
1698 if (cpu_has_mcheck)
1699 set_except_vector(24, handle_mcheck);
1701 if (cpu_has_mipsmt)
1702 set_except_vector(25, handle_mt);
1704 set_except_vector(26, handle_dsp);
1706 if (cpu_has_vce)
1707 /* Special exception: R4[04]00 uses also the divec space. */
1708 memcpy((void *)(ebase + 0x180), &except_vec3_r4000, 0x100);
1709 else if (cpu_has_4kex)
1710 memcpy((void *)(ebase + 0x180), &except_vec3_generic, 0x80);
1711 else
1712 memcpy((void *)(ebase + 0x080), &except_vec3_generic, 0x80);
1714 local_flush_icache_range(ebase, ebase + 0x400);
1715 flush_tlb_handlers();
1717 sort_extable(__start___dbe_table, __stop___dbe_table);
1719 register_cu2_notifier(&default_cu2_notifier);