blob: 9716f057a77bcaafb5783b8285b4a124aa82accd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Ralf Baechle36ccf1c2006-02-14 21:04:54 +00006 * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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.
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +010012 * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Ralf Baechle8e8a52e2007-05-31 14:00:19 +010014#include <linux/bug.h>
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +010015#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/init.h>
Nathan Lynch8742cd22011-09-30 13:49:35 -050017#include <linux/kernel.h>
Paul Gortmakerf9ded562012-02-28 19:24:46 -050018#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/sched.h>
21#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/spinlock.h>
23#include <linux/kallsyms.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000024#include <linux/bootmem.h>
Maxime Bizond4fd1982006-07-20 18:52:02 +020025#include <linux/interrupt.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010026#include <linux/ptrace.h>
Jason Wessel88547002008-07-29 15:58:53 -050027#include <linux/kgdb.h>
28#include <linux/kdebug.h>
David Daneyc1bf2072010-08-03 11:22:20 -070029#include <linux/kprobes.h>
Ralf Baechle69f3a7d2009-11-24 01:24:58 +000030#include <linux/notifier.h>
Jason Wessel5dd11d52010-05-20 21:04:26 -050031#include <linux/kdb.h>
David Howellsca4d3e672010-10-07 14:08:54 +010032#include <linux/irq.h>
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +080033#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#include <asm/bootinfo.h>
36#include <asm/branch.h>
37#include <asm/break.h>
Ralf Baechle69f3a7d2009-11-24 01:24:58 +000038#include <asm/cop2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/cpu.h>
Ralf Baechlee50c0a82005-05-31 11:49:19 +000040#include <asm/dsp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/fpu.h>
Ralf Baechleba3049e2008-10-28 17:38:42 +000042#include <asm/fpu_emulator.h>
Ralf Baechle340ee4b2005-08-17 17:44:08 +000043#include <asm/mipsregs.h>
44#include <asm/mipsmtregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/module.h>
46#include <asm/pgtable.h>
47#include <asm/ptrace.h>
48#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <asm/tlbdebug.h>
50#include <asm/traps.h>
51#include <asm/uaccess.h>
David Daneyb67b2b72008-09-23 00:08:45 -070052#include <asm/watch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <asm/types.h>
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090055#include <asm/stacktrace.h>
Florian Fainelli92bbe1b2010-01-28 15:22:37 +010056#include <asm/uasm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Atsushi Nemotoc65a5482007-11-12 02:05:18 +090058extern void check_wait(void);
59extern asmlinkage void r4k_wait(void);
60extern asmlinkage void rollback_handle_int(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010061extern asmlinkage void handle_int(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062extern asmlinkage void handle_tlbm(void);
63extern asmlinkage void handle_tlbl(void);
64extern asmlinkage void handle_tlbs(void);
65extern asmlinkage void handle_adel(void);
66extern asmlinkage void handle_ades(void);
67extern asmlinkage void handle_ibe(void);
68extern asmlinkage void handle_dbe(void);
69extern asmlinkage void handle_sys(void);
70extern asmlinkage void handle_bp(void);
71extern asmlinkage void handle_ri(void);
Atsushi Nemoto5b104962006-09-11 17:50:29 +090072extern asmlinkage void handle_ri_rdhwr_vivt(void);
73extern asmlinkage void handle_ri_rdhwr(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern asmlinkage void handle_cpu(void);
75extern asmlinkage void handle_ov(void);
76extern asmlinkage void handle_tr(void);
77extern asmlinkage void handle_fpe(void);
78extern asmlinkage void handle_mdmx(void);
79extern asmlinkage void handle_watch(void);
Ralf Baechle340ee4b2005-08-17 17:44:08 +000080extern asmlinkage void handle_mt(void);
Ralf Baechlee50c0a82005-05-31 11:49:19 +000081extern asmlinkage void handle_dsp(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern asmlinkage void handle_mcheck(void);
83extern asmlinkage void handle_reserved(void);
84
Ralf Baechle12616ed2005-10-18 10:26:46 +010085extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
David Daney515b0292010-10-21 16:32:26 -070086 struct mips_fpu_struct *ctx, int has_fpu,
87 void *__user *fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89void (*board_be_init)(void);
90int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
Ralf Baechlee01402b2005-07-14 15:57:16 +000091void (*board_nmi_handler_setup)(void);
92void (*board_ejtag_handler_setup)(void);
93void (*board_bind_eic_interrupt)(int irq, int regset);
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +000094void (*board_ebase_setup)(void);
David Daneyfcbf1df2012-05-15 00:04:46 -070095void __cpuinitdata(*board_cache_error_setup)(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Franck Bui-Huu4d157d52006-08-03 09:29:21 +020097static void show_raw_backtrace(unsigned long reg29)
Atsushi Nemotoe889d782006-07-25 23:51:36 +090098{
Ralf Baechle39b8d522008-04-28 17:14:26 +010099 unsigned long *sp = (unsigned long *)(reg29 & ~3);
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900100 unsigned long addr;
101
102 printk("Call Trace:");
103#ifdef CONFIG_KALLSYMS
104 printk("\n");
105#endif
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200106 while (!kstack_end(sp)) {
107 unsigned long __user *p =
108 (unsigned long __user *)(unsigned long)sp++;
109 if (__get_user(addr, p)) {
110 printk(" (Bad stack address)");
111 break;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100112 }
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200113 if (__kernel_text_address(addr))
114 print_ip_sym(addr);
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900115 }
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200116 printk("\n");
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900117}
118
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900119#ifdef CONFIG_KALLSYMS
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +0900120int raw_show_trace;
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900121static int __init set_raw_show_trace(char *str)
122{
123 raw_show_trace = 1;
124 return 1;
125}
126__setup("raw_show_trace", set_raw_show_trace);
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +0900127#endif
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200128
Ralf Baechleeae23f22007-10-14 23:27:21 +0100129static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900130{
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200131 unsigned long sp = regs->regs[29];
132 unsigned long ra = regs->regs[31];
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900133 unsigned long pc = regs->cp0_epc;
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900134
Vincent Wene909be82012-07-19 09:11:16 +0200135 if (!task)
136 task = current;
137
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900138 if (raw_show_trace || !__kernel_text_address(pc)) {
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200139 show_raw_backtrace(sp);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900140 return;
141 }
142 printk("Call Trace:\n");
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200143 do {
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200144 print_ip_sym(pc);
Atsushi Nemoto19246002006-09-29 18:02:51 +0900145 pc = unwind_stack(task, &sp, pc, &ra);
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200146 } while (pc);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900147 printk("\n");
148}
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*
151 * This routine abuses get_user()/put_user() to reference pointers
152 * with at least a bit of error checking ...
153 */
Ralf Baechleeae23f22007-10-14 23:27:21 +0100154static void show_stacktrace(struct task_struct *task,
155 const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 const int field = 2 * sizeof(unsigned long);
158 long stackdata;
159 int i;
Atsushi Nemoto5e0373b2007-07-13 23:02:42 +0900160 unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 printk("Stack :");
163 i = 0;
164 while ((unsigned long) sp & (PAGE_SIZE - 1)) {
165 if (i && ((i % (64 / field)) == 0))
166 printk("\n ");
167 if (i > 39) {
168 printk(" ...");
169 break;
170 }
171
172 if (__get_user(stackdata, sp++)) {
173 printk(" (Bad stack address)");
174 break;
175 }
176
177 printk(" %0*lx", field, stackdata);
178 i++;
179 }
180 printk("\n");
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200181 show_backtrace(task, regs);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900182}
183
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900184void show_stack(struct task_struct *task, unsigned long *sp)
185{
186 struct pt_regs regs;
187 if (sp) {
188 regs.regs[29] = (unsigned long)sp;
189 regs.regs[31] = 0;
190 regs.cp0_epc = 0;
191 } else {
192 if (task && task != current) {
193 regs.regs[29] = task->thread.reg29;
194 regs.regs[31] = 0;
195 regs.cp0_epc = task->thread.reg31;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500196#ifdef CONFIG_KGDB_KDB
197 } else if (atomic_read(&kgdb_active) != -1 &&
198 kdb_current_regs) {
199 memcpy(&regs, kdb_current_regs, sizeof(regs));
200#endif /* CONFIG_KGDB_KDB */
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900201 } else {
202 prepare_frametrace(&regs);
203 }
204 }
205 show_stacktrace(task, &regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208/*
209 * The architecture-independent dump_stack generator
210 */
211void dump_stack(void)
212{
Franck Bui-Huu1666a6f2006-08-03 09:29:19 +0200213 struct pt_regs regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Franck Bui-Huu1666a6f2006-08-03 09:29:19 +0200215 prepare_frametrace(&regs);
216 show_backtrace(current, &regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
219EXPORT_SYMBOL(dump_stack);
220
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900221static void show_code(unsigned int __user *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 long i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100224 unsigned short __user *pc16 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 printk("\nCode:");
227
Ralf Baechle39b8d522008-04-28 17:14:26 +0100228 if ((unsigned long)pc & 1)
229 pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 for(i = -3 ; i < 6 ; i++) {
231 unsigned int insn;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100232 if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 printk(" (Bad address in epc)\n");
234 break;
235 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100236 printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238}
239
Ralf Baechleeae23f22007-10-14 23:27:21 +0100240static void __show_regs(const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 const int field = 2 * sizeof(unsigned long);
243 unsigned int cause = regs->cp0_cause;
244 int i;
245
246 printk("Cpu %d\n", smp_processor_id());
247
248 /*
249 * Saved main processor registers
250 */
251 for (i = 0; i < 32; ) {
252 if ((i % 4) == 0)
253 printk("$%2d :", i);
254 if (i == 0)
255 printk(" %0*lx", field, 0UL);
256 else if (i == 26 || i == 27)
257 printk(" %*s", field, "");
258 else
259 printk(" %0*lx", field, regs->regs[i]);
260
261 i++;
262 if ((i % 4) == 0)
263 printk("\n");
264 }
265
Franck Bui-Huu9693a852007-02-02 17:41:47 +0100266#ifdef CONFIG_CPU_HAS_SMARTMIPS
267 printk("Acx : %0*lx\n", field, regs->acx);
268#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 printk("Hi : %0*lx\n", field, regs->hi);
270 printk("Lo : %0*lx\n", field, regs->lo);
271
272 /*
273 * Saved cp0 registers
274 */
Ralf Baechleb012cff2008-07-15 18:44:33 +0100275 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
276 (void *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 printk(" %s\n", print_tainted());
Ralf Baechleb012cff2008-07-15 18:44:33 +0100278 printk("ra : %0*lx %pS\n", field, regs->regs[31],
279 (void *) regs->regs[31]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 printk("Status: %08x ", (uint32_t) regs->cp0_status);
282
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000283 if (current_cpu_data.isa_level == MIPS_CPU_ISA_I) {
284 if (regs->cp0_status & ST0_KUO)
285 printk("KUo ");
286 if (regs->cp0_status & ST0_IEO)
287 printk("IEo ");
288 if (regs->cp0_status & ST0_KUP)
289 printk("KUp ");
290 if (regs->cp0_status & ST0_IEP)
291 printk("IEp ");
292 if (regs->cp0_status & ST0_KUC)
293 printk("KUc ");
294 if (regs->cp0_status & ST0_IEC)
295 printk("IEc ");
296 } else {
297 if (regs->cp0_status & ST0_KX)
298 printk("KX ");
299 if (regs->cp0_status & ST0_SX)
300 printk("SX ");
301 if (regs->cp0_status & ST0_UX)
302 printk("UX ");
303 switch (regs->cp0_status & ST0_KSU) {
304 case KSU_USER:
305 printk("USER ");
306 break;
307 case KSU_SUPERVISOR:
308 printk("SUPERVISOR ");
309 break;
310 case KSU_KERNEL:
311 printk("KERNEL ");
312 break;
313 default:
314 printk("BAD_MODE ");
315 break;
316 }
317 if (regs->cp0_status & ST0_ERL)
318 printk("ERL ");
319 if (regs->cp0_status & ST0_EXL)
320 printk("EXL ");
321 if (regs->cp0_status & ST0_IE)
322 printk("IE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 printk("\n");
325
326 printk("Cause : %08x\n", cause);
327
328 cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
329 if (1 <= cause && cause <= 5)
330 printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
331
Ralf Baechle9966db252007-10-11 23:46:17 +0100332 printk("PrId : %08x (%s)\n", read_c0_prid(),
333 cpu_name_string());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
335
Ralf Baechleeae23f22007-10-14 23:27:21 +0100336/*
337 * FIXME: really the generic show_regs should take a const pointer argument.
338 */
339void show_regs(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Ralf Baechleeae23f22007-10-14 23:27:21 +0100341 __show_regs((struct pt_regs *)regs);
342}
343
David Daneyc1bf2072010-08-03 11:22:20 -0700344void show_registers(struct pt_regs *regs)
Ralf Baechleeae23f22007-10-14 23:27:21 +0100345{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100346 const int field = 2 * sizeof(unsigned long);
347
Ralf Baechleeae23f22007-10-14 23:27:21 +0100348 __show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 print_modules();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100350 printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
351 current->comm, current->pid, current_thread_info(), current,
352 field, current_thread_info()->tp_value);
353 if (cpu_has_userlocal) {
354 unsigned long tls;
355
356 tls = read_c0_userlocal();
357 if (tls != current_thread_info()->tp_value)
358 printk("*HwTLS: %0*lx\n", field, tls);
359 }
360
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900361 show_stacktrace(current, regs);
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900362 show_code((unsigned int __user *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 printk("\n");
364}
365
David Daney70dc6f02010-08-03 15:44:43 -0700366static int regs_to_trapnr(struct pt_regs *regs)
367{
368 return (regs->cp0_cause >> 2) & 0x1f;
369}
370
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000371static DEFINE_RAW_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
David Daney70dc6f02010-08-03 15:44:43 -0700373void __noreturn die(const char *str, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 static int die_counter;
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400376 int sig = SIGSEGV;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100377#ifdef CONFIG_MIPS_MT_SMTC
Nathan Lynch8742cd22011-09-30 13:49:35 -0500378 unsigned long dvpret;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100379#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Nathan Lynch8742cd22011-09-30 13:49:35 -0500381 oops_enter();
382
Ralf Baechle10423c92011-05-13 10:33:28 +0100383 if (notify_die(DIE_OOPS, str, regs, 0, regs_to_trapnr(regs), SIGSEGV) == NOTIFY_STOP)
384 sig = 0;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 console_verbose();
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000387 raw_spin_lock_irq(&die_lock);
Nathan Lynch8742cd22011-09-30 13:49:35 -0500388#ifdef CONFIG_MIPS_MT_SMTC
389 dvpret = dvpe();
390#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100391 bust_spinlocks(1);
392#ifdef CONFIG_MIPS_MT_SMTC
393 mips_mt_regdump(dvpret);
394#endif /* CONFIG_MIPS_MT_SMTC */
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400395
Ralf Baechle178086c2005-10-13 17:07:54 +0100396 printk("%s[#%d]:\n", str, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 show_registers(regs);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700398 add_taint(TAINT_DIE);
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000399 raw_spin_unlock_irq(&die_lock);
Maxime Bizond4fd1982006-07-20 18:52:02 +0200400
Nathan Lynch8742cd22011-09-30 13:49:35 -0500401 oops_exit();
402
Maxime Bizond4fd1982006-07-20 18:52:02 +0200403 if (in_interrupt())
404 panic("Fatal exception in interrupt");
405
406 if (panic_on_oops) {
Ralf Baechleab75dc02011-11-17 15:07:31 +0000407 printk(KERN_EMERG "Fatal exception: panic in 5 seconds");
Maxime Bizond4fd1982006-07-20 18:52:02 +0200408 ssleep(5);
409 panic("Fatal exception");
410 }
411
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400412 do_exit(sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Thomas Bogendoerfer05106172008-08-04 19:44:34 +0200415extern struct exception_table_entry __start___dbe_table[];
416extern struct exception_table_entry __stop___dbe_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Ralf Baechleb6dcec92007-02-18 15:57:09 +0000418__asm__(
419" .section __dbe_table, \"a\"\n"
420" .previous \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422/* Given an address, look for it in the exception tables. */
423static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
424{
425 const struct exception_table_entry *e;
426
427 e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
428 if (!e)
429 e = search_module_dbetables(addr);
430 return e;
431}
432
433asmlinkage void do_be(struct pt_regs *regs)
434{
435 const int field = 2 * sizeof(unsigned long);
436 const struct exception_table_entry *fixup = NULL;
437 int data = regs->cp0_cause & 4;
438 int action = MIPS_BE_FATAL;
439
440 /* XXX For now. Fixme, this searches the wrong table ... */
441 if (data && !user_mode(regs))
442 fixup = search_dbe_tables(exception_epc(regs));
443
444 if (fixup)
445 action = MIPS_BE_FIXUP;
446
447 if (board_be_handler)
Atsushi Nemoto28fc5822007-07-13 01:49:49 +0900448 action = board_be_handler(regs, fixup != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 switch (action) {
451 case MIPS_BE_DISCARD:
452 return;
453 case MIPS_BE_FIXUP:
454 if (fixup) {
455 regs->cp0_epc = fixup->nextinsn;
456 return;
457 }
458 break;
459 default:
460 break;
461 }
462
463 /*
464 * Assume it would be too dangerous to continue ...
465 */
466 printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
467 data ? "Data" : "Instruction",
468 field, regs->cp0_epc, field, regs->regs[31]);
David Daney70dc6f02010-08-03 15:44:43 -0700469 if (notify_die(DIE_OOPS, "bus error", regs, 0, regs_to_trapnr(regs), SIGBUS)
Jason Wessel88547002008-07-29 15:58:53 -0500470 == NOTIFY_STOP)
471 return;
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 die_if_kernel("Oops", regs);
474 force_sig(SIGBUS, current);
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477/*
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100478 * ll/sc, rdhwr, sync emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 */
480
481#define OPCODE 0xfc000000
482#define BASE 0x03e00000
483#define RT 0x001f0000
484#define OFFSET 0x0000ffff
485#define LL 0xc0000000
486#define SC 0xe0000000
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100487#define SPEC0 0x00000000
Ralf Baechle3c370262005-04-13 17:43:59 +0000488#define SPEC3 0x7c000000
489#define RD 0x0000f800
490#define FUNC 0x0000003f
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100491#define SYNC 0x0000000f
Ralf Baechle3c370262005-04-13 17:43:59 +0000492#define RDHWR 0x0000003b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494/*
495 * The ll_bit is cleared by r*_switch.S
496 */
497
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200498unsigned int ll_bit;
499struct task_struct *ll_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100501static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000503 unsigned long value, __user *vaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 /*
507 * analyse the ll instruction that just caused a ri exception
508 * and put the referenced address to addr.
509 */
510
511 /* sign extend offset */
512 offset = opcode & OFFSET;
513 offset <<= 16;
514 offset >>= 16;
515
Ralf Baechlefe00f942005-03-01 19:22:29 +0000516 vaddr = (unsigned long __user *)
517 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100519 if ((unsigned long)vaddr & 3)
520 return SIGBUS;
521 if (get_user(value, vaddr))
522 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 preempt_disable();
525
526 if (ll_task == NULL || ll_task == current) {
527 ll_bit = 1;
528 } else {
529 ll_bit = 0;
530 }
531 ll_task = current;
532
533 preempt_enable();
534
535 regs->regs[(opcode & RT) >> 16] = value;
536
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100537 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
539
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100540static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000542 unsigned long __user *vaddr;
543 unsigned long reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /*
547 * analyse the sc instruction that just caused a ri exception
548 * and put the referenced address to addr.
549 */
550
551 /* sign extend offset */
552 offset = opcode & OFFSET;
553 offset <<= 16;
554 offset >>= 16;
555
Ralf Baechlefe00f942005-03-01 19:22:29 +0000556 vaddr = (unsigned long __user *)
557 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 reg = (opcode & RT) >> 16;
559
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100560 if ((unsigned long)vaddr & 3)
561 return SIGBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 preempt_disable();
564
565 if (ll_bit == 0 || ll_task != current) {
566 regs->regs[reg] = 0;
567 preempt_enable();
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100568 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570
571 preempt_enable();
572
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100573 if (put_user(regs->regs[reg], vaddr))
574 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 regs->regs[reg] = 1;
577
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100578 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581/*
582 * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
583 * opcodes are supposed to result in coprocessor unusable exceptions if
584 * executed on ll/sc-less processors. That's the theory. In practice a
585 * few processors such as NEC's VR4100 throw reserved instruction exceptions
586 * instead, so we're doing the emulation thing in both exception handlers.
587 */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100588static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800590 if ((opcode & OPCODE) == LL) {
591 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200592 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100593 return simulate_ll(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800594 }
595 if ((opcode & OPCODE) == SC) {
596 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200597 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100598 return simulate_sc(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100601 return -1; /* Must be something else ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
Ralf Baechle3c370262005-04-13 17:43:59 +0000604/*
605 * Simulate trapping 'rdhwr' instructions to provide user accessible
Chris Dearman1f5826b2006-05-08 18:02:16 +0100606 * registers not implemented in hardware.
Ralf Baechle3c370262005-04-13 17:43:59 +0000607 */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100608static int simulate_rdhwr(struct pt_regs *regs, unsigned int opcode)
Ralf Baechle3c370262005-04-13 17:43:59 +0000609{
Al Virodc8f6022006-01-12 01:06:07 -0800610 struct thread_info *ti = task_thread_info(current);
Ralf Baechle3c370262005-04-13 17:43:59 +0000611
612 if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
613 int rd = (opcode & RD) >> 11;
614 int rt = (opcode & RT) >> 16;
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800615 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200616 1, regs, 0);
Ralf Baechle3c370262005-04-13 17:43:59 +0000617 switch (rd) {
Chris Dearman1f5826b2006-05-08 18:02:16 +0100618 case 0: /* CPU number */
619 regs->regs[rt] = smp_processor_id();
620 return 0;
621 case 1: /* SYNCI length */
622 regs->regs[rt] = min(current_cpu_data.dcache.linesz,
623 current_cpu_data.icache.linesz);
624 return 0;
625 case 2: /* Read count register */
626 regs->regs[rt] = read_c0_count();
627 return 0;
628 case 3: /* Count register resolution */
629 switch (current_cpu_data.cputype) {
630 case CPU_20KC:
631 case CPU_25KF:
632 regs->regs[rt] = 1;
633 break;
Ralf Baechle3c370262005-04-13 17:43:59 +0000634 default:
Chris Dearman1f5826b2006-05-08 18:02:16 +0100635 regs->regs[rt] = 2;
636 }
637 return 0;
638 case 29:
639 regs->regs[rt] = ti->tp_value;
640 return 0;
641 default:
642 return -1;
Ralf Baechle3c370262005-04-13 17:43:59 +0000643 }
644 }
645
Daniel Jacobowitz56ebd512005-11-26 22:34:41 -0500646 /* Not ours. */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100647 return -1;
648}
Ralf Baechlee5679882006-11-30 01:14:47 +0000649
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100650static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
651{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800652 if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
653 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200654 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100655 return 0;
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800656 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100657
658 return -1; /* Must be something else ... */
Ralf Baechle3c370262005-04-13 17:43:59 +0000659}
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661asmlinkage void do_ov(struct pt_regs *regs)
662{
663 siginfo_t info;
664
Ralf Baechle36ccf1c2006-02-14 21:04:54 +0000665 die_if_kernel("Integer overflow", regs);
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 info.si_code = FPE_INTOVF;
668 info.si_signo = SIGFPE;
669 info.si_errno = 0;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000670 info.si_addr = (void __user *) regs->cp0_epc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 force_sig_info(SIGFPE, &info, current);
672}
673
David Daney515b0292010-10-21 16:32:26 -0700674static int process_fpemu_return(int sig, void __user *fault_addr)
675{
676 if (sig == SIGSEGV || sig == SIGBUS) {
677 struct siginfo si = {0};
678 si.si_addr = fault_addr;
679 si.si_signo = sig;
680 if (sig == SIGSEGV) {
681 if (find_vma(current->mm, (unsigned long)fault_addr))
682 si.si_code = SEGV_ACCERR;
683 else
684 si.si_code = SEGV_MAPERR;
685 } else {
686 si.si_code = BUS_ADRERR;
687 }
688 force_sig_info(sig, &si, current);
689 return 1;
690 } else if (sig) {
691 force_sig(sig, current);
692 return 1;
693 } else {
694 return 0;
695 }
696}
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698/*
699 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
700 */
701asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
702{
David Daney515b0292010-10-21 16:32:26 -0700703 siginfo_t info = {0};
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100704
David Daney70dc6f02010-08-03 15:44:43 -0700705 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs), SIGFPE)
Jason Wessel88547002008-07-29 15:58:53 -0500706 == NOTIFY_STOP)
707 return;
Chris Dearman57725f92006-06-30 23:35:28 +0100708 die_if_kernel("FP exception in kernel code", regs);
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (fcr31 & FPU_CSR_UNI_X) {
711 int sig;
David Daney515b0292010-10-21 16:32:26 -0700712 void __user *fault_addr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000715 * Unimplemented operation exception. If we've got the full
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 * software emulator on-board, let's use it...
717 *
718 * Force FPU to dump state into task/thread context. We're
719 * moving a lot of data here for what is probably a single
720 * instruction, but the alternative is to pre-decode the FP
721 * register operands before invoking the emulator, which seems
722 * a bit extreme for what should be an infrequent event.
723 */
Ralf Baechlecd21dfc2005-04-28 13:39:10 +0000724 /* Ensure 'resume' not overwrite saved fp context again. */
Atsushi Nemoto53dc8022007-03-10 01:07:45 +0900725 lose_fpu(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 /* Run the emulator */
David Daney515b0292010-10-21 16:32:26 -0700728 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
729 &fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 /*
732 * We can't allow the emulated instruction to leave any of
733 * the cause bit set in $fcr31.
734 */
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900735 current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 /* Restore the hardware register state */
Atsushi Nemoto53dc8022007-03-10 01:07:45 +0900738 own_fpu(1); /* Using the FPU again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 /* If something went wrong, signal */
David Daney515b0292010-10-21 16:32:26 -0700741 process_fpemu_return(sig, fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 return;
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100744 } else if (fcr31 & FPU_CSR_INV_X)
745 info.si_code = FPE_FLTINV;
746 else if (fcr31 & FPU_CSR_DIV_X)
747 info.si_code = FPE_FLTDIV;
748 else if (fcr31 & FPU_CSR_OVF_X)
749 info.si_code = FPE_FLTOVF;
750 else if (fcr31 & FPU_CSR_UDF_X)
751 info.si_code = FPE_FLTUND;
752 else if (fcr31 & FPU_CSR_INE_X)
753 info.si_code = FPE_FLTRES;
754 else
755 info.si_code = __SI_FAULT;
756 info.si_signo = SIGFPE;
757 info.si_errno = 0;
758 info.si_addr = (void __user *) regs->cp0_epc;
759 force_sig_info(SIGFPE, &info, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
Ralf Baechledf270052008-04-20 16:28:54 +0100762static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
763 const char *str)
764{
765 siginfo_t info;
766 char b[40];
767
Jason Wessel5dd11d52010-05-20 21:04:26 -0500768#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
David Daney70dc6f02010-08-03 15:44:43 -0700769 if (kgdb_ll_trap(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Jason Wessel5dd11d52010-05-20 21:04:26 -0500770 return;
771#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
772
David Daney70dc6f02010-08-03 15:44:43 -0700773 if (notify_die(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Jason Wessel88547002008-07-29 15:58:53 -0500774 return;
775
Ralf Baechledf270052008-04-20 16:28:54 +0100776 /*
777 * A short test says that IRIX 5.3 sends SIGTRAP for all trap
778 * insns, even for trap and break codes that indicate arithmetic
779 * failures. Weird ...
780 * But should we continue the brokenness??? --macro
781 */
782 switch (code) {
783 case BRK_OVERFLOW:
784 case BRK_DIVZERO:
785 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
786 die_if_kernel(b, regs);
787 if (code == BRK_DIVZERO)
788 info.si_code = FPE_INTDIV;
789 else
790 info.si_code = FPE_INTOVF;
791 info.si_signo = SIGFPE;
792 info.si_errno = 0;
793 info.si_addr = (void __user *) regs->cp0_epc;
794 force_sig_info(SIGFPE, &info, current);
795 break;
796 case BRK_BUG:
797 die_if_kernel("Kernel bug detected", regs);
798 force_sig(SIGTRAP, current);
799 break;
Ralf Baechleba3049e2008-10-28 17:38:42 +0000800 case BRK_MEMU:
801 /*
802 * Address errors may be deliberately induced by the FPU
803 * emulator to retake control of the CPU after executing the
804 * instruction in the delay slot of an emulated branch.
805 *
806 * Terminate if exception was recognized as a delay slot return
807 * otherwise handle as normal.
808 */
809 if (do_dsemulret(regs))
810 return;
811
812 die_if_kernel("Math emu break/trap", regs);
813 force_sig(SIGTRAP, current);
814 break;
Ralf Baechledf270052008-04-20 16:28:54 +0100815 default:
816 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
817 die_if_kernel(b, regs);
818 force_sig(SIGTRAP, current);
819 }
820}
821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822asmlinkage void do_bp(struct pt_regs *regs)
823{
824 unsigned int opcode, bcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Atsushi Nemotoba755f82007-04-12 20:02:54 +0900826 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
Ralf Baechlee5679882006-11-30 01:14:47 +0000827 goto out_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /*
830 * There is the ancient bug in the MIPS assemblers that the break
831 * code starts left to bit 16 instead to bit 6 in the opcode.
832 * Gas is bug-compatible, but not always, grrr...
833 * We handle both cases with a simple heuristics. --macro
834 */
835 bcode = ((opcode >> 6) & ((1 << 20) - 1));
Ralf Baechledf270052008-04-20 16:28:54 +0100836 if (bcode >= (1 << 10))
837 bcode >>= 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
David Daneyc1bf2072010-08-03 11:22:20 -0700839 /*
840 * notify the kprobe handlers, if instruction is likely to
841 * pertain to them.
842 */
843 switch (bcode) {
844 case BRK_KPROBE_BP:
David Daney70dc6f02010-08-03 15:44:43 -0700845 if (notify_die(DIE_BREAK, "debug", regs, bcode, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
David Daneyc1bf2072010-08-03 11:22:20 -0700846 return;
847 else
848 break;
849 case BRK_KPROBE_SSTEPBP:
David Daney70dc6f02010-08-03 15:44:43 -0700850 if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
David Daneyc1bf2072010-08-03 11:22:20 -0700851 return;
852 else
853 break;
854 default:
855 break;
856 }
857
Ralf Baechledf270052008-04-20 16:28:54 +0100858 do_trap_or_bp(regs, bcode, "Break");
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900859 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000860
861out_sigsegv:
862 force_sig(SIGSEGV, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863}
864
865asmlinkage void do_tr(struct pt_regs *regs)
866{
867 unsigned int opcode, tcode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Atsushi Nemotoba755f82007-04-12 20:02:54 +0900869 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
Ralf Baechlee5679882006-11-30 01:14:47 +0000870 goto out_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 /* Immediate versions don't provide a code. */
873 if (!(opcode & OPCODE))
874 tcode = ((opcode >> 6) & ((1 << 10) - 1));
875
Ralf Baechledf270052008-04-20 16:28:54 +0100876 do_trap_or_bp(regs, tcode, "Trap");
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900877 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000878
879out_sigsegv:
880 force_sig(SIGSEGV, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
883asmlinkage void do_ri(struct pt_regs *regs)
884{
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100885 unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
886 unsigned long old_epc = regs->cp0_epc;
887 unsigned int opcode = 0;
888 int status = -1;
889
David Daney70dc6f02010-08-03 15:44:43 -0700890 if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs), SIGILL)
Jason Wessel88547002008-07-29 15:58:53 -0500891 == NOTIFY_STOP)
892 return;
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 die_if_kernel("Reserved instruction in kernel code", regs);
895
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100896 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechle3c370262005-04-13 17:43:59 +0000897 return;
898
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100899 if (unlikely(get_user(opcode, epc) < 0))
900 status = SIGSEGV;
901
902 if (!cpu_has_llsc && status < 0)
903 status = simulate_llsc(regs, opcode);
904
905 if (status < 0)
906 status = simulate_rdhwr(regs, opcode);
907
908 if (status < 0)
909 status = simulate_sync(regs, opcode);
910
911 if (status < 0)
912 status = SIGILL;
913
914 if (unlikely(status > 0)) {
915 regs->cp0_epc = old_epc; /* Undo skip-over. */
916 force_sig(status, current);
917 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Ralf Baechled223a862007-07-10 17:33:02 +0100920/*
921 * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
922 * emulated more than some threshold number of instructions, force migration to
923 * a "CPU" that has FP support.
924 */
925static void mt_ase_fp_affinity(void)
926{
927#ifdef CONFIG_MIPS_MT_FPAFF
928 if (mt_fpemul_threshold > 0 &&
929 ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
930 /*
931 * If there's no FPU present, or if the application has already
932 * restricted the allowed set to exclude any CPUs with FPUs,
933 * we'll skip the procedure.
934 */
935 if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
936 cpumask_t tmask;
937
Kevin D. Kissell9cc12362008-09-09 21:33:36 +0200938 current->thread.user_cpus_allowed
939 = current->cpus_allowed;
940 cpus_and(tmask, current->cpus_allowed,
941 mt_fpu_cpumask);
Julia Lawalled1bbde2010-03-26 23:03:07 +0100942 set_cpus_allowed_ptr(current, &tmask);
Ralf Baechle293c5bd2007-07-25 16:19:33 +0100943 set_thread_flag(TIF_FPUBOUND);
Ralf Baechled223a862007-07-10 17:33:02 +0100944 }
945 }
946#endif /* CONFIG_MIPS_MT_FPAFF */
947}
948
Ralf Baechle69f3a7d2009-11-24 01:24:58 +0000949/*
950 * No lock; only written during early bootup by CPU 0.
951 */
952static RAW_NOTIFIER_HEAD(cu2_chain);
953
954int __ref register_cu2_notifier(struct notifier_block *nb)
955{
956 return raw_notifier_chain_register(&cu2_chain, nb);
957}
958
959int cu2_notifier_call_chain(unsigned long val, void *v)
960{
961 return raw_notifier_call_chain(&cu2_chain, val, v);
962}
963
964static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
965 void *data)
966{
967 struct pt_regs *regs = data;
968
969 switch (action) {
970 default:
971 die_if_kernel("Unhandled kernel unaligned access or invalid "
972 "instruction", regs);
973 /* Fall through */
974
975 case CU2_EXCEPTION:
976 force_sig(SIGILL, current);
977 }
978
979 return NOTIFY_OK;
980}
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982asmlinkage void do_cpu(struct pt_regs *regs)
983{
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100984 unsigned int __user *epc;
985 unsigned long old_epc;
986 unsigned int opcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 unsigned int cpid;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100988 int status;
David Daneyf9bb4cf2008-12-11 15:33:23 -0800989 unsigned long __maybe_unused flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Atsushi Nemoto53231802007-04-14 02:37:26 +0900991 die_if_kernel("do_cpu invoked from kernel context!", regs);
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
994
995 switch (cpid) {
996 case 0:
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100997 epc = (unsigned int __user *)exception_epc(regs);
998 old_epc = regs->cp0_epc;
999 opcode = 0;
1000 status = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001002 if (unlikely(compute_return_epc(regs) < 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return;
Ralf Baechle3c370262005-04-13 17:43:59 +00001004
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001005 if (unlikely(get_user(opcode, epc) < 0))
1006 status = SIGSEGV;
1007
1008 if (!cpu_has_llsc && status < 0)
1009 status = simulate_llsc(regs, opcode);
1010
1011 if (status < 0)
1012 status = simulate_rdhwr(regs, opcode);
1013
1014 if (status < 0)
1015 status = SIGILL;
1016
1017 if (unlikely(status > 0)) {
1018 regs->cp0_epc = old_epc; /* Undo skip-over. */
1019 force_sig(status, current);
1020 }
1021
1022 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 case 1:
Atsushi Nemoto53dc8022007-03-10 01:07:45 +09001025 if (used_math()) /* Using the FPU again. */
1026 own_fpu(1);
1027 else { /* First time FPU user. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 init_fpu();
1029 set_used_math();
1030 }
1031
Atsushi Nemoto53231802007-04-14 02:37:26 +09001032 if (!raw_cpu_has_fpu) {
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001033 int sig;
David Daney515b0292010-10-21 16:32:26 -07001034 void __user *fault_addr = NULL;
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001035 sig = fpu_emulator_cop1Handler(regs,
David Daney515b0292010-10-21 16:32:26 -07001036 &current->thread.fpu,
1037 0, &fault_addr);
1038 if (!process_fpemu_return(sig, fault_addr))
Ralf Baechled223a862007-07-10 17:33:02 +01001039 mt_ase_fp_affinity();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return;
1043
1044 case 2:
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001045 raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
Jesper Nilsson55dc9d52010-06-17 15:25:54 +02001046 return;
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 case 3:
1049 break;
1050 }
1051
1052 force_sig(SIGILL, current);
1053}
1054
1055asmlinkage void do_mdmx(struct pt_regs *regs)
1056{
1057 force_sig(SIGILL, current);
1058}
1059
David Daney8bc6d052009-01-05 15:29:58 -08001060/*
1061 * Called with interrupts disabled.
1062 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063asmlinkage void do_watch(struct pt_regs *regs)
1064{
David Daneyb67b2b72008-09-23 00:08:45 -07001065 u32 cause;
1066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 /*
David Daneyb67b2b72008-09-23 00:08:45 -07001068 * Clear WP (bit 22) bit of cause register so we don't loop
1069 * forever.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 */
David Daneyb67b2b72008-09-23 00:08:45 -07001071 cause = read_c0_cause();
1072 cause &= ~(1 << 22);
1073 write_c0_cause(cause);
1074
1075 /*
1076 * If the current thread has the watch registers loaded, save
1077 * their values and send SIGTRAP. Otherwise another thread
1078 * left the registers set, clear them and continue.
1079 */
1080 if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
1081 mips_read_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001082 local_irq_enable();
David Daneyb67b2b72008-09-23 00:08:45 -07001083 force_sig(SIGTRAP, current);
David Daney8bc6d052009-01-05 15:29:58 -08001084 } else {
David Daneyb67b2b72008-09-23 00:08:45 -07001085 mips_clear_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001086 local_irq_enable();
1087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
1090asmlinkage void do_mcheck(struct pt_regs *regs)
1091{
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001092 const int field = 2 * sizeof(unsigned long);
1093 int multi_match = regs->cp0_status & ST0_TS;
1094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 show_regs(regs);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001096
1097 if (multi_match) {
1098 printk("Index : %0x\n", read_c0_index());
1099 printk("Pagemask: %0x\n", read_c0_pagemask());
1100 printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
1101 printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
1102 printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
1103 printk("\n");
1104 dump_tlb_all();
1105 }
1106
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +09001107 show_code((unsigned int __user *) regs->cp0_epc);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 /*
1110 * Some chips may have other causes of machine check (e.g. SB1
1111 * graduation timer)
1112 */
1113 panic("Caught Machine Check exception - %scaused by multiple "
1114 "matching entries in the TLB.",
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001115 (multi_match) ? "" : "not ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001118asmlinkage void do_mt(struct pt_regs *regs)
1119{
Ralf Baechle41c594a2006-04-05 09:45:45 +01001120 int subcode;
1121
Ralf Baechle41c594a2006-04-05 09:45:45 +01001122 subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
1123 >> VPECONTROL_EXCPT_SHIFT;
1124 switch (subcode) {
1125 case 0:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001126 printk(KERN_DEBUG "Thread Underflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001127 break;
1128 case 1:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001129 printk(KERN_DEBUG "Thread Overflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001130 break;
1131 case 2:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001132 printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001133 break;
1134 case 3:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001135 printk(KERN_DEBUG "Gating Storage Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001136 break;
1137 case 4:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001138 printk(KERN_DEBUG "YIELD Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001139 break;
1140 case 5:
Masanari Iidaf232c7e2012-02-08 21:53:14 +09001141 printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001142 break;
1143 default:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001144 printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
Ralf Baechle41c594a2006-04-05 09:45:45 +01001145 subcode);
1146 break;
1147 }
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001148 die_if_kernel("MIPS MT Thread exception in kernel", regs);
1149
1150 force_sig(SIGILL, current);
1151}
1152
1153
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001154asmlinkage void do_dsp(struct pt_regs *regs)
1155{
1156 if (cpu_has_dsp)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001157 panic("Unexpected DSP exception");
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001158
1159 force_sig(SIGILL, current);
1160}
1161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162asmlinkage void do_reserved(struct pt_regs *regs)
1163{
1164 /*
1165 * Game over - no way to handle this if it ever occurs. Most probably
1166 * caused by a new unknown cpu type or after another deadly
1167 * hard/software error.
1168 */
1169 show_regs(regs);
1170 panic("Caught reserved exception %ld - should not happen.",
1171 (regs->cp0_cause & 0x7f) >> 2);
1172}
1173
Ralf Baechle39b8d522008-04-28 17:14:26 +01001174static int __initdata l1parity = 1;
1175static int __init nol1parity(char *s)
1176{
1177 l1parity = 0;
1178 return 1;
1179}
1180__setup("nol1par", nol1parity);
1181static int __initdata l2parity = 1;
1182static int __init nol2parity(char *s)
1183{
1184 l2parity = 0;
1185 return 1;
1186}
1187__setup("nol2par", nol2parity);
1188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189/*
1190 * Some MIPS CPUs can enable/disable for cache parity detection, but do
1191 * it different ways.
1192 */
1193static inline void parity_protection_init(void)
1194{
Ralf Baechle10cc3522007-10-11 23:46:15 +01001195 switch (current_cpu_type()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 case CPU_24K:
Nigel Stephens98a41de2006-04-27 15:50:32 +01001197 case CPU_34K:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001198 case CPU_74K:
1199 case CPU_1004K:
1200 {
1201#define ERRCTL_PE 0x80000000
1202#define ERRCTL_L2P 0x00800000
1203 unsigned long errctl;
1204 unsigned int l1parity_present, l2parity_present;
1205
1206 errctl = read_c0_ecc();
1207 errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
1208
1209 /* probe L1 parity support */
1210 write_c0_ecc(errctl | ERRCTL_PE);
1211 back_to_back_c0_hazard();
1212 l1parity_present = (read_c0_ecc() & ERRCTL_PE);
1213
1214 /* probe L2 parity support */
1215 write_c0_ecc(errctl|ERRCTL_L2P);
1216 back_to_back_c0_hazard();
1217 l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
1218
1219 if (l1parity_present && l2parity_present) {
1220 if (l1parity)
1221 errctl |= ERRCTL_PE;
1222 if (l1parity ^ l2parity)
1223 errctl |= ERRCTL_L2P;
1224 } else if (l1parity_present) {
1225 if (l1parity)
1226 errctl |= ERRCTL_PE;
1227 } else if (l2parity_present) {
1228 if (l2parity)
1229 errctl |= ERRCTL_L2P;
1230 } else {
1231 /* No parity available */
1232 }
1233
1234 printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
1235
1236 write_c0_ecc(errctl);
1237 back_to_back_c0_hazard();
1238 errctl = read_c0_ecc();
1239 printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
1240
1241 if (l1parity_present)
1242 printk(KERN_INFO "Cache parity protection %sabled\n",
1243 (errctl & ERRCTL_PE) ? "en" : "dis");
1244
1245 if (l2parity_present) {
1246 if (l1parity_present && l1parity)
1247 errctl ^= ERRCTL_L2P;
1248 printk(KERN_INFO "L2 cache parity protection %sabled\n",
1249 (errctl & ERRCTL_L2P) ? "en" : "dis");
1250 }
1251 }
1252 break;
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 case CPU_5KC:
Leonid Yegoshin78d48032012-07-06 21:56:01 +02001255 case CPU_5KE:
Ralf Baechle14f18b72005-03-01 18:15:08 +00001256 write_c0_ecc(0x80000000);
1257 back_to_back_c0_hazard();
1258 /* Set the PE bit (bit 31) in the c0_errctl register. */
1259 printk(KERN_INFO "Cache parity protection %sabled\n",
1260 (read_c0_ecc() & 0x80000000) ? "en" : "dis");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 break;
1262 case CPU_20KC:
1263 case CPU_25KF:
1264 /* Clear the DE bit (bit 16) in the c0_status register. */
1265 printk(KERN_INFO "Enable cache parity protection for "
1266 "MIPS 20KC/25KF CPUs.\n");
1267 clear_c0_status(ST0_DE);
1268 break;
1269 default:
1270 break;
1271 }
1272}
1273
1274asmlinkage void cache_parity_error(void)
1275{
1276 const int field = 2 * sizeof(unsigned long);
1277 unsigned int reg_val;
1278
1279 /* For the moment, report the problem and hang. */
1280 printk("Cache error exception:\n");
1281 printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1282 reg_val = read_c0_cacheerr();
1283 printk("c0_cacheerr == %08x\n", reg_val);
1284
1285 printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1286 reg_val & (1<<30) ? "secondary" : "primary",
1287 reg_val & (1<<31) ? "data" : "insn");
1288 printk("Error bits: %s%s%s%s%s%s%s\n",
1289 reg_val & (1<<29) ? "ED " : "",
1290 reg_val & (1<<28) ? "ET " : "",
1291 reg_val & (1<<26) ? "EE " : "",
1292 reg_val & (1<<25) ? "EB " : "",
1293 reg_val & (1<<24) ? "EI " : "",
1294 reg_val & (1<<23) ? "E1 " : "",
1295 reg_val & (1<<22) ? "E0 " : "");
1296 printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1297
Ralf Baechleec917c2c2005-10-07 16:58:15 +01001298#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (reg_val & (1<<22))
1300 printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
1301
1302 if (reg_val & (1<<23))
1303 printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
1304#endif
1305
1306 panic("Can't handle the cache error!");
1307}
1308
1309/*
1310 * SDBBP EJTAG debug exception handler.
1311 * We skip the instruction and return to the next instruction.
1312 */
1313void ejtag_exception_handler(struct pt_regs *regs)
1314{
1315 const int field = 2 * sizeof(unsigned long);
1316 unsigned long depc, old_epc;
1317 unsigned int debug;
1318
Chris Dearman70ae6122006-06-30 12:32:37 +01001319 printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 depc = read_c0_depc();
1321 debug = read_c0_debug();
Chris Dearman70ae6122006-06-30 12:32:37 +01001322 printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 if (debug & 0x80000000) {
1324 /*
1325 * In branch delay slot.
1326 * We cheat a little bit here and use EPC to calculate the
1327 * debug return address (DEPC). EPC is restored after the
1328 * calculation.
1329 */
1330 old_epc = regs->cp0_epc;
1331 regs->cp0_epc = depc;
1332 __compute_return_epc(regs);
1333 depc = regs->cp0_epc;
1334 regs->cp0_epc = old_epc;
1335 } else
1336 depc += 4;
1337 write_c0_depc(depc);
1338
1339#if 0
Chris Dearman70ae6122006-06-30 12:32:37 +01001340 printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 write_c0_debug(debug | 0x100);
1342#endif
1343}
1344
1345/*
1346 * NMI exception handler.
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001347 * No lock; only written during early bootup by CPU 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 */
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001349static RAW_NOTIFIER_HEAD(nmi_chain);
1350
1351int register_nmi_notifier(struct notifier_block *nb)
1352{
1353 return raw_notifier_chain_register(&nmi_chain, nb);
1354}
1355
Joe Perchesff2d8b12012-01-12 17:17:21 -08001356void __noreturn nmi_exception_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357{
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001358 raw_notifier_call_chain(&nmi_chain, 0, regs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001359 bust_spinlocks(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 printk("NMI taken!!!!\n");
1361 die("NMI", regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
Ralf Baechlee01402b2005-07-14 15:57:16 +00001364#define VECTORSPACING 0x100 /* for EI/VI mode */
1365
1366unsigned long ebase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367unsigned long exception_handlers[32];
Ralf Baechlee01402b2005-07-14 15:57:16 +00001368unsigned long vi_handlers[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Florian Fainelli2d1b6e92010-01-28 15:21:42 +01001370void __init *set_except_vector(int n, void *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
1372 unsigned long handler = (unsigned long) addr;
1373 unsigned long old_handler = exception_handlers[n];
1374
1375 exception_handlers[n] = handler;
1376 if (n == 0 && cpu_has_divec) {
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001377 unsigned long jump_mask = ~((1 << 28) - 1);
1378 u32 *buf = (u32 *)(ebase + 0x200);
1379 unsigned int k0 = 26;
1380 if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
1381 uasm_i_j(&buf, handler & ~jump_mask);
1382 uasm_i_nop(&buf);
1383 } else {
1384 UASM_i_LA(&buf, k0, handler);
1385 uasm_i_jr(&buf, k0);
1386 uasm_i_nop(&buf);
1387 }
1388 local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 }
1390 return (void *)old_handler;
1391}
1392
Atsushi Nemoto6ba07e52007-05-21 23:45:38 +09001393static asmlinkage void do_default_vi(void)
1394{
1395 show_regs(get_irq_regs());
1396 panic("Caught unexpected vectored interrupt.");
1397}
1398
Ralf Baechleef300e42007-05-06 18:31:18 +01001399static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001400{
1401 unsigned long handler;
1402 unsigned long old_handler = vi_handlers[n];
Ralf Baechlef6771db2007-11-08 18:02:29 +00001403 int srssets = current_cpu_data.srsets;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001404 u32 *w;
1405 unsigned char *b;
1406
Ralf Baechleb72b7092009-03-30 14:49:44 +02001407 BUG_ON(!cpu_has_veic && !cpu_has_vint);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001408
1409 if (addr == NULL) {
1410 handler = (unsigned long) do_default_vi;
1411 srs = 0;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001412 } else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001413 handler = (unsigned long) addr;
1414 vi_handlers[n] = (unsigned long) addr;
1415
1416 b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
1417
Ralf Baechlef6771db2007-11-08 18:02:29 +00001418 if (srs >= srssets)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001419 panic("Shadow register set %d not supported", srs);
1420
1421 if (cpu_has_veic) {
1422 if (board_bind_eic_interrupt)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001423 board_bind_eic_interrupt(n, srs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001424 } else if (cpu_has_vint) {
Ralf Baechlee01402b2005-07-14 15:57:16 +00001425 /* SRSMap is only defined if shadow sets are implemented */
Ralf Baechlef6771db2007-11-08 18:02:29 +00001426 if (srssets > 1)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001427 change_c0_srsmap(0xf << n*4, srs << n*4);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001428 }
1429
1430 if (srs == 0) {
1431 /*
1432 * If no shadow set is selected then use the default handler
1433 * that does normal register saving and a standard interrupt exit
1434 */
1435
1436 extern char except_vec_vi, except_vec_vi_lui;
1437 extern char except_vec_vi_ori, except_vec_vi_end;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001438 extern char rollback_except_vec_vi;
1439 char *vec_start = (cpu_wait == r4k_wait) ?
1440 &rollback_except_vec_vi : &except_vec_vi;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001441#ifdef CONFIG_MIPS_MT_SMTC
1442 /*
1443 * We need to provide the SMTC vectored interrupt handler
1444 * not only with the address of the handler, but with the
1445 * Status.IM bit to be masked before going there.
1446 */
1447 extern char except_vec_vi_mori;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001448 const int mori_offset = &except_vec_vi_mori - vec_start;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001449#endif /* CONFIG_MIPS_MT_SMTC */
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001450 const int handler_len = &except_vec_vi_end - vec_start;
1451 const int lui_offset = &except_vec_vi_lui - vec_start;
1452 const int ori_offset = &except_vec_vi_ori - vec_start;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001453
1454 if (handler_len > VECTORSPACING) {
1455 /*
1456 * Sigh... panicing won't help as the console
1457 * is probably not configured :(
1458 */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001459 panic("VECTORSPACING too small");
Ralf Baechlee01402b2005-07-14 15:57:16 +00001460 }
1461
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001462 memcpy(b, vec_start, handler_len);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001463#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle8e8a52e2007-05-31 14:00:19 +01001464 BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
1465
Ralf Baechle41c594a2006-04-05 09:45:45 +01001466 w = (u32 *)(b + mori_offset);
1467 *w = (*w & 0xffff0000) | (0x100 << n);
1468#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001469 w = (u32 *)(b + lui_offset);
1470 *w = (*w & 0xffff0000) | (((u32)handler >> 16) & 0xffff);
1471 w = (u32 *)(b + ori_offset);
1472 *w = (*w & 0xffff0000) | ((u32)handler & 0xffff);
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001473 local_flush_icache_range((unsigned long)b,
1474 (unsigned long)(b+handler_len));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001475 }
1476 else {
1477 /*
1478 * In other cases jump directly to the interrupt handler
1479 *
1480 * It is the handlers responsibility to save registers if required
1481 * (eg hi/lo) and return from the exception using "eret"
1482 */
1483 w = (u32 *)b;
1484 *w++ = 0x08000000 | (((u32)handler >> 2) & 0x03fffff); /* j handler */
1485 *w = 0;
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001486 local_flush_icache_range((unsigned long)b,
1487 (unsigned long)(b+8));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001488 }
1489
1490 return (void *)old_handler;
1491}
1492
Ralf Baechleef300e42007-05-06 18:31:18 +01001493void *set_vi_handler(int n, vi_handler_t addr)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001494{
Ralf Baechleff3eab22006-03-29 14:12:58 +01001495 return set_vi_srs_handler(n, addr, 0);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001496}
Ralf Baechlef41ae0b2006-06-05 17:24:46 +01001497
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498extern void tlb_init(void);
Ralf Baechle1d40cfc2005-07-15 15:23:23 +00001499extern void flush_tlb_handlers(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Ralf Baechle42f77542007-10-18 17:48:11 +01001501/*
1502 * Timer interrupt
1503 */
1504int cp0_compare_irq;
David VomLehn010c1082009-12-21 17:49:22 -08001505int cp0_compare_irq_shift;
Ralf Baechle42f77542007-10-18 17:48:11 +01001506
1507/*
1508 * Performance counter IRQ or -1 if shared with timer
1509 */
1510int cp0_perfcount_irq;
1511EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
1512
Chris Dearmanbdc94eb2007-10-03 10:43:56 +01001513static int __cpuinitdata noulri;
1514
1515static int __init ulri_disable(char *s)
1516{
1517 pr_info("Disabling ulri\n");
1518 noulri = 1;
1519
1520 return 1;
1521}
1522__setup("noulri", ulri_disable);
1523
David Daney6650df32012-05-15 00:04:50 -07001524void __cpuinit per_cpu_trap_init(bool is_boot_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
1526 unsigned int cpu = smp_processor_id();
1527 unsigned int status_set = ST0_CU0;
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001528 unsigned int hwrena = cpu_hwrena_impl_bits;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001529#ifdef CONFIG_MIPS_MT_SMTC
1530 int secondaryTC = 0;
1531 int bootTC = (cpu == 0);
1532
1533 /*
1534 * Only do per_cpu_trap_init() for first TC of Each VPE.
1535 * Note that this hack assumes that the SMTC init code
1536 * assigns TCs consecutively and in ascending order.
1537 */
1538
1539 if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
1540 ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
1541 secondaryTC = 1;
1542#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 /*
1545 * Disable coprocessors and select 32-bit or 64-bit addressing
1546 * and the 16/32 or 32/32 FPR register model. Reset the BEV
1547 * flag that some firmware may have left set and the TS bit (for
1548 * IP27). Set XX for ISA IV code to work.
1549 */
Ralf Baechle875d43e2005-09-03 15:56:16 -07001550#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
1552#endif
1553 if (current_cpu_data.isa_level == MIPS_CPU_ISA_IV)
1554 status_set |= ST0_XX;
Chris Dearmanbbaf2382007-12-13 22:42:19 +00001555 if (cpu_has_dsp)
1556 status_set |= ST0_MX;
1557
Ralf Baechleb38c7392006-02-07 01:20:43 +00001558 change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 status_set);
1560
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001561 if (cpu_has_mips_r2)
1562 hwrena |= 0x0000000f;
Ralf Baechlea3692022007-07-10 17:33:02 +01001563
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001564 if (!noulri && cpu_has_userlocal)
1565 hwrena |= (1 << 29);
Ralf Baechlea3692022007-07-10 17:33:02 +01001566
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001567 if (hwrena)
1568 write_c0_hwrena(hwrena);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001569
Ralf Baechle41c594a2006-04-05 09:45:45 +01001570#ifdef CONFIG_MIPS_MT_SMTC
1571 if (!secondaryTC) {
1572#endif /* CONFIG_MIPS_MT_SMTC */
1573
Ralf Baechlee01402b2005-07-14 15:57:16 +00001574 if (cpu_has_veic || cpu_has_vint) {
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001575 unsigned long sr = set_c0_status(ST0_BEV);
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001576 write_c0_ebase(ebase);
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001577 write_c0_status(sr);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001578 /* Setting vector spacing enables EI/VI mode */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001579 change_c0_intctl(0x3e0, VECTORSPACING);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001580 }
Ralf Baechled03d0a52005-08-17 13:44:26 +00001581 if (cpu_has_divec) {
1582 if (cpu_has_mipsmt) {
1583 unsigned int vpflags = dvpe();
1584 set_c0_cause(CAUSEF_IV);
1585 evpe(vpflags);
1586 } else
1587 set_c0_cause(CAUSEF_IV);
1588 }
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001589
1590 /*
1591 * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
1592 *
1593 * o read IntCtl.IPTI to determine the timer interrupt
1594 * o read IntCtl.IPPCI to determine the performance counter interrupt
1595 */
1596 if (cpu_has_mips_r2) {
David VomLehn010c1082009-12-21 17:49:22 -08001597 cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
1598 cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
1599 cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001600 if (cp0_perfcount_irq == cp0_compare_irq)
1601 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001602 } else {
1603 cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
Ralf Baechlec6a4ebb2012-07-06 23:56:00 +02001604 cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001605 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001606 }
1607
Ralf Baechle41c594a2006-04-05 09:45:45 +01001608#ifdef CONFIG_MIPS_MT_SMTC
1609 }
1610#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Maksim Rayskiy5c200192011-11-10 17:59:45 +00001612 if (!cpu_data[cpu].asid_cache)
1613 cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615 atomic_inc(&init_mm.mm_count);
1616 current->active_mm = &init_mm;
1617 BUG_ON(current->mm);
1618 enter_lazy_tlb(&init_mm, current);
1619
Ralf Baechle41c594a2006-04-05 09:45:45 +01001620#ifdef CONFIG_MIPS_MT_SMTC
1621 if (bootTC) {
1622#endif /* CONFIG_MIPS_MT_SMTC */
David Daney6650df32012-05-15 00:04:50 -07001623 /* Boot CPU's cache setup in setup_arch(). */
1624 if (!is_boot_cpu)
1625 cpu_cache_init();
Ralf Baechle41c594a2006-04-05 09:45:45 +01001626 tlb_init();
1627#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle6a058882007-05-31 14:03:45 +01001628 } else if (!secondaryTC) {
1629 /*
1630 * First TC in non-boot VPE must do subset of tlb_init()
1631 * for MMU countrol registers.
1632 */
1633 write_c0_pagemask(PM_DEFAULT_MASK);
1634 write_c0_wired(0);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001635 }
1636#endif /* CONFIG_MIPS_MT_SMTC */
David Daney3d8bfdd2010-12-21 14:19:11 -08001637 TLBMISS_HANDLER_SETUP();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Ralf Baechlee01402b2005-07-14 15:57:16 +00001640/* Install CPU exception handler */
David Daneye3dc81f22012-05-15 00:04:47 -07001641void __cpuinit set_handler(unsigned long offset, void *addr, unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001642{
1643 memcpy((void *)(ebase + offset), addr, size);
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001644 local_flush_icache_range(ebase + offset, ebase + offset + size);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001645}
1646
Ralf Baechle234fcd12008-03-08 09:56:28 +00001647static char panic_null_cerr[] __cpuinitdata =
Ralf Baechle641e97f2007-10-11 23:46:05 +01001648 "Trying to set NULL cache error exception handler";
1649
Ralf Baechle42fe7ee2009-01-28 18:48:23 +00001650/*
1651 * Install uncached CPU exception handler.
1652 * This is suitable only for the cache error exception which is the only
1653 * exception handler that is being run uncached.
1654 */
Ralf Baechle234fcd12008-03-08 09:56:28 +00001655void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
1656 unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001657{
Sebastian Andrzej Siewior4f81b012010-04-27 22:53:30 +02001658 unsigned long uncached_ebase = CKSEG1ADDR(ebase);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001659
Ralf Baechle641e97f2007-10-11 23:46:05 +01001660 if (!addr)
1661 panic(panic_null_cerr);
1662
Ralf Baechlee01402b2005-07-14 15:57:16 +00001663 memcpy((void *)(uncached_ebase + offset), addr, size);
1664}
1665
Atsushi Nemoto5b104962006-09-11 17:50:29 +09001666static int __initdata rdhwr_noopt;
1667static int __init set_rdhwr_noopt(char *str)
1668{
1669 rdhwr_noopt = 1;
1670 return 1;
1671}
1672
1673__setup("rdhwr_noopt", set_rdhwr_noopt);
1674
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675void __init trap_init(void)
1676{
1677 extern char except_vec3_generic, except_vec3_r4000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 extern char except_vec4;
1679 unsigned long i;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001680 int rollback;
1681
1682 check_wait();
1683 rollback = (cpu_wait == r4k_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Jason Wessel88547002008-07-29 15:58:53 -05001685#if defined(CONFIG_KGDB)
1686 if (kgdb_early_setup)
1687 return; /* Already done */
1688#endif
1689
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001690 if (cpu_has_veic || cpu_has_vint) {
1691 unsigned long size = 0x200 + VECTORSPACING*64;
1692 ebase = (unsigned long)
1693 __alloc_bootmem(size, 1 << fls(size), 0);
1694 } else {
David Daneyf6be75d2010-04-06 13:29:50 -07001695 ebase = CKSEG0;
David Daney566f74f2008-10-23 17:56:35 -07001696 if (cpu_has_mips_r2)
1697 ebase += (read_c0_ebase() & 0x3ffff000);
1698 }
Ralf Baechlee01402b2005-07-14 15:57:16 +00001699
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +00001700 if (board_ebase_setup)
1701 board_ebase_setup();
David Daney6650df32012-05-15 00:04:50 -07001702 per_cpu_trap_init(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 /*
1705 * Copy the generic exception handlers to their final destination.
1706 * This will be overriden later as suitable for a particular
1707 * configuration.
1708 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001709 set_handler(0x180, &except_vec3_generic, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711 /*
1712 * Setup default vectors
1713 */
1714 for (i = 0; i <= 31; i++)
1715 set_except_vector(i, handle_reserved);
1716
1717 /*
1718 * Copy the EJTAG debug exception vector handler code to it's final
1719 * destination.
1720 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001721 if (cpu_has_ejtag && board_ejtag_handler_setup)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001722 board_ejtag_handler_setup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 /*
1725 * Only some CPUs have the watch exceptions.
1726 */
1727 if (cpu_has_watch)
1728 set_except_vector(23, handle_watch);
1729
1730 /*
Ralf Baechlee01402b2005-07-14 15:57:16 +00001731 * Initialise interrupt handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001733 if (cpu_has_veic || cpu_has_vint) {
1734 int nvec = cpu_has_veic ? 64 : 8;
1735 for (i = 0; i < nvec; i++)
Ralf Baechleff3eab22006-03-29 14:12:58 +01001736 set_vi_handler(i, NULL);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001737 }
1738 else if (cpu_has_divec)
1739 set_handler(0x200, &except_vec4, 0x8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 /*
1742 * Some CPUs can enable/disable for cache parity detection, but does
1743 * it different ways.
1744 */
1745 parity_protection_init();
1746
1747 /*
1748 * The Data Bus Errors / Instruction Bus Errors are signaled
1749 * by external hardware. Therefore these two exceptions
1750 * may have board specific handlers.
1751 */
1752 if (board_be_init)
1753 board_be_init();
1754
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001755 set_except_vector(0, rollback ? rollback_handle_int : handle_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 set_except_vector(1, handle_tlbm);
1757 set_except_vector(2, handle_tlbl);
1758 set_except_vector(3, handle_tlbs);
1759
1760 set_except_vector(4, handle_adel);
1761 set_except_vector(5, handle_ades);
1762
1763 set_except_vector(6, handle_ibe);
1764 set_except_vector(7, handle_dbe);
1765
1766 set_except_vector(8, handle_sys);
1767 set_except_vector(9, handle_bp);
Atsushi Nemoto5b104962006-09-11 17:50:29 +09001768 set_except_vector(10, rdhwr_noopt ? handle_ri :
1769 (cpu_has_vtag_icache ?
1770 handle_ri_rdhwr_vivt : handle_ri_rdhwr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 set_except_vector(11, handle_cpu);
1772 set_except_vector(12, handle_ov);
1773 set_except_vector(13, handle_tr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Ralf Baechle10cc3522007-10-11 23:46:15 +01001775 if (current_cpu_type() == CPU_R6000 ||
1776 current_cpu_type() == CPU_R6000A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 /*
1778 * The R6000 is the only R-series CPU that features a machine
1779 * check exception (similar to the R4000 cache error) and
1780 * unaligned ldc1/sdc1 exception. The handlers have not been
1781 * written yet. Well, anyway there is no R6000 machine on the
1782 * current list of targets for Linux/MIPS.
1783 * (Duh, crap, there is someone with a triple R6k machine)
1784 */
1785 //set_except_vector(14, handle_mc);
1786 //set_except_vector(15, handle_ndc);
1787 }
1788
Ralf Baechlee01402b2005-07-14 15:57:16 +00001789
1790 if (board_nmi_handler_setup)
1791 board_nmi_handler_setup();
1792
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001793 if (cpu_has_fpu && !cpu_has_nofpuex)
1794 set_except_vector(15, handle_fpe);
1795
1796 set_except_vector(22, handle_mdmx);
1797
1798 if (cpu_has_mcheck)
1799 set_except_vector(24, handle_mcheck);
1800
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001801 if (cpu_has_mipsmt)
1802 set_except_vector(25, handle_mt);
1803
Chris Dearmanacaec422007-05-24 22:30:18 +01001804 set_except_vector(26, handle_dsp);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001805
David Daneyfcbf1df2012-05-15 00:04:46 -07001806 if (board_cache_error_setup)
1807 board_cache_error_setup();
1808
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001809 if (cpu_has_vce)
1810 /* Special exception: R4[04]00 uses also the divec space. */
David Daney566f74f2008-10-23 17:56:35 -07001811 memcpy((void *)(ebase + 0x180), &except_vec3_r4000, 0x100);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001812 else if (cpu_has_4kex)
David Daney566f74f2008-10-23 17:56:35 -07001813 memcpy((void *)(ebase + 0x180), &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001814 else
David Daney566f74f2008-10-23 17:56:35 -07001815 memcpy((void *)(ebase + 0x080), &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001816
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001817 local_flush_icache_range(ebase, ebase + 0x400);
Ralf Baechle1d40cfc2005-07-15 15:23:23 +00001818 flush_tlb_handlers();
Thomas Bogendoerfer05106172008-08-04 19:44:34 +02001819
1820 sort_extable(__start___dbe_table, __stop___dbe_table);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001821
Ralf Baechle4483b152010-08-05 13:25:59 +01001822 cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823}