blob: b0c7f80e05e51cee6d83387875ff98357ffd0307 [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
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +010011 * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
Steven J. Hill2a0b24f2013-03-25 12:15:55 -050012 * Copyright (C) 2000, 2001, 2012 MIPS Technologies, Inc. All rights reserved.
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>
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +020016#include <linux/context_tracking.h>
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +020017#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/init.h>
Nathan Lynch8742cd22011-09-30 13:49:35 -050019#include <linux/kernel.h>
Paul Gortmakerf9ded562012-02-28 19:24:46 -050020#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/sched.h>
23#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/spinlock.h>
25#include <linux/kallsyms.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000026#include <linux/bootmem.h>
Maxime Bizond4fd1982006-07-20 18:52:02 +020027#include <linux/interrupt.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010028#include <linux/ptrace.h>
Jason Wessel88547002008-07-29 15:58:53 -050029#include <linux/kgdb.h>
30#include <linux/kdebug.h>
David Daneyc1bf2072010-08-03 11:22:20 -070031#include <linux/kprobes.h>
Ralf Baechle69f3a7d2009-11-24 01:24:58 +000032#include <linux/notifier.h>
Jason Wessel5dd11d52010-05-20 21:04:26 -050033#include <linux/kdb.h>
David Howellsca4d3e672010-10-07 14:08:54 +010034#include <linux/irq.h>
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +080035#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/bootinfo.h>
38#include <asm/branch.h>
39#include <asm/break.h>
Ralf Baechle69f3a7d2009-11-24 01:24:58 +000040#include <asm/cop2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/cpu.h>
Ralf Baechle69f24d12013-09-17 10:25:47 +020042#include <asm/cpu-type.h>
Ralf Baechlee50c0a82005-05-31 11:49:19 +000043#include <asm/dsp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/fpu.h>
Ralf Baechleba3049e2008-10-28 17:38:42 +000045#include <asm/fpu_emulator.h>
Ralf Baechlebdc92d742013-05-21 16:59:19 +020046#include <asm/idle.h>
Ralf Baechle340ee4b2005-08-17 17:44:08 +000047#include <asm/mipsregs.h>
48#include <asm/mipsmtregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <asm/module.h>
50#include <asm/pgtable.h>
51#include <asm/ptrace.h>
52#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/tlbdebug.h>
54#include <asm/traps.h>
55#include <asm/uaccess.h>
David Daneyb67b2b72008-09-23 00:08:45 -070056#include <asm/watch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <asm/types.h>
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090059#include <asm/stacktrace.h>
Florian Fainelli92bbe1b2010-01-28 15:22:37 +010060#include <asm/uasm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Atsushi Nemotoc65a5482007-11-12 02:05:18 +090062extern void check_wait(void);
Atsushi Nemotoc65a5482007-11-12 02:05:18 +090063extern asmlinkage void rollback_handle_int(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010064extern asmlinkage void handle_int(void);
Ralf Baechle86a17082013-02-08 01:21:34 +010065extern u32 handle_tlbl[];
66extern u32 handle_tlbs[];
67extern u32 handle_tlbm[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern asmlinkage void handle_adel(void);
69extern asmlinkage void handle_ades(void);
70extern asmlinkage void handle_ibe(void);
71extern asmlinkage void handle_dbe(void);
72extern asmlinkage void handle_sys(void);
73extern asmlinkage void handle_bp(void);
74extern asmlinkage void handle_ri(void);
Atsushi Nemoto5b104962006-09-11 17:50:29 +090075extern asmlinkage void handle_ri_rdhwr_vivt(void);
76extern asmlinkage void handle_ri_rdhwr(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern asmlinkage void handle_cpu(void);
78extern asmlinkage void handle_ov(void);
79extern asmlinkage void handle_tr(void);
80extern asmlinkage void handle_fpe(void);
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +000081extern asmlinkage void handle_ftlb(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern asmlinkage void handle_mdmx(void);
83extern asmlinkage void handle_watch(void);
Ralf Baechle340ee4b2005-08-17 17:44:08 +000084extern asmlinkage void handle_mt(void);
Ralf Baechlee50c0a82005-05-31 11:49:19 +000085extern asmlinkage void handle_dsp(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086extern asmlinkage void handle_mcheck(void);
87extern asmlinkage void handle_reserved(void);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089void (*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);
Paul Gortmaker078a55f2013-06-18 13:38:59 +000095void(*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))
Ralf Baechle70342282013-01-22 12:59:30 +0100166 printk("\n ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 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
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900208static void show_code(unsigned int __user *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 long i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100211 unsigned short __user *pc16 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 printk("\nCode:");
214
Ralf Baechle39b8d522008-04-28 17:14:26 +0100215 if ((unsigned long)pc & 1)
216 pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 for(i = -3 ; i < 6 ; i++) {
218 unsigned int insn;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100219 if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 printk(" (Bad address in epc)\n");
221 break;
222 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100223 printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225}
226
Ralf Baechleeae23f22007-10-14 23:27:21 +0100227static void __show_regs(const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 const int field = 2 * sizeof(unsigned long);
230 unsigned int cause = regs->cp0_cause;
231 int i;
232
Tejun Heoa43cb952013-04-30 15:27:17 -0700233 show_regs_print_info(KERN_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /*
236 * Saved main processor registers
237 */
238 for (i = 0; i < 32; ) {
239 if ((i % 4) == 0)
240 printk("$%2d :", i);
241 if (i == 0)
242 printk(" %0*lx", field, 0UL);
243 else if (i == 26 || i == 27)
244 printk(" %*s", field, "");
245 else
246 printk(" %0*lx", field, regs->regs[i]);
247
248 i++;
249 if ((i % 4) == 0)
250 printk("\n");
251 }
252
Franck Bui-Huu9693a852007-02-02 17:41:47 +0100253#ifdef CONFIG_CPU_HAS_SMARTMIPS
254 printk("Acx : %0*lx\n", field, regs->acx);
255#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 printk("Hi : %0*lx\n", field, regs->hi);
257 printk("Lo : %0*lx\n", field, regs->lo);
258
259 /*
260 * Saved cp0 registers
261 */
Ralf Baechleb012cff2008-07-15 18:44:33 +0100262 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
263 (void *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 printk(" %s\n", print_tainted());
Ralf Baechleb012cff2008-07-15 18:44:33 +0100265 printk("ra : %0*lx %pS\n", field, regs->regs[31],
266 (void *) regs->regs[31]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Ralf Baechle70342282013-01-22 12:59:30 +0100268 printk("Status: %08x ", (uint32_t) regs->cp0_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Ralf Baechle1990e542013-06-26 17:06:34 +0200270 if (cpu_has_3kex) {
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000271 if (regs->cp0_status & ST0_KUO)
272 printk("KUo ");
273 if (regs->cp0_status & ST0_IEO)
274 printk("IEo ");
275 if (regs->cp0_status & ST0_KUP)
276 printk("KUp ");
277 if (regs->cp0_status & ST0_IEP)
278 printk("IEp ");
279 if (regs->cp0_status & ST0_KUC)
280 printk("KUc ");
281 if (regs->cp0_status & ST0_IEC)
282 printk("IEc ");
Ralf Baechle1990e542013-06-26 17:06:34 +0200283 } else if (cpu_has_4kex) {
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000284 if (regs->cp0_status & ST0_KX)
285 printk("KX ");
286 if (regs->cp0_status & ST0_SX)
287 printk("SX ");
288 if (regs->cp0_status & ST0_UX)
289 printk("UX ");
290 switch (regs->cp0_status & ST0_KSU) {
291 case KSU_USER:
292 printk("USER ");
293 break;
294 case KSU_SUPERVISOR:
295 printk("SUPERVISOR ");
296 break;
297 case KSU_KERNEL:
298 printk("KERNEL ");
299 break;
300 default:
301 printk("BAD_MODE ");
302 break;
303 }
304 if (regs->cp0_status & ST0_ERL)
305 printk("ERL ");
306 if (regs->cp0_status & ST0_EXL)
307 printk("EXL ");
308 if (regs->cp0_status & ST0_IE)
309 printk("IE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 printk("\n");
312
313 printk("Cause : %08x\n", cause);
314
315 cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
316 if (1 <= cause && cause <= 5)
317 printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
318
Ralf Baechle9966db252007-10-11 23:46:17 +0100319 printk("PrId : %08x (%s)\n", read_c0_prid(),
320 cpu_name_string());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
Ralf Baechleeae23f22007-10-14 23:27:21 +0100323/*
324 * FIXME: really the generic show_regs should take a const pointer argument.
325 */
326void show_regs(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Ralf Baechleeae23f22007-10-14 23:27:21 +0100328 __show_regs((struct pt_regs *)regs);
329}
330
David Daneyc1bf2072010-08-03 11:22:20 -0700331void show_registers(struct pt_regs *regs)
Ralf Baechleeae23f22007-10-14 23:27:21 +0100332{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100333 const int field = 2 * sizeof(unsigned long);
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100334 mm_segment_t old_fs = get_fs();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100335
Ralf Baechleeae23f22007-10-14 23:27:21 +0100336 __show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 print_modules();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100338 printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
339 current->comm, current->pid, current_thread_info(), current,
340 field, current_thread_info()->tp_value);
341 if (cpu_has_userlocal) {
342 unsigned long tls;
343
344 tls = read_c0_userlocal();
345 if (tls != current_thread_info()->tp_value)
346 printk("*HwTLS: %0*lx\n", field, tls);
347 }
348
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100349 if (!user_mode(regs))
350 /* Necessary for getting the correct stack content */
351 set_fs(KERNEL_DS);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900352 show_stacktrace(current, regs);
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900353 show_code((unsigned int __user *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 printk("\n");
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100355 set_fs(old_fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
David Daney70dc6f02010-08-03 15:44:43 -0700358static int regs_to_trapnr(struct pt_regs *regs)
359{
360 return (regs->cp0_cause >> 2) & 0x1f;
361}
362
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000363static DEFINE_RAW_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
David Daney70dc6f02010-08-03 15:44:43 -0700365void __noreturn die(const char *str, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 static int die_counter;
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400368 int sig = SIGSEGV;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100369#ifdef CONFIG_MIPS_MT_SMTC
Nathan Lynch8742cd22011-09-30 13:49:35 -0500370 unsigned long dvpret;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100371#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Nathan Lynch8742cd22011-09-30 13:49:35 -0500373 oops_enter();
374
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200375 if (notify_die(DIE_OOPS, str, regs, 0, regs_to_trapnr(regs),
376 SIGSEGV) == NOTIFY_STOP)
Ralf Baechle10423c92011-05-13 10:33:28 +0100377 sig = 0;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 console_verbose();
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000380 raw_spin_lock_irq(&die_lock);
Nathan Lynch8742cd22011-09-30 13:49:35 -0500381#ifdef CONFIG_MIPS_MT_SMTC
382 dvpret = dvpe();
383#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100384 bust_spinlocks(1);
385#ifdef CONFIG_MIPS_MT_SMTC
386 mips_mt_regdump(dvpret);
387#endif /* CONFIG_MIPS_MT_SMTC */
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400388
Ralf Baechle178086c2005-10-13 17:07:54 +0100389 printk("%s[#%d]:\n", str, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 show_registers(regs);
Rusty Russell373d4d02013-01-21 17:17:39 +1030391 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000392 raw_spin_unlock_irq(&die_lock);
Maxime Bizond4fd1982006-07-20 18:52:02 +0200393
Nathan Lynch8742cd22011-09-30 13:49:35 -0500394 oops_exit();
395
Maxime Bizond4fd1982006-07-20 18:52:02 +0200396 if (in_interrupt())
397 panic("Fatal exception in interrupt");
398
399 if (panic_on_oops) {
Ralf Baechleab75dc02011-11-17 15:07:31 +0000400 printk(KERN_EMERG "Fatal exception: panic in 5 seconds");
Maxime Bizond4fd1982006-07-20 18:52:02 +0200401 ssleep(5);
402 panic("Fatal exception");
403 }
404
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +0200405 if (regs && kexec_should_crash(current))
406 crash_kexec(regs);
407
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400408 do_exit(sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
Thomas Bogendoerfer05106172008-08-04 19:44:34 +0200411extern struct exception_table_entry __start___dbe_table[];
412extern struct exception_table_entry __stop___dbe_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Ralf Baechleb6dcec92007-02-18 15:57:09 +0000414__asm__(
415" .section __dbe_table, \"a\"\n"
416" .previous \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418/* Given an address, look for it in the exception tables. */
419static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
420{
421 const struct exception_table_entry *e;
422
423 e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
424 if (!e)
425 e = search_module_dbetables(addr);
426 return e;
427}
428
429asmlinkage void do_be(struct pt_regs *regs)
430{
431 const int field = 2 * sizeof(unsigned long);
432 const struct exception_table_entry *fixup = NULL;
433 int data = regs->cp0_cause & 4;
434 int action = MIPS_BE_FATAL;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200435 enum ctx_state prev_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200437 prev_state = exception_enter();
Ralf Baechle70342282013-01-22 12:59:30 +0100438 /* XXX For now. Fixme, this searches the wrong table ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (data && !user_mode(regs))
440 fixup = search_dbe_tables(exception_epc(regs));
441
442 if (fixup)
443 action = MIPS_BE_FIXUP;
444
445 if (board_be_handler)
Atsushi Nemoto28fc5822007-07-13 01:49:49 +0900446 action = board_be_handler(regs, fixup != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 switch (action) {
449 case MIPS_BE_DISCARD:
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200450 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 case MIPS_BE_FIXUP:
452 if (fixup) {
453 regs->cp0_epc = fixup->nextinsn;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200454 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456 break;
457 default:
458 break;
459 }
460
461 /*
462 * Assume it would be too dangerous to continue ...
463 */
464 printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
465 data ? "Data" : "Instruction",
466 field, regs->cp0_epc, field, regs->regs[31]);
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200467 if (notify_die(DIE_OOPS, "bus error", regs, 0, regs_to_trapnr(regs),
468 SIGBUS) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200469 goto out;
Jason Wessel88547002008-07-29 15:58:53 -0500470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 die_if_kernel("Oops", regs);
472 force_sig(SIGBUS, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200473
474out:
475 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478/*
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100479 * ll/sc, rdhwr, sync emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 */
481
482#define OPCODE 0xfc000000
483#define BASE 0x03e00000
484#define RT 0x001f0000
485#define OFFSET 0x0000ffff
486#define LL 0xc0000000
487#define SC 0xe0000000
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100488#define SPEC0 0x00000000
Ralf Baechle3c370262005-04-13 17:43:59 +0000489#define SPEC3 0x7c000000
490#define RD 0x0000f800
491#define FUNC 0x0000003f
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100492#define SYNC 0x0000000f
Ralf Baechle3c370262005-04-13 17:43:59 +0000493#define RDHWR 0x0000003b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500495/* microMIPS definitions */
496#define MM_POOL32A_FUNC 0xfc00ffff
497#define MM_RDHWR 0x00006b3c
498#define MM_RS 0x001f0000
499#define MM_RT 0x03e00000
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501/*
502 * The ll_bit is cleared by r*_switch.S
503 */
504
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200505unsigned int ll_bit;
506struct task_struct *ll_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100508static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000510 unsigned long value, __user *vaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 /*
514 * analyse the ll instruction that just caused a ri exception
515 * and put the referenced address to addr.
516 */
517
518 /* sign extend offset */
519 offset = opcode & OFFSET;
520 offset <<= 16;
521 offset >>= 16;
522
Ralf Baechlefe00f942005-03-01 19:22:29 +0000523 vaddr = (unsigned long __user *)
Steven J. Hillb9688312013-01-12 23:29:27 +0000524 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100526 if ((unsigned long)vaddr & 3)
527 return SIGBUS;
528 if (get_user(value, vaddr))
529 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 preempt_disable();
532
533 if (ll_task == NULL || ll_task == current) {
534 ll_bit = 1;
535 } else {
536 ll_bit = 0;
537 }
538 ll_task = current;
539
540 preempt_enable();
541
542 regs->regs[(opcode & RT) >> 16] = value;
543
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100544 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545}
546
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100547static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000549 unsigned long __user *vaddr;
550 unsigned long reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 /*
554 * analyse the sc instruction that just caused a ri exception
555 * and put the referenced address to addr.
556 */
557
558 /* sign extend offset */
559 offset = opcode & OFFSET;
560 offset <<= 16;
561 offset >>= 16;
562
Ralf Baechlefe00f942005-03-01 19:22:29 +0000563 vaddr = (unsigned long __user *)
Steven J. Hillb9688312013-01-12 23:29:27 +0000564 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 reg = (opcode & RT) >> 16;
566
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100567 if ((unsigned long)vaddr & 3)
568 return SIGBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 preempt_disable();
571
572 if (ll_bit == 0 || ll_task != current) {
573 regs->regs[reg] = 0;
574 preempt_enable();
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100575 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
578 preempt_enable();
579
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100580 if (put_user(regs->regs[reg], vaddr))
581 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 regs->regs[reg] = 1;
584
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100585 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588/*
589 * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
590 * opcodes are supposed to result in coprocessor unusable exceptions if
591 * executed on ll/sc-less processors. That's the theory. In practice a
592 * few processors such as NEC's VR4100 throw reserved instruction exceptions
593 * instead, so we're doing the emulation thing in both exception handlers.
594 */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100595static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800597 if ((opcode & OPCODE) == LL) {
598 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200599 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100600 return simulate_ll(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800601 }
602 if ((opcode & OPCODE) == SC) {
603 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200604 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100605 return simulate_sc(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100608 return -1; /* Must be something else ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
Ralf Baechle3c370262005-04-13 17:43:59 +0000611/*
612 * Simulate trapping 'rdhwr' instructions to provide user accessible
Chris Dearman1f5826b2006-05-08 18:02:16 +0100613 * registers not implemented in hardware.
Ralf Baechle3c370262005-04-13 17:43:59 +0000614 */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500615static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
Ralf Baechle3c370262005-04-13 17:43:59 +0000616{
Al Virodc8f6022006-01-12 01:06:07 -0800617 struct thread_info *ti = task_thread_info(current);
Ralf Baechle3c370262005-04-13 17:43:59 +0000618
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500619 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
620 1, regs, 0);
621 switch (rd) {
622 case 0: /* CPU number */
623 regs->regs[rt] = smp_processor_id();
624 return 0;
625 case 1: /* SYNCI length */
626 regs->regs[rt] = min(current_cpu_data.dcache.linesz,
627 current_cpu_data.icache.linesz);
628 return 0;
629 case 2: /* Read count register */
630 regs->regs[rt] = read_c0_count();
631 return 0;
632 case 3: /* Count register resolution */
Ralf Baechle69f24d12013-09-17 10:25:47 +0200633 switch (current_cpu_type()) {
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500634 case CPU_20KC:
635 case CPU_25KF:
636 regs->regs[rt] = 1;
637 break;
638 default:
639 regs->regs[rt] = 2;
640 }
641 return 0;
642 case 29:
643 regs->regs[rt] = ti->tp_value;
644 return 0;
645 default:
646 return -1;
647 }
648}
649
650static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
651{
Ralf Baechle3c370262005-04-13 17:43:59 +0000652 if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
653 int rd = (opcode & RD) >> 11;
654 int rt = (opcode & RT) >> 16;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500655
656 simulate_rdhwr(regs, rd, rt);
657 return 0;
658 }
659
660 /* Not ours. */
661 return -1;
662}
663
664static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned short opcode)
665{
666 if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
667 int rd = (opcode & MM_RS) >> 16;
668 int rt = (opcode & MM_RT) >> 21;
669 simulate_rdhwr(regs, rd, rt);
670 return 0;
Ralf Baechle3c370262005-04-13 17:43:59 +0000671 }
672
Daniel Jacobowitz56ebd512005-11-26 22:34:41 -0500673 /* Not ours. */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100674 return -1;
675}
Ralf Baechlee5679882006-11-30 01:14:47 +0000676
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100677static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
678{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800679 if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
680 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200681 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100682 return 0;
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800683 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100684
685 return -1; /* Must be something else ... */
Ralf Baechle3c370262005-04-13 17:43:59 +0000686}
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688asmlinkage void do_ov(struct pt_regs *regs)
689{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200690 enum ctx_state prev_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 siginfo_t info;
692
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200693 prev_state = exception_enter();
Ralf Baechle36ccf1c2006-02-14 21:04:54 +0000694 die_if_kernel("Integer overflow", regs);
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 info.si_code = FPE_INTOVF;
697 info.si_signo = SIGFPE;
698 info.si_errno = 0;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000699 info.si_addr = (void __user *) regs->cp0_epc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 force_sig_info(SIGFPE, &info, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200701 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702}
703
Leonid Yegoshin102cedc2013-03-25 12:09:02 -0500704int process_fpemu_return(int sig, void __user *fault_addr)
David Daney515b0292010-10-21 16:32:26 -0700705{
706 if (sig == SIGSEGV || sig == SIGBUS) {
707 struct siginfo si = {0};
708 si.si_addr = fault_addr;
709 si.si_signo = sig;
710 if (sig == SIGSEGV) {
711 if (find_vma(current->mm, (unsigned long)fault_addr))
712 si.si_code = SEGV_ACCERR;
713 else
714 si.si_code = SEGV_MAPERR;
715 } else {
716 si.si_code = BUS_ADRERR;
717 }
718 force_sig_info(sig, &si, current);
719 return 1;
720 } else if (sig) {
721 force_sig(sig, current);
722 return 1;
723 } else {
724 return 0;
725 }
726}
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728/*
729 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
730 */
731asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
732{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200733 enum ctx_state prev_state;
David Daney515b0292010-10-21 16:32:26 -0700734 siginfo_t info = {0};
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100735
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200736 prev_state = exception_enter();
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200737 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs),
738 SIGFPE) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200739 goto out;
Chris Dearman57725f92006-06-30 23:35:28 +0100740 die_if_kernel("FP exception in kernel code", regs);
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 if (fcr31 & FPU_CSR_UNI_X) {
743 int sig;
David Daney515b0292010-10-21 16:32:26 -0700744 void __user *fault_addr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000747 * Unimplemented operation exception. If we've got the full
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 * software emulator on-board, let's use it...
749 *
750 * Force FPU to dump state into task/thread context. We're
751 * moving a lot of data here for what is probably a single
752 * instruction, but the alternative is to pre-decode the FP
753 * register operands before invoking the emulator, which seems
754 * a bit extreme for what should be an infrequent event.
755 */
Ralf Baechlecd21dfc2005-04-28 13:39:10 +0000756 /* Ensure 'resume' not overwrite saved fp context again. */
Atsushi Nemoto53dc8022007-03-10 01:07:45 +0900757 lose_fpu(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 /* Run the emulator */
David Daney515b0292010-10-21 16:32:26 -0700760 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
761 &fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /*
764 * We can't allow the emulated instruction to leave any of
765 * the cause bit set in $fcr31.
766 */
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900767 current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 /* Restore the hardware register state */
Ralf Baechle70342282013-01-22 12:59:30 +0100770 own_fpu(1); /* Using the FPU again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 /* If something went wrong, signal */
David Daney515b0292010-10-21 16:32:26 -0700773 process_fpemu_return(sig, fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200775 goto out;
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100776 } else if (fcr31 & FPU_CSR_INV_X)
777 info.si_code = FPE_FLTINV;
778 else if (fcr31 & FPU_CSR_DIV_X)
779 info.si_code = FPE_FLTDIV;
780 else if (fcr31 & FPU_CSR_OVF_X)
781 info.si_code = FPE_FLTOVF;
782 else if (fcr31 & FPU_CSR_UDF_X)
783 info.si_code = FPE_FLTUND;
784 else if (fcr31 & FPU_CSR_INE_X)
785 info.si_code = FPE_FLTRES;
786 else
787 info.si_code = __SI_FAULT;
788 info.si_signo = SIGFPE;
789 info.si_errno = 0;
790 info.si_addr = (void __user *) regs->cp0_epc;
791 force_sig_info(SIGFPE, &info, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200792
793out:
794 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
Ralf Baechledf270052008-04-20 16:28:54 +0100797static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
798 const char *str)
799{
800 siginfo_t info;
801 char b[40];
802
Jason Wessel5dd11d52010-05-20 21:04:26 -0500803#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
David Daney70dc6f02010-08-03 15:44:43 -0700804 if (kgdb_ll_trap(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Jason Wessel5dd11d52010-05-20 21:04:26 -0500805 return;
806#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
807
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200808 if (notify_die(DIE_TRAP, str, regs, code, regs_to_trapnr(regs),
809 SIGTRAP) == NOTIFY_STOP)
Jason Wessel88547002008-07-29 15:58:53 -0500810 return;
811
Ralf Baechledf270052008-04-20 16:28:54 +0100812 /*
813 * A short test says that IRIX 5.3 sends SIGTRAP for all trap
814 * insns, even for trap and break codes that indicate arithmetic
815 * failures. Weird ...
816 * But should we continue the brokenness??? --macro
817 */
818 switch (code) {
819 case BRK_OVERFLOW:
820 case BRK_DIVZERO:
821 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
822 die_if_kernel(b, regs);
823 if (code == BRK_DIVZERO)
824 info.si_code = FPE_INTDIV;
825 else
826 info.si_code = FPE_INTOVF;
827 info.si_signo = SIGFPE;
828 info.si_errno = 0;
829 info.si_addr = (void __user *) regs->cp0_epc;
830 force_sig_info(SIGFPE, &info, current);
831 break;
832 case BRK_BUG:
833 die_if_kernel("Kernel bug detected", regs);
834 force_sig(SIGTRAP, current);
835 break;
Ralf Baechleba3049e2008-10-28 17:38:42 +0000836 case BRK_MEMU:
837 /*
838 * Address errors may be deliberately induced by the FPU
839 * emulator to retake control of the CPU after executing the
840 * instruction in the delay slot of an emulated branch.
841 *
842 * Terminate if exception was recognized as a delay slot return
843 * otherwise handle as normal.
844 */
845 if (do_dsemulret(regs))
846 return;
847
848 die_if_kernel("Math emu break/trap", regs);
849 force_sig(SIGTRAP, current);
850 break;
Ralf Baechledf270052008-04-20 16:28:54 +0100851 default:
852 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
853 die_if_kernel(b, regs);
854 force_sig(SIGTRAP, current);
855 }
856}
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858asmlinkage void do_bp(struct pt_regs *regs)
859{
860 unsigned int opcode, bcode;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200861 enum ctx_state prev_state;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500862 unsigned long epc;
863 u16 instr[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200865 prev_state = exception_enter();
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500866 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], (u16 __user *)msk_isa16_mode(epc)))
877 goto out_sigsegv;
878 bcode = (instr[0] >> 6) & 0x3f;
879 do_trap_or_bp(regs, bcode, "Break");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200880 goto out;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500881 }
882 } else {
883 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
884 goto out_sigsegv;
885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 /*
888 * There is the ancient bug in the MIPS assemblers that the break
889 * code starts left to bit 16 instead to bit 6 in the opcode.
890 * Gas is bug-compatible, but not always, grrr...
891 * We handle both cases with a simple heuristics. --macro
892 */
893 bcode = ((opcode >> 6) & ((1 << 20) - 1));
Ralf Baechledf270052008-04-20 16:28:54 +0100894 if (bcode >= (1 << 10))
895 bcode >>= 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
David Daneyc1bf2072010-08-03 11:22:20 -0700897 /*
898 * notify the kprobe handlers, if instruction is likely to
899 * pertain to them.
900 */
901 switch (bcode) {
902 case BRK_KPROBE_BP:
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200903 if (notify_die(DIE_BREAK, "debug", regs, bcode,
904 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200905 goto out;
David Daneyc1bf2072010-08-03 11:22:20 -0700906 else
907 break;
908 case BRK_KPROBE_SSTEPBP:
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200909 if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
910 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200911 goto out;
David Daneyc1bf2072010-08-03 11:22:20 -0700912 else
913 break;
914 default:
915 break;
916 }
917
Ralf Baechledf270052008-04-20 16:28:54 +0100918 do_trap_or_bp(regs, bcode, "Break");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200919
920out:
921 exception_exit(prev_state);
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900922 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000923
924out_sigsegv:
925 force_sig(SIGSEGV, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200926 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
929asmlinkage void do_tr(struct pt_regs *regs)
930{
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000931 u32 opcode, tcode = 0;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200932 enum ctx_state prev_state;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500933 u16 instr[2];
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000934 unsigned long epc = msk_isa16_mode(exception_epc(regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200936 prev_state = exception_enter();
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000937 if (get_isa16_mode(regs->cp0_epc)) {
938 if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
939 __get_user(instr[1], (u16 __user *)(epc + 2)))
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500940 goto out_sigsegv;
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000941 opcode = (instr[0] << 16) | instr[1];
942 /* Immediate versions don't provide a code. */
943 if (!(opcode & OPCODE))
944 tcode = (opcode >> 12) & ((1 << 4) - 1);
945 } else {
946 if (__get_user(opcode, (u32 __user *)epc))
947 goto out_sigsegv;
948 /* Immediate versions don't provide a code. */
949 if (!(opcode & OPCODE))
950 tcode = (opcode >> 6) & ((1 << 10) - 1);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500951 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Ralf Baechledf270052008-04-20 16:28:54 +0100953 do_trap_or_bp(regs, tcode, "Trap");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200954
955out:
956 exception_exit(prev_state);
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900957 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000958
959out_sigsegv:
960 force_sig(SIGSEGV, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200961 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962}
963
964asmlinkage void do_ri(struct pt_regs *regs)
965{
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100966 unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
967 unsigned long old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500968 unsigned long old31 = regs->regs[31];
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200969 enum ctx_state prev_state;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100970 unsigned int opcode = 0;
971 int status = -1;
972
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200973 prev_state = exception_enter();
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200974 if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs),
975 SIGILL) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200976 goto out;
Jason Wessel88547002008-07-29 15:58:53 -0500977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 die_if_kernel("Reserved instruction in kernel code", regs);
979
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100980 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200981 goto out;
Ralf Baechle3c370262005-04-13 17:43:59 +0000982
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500983 if (get_isa16_mode(regs->cp0_epc)) {
984 unsigned short mmop[2] = { 0 };
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100985
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500986 if (unlikely(get_user(mmop[0], epc) < 0))
987 status = SIGSEGV;
988 if (unlikely(get_user(mmop[1], epc) < 0))
989 status = SIGSEGV;
990 opcode = (mmop[0] << 16) | mmop[1];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100991
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500992 if (status < 0)
993 status = simulate_rdhwr_mm(regs, opcode);
994 } else {
995 if (unlikely(get_user(opcode, epc) < 0))
996 status = SIGSEGV;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100997
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500998 if (!cpu_has_llsc && status < 0)
999 status = simulate_llsc(regs, opcode);
1000
1001 if (status < 0)
1002 status = simulate_rdhwr_normal(regs, opcode);
1003
1004 if (status < 0)
1005 status = simulate_sync(regs, opcode);
1006 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001007
1008 if (status < 0)
1009 status = SIGILL;
1010
1011 if (unlikely(status > 0)) {
1012 regs->cp0_epc = old_epc; /* Undo skip-over. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001013 regs->regs[31] = old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001014 force_sig(status, current);
1015 }
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001016
1017out:
1018 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Ralf Baechled223a862007-07-10 17:33:02 +01001021/*
1022 * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
1023 * emulated more than some threshold number of instructions, force migration to
1024 * a "CPU" that has FP support.
1025 */
1026static void mt_ase_fp_affinity(void)
1027{
1028#ifdef CONFIG_MIPS_MT_FPAFF
1029 if (mt_fpemul_threshold > 0 &&
1030 ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
1031 /*
1032 * If there's no FPU present, or if the application has already
1033 * restricted the allowed set to exclude any CPUs with FPUs,
1034 * we'll skip the procedure.
1035 */
1036 if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
1037 cpumask_t tmask;
1038
Kevin D. Kissell9cc12362008-09-09 21:33:36 +02001039 current->thread.user_cpus_allowed
1040 = current->cpus_allowed;
1041 cpus_and(tmask, current->cpus_allowed,
1042 mt_fpu_cpumask);
Julia Lawalled1bbde2010-03-26 23:03:07 +01001043 set_cpus_allowed_ptr(current, &tmask);
Ralf Baechle293c5bd2007-07-25 16:19:33 +01001044 set_thread_flag(TIF_FPUBOUND);
Ralf Baechled223a862007-07-10 17:33:02 +01001045 }
1046 }
1047#endif /* CONFIG_MIPS_MT_FPAFF */
1048}
1049
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001050/*
1051 * No lock; only written during early bootup by CPU 0.
1052 */
1053static RAW_NOTIFIER_HEAD(cu2_chain);
1054
1055int __ref register_cu2_notifier(struct notifier_block *nb)
1056{
1057 return raw_notifier_chain_register(&cu2_chain, nb);
1058}
1059
1060int cu2_notifier_call_chain(unsigned long val, void *v)
1061{
1062 return raw_notifier_call_chain(&cu2_chain, val, v);
1063}
1064
1065static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
Ralf Baechle70342282013-01-22 12:59:30 +01001066 void *data)
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001067{
1068 struct pt_regs *regs = data;
1069
Jayachandran C83bee792013-06-10 06:30:01 +00001070 die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001071 "instruction", regs);
Jayachandran C83bee792013-06-10 06:30:01 +00001072 force_sig(SIGILL, current);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001073
1074 return NOTIFY_OK;
1075}
1076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077asmlinkage void do_cpu(struct pt_regs *regs)
1078{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001079 enum ctx_state prev_state;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001080 unsigned int __user *epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001081 unsigned long old_epc, old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001082 unsigned int opcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 unsigned int cpid;
Paul Burton597ce172013-11-22 13:12:07 +00001084 int status, err;
David Daneyf9bb4cf2008-12-11 15:33:23 -08001085 unsigned long __maybe_unused flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001087 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
1089
Jayachandran C83bee792013-06-10 06:30:01 +00001090 if (cpid != 2)
1091 die_if_kernel("do_cpu invoked from kernel context!", regs);
1092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 switch (cpid) {
1094 case 0:
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001095 epc = (unsigned int __user *)exception_epc(regs);
1096 old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001097 old31 = regs->regs[31];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001098 opcode = 0;
1099 status = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001101 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001102 goto out;
Ralf Baechle3c370262005-04-13 17:43:59 +00001103
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001104 if (get_isa16_mode(regs->cp0_epc)) {
1105 unsigned short mmop[2] = { 0 };
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001106
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001107 if (unlikely(get_user(mmop[0], epc) < 0))
1108 status = SIGSEGV;
1109 if (unlikely(get_user(mmop[1], epc) < 0))
1110 status = SIGSEGV;
1111 opcode = (mmop[0] << 16) | mmop[1];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001112
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001113 if (status < 0)
1114 status = simulate_rdhwr_mm(regs, opcode);
1115 } else {
1116 if (unlikely(get_user(opcode, epc) < 0))
1117 status = SIGSEGV;
1118
1119 if (!cpu_has_llsc && status < 0)
1120 status = simulate_llsc(regs, opcode);
1121
1122 if (status < 0)
1123 status = simulate_rdhwr_normal(regs, opcode);
1124 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001125
1126 if (status < 0)
1127 status = SIGILL;
1128
1129 if (unlikely(status > 0)) {
1130 regs->cp0_epc = old_epc; /* Undo skip-over. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001131 regs->regs[31] = old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001132 force_sig(status, current);
1133 }
1134
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001135 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001137 case 3:
1138 /*
1139 * Old (MIPS I and MIPS II) processors will set this code
1140 * for COP1X opcode instructions that replaced the original
Ralf Baechle70342282013-01-22 12:59:30 +01001141 * COP3 space. We don't limit COP1 space instructions in
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001142 * the emulator according to the CPU ISA, so we want to
1143 * treat COP1X instructions consistently regardless of which
Ralf Baechle70342282013-01-22 12:59:30 +01001144 * code the CPU chose. Therefore we redirect this trap to
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001145 * the FP emulator too.
1146 *
1147 * Then some newer FPU-less processors use this code
1148 * erroneously too, so they are covered by this choice
1149 * as well.
1150 */
1151 if (raw_cpu_has_fpu)
1152 break;
1153 /* Fall through. */
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 case 1:
Ralf Baechle70342282013-01-22 12:59:30 +01001156 if (used_math()) /* Using the FPU again. */
Paul Burton597ce172013-11-22 13:12:07 +00001157 err = own_fpu(1);
Ralf Baechle70342282013-01-22 12:59:30 +01001158 else { /* First time FPU user. */
Paul Burton597ce172013-11-22 13:12:07 +00001159 err = init_fpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 set_used_math();
1161 }
1162
Paul Burton597ce172013-11-22 13:12:07 +00001163 if (!raw_cpu_has_fpu || err) {
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001164 int sig;
David Daney515b0292010-10-21 16:32:26 -07001165 void __user *fault_addr = NULL;
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001166 sig = fpu_emulator_cop1Handler(regs,
David Daney515b0292010-10-21 16:32:26 -07001167 &current->thread.fpu,
1168 0, &fault_addr);
Paul Burton597ce172013-11-22 13:12:07 +00001169 if (!process_fpemu_return(sig, fault_addr) && !err)
Ralf Baechled223a862007-07-10 17:33:02 +01001170 mt_ase_fp_affinity();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
1172
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001173 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175 case 2:
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001176 raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001177 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 }
1179
1180 force_sig(SIGILL, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001181
1182out:
1183 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184}
1185
1186asmlinkage void do_mdmx(struct pt_regs *regs)
1187{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001188 enum ctx_state prev_state;
1189
1190 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 force_sig(SIGILL, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001192 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
David Daney8bc6d052009-01-05 15:29:58 -08001195/*
1196 * Called with interrupts disabled.
1197 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198asmlinkage void do_watch(struct pt_regs *regs)
1199{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001200 enum ctx_state prev_state;
David Daneyb67b2b72008-09-23 00:08:45 -07001201 u32 cause;
1202
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001203 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 /*
David Daneyb67b2b72008-09-23 00:08:45 -07001205 * Clear WP (bit 22) bit of cause register so we don't loop
1206 * forever.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 */
David Daneyb67b2b72008-09-23 00:08:45 -07001208 cause = read_c0_cause();
1209 cause &= ~(1 << 22);
1210 write_c0_cause(cause);
1211
1212 /*
1213 * If the current thread has the watch registers loaded, save
1214 * their values and send SIGTRAP. Otherwise another thread
1215 * left the registers set, clear them and continue.
1216 */
1217 if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
1218 mips_read_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001219 local_irq_enable();
David Daneyb67b2b72008-09-23 00:08:45 -07001220 force_sig(SIGTRAP, current);
David Daney8bc6d052009-01-05 15:29:58 -08001221 } else {
David Daneyb67b2b72008-09-23 00:08:45 -07001222 mips_clear_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001223 local_irq_enable();
1224 }
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001225 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226}
1227
1228asmlinkage void do_mcheck(struct pt_regs *regs)
1229{
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001230 const int field = 2 * sizeof(unsigned long);
1231 int multi_match = regs->cp0_status & ST0_TS;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001232 enum ctx_state prev_state;
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001233
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001234 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 show_regs(regs);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001236
1237 if (multi_match) {
Ralf Baechle70342282013-01-22 12:59:30 +01001238 printk("Index : %0x\n", read_c0_index());
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001239 printk("Pagemask: %0x\n", read_c0_pagemask());
1240 printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
1241 printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
1242 printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
1243 printk("\n");
1244 dump_tlb_all();
1245 }
1246
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +09001247 show_code((unsigned int __user *) regs->cp0_epc);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 /*
1250 * Some chips may have other causes of machine check (e.g. SB1
1251 * graduation timer)
1252 */
1253 panic("Caught Machine Check exception - %scaused by multiple "
1254 "matching entries in the TLB.",
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001255 (multi_match) ? "" : "not ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001258asmlinkage void do_mt(struct pt_regs *regs)
1259{
Ralf Baechle41c594a2006-04-05 09:45:45 +01001260 int subcode;
1261
Ralf Baechle41c594a2006-04-05 09:45:45 +01001262 subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
1263 >> VPECONTROL_EXCPT_SHIFT;
1264 switch (subcode) {
1265 case 0:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001266 printk(KERN_DEBUG "Thread Underflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001267 break;
1268 case 1:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001269 printk(KERN_DEBUG "Thread Overflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001270 break;
1271 case 2:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001272 printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001273 break;
1274 case 3:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001275 printk(KERN_DEBUG "Gating Storage Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001276 break;
1277 case 4:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001278 printk(KERN_DEBUG "YIELD Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001279 break;
1280 case 5:
Masanari Iidaf232c7e2012-02-08 21:53:14 +09001281 printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001282 break;
1283 default:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001284 printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
Ralf Baechle41c594a2006-04-05 09:45:45 +01001285 subcode);
1286 break;
1287 }
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001288 die_if_kernel("MIPS MT Thread exception in kernel", regs);
1289
1290 force_sig(SIGILL, current);
1291}
1292
1293
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001294asmlinkage void do_dsp(struct pt_regs *regs)
1295{
1296 if (cpu_has_dsp)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001297 panic("Unexpected DSP exception");
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001298
1299 force_sig(SIGILL, current);
1300}
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302asmlinkage void do_reserved(struct pt_regs *regs)
1303{
1304 /*
Ralf Baechle70342282013-01-22 12:59:30 +01001305 * Game over - no way to handle this if it ever occurs. Most probably
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 * caused by a new unknown cpu type or after another deadly
1307 * hard/software error.
1308 */
1309 show_regs(regs);
1310 panic("Caught reserved exception %ld - should not happen.",
1311 (regs->cp0_cause & 0x7f) >> 2);
1312}
1313
Ralf Baechle39b8d522008-04-28 17:14:26 +01001314static int __initdata l1parity = 1;
1315static int __init nol1parity(char *s)
1316{
1317 l1parity = 0;
1318 return 1;
1319}
1320__setup("nol1par", nol1parity);
1321static int __initdata l2parity = 1;
1322static int __init nol2parity(char *s)
1323{
1324 l2parity = 0;
1325 return 1;
1326}
1327__setup("nol2par", nol2parity);
1328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329/*
1330 * Some MIPS CPUs can enable/disable for cache parity detection, but do
1331 * it different ways.
1332 */
1333static inline void parity_protection_init(void)
1334{
Ralf Baechle10cc3522007-10-11 23:46:15 +01001335 switch (current_cpu_type()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 case CPU_24K:
Nigel Stephens98a41de2006-04-27 15:50:32 +01001337 case CPU_34K:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001338 case CPU_74K:
1339 case CPU_1004K:
Steven J. Hill442e14a2014-01-17 15:03:50 -06001340 case CPU_1074K:
Leonid Yegoshin26ab96d2013-11-27 10:07:53 +00001341 case CPU_INTERAPTIV:
Leonid Yegoshin708ac4b2013-11-14 16:12:27 +00001342 case CPU_PROAPTIV:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001343 {
1344#define ERRCTL_PE 0x80000000
1345#define ERRCTL_L2P 0x00800000
1346 unsigned long errctl;
1347 unsigned int l1parity_present, l2parity_present;
1348
1349 errctl = read_c0_ecc();
1350 errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
1351
1352 /* probe L1 parity support */
1353 write_c0_ecc(errctl | ERRCTL_PE);
1354 back_to_back_c0_hazard();
1355 l1parity_present = (read_c0_ecc() & ERRCTL_PE);
1356
1357 /* probe L2 parity support */
1358 write_c0_ecc(errctl|ERRCTL_L2P);
1359 back_to_back_c0_hazard();
1360 l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
1361
1362 if (l1parity_present && l2parity_present) {
1363 if (l1parity)
1364 errctl |= ERRCTL_PE;
1365 if (l1parity ^ l2parity)
1366 errctl |= ERRCTL_L2P;
1367 } else if (l1parity_present) {
1368 if (l1parity)
1369 errctl |= ERRCTL_PE;
1370 } else if (l2parity_present) {
1371 if (l2parity)
1372 errctl |= ERRCTL_L2P;
1373 } else {
1374 /* No parity available */
1375 }
1376
1377 printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
1378
1379 write_c0_ecc(errctl);
1380 back_to_back_c0_hazard();
1381 errctl = read_c0_ecc();
1382 printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
1383
1384 if (l1parity_present)
1385 printk(KERN_INFO "Cache parity protection %sabled\n",
1386 (errctl & ERRCTL_PE) ? "en" : "dis");
1387
1388 if (l2parity_present) {
1389 if (l1parity_present && l1parity)
1390 errctl ^= ERRCTL_L2P;
1391 printk(KERN_INFO "L2 cache parity protection %sabled\n",
1392 (errctl & ERRCTL_L2P) ? "en" : "dis");
1393 }
1394 }
1395 break;
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 case CPU_5KC:
Leonid Yegoshin78d48032012-07-06 21:56:01 +02001398 case CPU_5KE:
Kelvin Cheung2fa36392012-06-20 20:05:32 +01001399 case CPU_LOONGSON1:
Ralf Baechle14f18b72005-03-01 18:15:08 +00001400 write_c0_ecc(0x80000000);
1401 back_to_back_c0_hazard();
1402 /* Set the PE bit (bit 31) in the c0_errctl register. */
1403 printk(KERN_INFO "Cache parity protection %sabled\n",
1404 (read_c0_ecc() & 0x80000000) ? "en" : "dis");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 break;
1406 case CPU_20KC:
1407 case CPU_25KF:
1408 /* Clear the DE bit (bit 16) in the c0_status register. */
1409 printk(KERN_INFO "Enable cache parity protection for "
1410 "MIPS 20KC/25KF CPUs.\n");
1411 clear_c0_status(ST0_DE);
1412 break;
1413 default:
1414 break;
1415 }
1416}
1417
1418asmlinkage void cache_parity_error(void)
1419{
1420 const int field = 2 * sizeof(unsigned long);
1421 unsigned int reg_val;
1422
1423 /* For the moment, report the problem and hang. */
1424 printk("Cache error exception:\n");
1425 printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1426 reg_val = read_c0_cacheerr();
1427 printk("c0_cacheerr == %08x\n", reg_val);
1428
1429 printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1430 reg_val & (1<<30) ? "secondary" : "primary",
1431 reg_val & (1<<31) ? "data" : "insn");
Leonid Yegoshin6de20452013-10-10 09:58:59 +01001432 if (cpu_has_mips_r2 &&
1433 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1434 pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
1435 reg_val & (1<<29) ? "ED " : "",
1436 reg_val & (1<<28) ? "ET " : "",
1437 reg_val & (1<<27) ? "ES " : "",
1438 reg_val & (1<<26) ? "EE " : "",
1439 reg_val & (1<<25) ? "EB " : "",
1440 reg_val & (1<<24) ? "EI " : "",
1441 reg_val & (1<<23) ? "E1 " : "",
1442 reg_val & (1<<22) ? "E0 " : "");
1443 } else {
1444 pr_err("Error bits: %s%s%s%s%s%s%s\n",
1445 reg_val & (1<<29) ? "ED " : "",
1446 reg_val & (1<<28) ? "ET " : "",
1447 reg_val & (1<<26) ? "EE " : "",
1448 reg_val & (1<<25) ? "EB " : "",
1449 reg_val & (1<<24) ? "EI " : "",
1450 reg_val & (1<<23) ? "E1 " : "",
1451 reg_val & (1<<22) ? "E0 " : "");
1452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1454
Ralf Baechleec917c2c2005-10-07 16:58:15 +01001455#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 if (reg_val & (1<<22))
1457 printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
1458
1459 if (reg_val & (1<<23))
1460 printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
1461#endif
1462
1463 panic("Can't handle the cache error!");
1464}
1465
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +00001466asmlinkage void do_ftlb(void)
1467{
1468 const int field = 2 * sizeof(unsigned long);
1469 unsigned int reg_val;
1470
1471 /* For the moment, report the problem and hang. */
1472 if (cpu_has_mips_r2 &&
1473 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1474 pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
1475 read_c0_ecc());
1476 pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1477 reg_val = read_c0_cacheerr();
1478 pr_err("c0_cacheerr == %08x\n", reg_val);
1479
1480 if ((reg_val & 0xc0000000) == 0xc0000000) {
1481 pr_err("Decoded c0_cacheerr: FTLB parity error\n");
1482 } else {
1483 pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1484 reg_val & (1<<30) ? "secondary" : "primary",
1485 reg_val & (1<<31) ? "data" : "insn");
1486 }
1487 } else {
1488 pr_err("FTLB error exception\n");
1489 }
1490 /* Just print the cacheerr bits for now */
1491 cache_parity_error();
1492}
1493
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494/*
1495 * SDBBP EJTAG debug exception handler.
1496 * We skip the instruction and return to the next instruction.
1497 */
1498void ejtag_exception_handler(struct pt_regs *regs)
1499{
1500 const int field = 2 * sizeof(unsigned long);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001501 unsigned long depc, old_epc, old_ra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 unsigned int debug;
1503
Chris Dearman70ae6122006-06-30 12:32:37 +01001504 printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 depc = read_c0_depc();
1506 debug = read_c0_debug();
Chris Dearman70ae6122006-06-30 12:32:37 +01001507 printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 if (debug & 0x80000000) {
1509 /*
1510 * In branch delay slot.
1511 * We cheat a little bit here and use EPC to calculate the
1512 * debug return address (DEPC). EPC is restored after the
1513 * calculation.
1514 */
1515 old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001516 old_ra = regs->regs[31];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 regs->cp0_epc = depc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001518 compute_return_epc(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 depc = regs->cp0_epc;
1520 regs->cp0_epc = old_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001521 regs->regs[31] = old_ra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 } else
1523 depc += 4;
1524 write_c0_depc(depc);
1525
1526#if 0
Chris Dearman70ae6122006-06-30 12:32:37 +01001527 printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 write_c0_debug(debug | 0x100);
1529#endif
1530}
1531
1532/*
1533 * NMI exception handler.
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001534 * No lock; only written during early bootup by CPU 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 */
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001536static RAW_NOTIFIER_HEAD(nmi_chain);
1537
1538int register_nmi_notifier(struct notifier_block *nb)
1539{
1540 return raw_notifier_chain_register(&nmi_chain, nb);
1541}
1542
Joe Perchesff2d8b12012-01-12 17:17:21 -08001543void __noreturn nmi_exception_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +01001545 char str[100];
1546
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001547 raw_notifier_call_chain(&nmi_chain, 0, regs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001548 bust_spinlocks(1);
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +01001549 snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
1550 smp_processor_id(), regs->cp0_epc);
1551 regs->cp0_epc = read_c0_errorepc();
1552 die(str, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Ralf Baechlee01402b2005-07-14 15:57:16 +00001555#define VECTORSPACING 0x100 /* for EI/VI mode */
1556
1557unsigned long ebase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558unsigned long exception_handlers[32];
Ralf Baechlee01402b2005-07-14 15:57:16 +00001559unsigned long vi_handlers[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Florian Fainelli2d1b6e92010-01-28 15:21:42 +01001561void __init *set_except_vector(int n, void *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
1563 unsigned long handler = (unsigned long) addr;
Ralf Baechleb22d1b62013-05-09 17:57:30 +02001564 unsigned long old_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001566#ifdef CONFIG_CPU_MICROMIPS
1567 /*
1568 * Only the TLB handlers are cache aligned with an even
1569 * address. All other handlers are on an odd address and
1570 * require no modification. Otherwise, MIPS32 mode will
1571 * be entered when handling any TLB exceptions. That
1572 * would be bad...since we must stay in microMIPS mode.
1573 */
1574 if (!(handler & 0x1))
1575 handler |= 1;
1576#endif
Ralf Baechleb22d1b62013-05-09 17:57:30 +02001577 old_handler = xchg(&exception_handlers[n], handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 if (n == 0 && cpu_has_divec) {
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001580#ifdef CONFIG_CPU_MICROMIPS
1581 unsigned long jump_mask = ~((1 << 27) - 1);
1582#else
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001583 unsigned long jump_mask = ~((1 << 28) - 1);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001584#endif
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001585 u32 *buf = (u32 *)(ebase + 0x200);
1586 unsigned int k0 = 26;
1587 if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
1588 uasm_i_j(&buf, handler & ~jump_mask);
1589 uasm_i_nop(&buf);
1590 } else {
1591 UASM_i_LA(&buf, k0, handler);
1592 uasm_i_jr(&buf, k0);
1593 uasm_i_nop(&buf);
1594 }
1595 local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 }
1597 return (void *)old_handler;
1598}
1599
Ralf Baechle86a17082013-02-08 01:21:34 +01001600static void do_default_vi(void)
Atsushi Nemoto6ba07e52007-05-21 23:45:38 +09001601{
1602 show_regs(get_irq_regs());
1603 panic("Caught unexpected vectored interrupt.");
1604}
1605
Ralf Baechleef300e42007-05-06 18:31:18 +01001606static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001607{
1608 unsigned long handler;
1609 unsigned long old_handler = vi_handlers[n];
Ralf Baechlef6771db2007-11-08 18:02:29 +00001610 int srssets = current_cpu_data.srsets;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001611 u16 *h;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001612 unsigned char *b;
1613
Ralf Baechleb72b7092009-03-30 14:49:44 +02001614 BUG_ON(!cpu_has_veic && !cpu_has_vint);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001615
1616 if (addr == NULL) {
1617 handler = (unsigned long) do_default_vi;
1618 srs = 0;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001619 } else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001620 handler = (unsigned long) addr;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001621 vi_handlers[n] = handler;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001622
1623 b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
1624
Ralf Baechlef6771db2007-11-08 18:02:29 +00001625 if (srs >= srssets)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001626 panic("Shadow register set %d not supported", srs);
1627
1628 if (cpu_has_veic) {
1629 if (board_bind_eic_interrupt)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001630 board_bind_eic_interrupt(n, srs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001631 } else if (cpu_has_vint) {
Ralf Baechlee01402b2005-07-14 15:57:16 +00001632 /* SRSMap is only defined if shadow sets are implemented */
Ralf Baechlef6771db2007-11-08 18:02:29 +00001633 if (srssets > 1)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001634 change_c0_srsmap(0xf << n*4, srs << n*4);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001635 }
1636
1637 if (srs == 0) {
1638 /*
1639 * If no shadow set is selected then use the default handler
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001640 * that does normal register saving and standard interrupt exit
Ralf Baechlee01402b2005-07-14 15:57:16 +00001641 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001642 extern char except_vec_vi, except_vec_vi_lui;
1643 extern char except_vec_vi_ori, except_vec_vi_end;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001644 extern char rollback_except_vec_vi;
Ralf Baechlef94d9a82013-05-21 17:30:36 +02001645 char *vec_start = using_rollback_handler() ?
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001646 &rollback_except_vec_vi : &except_vec_vi;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001647#ifdef CONFIG_MIPS_MT_SMTC
1648 /*
1649 * We need to provide the SMTC vectored interrupt handler
1650 * not only with the address of the handler, but with the
1651 * Status.IM bit to be masked before going there.
1652 */
1653 extern char except_vec_vi_mori;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001654#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1655 const int mori_offset = &except_vec_vi_mori - vec_start + 2;
1656#else
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001657 const int mori_offset = &except_vec_vi_mori - vec_start;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001658#endif
Ralf Baechle41c594a2006-04-05 09:45:45 +01001659#endif /* CONFIG_MIPS_MT_SMTC */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001660#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1661 const int lui_offset = &except_vec_vi_lui - vec_start + 2;
1662 const int ori_offset = &except_vec_vi_ori - vec_start + 2;
1663#else
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001664 const int lui_offset = &except_vec_vi_lui - vec_start;
1665 const int ori_offset = &except_vec_vi_ori - vec_start;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001666#endif
1667 const int handler_len = &except_vec_vi_end - vec_start;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001668
1669 if (handler_len > VECTORSPACING) {
1670 /*
1671 * Sigh... panicing won't help as the console
1672 * is probably not configured :(
1673 */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001674 panic("VECTORSPACING too small");
Ralf Baechlee01402b2005-07-14 15:57:16 +00001675 }
1676
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001677 set_handler(((unsigned long)b - ebase), vec_start,
1678#ifdef CONFIG_CPU_MICROMIPS
1679 (handler_len - 1));
1680#else
1681 handler_len);
1682#endif
Ralf Baechle41c594a2006-04-05 09:45:45 +01001683#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle8e8a52e2007-05-31 14:00:19 +01001684 BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
1685
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001686 h = (u16 *)(b + mori_offset);
1687 *h = (0x100 << n);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001688#endif /* CONFIG_MIPS_MT_SMTC */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001689 h = (u16 *)(b + lui_offset);
1690 *h = (handler >> 16) & 0xffff;
1691 h = (u16 *)(b + ori_offset);
1692 *h = (handler & 0xffff);
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001693 local_flush_icache_range((unsigned long)b,
1694 (unsigned long)(b+handler_len));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001695 }
1696 else {
1697 /*
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001698 * In other cases jump directly to the interrupt handler. It
1699 * is the handler's responsibility to save registers if required
1700 * (eg hi/lo) and return from the exception using "eret".
Ralf Baechlee01402b2005-07-14 15:57:16 +00001701 */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001702 u32 insn;
1703
1704 h = (u16 *)b;
1705 /* j handler */
1706#ifdef CONFIG_CPU_MICROMIPS
1707 insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
1708#else
1709 insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
1710#endif
1711 h[0] = (insn >> 16) & 0xffff;
1712 h[1] = insn & 0xffff;
1713 h[2] = 0;
1714 h[3] = 0;
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001715 local_flush_icache_range((unsigned long)b,
1716 (unsigned long)(b+8));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001717 }
1718
1719 return (void *)old_handler;
1720}
1721
Ralf Baechleef300e42007-05-06 18:31:18 +01001722void *set_vi_handler(int n, vi_handler_t addr)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001723{
Ralf Baechleff3eab22006-03-29 14:12:58 +01001724 return set_vi_srs_handler(n, addr, 0);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001725}
Ralf Baechlef41ae0b2006-06-05 17:24:46 +01001726
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727extern void tlb_init(void);
1728
Ralf Baechle42f77542007-10-18 17:48:11 +01001729/*
1730 * Timer interrupt
1731 */
1732int cp0_compare_irq;
Ralf Baechle68b63522012-07-19 09:13:52 +02001733EXPORT_SYMBOL_GPL(cp0_compare_irq);
David VomLehn010c1082009-12-21 17:49:22 -08001734int cp0_compare_irq_shift;
Ralf Baechle42f77542007-10-18 17:48:11 +01001735
1736/*
1737 * Performance counter IRQ or -1 if shared with timer
1738 */
1739int cp0_perfcount_irq;
1740EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
1741
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001742static int noulri;
Chris Dearmanbdc94eb2007-10-03 10:43:56 +01001743
1744static int __init ulri_disable(char *s)
1745{
1746 pr_info("Disabling ulri\n");
1747 noulri = 1;
1748
1749 return 1;
1750}
1751__setup("noulri", ulri_disable);
1752
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001753void per_cpu_trap_init(bool is_boot_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
1755 unsigned int cpu = smp_processor_id();
1756 unsigned int status_set = ST0_CU0;
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001757 unsigned int hwrena = cpu_hwrena_impl_bits;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001758#ifdef CONFIG_MIPS_MT_SMTC
1759 int secondaryTC = 0;
1760 int bootTC = (cpu == 0);
1761
1762 /*
1763 * Only do per_cpu_trap_init() for first TC of Each VPE.
1764 * Note that this hack assumes that the SMTC init code
1765 * assigns TCs consecutively and in ascending order.
1766 */
1767
1768 if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
1769 ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
1770 secondaryTC = 1;
1771#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
1773 /*
1774 * Disable coprocessors and select 32-bit or 64-bit addressing
1775 * and the 16/32 or 32/32 FPR register model. Reset the BEV
1776 * flag that some firmware may have left set and the TS bit (for
1777 * IP27). Set XX for ISA IV code to work.
1778 */
Ralf Baechle875d43e2005-09-03 15:56:16 -07001779#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
1781#endif
Deng-Cheng Zhuadb37892013-04-01 18:14:28 +00001782 if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 status_set |= ST0_XX;
Chris Dearmanbbaf2382007-12-13 22:42:19 +00001784 if (cpu_has_dsp)
1785 status_set |= ST0_MX;
1786
Ralf Baechleb38c7392006-02-07 01:20:43 +00001787 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 -07001788 status_set);
1789
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001790 if (cpu_has_mips_r2)
1791 hwrena |= 0x0000000f;
Ralf Baechlea3692022007-07-10 17:33:02 +01001792
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001793 if (!noulri && cpu_has_userlocal)
1794 hwrena |= (1 << 29);
Ralf Baechlea3692022007-07-10 17:33:02 +01001795
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001796 if (hwrena)
1797 write_c0_hwrena(hwrena);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001798
Ralf Baechle41c594a2006-04-05 09:45:45 +01001799#ifdef CONFIG_MIPS_MT_SMTC
1800 if (!secondaryTC) {
1801#endif /* CONFIG_MIPS_MT_SMTC */
1802
Ralf Baechlee01402b2005-07-14 15:57:16 +00001803 if (cpu_has_veic || cpu_has_vint) {
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001804 unsigned long sr = set_c0_status(ST0_BEV);
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001805 write_c0_ebase(ebase);
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001806 write_c0_status(sr);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001807 /* Setting vector spacing enables EI/VI mode */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001808 change_c0_intctl(0x3e0, VECTORSPACING);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001809 }
Ralf Baechled03d0a52005-08-17 13:44:26 +00001810 if (cpu_has_divec) {
1811 if (cpu_has_mipsmt) {
1812 unsigned int vpflags = dvpe();
1813 set_c0_cause(CAUSEF_IV);
1814 evpe(vpflags);
1815 } else
1816 set_c0_cause(CAUSEF_IV);
1817 }
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001818
1819 /*
1820 * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
1821 *
1822 * o read IntCtl.IPTI to determine the timer interrupt
1823 * o read IntCtl.IPPCI to determine the performance counter interrupt
1824 */
1825 if (cpu_has_mips_r2) {
David VomLehn010c1082009-12-21 17:49:22 -08001826 cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
1827 cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
1828 cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001829 if (cp0_perfcount_irq == cp0_compare_irq)
1830 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001831 } else {
1832 cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
Ralf Baechlec6a4ebb2012-07-06 23:56:00 +02001833 cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001834 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001835 }
1836
Ralf Baechle41c594a2006-04-05 09:45:45 +01001837#ifdef CONFIG_MIPS_MT_SMTC
1838 }
1839#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
David Daney48c4ac92013-05-13 13:56:44 -07001841 if (!cpu_data[cpu].asid_cache)
1842 cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 atomic_inc(&init_mm.mm_count);
1845 current->active_mm = &init_mm;
1846 BUG_ON(current->mm);
1847 enter_lazy_tlb(&init_mm, current);
1848
Ralf Baechle41c594a2006-04-05 09:45:45 +01001849#ifdef CONFIG_MIPS_MT_SMTC
1850 if (bootTC) {
1851#endif /* CONFIG_MIPS_MT_SMTC */
David Daney6650df32012-05-15 00:04:50 -07001852 /* Boot CPU's cache setup in setup_arch(). */
1853 if (!is_boot_cpu)
1854 cpu_cache_init();
Ralf Baechle41c594a2006-04-05 09:45:45 +01001855 tlb_init();
1856#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle6a058882007-05-31 14:03:45 +01001857 } else if (!secondaryTC) {
1858 /*
1859 * First TC in non-boot VPE must do subset of tlb_init()
1860 * for MMU countrol registers.
1861 */
1862 write_c0_pagemask(PM_DEFAULT_MASK);
1863 write_c0_wired(0);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001864 }
1865#endif /* CONFIG_MIPS_MT_SMTC */
David Daney3d8bfdd2010-12-21 14:19:11 -08001866 TLBMISS_HANDLER_SETUP();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867}
1868
Ralf Baechlee01402b2005-07-14 15:57:16 +00001869/* Install CPU exception handler */
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001870void set_handler(unsigned long offset, void *addr, unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001871{
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001872#ifdef CONFIG_CPU_MICROMIPS
1873 memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
1874#else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001875 memcpy((void *)(ebase + offset), addr, size);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001876#endif
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001877 local_flush_icache_range(ebase + offset, ebase + offset + size);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001878}
1879
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001880static char panic_null_cerr[] =
Ralf Baechle641e97f2007-10-11 23:46:05 +01001881 "Trying to set NULL cache error exception handler";
1882
Ralf Baechle42fe7ee2009-01-28 18:48:23 +00001883/*
1884 * Install uncached CPU exception handler.
1885 * This is suitable only for the cache error exception which is the only
1886 * exception handler that is being run uncached.
1887 */
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001888void set_uncached_handler(unsigned long offset, void *addr,
Ralf Baechle234fcd12008-03-08 09:56:28 +00001889 unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001890{
Sebastian Andrzej Siewior4f81b012010-04-27 22:53:30 +02001891 unsigned long uncached_ebase = CKSEG1ADDR(ebase);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001892
Ralf Baechle641e97f2007-10-11 23:46:05 +01001893 if (!addr)
1894 panic(panic_null_cerr);
1895
Ralf Baechlee01402b2005-07-14 15:57:16 +00001896 memcpy((void *)(uncached_ebase + offset), addr, size);
1897}
1898
Atsushi Nemoto5b104962006-09-11 17:50:29 +09001899static int __initdata rdhwr_noopt;
1900static int __init set_rdhwr_noopt(char *str)
1901{
1902 rdhwr_noopt = 1;
1903 return 1;
1904}
1905
1906__setup("rdhwr_noopt", set_rdhwr_noopt);
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908void __init trap_init(void)
1909{
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001910 extern char except_vec3_generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 extern char except_vec4;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001912 extern char except_vec3_r4000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 unsigned long i;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001914
1915 check_wait();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
Jason Wessel88547002008-07-29 15:58:53 -05001917#if defined(CONFIG_KGDB)
1918 if (kgdb_early_setup)
Ralf Baechle70342282013-01-22 12:59:30 +01001919 return; /* Already done */
Jason Wessel88547002008-07-29 15:58:53 -05001920#endif
1921
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001922 if (cpu_has_veic || cpu_has_vint) {
1923 unsigned long size = 0x200 + VECTORSPACING*64;
1924 ebase = (unsigned long)
1925 __alloc_bootmem(size, 1 << fls(size), 0);
1926 } else {
Sanjay Lal9843b032012-11-21 18:34:03 -08001927#ifdef CONFIG_KVM_GUEST
1928#define KVM_GUEST_KSEG0 0x40000000
1929 ebase = KVM_GUEST_KSEG0;
1930#else
1931 ebase = CKSEG0;
1932#endif
David Daney566f74f2008-10-23 17:56:35 -07001933 if (cpu_has_mips_r2)
1934 ebase += (read_c0_ebase() & 0x3ffff000);
1935 }
Ralf Baechlee01402b2005-07-14 15:57:16 +00001936
Steven J. Hillc6213c62013-06-05 21:25:17 +00001937 if (cpu_has_mmips) {
1938 unsigned int config3 = read_c0_config3();
1939
1940 if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
1941 write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
1942 else
1943 write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
1944 }
1945
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +00001946 if (board_ebase_setup)
1947 board_ebase_setup();
David Daney6650df32012-05-15 00:04:50 -07001948 per_cpu_trap_init(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
1950 /*
1951 * Copy the generic exception handlers to their final destination.
1952 * This will be overriden later as suitable for a particular
1953 * configuration.
1954 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001955 set_handler(0x180, &except_vec3_generic, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
1957 /*
1958 * Setup default vectors
1959 */
1960 for (i = 0; i <= 31; i++)
1961 set_except_vector(i, handle_reserved);
1962
1963 /*
1964 * Copy the EJTAG debug exception vector handler code to it's final
1965 * destination.
1966 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001967 if (cpu_has_ejtag && board_ejtag_handler_setup)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001968 board_ejtag_handler_setup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
1970 /*
1971 * Only some CPUs have the watch exceptions.
1972 */
1973 if (cpu_has_watch)
1974 set_except_vector(23, handle_watch);
1975
1976 /*
Ralf Baechlee01402b2005-07-14 15:57:16 +00001977 * Initialise interrupt handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001979 if (cpu_has_veic || cpu_has_vint) {
1980 int nvec = cpu_has_veic ? 64 : 8;
1981 for (i = 0; i < nvec; i++)
Ralf Baechleff3eab22006-03-29 14:12:58 +01001982 set_vi_handler(i, NULL);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001983 }
1984 else if (cpu_has_divec)
1985 set_handler(0x200, &except_vec4, 0x8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 /*
1988 * Some CPUs can enable/disable for cache parity detection, but does
1989 * it different ways.
1990 */
1991 parity_protection_init();
1992
1993 /*
1994 * The Data Bus Errors / Instruction Bus Errors are signaled
1995 * by external hardware. Therefore these two exceptions
1996 * may have board specific handlers.
1997 */
1998 if (board_be_init)
1999 board_be_init();
2000
Ralf Baechlef94d9a82013-05-21 17:30:36 +02002001 set_except_vector(0, using_rollback_handler() ? rollback_handle_int
2002 : handle_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 set_except_vector(1, handle_tlbm);
2004 set_except_vector(2, handle_tlbl);
2005 set_except_vector(3, handle_tlbs);
2006
2007 set_except_vector(4, handle_adel);
2008 set_except_vector(5, handle_ades);
2009
2010 set_except_vector(6, handle_ibe);
2011 set_except_vector(7, handle_dbe);
2012
2013 set_except_vector(8, handle_sys);
2014 set_except_vector(9, handle_bp);
Atsushi Nemoto5b104962006-09-11 17:50:29 +09002015 set_except_vector(10, rdhwr_noopt ? handle_ri :
2016 (cpu_has_vtag_icache ?
2017 handle_ri_rdhwr_vivt : handle_ri_rdhwr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 set_except_vector(11, handle_cpu);
2019 set_except_vector(12, handle_ov);
2020 set_except_vector(13, handle_tr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Ralf Baechle10cc3522007-10-11 23:46:15 +01002022 if (current_cpu_type() == CPU_R6000 ||
2023 current_cpu_type() == CPU_R6000A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 /*
2025 * The R6000 is the only R-series CPU that features a machine
2026 * check exception (similar to the R4000 cache error) and
2027 * unaligned ldc1/sdc1 exception. The handlers have not been
Ralf Baechle70342282013-01-22 12:59:30 +01002028 * written yet. Well, anyway there is no R6000 machine on the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 * current list of targets for Linux/MIPS.
2030 * (Duh, crap, there is someone with a triple R6k machine)
2031 */
2032 //set_except_vector(14, handle_mc);
2033 //set_except_vector(15, handle_ndc);
2034 }
2035
Ralf Baechlee01402b2005-07-14 15:57:16 +00002036
2037 if (board_nmi_handler_setup)
2038 board_nmi_handler_setup();
2039
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002040 if (cpu_has_fpu && !cpu_has_nofpuex)
2041 set_except_vector(15, handle_fpe);
2042
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +00002043 set_except_vector(16, handle_ftlb);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002044 set_except_vector(22, handle_mdmx);
2045
2046 if (cpu_has_mcheck)
2047 set_except_vector(24, handle_mcheck);
2048
Ralf Baechle340ee4b2005-08-17 17:44:08 +00002049 if (cpu_has_mipsmt)
2050 set_except_vector(25, handle_mt);
2051
Chris Dearmanacaec422007-05-24 22:30:18 +01002052 set_except_vector(26, handle_dsp);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002053
David Daneyfcbf1df2012-05-15 00:04:46 -07002054 if (board_cache_error_setup)
2055 board_cache_error_setup();
2056
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002057 if (cpu_has_vce)
2058 /* Special exception: R4[04]00 uses also the divec space. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002059 set_handler(0x180, &except_vec3_r4000, 0x100);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002060 else if (cpu_has_4kex)
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002061 set_handler(0x180, &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002062 else
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002063 set_handler(0x080, &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002064
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02002065 local_flush_icache_range(ebase, ebase + 0x400);
Thomas Bogendoerfer05106172008-08-04 19:44:34 +02002066
2067 sort_extable(__start___dbe_table, __stop___dbe_table);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00002068
Ralf Baechle4483b152010-08-05 13:25:59 +01002069 cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}