]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/mips/kernel/traps.c
MIPS: MT: Remove SMTC support
[mirror_ubuntu-zesty-kernel.git] / arch / mips / kernel / traps.c
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 - 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) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
12 * Copyright (C) 2000, 2001, 2012 MIPS Technologies, Inc. All rights reserved.
13 * Copyright (C) 2014, Imagination Technologies Ltd.
14 */
15 #include <linux/bug.h>
16 #include <linux/compiler.h>
17 #include <linux/context_tracking.h>
18 #include <linux/kexec.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/sched.h>
24 #include <linux/smp.h>
25 #include <linux/spinlock.h>
26 #include <linux/kallsyms.h>
27 #include <linux/bootmem.h>
28 #include <linux/interrupt.h>
29 #include <linux/ptrace.h>
30 #include <linux/kgdb.h>
31 #include <linux/kdebug.h>
32 #include <linux/kprobes.h>
33 #include <linux/notifier.h>
34 #include <linux/kdb.h>
35 #include <linux/irq.h>
36 #include <linux/perf_event.h>
37
38 #include <asm/bootinfo.h>
39 #include <asm/branch.h>
40 #include <asm/break.h>
41 #include <asm/cop2.h>
42 #include <asm/cpu.h>
43 #include <asm/cpu-type.h>
44 #include <asm/dsp.h>
45 #include <asm/fpu.h>
46 #include <asm/fpu_emulator.h>
47 #include <asm/idle.h>
48 #include <asm/mipsregs.h>
49 #include <asm/mipsmtregs.h>
50 #include <asm/module.h>
51 #include <asm/msa.h>
52 #include <asm/pgtable.h>
53 #include <asm/ptrace.h>
54 #include <asm/sections.h>
55 #include <asm/tlbdebug.h>
56 #include <asm/traps.h>
57 #include <asm/uaccess.h>
58 #include <asm/watch.h>
59 #include <asm/mmu_context.h>
60 #include <asm/types.h>
61 #include <asm/stacktrace.h>
62 #include <asm/uasm.h>
63
64 extern void check_wait(void);
65 extern asmlinkage void rollback_handle_int(void);
66 extern asmlinkage void handle_int(void);
67 extern u32 handle_tlbl[];
68 extern u32 handle_tlbs[];
69 extern u32 handle_tlbm[];
70 extern asmlinkage void handle_adel(void);
71 extern asmlinkage void handle_ades(void);
72 extern asmlinkage void handle_ibe(void);
73 extern asmlinkage void handle_dbe(void);
74 extern asmlinkage void handle_sys(void);
75 extern asmlinkage void handle_bp(void);
76 extern asmlinkage void handle_ri(void);
77 extern asmlinkage void handle_ri_rdhwr_vivt(void);
78 extern asmlinkage void handle_ri_rdhwr(void);
79 extern asmlinkage void handle_cpu(void);
80 extern asmlinkage void handle_ov(void);
81 extern asmlinkage void handle_tr(void);
82 extern asmlinkage void handle_msa_fpe(void);
83 extern asmlinkage void handle_fpe(void);
84 extern asmlinkage void handle_ftlb(void);
85 extern asmlinkage void handle_msa(void);
86 extern asmlinkage void handle_mdmx(void);
87 extern asmlinkage void handle_watch(void);
88 extern asmlinkage void handle_mt(void);
89 extern asmlinkage void handle_dsp(void);
90 extern asmlinkage void handle_mcheck(void);
91 extern asmlinkage void handle_reserved(void);
92
93 void (*board_be_init)(void);
94 int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
95 void (*board_nmi_handler_setup)(void);
96 void (*board_ejtag_handler_setup)(void);
97 void (*board_bind_eic_interrupt)(int irq, int regset);
98 void (*board_ebase_setup)(void);
99 void(*board_cache_error_setup)(void);
100
101 static void show_raw_backtrace(unsigned long reg29)
102 {
103 unsigned long *sp = (unsigned long *)(reg29 & ~3);
104 unsigned long addr;
105
106 printk("Call Trace:");
107 #ifdef CONFIG_KALLSYMS
108 printk("\n");
109 #endif
110 while (!kstack_end(sp)) {
111 unsigned long __user *p =
112 (unsigned long __user *)(unsigned long)sp++;
113 if (__get_user(addr, p)) {
114 printk(" (Bad stack address)");
115 break;
116 }
117 if (__kernel_text_address(addr))
118 print_ip_sym(addr);
119 }
120 printk("\n");
121 }
122
123 #ifdef CONFIG_KALLSYMS
124 int raw_show_trace;
125 static int __init set_raw_show_trace(char *str)
126 {
127 raw_show_trace = 1;
128 return 1;
129 }
130 __setup("raw_show_trace", set_raw_show_trace);
131 #endif
132
133 static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
134 {
135 unsigned long sp = regs->regs[29];
136 unsigned long ra = regs->regs[31];
137 unsigned long pc = regs->cp0_epc;
138
139 if (!task)
140 task = current;
141
142 if (raw_show_trace || !__kernel_text_address(pc)) {
143 show_raw_backtrace(sp);
144 return;
145 }
146 printk("Call Trace:\n");
147 do {
148 print_ip_sym(pc);
149 pc = unwind_stack(task, &sp, pc, &ra);
150 } while (pc);
151 printk("\n");
152 }
153
154 /*
155 * This routine abuses get_user()/put_user() to reference pointers
156 * with at least a bit of error checking ...
157 */
158 static void show_stacktrace(struct task_struct *task,
159 const struct pt_regs *regs)
160 {
161 const int field = 2 * sizeof(unsigned long);
162 long stackdata;
163 int i;
164 unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
165
166 printk("Stack :");
167 i = 0;
168 while ((unsigned long) sp & (PAGE_SIZE - 1)) {
169 if (i && ((i % (64 / field)) == 0))
170 printk("\n ");
171 if (i > 39) {
172 printk(" ...");
173 break;
174 }
175
176 if (__get_user(stackdata, sp++)) {
177 printk(" (Bad stack address)");
178 break;
179 }
180
181 printk(" %0*lx", field, stackdata);
182 i++;
183 }
184 printk("\n");
185 show_backtrace(task, regs);
186 }
187
188 void show_stack(struct task_struct *task, unsigned long *sp)
189 {
190 struct pt_regs regs;
191 if (sp) {
192 regs.regs[29] = (unsigned long)sp;
193 regs.regs[31] = 0;
194 regs.cp0_epc = 0;
195 } else {
196 if (task && task != current) {
197 regs.regs[29] = task->thread.reg29;
198 regs.regs[31] = 0;
199 regs.cp0_epc = task->thread.reg31;
200 #ifdef CONFIG_KGDB_KDB
201 } else if (atomic_read(&kgdb_active) != -1 &&
202 kdb_current_regs) {
203 memcpy(&regs, kdb_current_regs, sizeof(regs));
204 #endif /* CONFIG_KGDB_KDB */
205 } else {
206 prepare_frametrace(&regs);
207 }
208 }
209 show_stacktrace(task, &regs);
210 }
211
212 static void show_code(unsigned int __user *pc)
213 {
214 long i;
215 unsigned short __user *pc16 = NULL;
216
217 printk("\nCode:");
218
219 if ((unsigned long)pc & 1)
220 pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
221 for(i = -3 ; i < 6 ; i++) {
222 unsigned int insn;
223 if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
224 printk(" (Bad address in epc)\n");
225 break;
226 }
227 printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
228 }
229 }
230
231 static void __show_regs(const struct pt_regs *regs)
232 {
233 const int field = 2 * sizeof(unsigned long);
234 unsigned int cause = regs->cp0_cause;
235 int i;
236
237 show_regs_print_info(KERN_DEFAULT);
238
239 /*
240 * Saved main processor registers
241 */
242 for (i = 0; i < 32; ) {
243 if ((i % 4) == 0)
244 printk("$%2d :", i);
245 if (i == 0)
246 printk(" %0*lx", field, 0UL);
247 else if (i == 26 || i == 27)
248 printk(" %*s", field, "");
249 else
250 printk(" %0*lx", field, regs->regs[i]);
251
252 i++;
253 if ((i % 4) == 0)
254 printk("\n");
255 }
256
257 #ifdef CONFIG_CPU_HAS_SMARTMIPS
258 printk("Acx : %0*lx\n", field, regs->acx);
259 #endif
260 printk("Hi : %0*lx\n", field, regs->hi);
261 printk("Lo : %0*lx\n", field, regs->lo);
262
263 /*
264 * Saved cp0 registers
265 */
266 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
267 (void *) regs->cp0_epc);
268 printk(" %s\n", print_tainted());
269 printk("ra : %0*lx %pS\n", field, regs->regs[31],
270 (void *) regs->regs[31]);
271
272 printk("Status: %08x ", (uint32_t) regs->cp0_status);
273
274 if (cpu_has_3kex) {
275 if (regs->cp0_status & ST0_KUO)
276 printk("KUo ");
277 if (regs->cp0_status & ST0_IEO)
278 printk("IEo ");
279 if (regs->cp0_status & ST0_KUP)
280 printk("KUp ");
281 if (regs->cp0_status & ST0_IEP)
282 printk("IEp ");
283 if (regs->cp0_status & ST0_KUC)
284 printk("KUc ");
285 if (regs->cp0_status & ST0_IEC)
286 printk("IEc ");
287 } else if (cpu_has_4kex) {
288 if (regs->cp0_status & ST0_KX)
289 printk("KX ");
290 if (regs->cp0_status & ST0_SX)
291 printk("SX ");
292 if (regs->cp0_status & ST0_UX)
293 printk("UX ");
294 switch (regs->cp0_status & ST0_KSU) {
295 case KSU_USER:
296 printk("USER ");
297 break;
298 case KSU_SUPERVISOR:
299 printk("SUPERVISOR ");
300 break;
301 case KSU_KERNEL:
302 printk("KERNEL ");
303 break;
304 default:
305 printk("BAD_MODE ");
306 break;
307 }
308 if (regs->cp0_status & ST0_ERL)
309 printk("ERL ");
310 if (regs->cp0_status & ST0_EXL)
311 printk("EXL ");
312 if (regs->cp0_status & ST0_IE)
313 printk("IE ");
314 }
315 printk("\n");
316
317 printk("Cause : %08x\n", cause);
318
319 cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
320 if (1 <= cause && cause <= 5)
321 printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
322
323 printk("PrId : %08x (%s)\n", read_c0_prid(),
324 cpu_name_string());
325 }
326
327 /*
328 * FIXME: really the generic show_regs should take a const pointer argument.
329 */
330 void show_regs(struct pt_regs *regs)
331 {
332 __show_regs((struct pt_regs *)regs);
333 }
334
335 void show_registers(struct pt_regs *regs)
336 {
337 const int field = 2 * sizeof(unsigned long);
338 mm_segment_t old_fs = get_fs();
339
340 __show_regs(regs);
341 print_modules();
342 printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
343 current->comm, current->pid, current_thread_info(), current,
344 field, current_thread_info()->tp_value);
345 if (cpu_has_userlocal) {
346 unsigned long tls;
347
348 tls = read_c0_userlocal();
349 if (tls != current_thread_info()->tp_value)
350 printk("*HwTLS: %0*lx\n", field, tls);
351 }
352
353 if (!user_mode(regs))
354 /* Necessary for getting the correct stack content */
355 set_fs(KERNEL_DS);
356 show_stacktrace(current, regs);
357 show_code((unsigned int __user *) regs->cp0_epc);
358 printk("\n");
359 set_fs(old_fs);
360 }
361
362 static int regs_to_trapnr(struct pt_regs *regs)
363 {
364 return (regs->cp0_cause >> 2) & 0x1f;
365 }
366
367 static DEFINE_RAW_SPINLOCK(die_lock);
368
369 void __noreturn die(const char *str, struct pt_regs *regs)
370 {
371 static int die_counter;
372 int sig = SIGSEGV;
373
374 oops_enter();
375
376 if (notify_die(DIE_OOPS, str, regs, 0, regs_to_trapnr(regs),
377 SIGSEGV) == NOTIFY_STOP)
378 sig = 0;
379
380 console_verbose();
381 raw_spin_lock_irq(&die_lock);
382 bust_spinlocks(1);
383
384 printk("%s[#%d]:\n", str, ++die_counter);
385 show_registers(regs);
386 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
387 raw_spin_unlock_irq(&die_lock);
388
389 oops_exit();
390
391 if (in_interrupt())
392 panic("Fatal exception in interrupt");
393
394 if (panic_on_oops) {
395 printk(KERN_EMERG "Fatal exception: panic in 5 seconds");
396 ssleep(5);
397 panic("Fatal exception");
398 }
399
400 if (regs && kexec_should_crash(current))
401 crash_kexec(regs);
402
403 do_exit(sig);
404 }
405
406 extern struct exception_table_entry __start___dbe_table[];
407 extern struct exception_table_entry __stop___dbe_table[];
408
409 __asm__(
410 " .section __dbe_table, \"a\"\n"
411 " .previous \n");
412
413 /* Given an address, look for it in the exception tables. */
414 static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
415 {
416 const struct exception_table_entry *e;
417
418 e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
419 if (!e)
420 e = search_module_dbetables(addr);
421 return e;
422 }
423
424 asmlinkage void do_be(struct pt_regs *regs)
425 {
426 const int field = 2 * sizeof(unsigned long);
427 const struct exception_table_entry *fixup = NULL;
428 int data = regs->cp0_cause & 4;
429 int action = MIPS_BE_FATAL;
430 enum ctx_state prev_state;
431
432 prev_state = exception_enter();
433 /* XXX For now. Fixme, this searches the wrong table ... */
434 if (data && !user_mode(regs))
435 fixup = search_dbe_tables(exception_epc(regs));
436
437 if (fixup)
438 action = MIPS_BE_FIXUP;
439
440 if (board_be_handler)
441 action = board_be_handler(regs, fixup != NULL);
442
443 switch (action) {
444 case MIPS_BE_DISCARD:
445 goto out;
446 case MIPS_BE_FIXUP:
447 if (fixup) {
448 regs->cp0_epc = fixup->nextinsn;
449 goto out;
450 }
451 break;
452 default:
453 break;
454 }
455
456 /*
457 * Assume it would be too dangerous to continue ...
458 */
459 printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
460 data ? "Data" : "Instruction",
461 field, regs->cp0_epc, field, regs->regs[31]);
462 if (notify_die(DIE_OOPS, "bus error", regs, 0, regs_to_trapnr(regs),
463 SIGBUS) == NOTIFY_STOP)
464 goto out;
465
466 die_if_kernel("Oops", regs);
467 force_sig(SIGBUS, current);
468
469 out:
470 exception_exit(prev_state);
471 }
472
473 /*
474 * ll/sc, rdhwr, sync emulation
475 */
476
477 #define OPCODE 0xfc000000
478 #define BASE 0x03e00000
479 #define RT 0x001f0000
480 #define OFFSET 0x0000ffff
481 #define LL 0xc0000000
482 #define SC 0xe0000000
483 #define SPEC0 0x00000000
484 #define SPEC3 0x7c000000
485 #define RD 0x0000f800
486 #define FUNC 0x0000003f
487 #define SYNC 0x0000000f
488 #define RDHWR 0x0000003b
489
490 /* microMIPS definitions */
491 #define MM_POOL32A_FUNC 0xfc00ffff
492 #define MM_RDHWR 0x00006b3c
493 #define MM_RS 0x001f0000
494 #define MM_RT 0x03e00000
495
496 /*
497 * The ll_bit is cleared by r*_switch.S
498 */
499
500 unsigned int ll_bit;
501 struct task_struct *ll_task;
502
503 static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
504 {
505 unsigned long value, __user *vaddr;
506 long offset;
507
508 /*
509 * analyse the ll instruction that just caused a ri exception
510 * and put the referenced address to addr.
511 */
512
513 /* sign extend offset */
514 offset = opcode & OFFSET;
515 offset <<= 16;
516 offset >>= 16;
517
518 vaddr = (unsigned long __user *)
519 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
520
521 if ((unsigned long)vaddr & 3)
522 return SIGBUS;
523 if (get_user(value, vaddr))
524 return SIGSEGV;
525
526 preempt_disable();
527
528 if (ll_task == NULL || ll_task == current) {
529 ll_bit = 1;
530 } else {
531 ll_bit = 0;
532 }
533 ll_task = current;
534
535 preempt_enable();
536
537 regs->regs[(opcode & RT) >> 16] = value;
538
539 return 0;
540 }
541
542 static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
543 {
544 unsigned long __user *vaddr;
545 unsigned long reg;
546 long offset;
547
548 /*
549 * analyse the sc instruction that just caused a ri exception
550 * and put the referenced address to addr.
551 */
552
553 /* sign extend offset */
554 offset = opcode & OFFSET;
555 offset <<= 16;
556 offset >>= 16;
557
558 vaddr = (unsigned long __user *)
559 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
560 reg = (opcode & RT) >> 16;
561
562 if ((unsigned long)vaddr & 3)
563 return SIGBUS;
564
565 preempt_disable();
566
567 if (ll_bit == 0 || ll_task != current) {
568 regs->regs[reg] = 0;
569 preempt_enable();
570 return 0;
571 }
572
573 preempt_enable();
574
575 if (put_user(regs->regs[reg], vaddr))
576 return SIGSEGV;
577
578 regs->regs[reg] = 1;
579
580 return 0;
581 }
582
583 /*
584 * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
585 * opcodes are supposed to result in coprocessor unusable exceptions if
586 * executed on ll/sc-less processors. That's the theory. In practice a
587 * few processors such as NEC's VR4100 throw reserved instruction exceptions
588 * instead, so we're doing the emulation thing in both exception handlers.
589 */
590 static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
591 {
592 if ((opcode & OPCODE) == LL) {
593 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
594 1, regs, 0);
595 return simulate_ll(regs, opcode);
596 }
597 if ((opcode & OPCODE) == SC) {
598 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
599 1, regs, 0);
600 return simulate_sc(regs, opcode);
601 }
602
603 return -1; /* Must be something else ... */
604 }
605
606 /*
607 * Simulate trapping 'rdhwr' instructions to provide user accessible
608 * registers not implemented in hardware.
609 */
610 static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
611 {
612 struct thread_info *ti = task_thread_info(current);
613
614 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
615 1, regs, 0);
616 switch (rd) {
617 case 0: /* CPU number */
618 regs->regs[rt] = smp_processor_id();
619 return 0;
620 case 1: /* SYNCI length */
621 regs->regs[rt] = min(current_cpu_data.dcache.linesz,
622 current_cpu_data.icache.linesz);
623 return 0;
624 case 2: /* Read count register */
625 regs->regs[rt] = read_c0_count();
626 return 0;
627 case 3: /* Count register resolution */
628 switch (current_cpu_type()) {
629 case CPU_20KC:
630 case CPU_25KF:
631 regs->regs[rt] = 1;
632 break;
633 default:
634 regs->regs[rt] = 2;
635 }
636 return 0;
637 case 29:
638 regs->regs[rt] = ti->tp_value;
639 return 0;
640 default:
641 return -1;
642 }
643 }
644
645 static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
646 {
647 if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
648 int rd = (opcode & RD) >> 11;
649 int rt = (opcode & RT) >> 16;
650
651 simulate_rdhwr(regs, rd, rt);
652 return 0;
653 }
654
655 /* Not ours. */
656 return -1;
657 }
658
659 static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned short opcode)
660 {
661 if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
662 int rd = (opcode & MM_RS) >> 16;
663 int rt = (opcode & MM_RT) >> 21;
664 simulate_rdhwr(regs, rd, rt);
665 return 0;
666 }
667
668 /* Not ours. */
669 return -1;
670 }
671
672 static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
673 {
674 if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
675 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
676 1, regs, 0);
677 return 0;
678 }
679
680 return -1; /* Must be something else ... */
681 }
682
683 asmlinkage void do_ov(struct pt_regs *regs)
684 {
685 enum ctx_state prev_state;
686 siginfo_t info;
687
688 prev_state = exception_enter();
689 die_if_kernel("Integer overflow", regs);
690
691 info.si_code = FPE_INTOVF;
692 info.si_signo = SIGFPE;
693 info.si_errno = 0;
694 info.si_addr = (void __user *) regs->cp0_epc;
695 force_sig_info(SIGFPE, &info, current);
696 exception_exit(prev_state);
697 }
698
699 int process_fpemu_return(int sig, void __user *fault_addr)
700 {
701 if (sig == SIGSEGV || sig == SIGBUS) {
702 struct siginfo si = {0};
703 si.si_addr = fault_addr;
704 si.si_signo = sig;
705 if (sig == SIGSEGV) {
706 if (find_vma(current->mm, (unsigned long)fault_addr))
707 si.si_code = SEGV_ACCERR;
708 else
709 si.si_code = SEGV_MAPERR;
710 } else {
711 si.si_code = BUS_ADRERR;
712 }
713 force_sig_info(sig, &si, current);
714 return 1;
715 } else if (sig) {
716 force_sig(sig, current);
717 return 1;
718 } else {
719 return 0;
720 }
721 }
722
723 /*
724 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
725 */
726 asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
727 {
728 enum ctx_state prev_state;
729 siginfo_t info = {0};
730
731 prev_state = exception_enter();
732 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs),
733 SIGFPE) == NOTIFY_STOP)
734 goto out;
735 die_if_kernel("FP exception in kernel code", regs);
736
737 if (fcr31 & FPU_CSR_UNI_X) {
738 int sig;
739 void __user *fault_addr = NULL;
740
741 /*
742 * Unimplemented operation exception. If we've got the full
743 * software emulator on-board, let's use it...
744 *
745 * Force FPU to dump state into task/thread context. We're
746 * moving a lot of data here for what is probably a single
747 * instruction, but the alternative is to pre-decode the FP
748 * register operands before invoking the emulator, which seems
749 * a bit extreme for what should be an infrequent event.
750 */
751 /* Ensure 'resume' not overwrite saved fp context again. */
752 lose_fpu(1);
753
754 /* Run the emulator */
755 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
756 &fault_addr);
757
758 /*
759 * We can't allow the emulated instruction to leave any of
760 * the cause bit set in $fcr31.
761 */
762 current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
763
764 /* Restore the hardware register state */
765 own_fpu(1); /* Using the FPU again. */
766
767 /* If something went wrong, signal */
768 process_fpemu_return(sig, fault_addr);
769
770 goto out;
771 } else if (fcr31 & FPU_CSR_INV_X)
772 info.si_code = FPE_FLTINV;
773 else if (fcr31 & FPU_CSR_DIV_X)
774 info.si_code = FPE_FLTDIV;
775 else if (fcr31 & FPU_CSR_OVF_X)
776 info.si_code = FPE_FLTOVF;
777 else if (fcr31 & FPU_CSR_UDF_X)
778 info.si_code = FPE_FLTUND;
779 else if (fcr31 & FPU_CSR_INE_X)
780 info.si_code = FPE_FLTRES;
781 else
782 info.si_code = __SI_FAULT;
783 info.si_signo = SIGFPE;
784 info.si_errno = 0;
785 info.si_addr = (void __user *) regs->cp0_epc;
786 force_sig_info(SIGFPE, &info, current);
787
788 out:
789 exception_exit(prev_state);
790 }
791
792 static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
793 const char *str)
794 {
795 siginfo_t info;
796 char b[40];
797
798 #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
799 if (kgdb_ll_trap(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
800 return;
801 #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
802
803 if (notify_die(DIE_TRAP, str, regs, code, regs_to_trapnr(regs),
804 SIGTRAP) == NOTIFY_STOP)
805 return;
806
807 /*
808 * A short test says that IRIX 5.3 sends SIGTRAP for all trap
809 * insns, even for trap and break codes that indicate arithmetic
810 * failures. Weird ...
811 * But should we continue the brokenness??? --macro
812 */
813 switch (code) {
814 case BRK_OVERFLOW:
815 case BRK_DIVZERO:
816 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
817 die_if_kernel(b, regs);
818 if (code == BRK_DIVZERO)
819 info.si_code = FPE_INTDIV;
820 else
821 info.si_code = FPE_INTOVF;
822 info.si_signo = SIGFPE;
823 info.si_errno = 0;
824 info.si_addr = (void __user *) regs->cp0_epc;
825 force_sig_info(SIGFPE, &info, current);
826 break;
827 case BRK_BUG:
828 die_if_kernel("Kernel bug detected", regs);
829 force_sig(SIGTRAP, current);
830 break;
831 case BRK_MEMU:
832 /*
833 * Address errors may be deliberately induced by the FPU
834 * emulator to retake control of the CPU after executing the
835 * instruction in the delay slot of an emulated branch.
836 *
837 * Terminate if exception was recognized as a delay slot return
838 * otherwise handle as normal.
839 */
840 if (do_dsemulret(regs))
841 return;
842
843 die_if_kernel("Math emu break/trap", regs);
844 force_sig(SIGTRAP, current);
845 break;
846 default:
847 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
848 die_if_kernel(b, regs);
849 force_sig(SIGTRAP, current);
850 }
851 }
852
853 asmlinkage void do_bp(struct pt_regs *regs)
854 {
855 unsigned int opcode, bcode;
856 enum ctx_state prev_state;
857 unsigned long epc;
858 u16 instr[2];
859 mm_segment_t seg;
860
861 seg = get_fs();
862 if (!user_mode(regs))
863 set_fs(KERNEL_DS);
864
865 prev_state = exception_enter();
866 if (get_isa16_mode(regs->cp0_epc)) {
867 /* Calculate EPC. */
868 epc = exception_epc(regs);
869 if (cpu_has_mmips) {
870 if ((__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)) ||
871 (__get_user(instr[1], (u16 __user *)msk_isa16_mode(epc + 2)))))
872 goto out_sigsegv;
873 opcode = (instr[0] << 16) | instr[1];
874 } else {
875 /* MIPS16e mode */
876 if (__get_user(instr[0],
877 (u16 __user *)msk_isa16_mode(epc)))
878 goto out_sigsegv;
879 bcode = (instr[0] >> 6) & 0x3f;
880 do_trap_or_bp(regs, bcode, "Break");
881 goto out;
882 }
883 } else {
884 if (__get_user(opcode,
885 (unsigned int __user *) exception_epc(regs)))
886 goto out_sigsegv;
887 }
888
889 /*
890 * There is the ancient bug in the MIPS assemblers that the break
891 * code starts left to bit 16 instead to bit 6 in the opcode.
892 * Gas is bug-compatible, but not always, grrr...
893 * We handle both cases with a simple heuristics. --macro
894 */
895 bcode = ((opcode >> 6) & ((1 << 20) - 1));
896 if (bcode >= (1 << 10))
897 bcode >>= 10;
898
899 /*
900 * notify the kprobe handlers, if instruction is likely to
901 * pertain to them.
902 */
903 switch (bcode) {
904 case BRK_KPROBE_BP:
905 if (notify_die(DIE_BREAK, "debug", regs, bcode,
906 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
907 goto out;
908 else
909 break;
910 case BRK_KPROBE_SSTEPBP:
911 if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
912 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
913 goto out;
914 else
915 break;
916 default:
917 break;
918 }
919
920 do_trap_or_bp(regs, bcode, "Break");
921
922 out:
923 set_fs(seg);
924 exception_exit(prev_state);
925 return;
926
927 out_sigsegv:
928 force_sig(SIGSEGV, current);
929 goto out;
930 }
931
932 asmlinkage void do_tr(struct pt_regs *regs)
933 {
934 u32 opcode, tcode = 0;
935 enum ctx_state prev_state;
936 u16 instr[2];
937 mm_segment_t seg;
938 unsigned long epc = msk_isa16_mode(exception_epc(regs));
939
940 seg = get_fs();
941 if (!user_mode(regs))
942 set_fs(get_ds());
943
944 prev_state = exception_enter();
945 if (get_isa16_mode(regs->cp0_epc)) {
946 if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
947 __get_user(instr[1], (u16 __user *)(epc + 2)))
948 goto out_sigsegv;
949 opcode = (instr[0] << 16) | instr[1];
950 /* Immediate versions don't provide a code. */
951 if (!(opcode & OPCODE))
952 tcode = (opcode >> 12) & ((1 << 4) - 1);
953 } else {
954 if (__get_user(opcode, (u32 __user *)epc))
955 goto out_sigsegv;
956 /* Immediate versions don't provide a code. */
957 if (!(opcode & OPCODE))
958 tcode = (opcode >> 6) & ((1 << 10) - 1);
959 }
960
961 do_trap_or_bp(regs, tcode, "Trap");
962
963 out:
964 set_fs(seg);
965 exception_exit(prev_state);
966 return;
967
968 out_sigsegv:
969 force_sig(SIGSEGV, current);
970 goto out;
971 }
972
973 asmlinkage void do_ri(struct pt_regs *regs)
974 {
975 unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
976 unsigned long old_epc = regs->cp0_epc;
977 unsigned long old31 = regs->regs[31];
978 enum ctx_state prev_state;
979 unsigned int opcode = 0;
980 int status = -1;
981
982 prev_state = exception_enter();
983 if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs),
984 SIGILL) == NOTIFY_STOP)
985 goto out;
986
987 die_if_kernel("Reserved instruction in kernel code", regs);
988
989 if (unlikely(compute_return_epc(regs) < 0))
990 goto out;
991
992 if (get_isa16_mode(regs->cp0_epc)) {
993 unsigned short mmop[2] = { 0 };
994
995 if (unlikely(get_user(mmop[0], epc) < 0))
996 status = SIGSEGV;
997 if (unlikely(get_user(mmop[1], epc) < 0))
998 status = SIGSEGV;
999 opcode = (mmop[0] << 16) | mmop[1];
1000
1001 if (status < 0)
1002 status = simulate_rdhwr_mm(regs, opcode);
1003 } else {
1004 if (unlikely(get_user(opcode, epc) < 0))
1005 status = SIGSEGV;
1006
1007 if (!cpu_has_llsc && status < 0)
1008 status = simulate_llsc(regs, opcode);
1009
1010 if (status < 0)
1011 status = simulate_rdhwr_normal(regs, opcode);
1012
1013 if (status < 0)
1014 status = simulate_sync(regs, opcode);
1015 }
1016
1017 if (status < 0)
1018 status = SIGILL;
1019
1020 if (unlikely(status > 0)) {
1021 regs->cp0_epc = old_epc; /* Undo skip-over. */
1022 regs->regs[31] = old31;
1023 force_sig(status, current);
1024 }
1025
1026 out:
1027 exception_exit(prev_state);
1028 }
1029
1030 /*
1031 * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
1032 * emulated more than some threshold number of instructions, force migration to
1033 * a "CPU" that has FP support.
1034 */
1035 static void mt_ase_fp_affinity(void)
1036 {
1037 #ifdef CONFIG_MIPS_MT_FPAFF
1038 if (mt_fpemul_threshold > 0 &&
1039 ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
1040 /*
1041 * If there's no FPU present, or if the application has already
1042 * restricted the allowed set to exclude any CPUs with FPUs,
1043 * we'll skip the procedure.
1044 */
1045 if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
1046 cpumask_t tmask;
1047
1048 current->thread.user_cpus_allowed
1049 = current->cpus_allowed;
1050 cpus_and(tmask, current->cpus_allowed,
1051 mt_fpu_cpumask);
1052 set_cpus_allowed_ptr(current, &tmask);
1053 set_thread_flag(TIF_FPUBOUND);
1054 }
1055 }
1056 #endif /* CONFIG_MIPS_MT_FPAFF */
1057 }
1058
1059 /*
1060 * No lock; only written during early bootup by CPU 0.
1061 */
1062 static RAW_NOTIFIER_HEAD(cu2_chain);
1063
1064 int __ref register_cu2_notifier(struct notifier_block *nb)
1065 {
1066 return raw_notifier_chain_register(&cu2_chain, nb);
1067 }
1068
1069 int cu2_notifier_call_chain(unsigned long val, void *v)
1070 {
1071 return raw_notifier_call_chain(&cu2_chain, val, v);
1072 }
1073
1074 static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
1075 void *data)
1076 {
1077 struct pt_regs *regs = data;
1078
1079 die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
1080 "instruction", regs);
1081 force_sig(SIGILL, current);
1082
1083 return NOTIFY_OK;
1084 }
1085
1086 static int enable_restore_fp_context(int msa)
1087 {
1088 int err, was_fpu_owner;
1089
1090 if (!used_math()) {
1091 /* First time FP context user. */
1092 err = init_fpu();
1093 if (msa && !err)
1094 enable_msa();
1095 if (!err)
1096 set_used_math();
1097 return err;
1098 }
1099
1100 /*
1101 * This task has formerly used the FP context.
1102 *
1103 * If this thread has no live MSA vector context then we can simply
1104 * restore the scalar FP context. If it has live MSA vector context
1105 * (that is, it has or may have used MSA since last performing a
1106 * function call) then we'll need to restore the vector context. This
1107 * applies even if we're currently only executing a scalar FP
1108 * instruction. This is because if we were to later execute an MSA
1109 * instruction then we'd either have to:
1110 *
1111 * - Restore the vector context & clobber any registers modified by
1112 * scalar FP instructions between now & then.
1113 *
1114 * or
1115 *
1116 * - Not restore the vector context & lose the most significant bits
1117 * of all vector registers.
1118 *
1119 * Neither of those options is acceptable. We cannot restore the least
1120 * significant bits of the registers now & only restore the most
1121 * significant bits later because the most significant bits of any
1122 * vector registers whose aliased FP register is modified now will have
1123 * been zeroed. We'd have no way to know that when restoring the vector
1124 * context & thus may load an outdated value for the most significant
1125 * bits of a vector register.
1126 */
1127 if (!msa && !thread_msa_context_live())
1128 return own_fpu(1);
1129
1130 /*
1131 * This task is using or has previously used MSA. Thus we require
1132 * that Status.FR == 1.
1133 */
1134 was_fpu_owner = is_fpu_owner();
1135 err = own_fpu(0);
1136 if (err)
1137 return err;
1138
1139 enable_msa();
1140 write_msa_csr(current->thread.fpu.msacsr);
1141 set_thread_flag(TIF_USEDMSA);
1142
1143 /*
1144 * If this is the first time that the task is using MSA and it has
1145 * previously used scalar FP in this time slice then we already nave
1146 * FP context which we shouldn't clobber.
1147 */
1148 if (!test_and_set_thread_flag(TIF_MSA_CTX_LIVE) && was_fpu_owner)
1149 return 0;
1150
1151 /* We need to restore the vector context. */
1152 restore_msa(current);
1153 return 0;
1154 }
1155
1156 asmlinkage void do_cpu(struct pt_regs *regs)
1157 {
1158 enum ctx_state prev_state;
1159 unsigned int __user *epc;
1160 unsigned long old_epc, old31;
1161 unsigned int opcode;
1162 unsigned int cpid;
1163 int status, err;
1164 unsigned long __maybe_unused flags;
1165
1166 prev_state = exception_enter();
1167 cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
1168
1169 if (cpid != 2)
1170 die_if_kernel("do_cpu invoked from kernel context!", regs);
1171
1172 switch (cpid) {
1173 case 0:
1174 epc = (unsigned int __user *)exception_epc(regs);
1175 old_epc = regs->cp0_epc;
1176 old31 = regs->regs[31];
1177 opcode = 0;
1178 status = -1;
1179
1180 if (unlikely(compute_return_epc(regs) < 0))
1181 goto out;
1182
1183 if (get_isa16_mode(regs->cp0_epc)) {
1184 unsigned short mmop[2] = { 0 };
1185
1186 if (unlikely(get_user(mmop[0], epc) < 0))
1187 status = SIGSEGV;
1188 if (unlikely(get_user(mmop[1], epc) < 0))
1189 status = SIGSEGV;
1190 opcode = (mmop[0] << 16) | mmop[1];
1191
1192 if (status < 0)
1193 status = simulate_rdhwr_mm(regs, opcode);
1194 } else {
1195 if (unlikely(get_user(opcode, epc) < 0))
1196 status = SIGSEGV;
1197
1198 if (!cpu_has_llsc && status < 0)
1199 status = simulate_llsc(regs, opcode);
1200
1201 if (status < 0)
1202 status = simulate_rdhwr_normal(regs, opcode);
1203 }
1204
1205 if (status < 0)
1206 status = SIGILL;
1207
1208 if (unlikely(status > 0)) {
1209 regs->cp0_epc = old_epc; /* Undo skip-over. */
1210 regs->regs[31] = old31;
1211 force_sig(status, current);
1212 }
1213
1214 goto out;
1215
1216 case 3:
1217 /*
1218 * Old (MIPS I and MIPS II) processors will set this code
1219 * for COP1X opcode instructions that replaced the original
1220 * COP3 space. We don't limit COP1 space instructions in
1221 * the emulator according to the CPU ISA, so we want to
1222 * treat COP1X instructions consistently regardless of which
1223 * code the CPU chose. Therefore we redirect this trap to
1224 * the FP emulator too.
1225 *
1226 * Then some newer FPU-less processors use this code
1227 * erroneously too, so they are covered by this choice
1228 * as well.
1229 */
1230 if (raw_cpu_has_fpu)
1231 break;
1232 /* Fall through. */
1233
1234 case 1:
1235 err = enable_restore_fp_context(0);
1236
1237 if (!raw_cpu_has_fpu || err) {
1238 int sig;
1239 void __user *fault_addr = NULL;
1240 sig = fpu_emulator_cop1Handler(regs,
1241 &current->thread.fpu,
1242 0, &fault_addr);
1243 if (!process_fpemu_return(sig, fault_addr) && !err)
1244 mt_ase_fp_affinity();
1245 }
1246
1247 goto out;
1248
1249 case 2:
1250 raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
1251 goto out;
1252 }
1253
1254 force_sig(SIGILL, current);
1255
1256 out:
1257 exception_exit(prev_state);
1258 }
1259
1260 asmlinkage void do_msa_fpe(struct pt_regs *regs)
1261 {
1262 enum ctx_state prev_state;
1263
1264 prev_state = exception_enter();
1265 die_if_kernel("do_msa_fpe invoked from kernel context!", regs);
1266 force_sig(SIGFPE, current);
1267 exception_exit(prev_state);
1268 }
1269
1270 asmlinkage void do_msa(struct pt_regs *regs)
1271 {
1272 enum ctx_state prev_state;
1273 int err;
1274
1275 prev_state = exception_enter();
1276
1277 if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) {
1278 force_sig(SIGILL, current);
1279 goto out;
1280 }
1281
1282 die_if_kernel("do_msa invoked from kernel context!", regs);
1283
1284 err = enable_restore_fp_context(1);
1285 if (err)
1286 force_sig(SIGILL, current);
1287 out:
1288 exception_exit(prev_state);
1289 }
1290
1291 asmlinkage void do_mdmx(struct pt_regs *regs)
1292 {
1293 enum ctx_state prev_state;
1294
1295 prev_state = exception_enter();
1296 force_sig(SIGILL, current);
1297 exception_exit(prev_state);
1298 }
1299
1300 /*
1301 * Called with interrupts disabled.
1302 */
1303 asmlinkage void do_watch(struct pt_regs *regs)
1304 {
1305 enum ctx_state prev_state;
1306 u32 cause;
1307
1308 prev_state = exception_enter();
1309 /*
1310 * Clear WP (bit 22) bit of cause register so we don't loop
1311 * forever.
1312 */
1313 cause = read_c0_cause();
1314 cause &= ~(1 << 22);
1315 write_c0_cause(cause);
1316
1317 /*
1318 * If the current thread has the watch registers loaded, save
1319 * their values and send SIGTRAP. Otherwise another thread
1320 * left the registers set, clear them and continue.
1321 */
1322 if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
1323 mips_read_watch_registers();
1324 local_irq_enable();
1325 force_sig(SIGTRAP, current);
1326 } else {
1327 mips_clear_watch_registers();
1328 local_irq_enable();
1329 }
1330 exception_exit(prev_state);
1331 }
1332
1333 asmlinkage void do_mcheck(struct pt_regs *regs)
1334 {
1335 const int field = 2 * sizeof(unsigned long);
1336 int multi_match = regs->cp0_status & ST0_TS;
1337 enum ctx_state prev_state;
1338
1339 prev_state = exception_enter();
1340 show_regs(regs);
1341
1342 if (multi_match) {
1343 printk("Index : %0x\n", read_c0_index());
1344 printk("Pagemask: %0x\n", read_c0_pagemask());
1345 printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
1346 printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
1347 printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
1348 printk("\n");
1349 dump_tlb_all();
1350 }
1351
1352 show_code((unsigned int __user *) regs->cp0_epc);
1353
1354 /*
1355 * Some chips may have other causes of machine check (e.g. SB1
1356 * graduation timer)
1357 */
1358 panic("Caught Machine Check exception - %scaused by multiple "
1359 "matching entries in the TLB.",
1360 (multi_match) ? "" : "not ");
1361 }
1362
1363 asmlinkage void do_mt(struct pt_regs *regs)
1364 {
1365 int subcode;
1366
1367 subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
1368 >> VPECONTROL_EXCPT_SHIFT;
1369 switch (subcode) {
1370 case 0:
1371 printk(KERN_DEBUG "Thread Underflow\n");
1372 break;
1373 case 1:
1374 printk(KERN_DEBUG "Thread Overflow\n");
1375 break;
1376 case 2:
1377 printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
1378 break;
1379 case 3:
1380 printk(KERN_DEBUG "Gating Storage Exception\n");
1381 break;
1382 case 4:
1383 printk(KERN_DEBUG "YIELD Scheduler Exception\n");
1384 break;
1385 case 5:
1386 printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
1387 break;
1388 default:
1389 printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
1390 subcode);
1391 break;
1392 }
1393 die_if_kernel("MIPS MT Thread exception in kernel", regs);
1394
1395 force_sig(SIGILL, current);
1396 }
1397
1398
1399 asmlinkage void do_dsp(struct pt_regs *regs)
1400 {
1401 if (cpu_has_dsp)
1402 panic("Unexpected DSP exception");
1403
1404 force_sig(SIGILL, current);
1405 }
1406
1407 asmlinkage void do_reserved(struct pt_regs *regs)
1408 {
1409 /*
1410 * Game over - no way to handle this if it ever occurs. Most probably
1411 * caused by a new unknown cpu type or after another deadly
1412 * hard/software error.
1413 */
1414 show_regs(regs);
1415 panic("Caught reserved exception %ld - should not happen.",
1416 (regs->cp0_cause & 0x7f) >> 2);
1417 }
1418
1419 static int __initdata l1parity = 1;
1420 static int __init nol1parity(char *s)
1421 {
1422 l1parity = 0;
1423 return 1;
1424 }
1425 __setup("nol1par", nol1parity);
1426 static int __initdata l2parity = 1;
1427 static int __init nol2parity(char *s)
1428 {
1429 l2parity = 0;
1430 return 1;
1431 }
1432 __setup("nol2par", nol2parity);
1433
1434 /*
1435 * Some MIPS CPUs can enable/disable for cache parity detection, but do
1436 * it different ways.
1437 */
1438 static inline void parity_protection_init(void)
1439 {
1440 switch (current_cpu_type()) {
1441 case CPU_24K:
1442 case CPU_34K:
1443 case CPU_74K:
1444 case CPU_1004K:
1445 case CPU_1074K:
1446 case CPU_INTERAPTIV:
1447 case CPU_PROAPTIV:
1448 case CPU_P5600:
1449 {
1450 #define ERRCTL_PE 0x80000000
1451 #define ERRCTL_L2P 0x00800000
1452 unsigned long errctl;
1453 unsigned int l1parity_present, l2parity_present;
1454
1455 errctl = read_c0_ecc();
1456 errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
1457
1458 /* probe L1 parity support */
1459 write_c0_ecc(errctl | ERRCTL_PE);
1460 back_to_back_c0_hazard();
1461 l1parity_present = (read_c0_ecc() & ERRCTL_PE);
1462
1463 /* probe L2 parity support */
1464 write_c0_ecc(errctl|ERRCTL_L2P);
1465 back_to_back_c0_hazard();
1466 l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
1467
1468 if (l1parity_present && l2parity_present) {
1469 if (l1parity)
1470 errctl |= ERRCTL_PE;
1471 if (l1parity ^ l2parity)
1472 errctl |= ERRCTL_L2P;
1473 } else if (l1parity_present) {
1474 if (l1parity)
1475 errctl |= ERRCTL_PE;
1476 } else if (l2parity_present) {
1477 if (l2parity)
1478 errctl |= ERRCTL_L2P;
1479 } else {
1480 /* No parity available */
1481 }
1482
1483 printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
1484
1485 write_c0_ecc(errctl);
1486 back_to_back_c0_hazard();
1487 errctl = read_c0_ecc();
1488 printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
1489
1490 if (l1parity_present)
1491 printk(KERN_INFO "Cache parity protection %sabled\n",
1492 (errctl & ERRCTL_PE) ? "en" : "dis");
1493
1494 if (l2parity_present) {
1495 if (l1parity_present && l1parity)
1496 errctl ^= ERRCTL_L2P;
1497 printk(KERN_INFO "L2 cache parity protection %sabled\n",
1498 (errctl & ERRCTL_L2P) ? "en" : "dis");
1499 }
1500 }
1501 break;
1502
1503 case CPU_5KC:
1504 case CPU_5KE:
1505 case CPU_LOONGSON1:
1506 write_c0_ecc(0x80000000);
1507 back_to_back_c0_hazard();
1508 /* Set the PE bit (bit 31) in the c0_errctl register. */
1509 printk(KERN_INFO "Cache parity protection %sabled\n",
1510 (read_c0_ecc() & 0x80000000) ? "en" : "dis");
1511 break;
1512 case CPU_20KC:
1513 case CPU_25KF:
1514 /* Clear the DE bit (bit 16) in the c0_status register. */
1515 printk(KERN_INFO "Enable cache parity protection for "
1516 "MIPS 20KC/25KF CPUs.\n");
1517 clear_c0_status(ST0_DE);
1518 break;
1519 default:
1520 break;
1521 }
1522 }
1523
1524 asmlinkage void cache_parity_error(void)
1525 {
1526 const int field = 2 * sizeof(unsigned long);
1527 unsigned int reg_val;
1528
1529 /* For the moment, report the problem and hang. */
1530 printk("Cache error exception:\n");
1531 printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1532 reg_val = read_c0_cacheerr();
1533 printk("c0_cacheerr == %08x\n", reg_val);
1534
1535 printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1536 reg_val & (1<<30) ? "secondary" : "primary",
1537 reg_val & (1<<31) ? "data" : "insn");
1538 if (cpu_has_mips_r2 &&
1539 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1540 pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
1541 reg_val & (1<<29) ? "ED " : "",
1542 reg_val & (1<<28) ? "ET " : "",
1543 reg_val & (1<<27) ? "ES " : "",
1544 reg_val & (1<<26) ? "EE " : "",
1545 reg_val & (1<<25) ? "EB " : "",
1546 reg_val & (1<<24) ? "EI " : "",
1547 reg_val & (1<<23) ? "E1 " : "",
1548 reg_val & (1<<22) ? "E0 " : "");
1549 } else {
1550 pr_err("Error bits: %s%s%s%s%s%s%s\n",
1551 reg_val & (1<<29) ? "ED " : "",
1552 reg_val & (1<<28) ? "ET " : "",
1553 reg_val & (1<<26) ? "EE " : "",
1554 reg_val & (1<<25) ? "EB " : "",
1555 reg_val & (1<<24) ? "EI " : "",
1556 reg_val & (1<<23) ? "E1 " : "",
1557 reg_val & (1<<22) ? "E0 " : "");
1558 }
1559 printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1560
1561 #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
1562 if (reg_val & (1<<22))
1563 printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
1564
1565 if (reg_val & (1<<23))
1566 printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
1567 #endif
1568
1569 panic("Can't handle the cache error!");
1570 }
1571
1572 asmlinkage void do_ftlb(void)
1573 {
1574 const int field = 2 * sizeof(unsigned long);
1575 unsigned int reg_val;
1576
1577 /* For the moment, report the problem and hang. */
1578 if (cpu_has_mips_r2 &&
1579 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1580 pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
1581 read_c0_ecc());
1582 pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1583 reg_val = read_c0_cacheerr();
1584 pr_err("c0_cacheerr == %08x\n", reg_val);
1585
1586 if ((reg_val & 0xc0000000) == 0xc0000000) {
1587 pr_err("Decoded c0_cacheerr: FTLB parity error\n");
1588 } else {
1589 pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1590 reg_val & (1<<30) ? "secondary" : "primary",
1591 reg_val & (1<<31) ? "data" : "insn");
1592 }
1593 } else {
1594 pr_err("FTLB error exception\n");
1595 }
1596 /* Just print the cacheerr bits for now */
1597 cache_parity_error();
1598 }
1599
1600 /*
1601 * SDBBP EJTAG debug exception handler.
1602 * We skip the instruction and return to the next instruction.
1603 */
1604 void ejtag_exception_handler(struct pt_regs *regs)
1605 {
1606 const int field = 2 * sizeof(unsigned long);
1607 unsigned long depc, old_epc, old_ra;
1608 unsigned int debug;
1609
1610 printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
1611 depc = read_c0_depc();
1612 debug = read_c0_debug();
1613 printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
1614 if (debug & 0x80000000) {
1615 /*
1616 * In branch delay slot.
1617 * We cheat a little bit here and use EPC to calculate the
1618 * debug return address (DEPC). EPC is restored after the
1619 * calculation.
1620 */
1621 old_epc = regs->cp0_epc;
1622 old_ra = regs->regs[31];
1623 regs->cp0_epc = depc;
1624 compute_return_epc(regs);
1625 depc = regs->cp0_epc;
1626 regs->cp0_epc = old_epc;
1627 regs->regs[31] = old_ra;
1628 } else
1629 depc += 4;
1630 write_c0_depc(depc);
1631
1632 #if 0
1633 printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
1634 write_c0_debug(debug | 0x100);
1635 #endif
1636 }
1637
1638 /*
1639 * NMI exception handler.
1640 * No lock; only written during early bootup by CPU 0.
1641 */
1642 static RAW_NOTIFIER_HEAD(nmi_chain);
1643
1644 int register_nmi_notifier(struct notifier_block *nb)
1645 {
1646 return raw_notifier_chain_register(&nmi_chain, nb);
1647 }
1648
1649 void __noreturn nmi_exception_handler(struct pt_regs *regs)
1650 {
1651 char str[100];
1652
1653 raw_notifier_call_chain(&nmi_chain, 0, regs);
1654 bust_spinlocks(1);
1655 snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
1656 smp_processor_id(), regs->cp0_epc);
1657 regs->cp0_epc = read_c0_errorepc();
1658 die(str, regs);
1659 }
1660
1661 #define VECTORSPACING 0x100 /* for EI/VI mode */
1662
1663 unsigned long ebase;
1664 unsigned long exception_handlers[32];
1665 unsigned long vi_handlers[64];
1666
1667 void __init *set_except_vector(int n, void *addr)
1668 {
1669 unsigned long handler = (unsigned long) addr;
1670 unsigned long old_handler;
1671
1672 #ifdef CONFIG_CPU_MICROMIPS
1673 /*
1674 * Only the TLB handlers are cache aligned with an even
1675 * address. All other handlers are on an odd address and
1676 * require no modification. Otherwise, MIPS32 mode will
1677 * be entered when handling any TLB exceptions. That
1678 * would be bad...since we must stay in microMIPS mode.
1679 */
1680 if (!(handler & 0x1))
1681 handler |= 1;
1682 #endif
1683 old_handler = xchg(&exception_handlers[n], handler);
1684
1685 if (n == 0 && cpu_has_divec) {
1686 #ifdef CONFIG_CPU_MICROMIPS
1687 unsigned long jump_mask = ~((1 << 27) - 1);
1688 #else
1689 unsigned long jump_mask = ~((1 << 28) - 1);
1690 #endif
1691 u32 *buf = (u32 *)(ebase + 0x200);
1692 unsigned int k0 = 26;
1693 if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
1694 uasm_i_j(&buf, handler & ~jump_mask);
1695 uasm_i_nop(&buf);
1696 } else {
1697 UASM_i_LA(&buf, k0, handler);
1698 uasm_i_jr(&buf, k0);
1699 uasm_i_nop(&buf);
1700 }
1701 local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
1702 }
1703 return (void *)old_handler;
1704 }
1705
1706 static void do_default_vi(void)
1707 {
1708 show_regs(get_irq_regs());
1709 panic("Caught unexpected vectored interrupt.");
1710 }
1711
1712 static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
1713 {
1714 unsigned long handler;
1715 unsigned long old_handler = vi_handlers[n];
1716 int srssets = current_cpu_data.srsets;
1717 u16 *h;
1718 unsigned char *b;
1719
1720 BUG_ON(!cpu_has_veic && !cpu_has_vint);
1721
1722 if (addr == NULL) {
1723 handler = (unsigned long) do_default_vi;
1724 srs = 0;
1725 } else
1726 handler = (unsigned long) addr;
1727 vi_handlers[n] = handler;
1728
1729 b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
1730
1731 if (srs >= srssets)
1732 panic("Shadow register set %d not supported", srs);
1733
1734 if (cpu_has_veic) {
1735 if (board_bind_eic_interrupt)
1736 board_bind_eic_interrupt(n, srs);
1737 } else if (cpu_has_vint) {
1738 /* SRSMap is only defined if shadow sets are implemented */
1739 if (srssets > 1)
1740 change_c0_srsmap(0xf << n*4, srs << n*4);
1741 }
1742
1743 if (srs == 0) {
1744 /*
1745 * If no shadow set is selected then use the default handler
1746 * that does normal register saving and standard interrupt exit
1747 */
1748 extern char except_vec_vi, except_vec_vi_lui;
1749 extern char except_vec_vi_ori, except_vec_vi_end;
1750 extern char rollback_except_vec_vi;
1751 char *vec_start = using_rollback_handler() ?
1752 &rollback_except_vec_vi : &except_vec_vi;
1753 #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1754 const int lui_offset = &except_vec_vi_lui - vec_start + 2;
1755 const int ori_offset = &except_vec_vi_ori - vec_start + 2;
1756 #else
1757 const int lui_offset = &except_vec_vi_lui - vec_start;
1758 const int ori_offset = &except_vec_vi_ori - vec_start;
1759 #endif
1760 const int handler_len = &except_vec_vi_end - vec_start;
1761
1762 if (handler_len > VECTORSPACING) {
1763 /*
1764 * Sigh... panicing won't help as the console
1765 * is probably not configured :(
1766 */
1767 panic("VECTORSPACING too small");
1768 }
1769
1770 set_handler(((unsigned long)b - ebase), vec_start,
1771 #ifdef CONFIG_CPU_MICROMIPS
1772 (handler_len - 1));
1773 #else
1774 handler_len);
1775 #endif
1776 h = (u16 *)(b + lui_offset);
1777 *h = (handler >> 16) & 0xffff;
1778 h = (u16 *)(b + ori_offset);
1779 *h = (handler & 0xffff);
1780 local_flush_icache_range((unsigned long)b,
1781 (unsigned long)(b+handler_len));
1782 }
1783 else {
1784 /*
1785 * In other cases jump directly to the interrupt handler. It
1786 * is the handler's responsibility to save registers if required
1787 * (eg hi/lo) and return from the exception using "eret".
1788 */
1789 u32 insn;
1790
1791 h = (u16 *)b;
1792 /* j handler */
1793 #ifdef CONFIG_CPU_MICROMIPS
1794 insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
1795 #else
1796 insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
1797 #endif
1798 h[0] = (insn >> 16) & 0xffff;
1799 h[1] = insn & 0xffff;
1800 h[2] = 0;
1801 h[3] = 0;
1802 local_flush_icache_range((unsigned long)b,
1803 (unsigned long)(b+8));
1804 }
1805
1806 return (void *)old_handler;
1807 }
1808
1809 void *set_vi_handler(int n, vi_handler_t addr)
1810 {
1811 return set_vi_srs_handler(n, addr, 0);
1812 }
1813
1814 extern void tlb_init(void);
1815
1816 /*
1817 * Timer interrupt
1818 */
1819 int cp0_compare_irq;
1820 EXPORT_SYMBOL_GPL(cp0_compare_irq);
1821 int cp0_compare_irq_shift;
1822
1823 /*
1824 * Performance counter IRQ or -1 if shared with timer
1825 */
1826 int cp0_perfcount_irq;
1827 EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
1828
1829 static int noulri;
1830
1831 static int __init ulri_disable(char *s)
1832 {
1833 pr_info("Disabling ulri\n");
1834 noulri = 1;
1835
1836 return 1;
1837 }
1838 __setup("noulri", ulri_disable);
1839
1840 void per_cpu_trap_init(bool is_boot_cpu)
1841 {
1842 unsigned int cpu = smp_processor_id();
1843 unsigned int status_set = ST0_CU0;
1844 unsigned int hwrena = cpu_hwrena_impl_bits;
1845
1846 /*
1847 * Disable coprocessors and select 32-bit or 64-bit addressing
1848 * and the 16/32 or 32/32 FPR register model. Reset the BEV
1849 * flag that some firmware may have left set and the TS bit (for
1850 * IP27). Set XX for ISA IV code to work.
1851 */
1852 #ifdef CONFIG_64BIT
1853 status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
1854 #endif
1855 if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
1856 status_set |= ST0_XX;
1857 if (cpu_has_dsp)
1858 status_set |= ST0_MX;
1859
1860 change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
1861 status_set);
1862
1863 if (cpu_has_mips_r2)
1864 hwrena |= 0x0000000f;
1865
1866 if (!noulri && cpu_has_userlocal)
1867 hwrena |= (1 << 29);
1868
1869 if (hwrena)
1870 write_c0_hwrena(hwrena);
1871
1872 if (cpu_has_veic || cpu_has_vint) {
1873 unsigned long sr = set_c0_status(ST0_BEV);
1874 write_c0_ebase(ebase);
1875 write_c0_status(sr);
1876 /* Setting vector spacing enables EI/VI mode */
1877 change_c0_intctl(0x3e0, VECTORSPACING);
1878 }
1879 if (cpu_has_divec) {
1880 if (cpu_has_mipsmt) {
1881 unsigned int vpflags = dvpe();
1882 set_c0_cause(CAUSEF_IV);
1883 evpe(vpflags);
1884 } else
1885 set_c0_cause(CAUSEF_IV);
1886 }
1887
1888 /*
1889 * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
1890 *
1891 * o read IntCtl.IPTI to determine the timer interrupt
1892 * o read IntCtl.IPPCI to determine the performance counter interrupt
1893 */
1894 if (cpu_has_mips_r2) {
1895 cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
1896 cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
1897 cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
1898 if (cp0_perfcount_irq == cp0_compare_irq)
1899 cp0_perfcount_irq = -1;
1900 } else {
1901 cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
1902 cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
1903 cp0_perfcount_irq = -1;
1904 }
1905
1906 if (!cpu_data[cpu].asid_cache)
1907 cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
1908
1909 atomic_inc(&init_mm.mm_count);
1910 current->active_mm = &init_mm;
1911 BUG_ON(current->mm);
1912 enter_lazy_tlb(&init_mm, current);
1913
1914 /* Boot CPU's cache setup in setup_arch(). */
1915 if (!is_boot_cpu)
1916 cpu_cache_init();
1917 tlb_init();
1918 TLBMISS_HANDLER_SETUP();
1919 }
1920
1921 /* Install CPU exception handler */
1922 void set_handler(unsigned long offset, void *addr, unsigned long size)
1923 {
1924 #ifdef CONFIG_CPU_MICROMIPS
1925 memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
1926 #else
1927 memcpy((void *)(ebase + offset), addr, size);
1928 #endif
1929 local_flush_icache_range(ebase + offset, ebase + offset + size);
1930 }
1931
1932 static char panic_null_cerr[] =
1933 "Trying to set NULL cache error exception handler";
1934
1935 /*
1936 * Install uncached CPU exception handler.
1937 * This is suitable only for the cache error exception which is the only
1938 * exception handler that is being run uncached.
1939 */
1940 void set_uncached_handler(unsigned long offset, void *addr,
1941 unsigned long size)
1942 {
1943 unsigned long uncached_ebase = CKSEG1ADDR(ebase);
1944
1945 if (!addr)
1946 panic(panic_null_cerr);
1947
1948 memcpy((void *)(uncached_ebase + offset), addr, size);
1949 }
1950
1951 static int __initdata rdhwr_noopt;
1952 static int __init set_rdhwr_noopt(char *str)
1953 {
1954 rdhwr_noopt = 1;
1955 return 1;
1956 }
1957
1958 __setup("rdhwr_noopt", set_rdhwr_noopt);
1959
1960 void __init trap_init(void)
1961 {
1962 extern char except_vec3_generic;
1963 extern char except_vec4;
1964 extern char except_vec3_r4000;
1965 unsigned long i;
1966
1967 check_wait();
1968
1969 #if defined(CONFIG_KGDB)
1970 if (kgdb_early_setup)
1971 return; /* Already done */
1972 #endif
1973
1974 if (cpu_has_veic || cpu_has_vint) {
1975 unsigned long size = 0x200 + VECTORSPACING*64;
1976 ebase = (unsigned long)
1977 __alloc_bootmem(size, 1 << fls(size), 0);
1978 } else {
1979 #ifdef CONFIG_KVM_GUEST
1980 #define KVM_GUEST_KSEG0 0x40000000
1981 ebase = KVM_GUEST_KSEG0;
1982 #else
1983 ebase = CKSEG0;
1984 #endif
1985 if (cpu_has_mips_r2)
1986 ebase += (read_c0_ebase() & 0x3ffff000);
1987 }
1988
1989 if (cpu_has_mmips) {
1990 unsigned int config3 = read_c0_config3();
1991
1992 if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
1993 write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
1994 else
1995 write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
1996 }
1997
1998 if (board_ebase_setup)
1999 board_ebase_setup();
2000 per_cpu_trap_init(true);
2001
2002 /*
2003 * Copy the generic exception handlers to their final destination.
2004 * This will be overriden later as suitable for a particular
2005 * configuration.
2006 */
2007 set_handler(0x180, &except_vec3_generic, 0x80);
2008
2009 /*
2010 * Setup default vectors
2011 */
2012 for (i = 0; i <= 31; i++)
2013 set_except_vector(i, handle_reserved);
2014
2015 /*
2016 * Copy the EJTAG debug exception vector handler code to it's final
2017 * destination.
2018 */
2019 if (cpu_has_ejtag && board_ejtag_handler_setup)
2020 board_ejtag_handler_setup();
2021
2022 /*
2023 * Only some CPUs have the watch exceptions.
2024 */
2025 if (cpu_has_watch)
2026 set_except_vector(23, handle_watch);
2027
2028 /*
2029 * Initialise interrupt handlers
2030 */
2031 if (cpu_has_veic || cpu_has_vint) {
2032 int nvec = cpu_has_veic ? 64 : 8;
2033 for (i = 0; i < nvec; i++)
2034 set_vi_handler(i, NULL);
2035 }
2036 else if (cpu_has_divec)
2037 set_handler(0x200, &except_vec4, 0x8);
2038
2039 /*
2040 * Some CPUs can enable/disable for cache parity detection, but does
2041 * it different ways.
2042 */
2043 parity_protection_init();
2044
2045 /*
2046 * The Data Bus Errors / Instruction Bus Errors are signaled
2047 * by external hardware. Therefore these two exceptions
2048 * may have board specific handlers.
2049 */
2050 if (board_be_init)
2051 board_be_init();
2052
2053 set_except_vector(0, using_rollback_handler() ? rollback_handle_int
2054 : handle_int);
2055 set_except_vector(1, handle_tlbm);
2056 set_except_vector(2, handle_tlbl);
2057 set_except_vector(3, handle_tlbs);
2058
2059 set_except_vector(4, handle_adel);
2060 set_except_vector(5, handle_ades);
2061
2062 set_except_vector(6, handle_ibe);
2063 set_except_vector(7, handle_dbe);
2064
2065 set_except_vector(8, handle_sys);
2066 set_except_vector(9, handle_bp);
2067 set_except_vector(10, rdhwr_noopt ? handle_ri :
2068 (cpu_has_vtag_icache ?
2069 handle_ri_rdhwr_vivt : handle_ri_rdhwr));
2070 set_except_vector(11, handle_cpu);
2071 set_except_vector(12, handle_ov);
2072 set_except_vector(13, handle_tr);
2073 set_except_vector(14, handle_msa_fpe);
2074
2075 if (current_cpu_type() == CPU_R6000 ||
2076 current_cpu_type() == CPU_R6000A) {
2077 /*
2078 * The R6000 is the only R-series CPU that features a machine
2079 * check exception (similar to the R4000 cache error) and
2080 * unaligned ldc1/sdc1 exception. The handlers have not been
2081 * written yet. Well, anyway there is no R6000 machine on the
2082 * current list of targets for Linux/MIPS.
2083 * (Duh, crap, there is someone with a triple R6k machine)
2084 */
2085 //set_except_vector(14, handle_mc);
2086 //set_except_vector(15, handle_ndc);
2087 }
2088
2089
2090 if (board_nmi_handler_setup)
2091 board_nmi_handler_setup();
2092
2093 if (cpu_has_fpu && !cpu_has_nofpuex)
2094 set_except_vector(15, handle_fpe);
2095
2096 set_except_vector(16, handle_ftlb);
2097 set_except_vector(21, handle_msa);
2098 set_except_vector(22, handle_mdmx);
2099
2100 if (cpu_has_mcheck)
2101 set_except_vector(24, handle_mcheck);
2102
2103 if (cpu_has_mipsmt)
2104 set_except_vector(25, handle_mt);
2105
2106 set_except_vector(26, handle_dsp);
2107
2108 if (board_cache_error_setup)
2109 board_cache_error_setup();
2110
2111 if (cpu_has_vce)
2112 /* Special exception: R4[04]00 uses also the divec space. */
2113 set_handler(0x180, &except_vec3_r4000, 0x100);
2114 else if (cpu_has_4kex)
2115 set_handler(0x180, &except_vec3_generic, 0x80);
2116 else
2117 set_handler(0x080, &except_vec3_generic, 0x80);
2118
2119 local_flush_icache_range(ebase, ebase + 0x400);
2120
2121 sort_extable(__start___dbe_table, __stop___dbe_table);
2122
2123 cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
2124 }