blob: 4f27cbfad1e57d4cc93aa4efb09eb56a92664ad3 [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>
Paul Burton1db1af82014-01-27 15:23:11 +000050#include <asm/msa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/pgtable.h>
52#include <asm/ptrace.h>
53#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <asm/tlbdebug.h>
55#include <asm/traps.h>
56#include <asm/uaccess.h>
David Daneyb67b2b72008-09-23 00:08:45 -070057#include <asm/watch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <asm/types.h>
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090060#include <asm/stacktrace.h>
Florian Fainelli92bbe1b2010-01-28 15:22:37 +010061#include <asm/uasm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Atsushi Nemotoc65a5482007-11-12 02:05:18 +090063extern void check_wait(void);
Atsushi Nemotoc65a5482007-11-12 02:05:18 +090064extern asmlinkage void rollback_handle_int(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010065extern asmlinkage void handle_int(void);
Ralf Baechle86a17082013-02-08 01:21:34 +010066extern u32 handle_tlbl[];
67extern u32 handle_tlbs[];
68extern u32 handle_tlbm[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern asmlinkage void handle_adel(void);
70extern asmlinkage void handle_ades(void);
71extern asmlinkage void handle_ibe(void);
72extern asmlinkage void handle_dbe(void);
73extern asmlinkage void handle_sys(void);
74extern asmlinkage void handle_bp(void);
75extern asmlinkage void handle_ri(void);
Atsushi Nemoto5b104962006-09-11 17:50:29 +090076extern asmlinkage void handle_ri_rdhwr_vivt(void);
77extern asmlinkage void handle_ri_rdhwr(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern asmlinkage void handle_cpu(void);
79extern asmlinkage void handle_ov(void);
80extern asmlinkage void handle_tr(void);
81extern asmlinkage void handle_fpe(void);
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +000082extern asmlinkage void handle_ftlb(void);
Paul Burton1db1af82014-01-27 15:23:11 +000083extern asmlinkage void handle_msa(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern asmlinkage void handle_mdmx(void);
85extern asmlinkage void handle_watch(void);
Ralf Baechle340ee4b2005-08-17 17:44:08 +000086extern asmlinkage void handle_mt(void);
Ralf Baechlee50c0a82005-05-31 11:49:19 +000087extern asmlinkage void handle_dsp(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern asmlinkage void handle_mcheck(void);
89extern asmlinkage void handle_reserved(void);
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091void (*board_be_init)(void);
92int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
Ralf Baechlee01402b2005-07-14 15:57:16 +000093void (*board_nmi_handler_setup)(void);
94void (*board_ejtag_handler_setup)(void);
95void (*board_bind_eic_interrupt)(int irq, int regset);
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +000096void (*board_ebase_setup)(void);
Paul Gortmaker078a55f2013-06-18 13:38:59 +000097void(*board_cache_error_setup)(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Franck Bui-Huu4d157d52006-08-03 09:29:21 +020099static void show_raw_backtrace(unsigned long reg29)
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900100{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100101 unsigned long *sp = (unsigned long *)(reg29 & ~3);
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900102 unsigned long addr;
103
104 printk("Call Trace:");
105#ifdef CONFIG_KALLSYMS
106 printk("\n");
107#endif
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200108 while (!kstack_end(sp)) {
109 unsigned long __user *p =
110 (unsigned long __user *)(unsigned long)sp++;
111 if (__get_user(addr, p)) {
112 printk(" (Bad stack address)");
113 break;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100114 }
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200115 if (__kernel_text_address(addr))
116 print_ip_sym(addr);
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900117 }
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200118 printk("\n");
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900119}
120
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900121#ifdef CONFIG_KALLSYMS
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +0900122int raw_show_trace;
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900123static int __init set_raw_show_trace(char *str)
124{
125 raw_show_trace = 1;
126 return 1;
127}
128__setup("raw_show_trace", set_raw_show_trace);
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +0900129#endif
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200130
Ralf Baechleeae23f22007-10-14 23:27:21 +0100131static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900132{
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200133 unsigned long sp = regs->regs[29];
134 unsigned long ra = regs->regs[31];
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900135 unsigned long pc = regs->cp0_epc;
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900136
Vincent Wene909be82012-07-19 09:11:16 +0200137 if (!task)
138 task = current;
139
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900140 if (raw_show_trace || !__kernel_text_address(pc)) {
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200141 show_raw_backtrace(sp);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900142 return;
143 }
144 printk("Call Trace:\n");
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200145 do {
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200146 print_ip_sym(pc);
Atsushi Nemoto19246002006-09-29 18:02:51 +0900147 pc = unwind_stack(task, &sp, pc, &ra);
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200148 } while (pc);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900149 printk("\n");
150}
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*
153 * This routine abuses get_user()/put_user() to reference pointers
154 * with at least a bit of error checking ...
155 */
Ralf Baechleeae23f22007-10-14 23:27:21 +0100156static void show_stacktrace(struct task_struct *task,
157 const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 const int field = 2 * sizeof(unsigned long);
160 long stackdata;
161 int i;
Atsushi Nemoto5e0373b2007-07-13 23:02:42 +0900162 unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 printk("Stack :");
165 i = 0;
166 while ((unsigned long) sp & (PAGE_SIZE - 1)) {
167 if (i && ((i % (64 / field)) == 0))
Ralf Baechle70342282013-01-22 12:59:30 +0100168 printk("\n ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 if (i > 39) {
170 printk(" ...");
171 break;
172 }
173
174 if (__get_user(stackdata, sp++)) {
175 printk(" (Bad stack address)");
176 break;
177 }
178
179 printk(" %0*lx", field, stackdata);
180 i++;
181 }
182 printk("\n");
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200183 show_backtrace(task, regs);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900184}
185
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900186void show_stack(struct task_struct *task, unsigned long *sp)
187{
188 struct pt_regs regs;
189 if (sp) {
190 regs.regs[29] = (unsigned long)sp;
191 regs.regs[31] = 0;
192 regs.cp0_epc = 0;
193 } else {
194 if (task && task != current) {
195 regs.regs[29] = task->thread.reg29;
196 regs.regs[31] = 0;
197 regs.cp0_epc = task->thread.reg31;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500198#ifdef CONFIG_KGDB_KDB
199 } else if (atomic_read(&kgdb_active) != -1 &&
200 kdb_current_regs) {
201 memcpy(&regs, kdb_current_regs, sizeof(regs));
202#endif /* CONFIG_KGDB_KDB */
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900203 } else {
204 prepare_frametrace(&regs);
205 }
206 }
207 show_stacktrace(task, &regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900210static void show_code(unsigned int __user *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 long i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100213 unsigned short __user *pc16 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 printk("\nCode:");
216
Ralf Baechle39b8d522008-04-28 17:14:26 +0100217 if ((unsigned long)pc & 1)
218 pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 for(i = -3 ; i < 6 ; i++) {
220 unsigned int insn;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100221 if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 printk(" (Bad address in epc)\n");
223 break;
224 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100225 printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227}
228
Ralf Baechleeae23f22007-10-14 23:27:21 +0100229static void __show_regs(const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 const int field = 2 * sizeof(unsigned long);
232 unsigned int cause = regs->cp0_cause;
233 int i;
234
Tejun Heoa43cb952013-04-30 15:27:17 -0700235 show_regs_print_info(KERN_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 /*
238 * Saved main processor registers
239 */
240 for (i = 0; i < 32; ) {
241 if ((i % 4) == 0)
242 printk("$%2d :", i);
243 if (i == 0)
244 printk(" %0*lx", field, 0UL);
245 else if (i == 26 || i == 27)
246 printk(" %*s", field, "");
247 else
248 printk(" %0*lx", field, regs->regs[i]);
249
250 i++;
251 if ((i % 4) == 0)
252 printk("\n");
253 }
254
Franck Bui-Huu9693a852007-02-02 17:41:47 +0100255#ifdef CONFIG_CPU_HAS_SMARTMIPS
256 printk("Acx : %0*lx\n", field, regs->acx);
257#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 printk("Hi : %0*lx\n", field, regs->hi);
259 printk("Lo : %0*lx\n", field, regs->lo);
260
261 /*
262 * Saved cp0 registers
263 */
Ralf Baechleb012cff2008-07-15 18:44:33 +0100264 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
265 (void *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 printk(" %s\n", print_tainted());
Ralf Baechleb012cff2008-07-15 18:44:33 +0100267 printk("ra : %0*lx %pS\n", field, regs->regs[31],
268 (void *) regs->regs[31]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Ralf Baechle70342282013-01-22 12:59:30 +0100270 printk("Status: %08x ", (uint32_t) regs->cp0_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Ralf Baechle1990e542013-06-26 17:06:34 +0200272 if (cpu_has_3kex) {
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000273 if (regs->cp0_status & ST0_KUO)
274 printk("KUo ");
275 if (regs->cp0_status & ST0_IEO)
276 printk("IEo ");
277 if (regs->cp0_status & ST0_KUP)
278 printk("KUp ");
279 if (regs->cp0_status & ST0_IEP)
280 printk("IEp ");
281 if (regs->cp0_status & ST0_KUC)
282 printk("KUc ");
283 if (regs->cp0_status & ST0_IEC)
284 printk("IEc ");
Ralf Baechle1990e542013-06-26 17:06:34 +0200285 } else if (cpu_has_4kex) {
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000286 if (regs->cp0_status & ST0_KX)
287 printk("KX ");
288 if (regs->cp0_status & ST0_SX)
289 printk("SX ");
290 if (regs->cp0_status & ST0_UX)
291 printk("UX ");
292 switch (regs->cp0_status & ST0_KSU) {
293 case KSU_USER:
294 printk("USER ");
295 break;
296 case KSU_SUPERVISOR:
297 printk("SUPERVISOR ");
298 break;
299 case KSU_KERNEL:
300 printk("KERNEL ");
301 break;
302 default:
303 printk("BAD_MODE ");
304 break;
305 }
306 if (regs->cp0_status & ST0_ERL)
307 printk("ERL ");
308 if (regs->cp0_status & ST0_EXL)
309 printk("EXL ");
310 if (regs->cp0_status & ST0_IE)
311 printk("IE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 printk("\n");
314
315 printk("Cause : %08x\n", cause);
316
317 cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
318 if (1 <= cause && cause <= 5)
319 printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
320
Ralf Baechle9966db252007-10-11 23:46:17 +0100321 printk("PrId : %08x (%s)\n", read_c0_prid(),
322 cpu_name_string());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323}
324
Ralf Baechleeae23f22007-10-14 23:27:21 +0100325/*
326 * FIXME: really the generic show_regs should take a const pointer argument.
327 */
328void show_regs(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Ralf Baechleeae23f22007-10-14 23:27:21 +0100330 __show_regs((struct pt_regs *)regs);
331}
332
David Daneyc1bf2072010-08-03 11:22:20 -0700333void show_registers(struct pt_regs *regs)
Ralf Baechleeae23f22007-10-14 23:27:21 +0100334{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100335 const int field = 2 * sizeof(unsigned long);
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100336 mm_segment_t old_fs = get_fs();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100337
Ralf Baechleeae23f22007-10-14 23:27:21 +0100338 __show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 print_modules();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100340 printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
341 current->comm, current->pid, current_thread_info(), current,
342 field, current_thread_info()->tp_value);
343 if (cpu_has_userlocal) {
344 unsigned long tls;
345
346 tls = read_c0_userlocal();
347 if (tls != current_thread_info()->tp_value)
348 printk("*HwTLS: %0*lx\n", field, tls);
349 }
350
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100351 if (!user_mode(regs))
352 /* Necessary for getting the correct stack content */
353 set_fs(KERNEL_DS);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900354 show_stacktrace(current, regs);
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900355 show_code((unsigned int __user *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 printk("\n");
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100357 set_fs(old_fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
David Daney70dc6f02010-08-03 15:44:43 -0700360static int regs_to_trapnr(struct pt_regs *regs)
361{
362 return (regs->cp0_cause >> 2) & 0x1f;
363}
364
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000365static DEFINE_RAW_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
David Daney70dc6f02010-08-03 15:44:43 -0700367void __noreturn die(const char *str, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 static int die_counter;
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400370 int sig = SIGSEGV;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100371#ifdef CONFIG_MIPS_MT_SMTC
Nathan Lynch8742cd22011-09-30 13:49:35 -0500372 unsigned long dvpret;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100373#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Nathan Lynch8742cd22011-09-30 13:49:35 -0500375 oops_enter();
376
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200377 if (notify_die(DIE_OOPS, str, regs, 0, regs_to_trapnr(regs),
378 SIGSEGV) == NOTIFY_STOP)
Ralf Baechle10423c92011-05-13 10:33:28 +0100379 sig = 0;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 console_verbose();
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000382 raw_spin_lock_irq(&die_lock);
Nathan Lynch8742cd22011-09-30 13:49:35 -0500383#ifdef CONFIG_MIPS_MT_SMTC
384 dvpret = dvpe();
385#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100386 bust_spinlocks(1);
387#ifdef CONFIG_MIPS_MT_SMTC
388 mips_mt_regdump(dvpret);
389#endif /* CONFIG_MIPS_MT_SMTC */
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400390
Ralf Baechle178086c2005-10-13 17:07:54 +0100391 printk("%s[#%d]:\n", str, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 show_registers(regs);
Rusty Russell373d4d02013-01-21 17:17:39 +1030393 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000394 raw_spin_unlock_irq(&die_lock);
Maxime Bizond4fd1982006-07-20 18:52:02 +0200395
Nathan Lynch8742cd22011-09-30 13:49:35 -0500396 oops_exit();
397
Maxime Bizond4fd1982006-07-20 18:52:02 +0200398 if (in_interrupt())
399 panic("Fatal exception in interrupt");
400
401 if (panic_on_oops) {
Ralf Baechleab75dc02011-11-17 15:07:31 +0000402 printk(KERN_EMERG "Fatal exception: panic in 5 seconds");
Maxime Bizond4fd1982006-07-20 18:52:02 +0200403 ssleep(5);
404 panic("Fatal exception");
405 }
406
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +0200407 if (regs && kexec_should_crash(current))
408 crash_kexec(regs);
409
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400410 do_exit(sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
Thomas Bogendoerfer05106172008-08-04 19:44:34 +0200413extern struct exception_table_entry __start___dbe_table[];
414extern struct exception_table_entry __stop___dbe_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Ralf Baechleb6dcec92007-02-18 15:57:09 +0000416__asm__(
417" .section __dbe_table, \"a\"\n"
418" .previous \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420/* Given an address, look for it in the exception tables. */
421static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
422{
423 const struct exception_table_entry *e;
424
425 e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
426 if (!e)
427 e = search_module_dbetables(addr);
428 return e;
429}
430
431asmlinkage void do_be(struct pt_regs *regs)
432{
433 const int field = 2 * sizeof(unsigned long);
434 const struct exception_table_entry *fixup = NULL;
435 int data = regs->cp0_cause & 4;
436 int action = MIPS_BE_FATAL;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200437 enum ctx_state prev_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200439 prev_state = exception_enter();
Ralf Baechle70342282013-01-22 12:59:30 +0100440 /* XXX For now. Fixme, this searches the wrong table ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 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:
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200452 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 case MIPS_BE_FIXUP:
454 if (fixup) {
455 regs->cp0_epc = fixup->nextinsn;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200456 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
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]);
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200469 if (notify_die(DIE_OOPS, "bus error", regs, 0, regs_to_trapnr(regs),
470 SIGBUS) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200471 goto out;
Jason Wessel88547002008-07-29 15:58:53 -0500472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 die_if_kernel("Oops", regs);
474 force_sig(SIGBUS, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200475
476out:
477 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480/*
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100481 * ll/sc, rdhwr, sync emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 */
483
484#define OPCODE 0xfc000000
485#define BASE 0x03e00000
486#define RT 0x001f0000
487#define OFFSET 0x0000ffff
488#define LL 0xc0000000
489#define SC 0xe0000000
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100490#define SPEC0 0x00000000
Ralf Baechle3c370262005-04-13 17:43:59 +0000491#define SPEC3 0x7c000000
492#define RD 0x0000f800
493#define FUNC 0x0000003f
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100494#define SYNC 0x0000000f
Ralf Baechle3c370262005-04-13 17:43:59 +0000495#define RDHWR 0x0000003b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500497/* microMIPS definitions */
498#define MM_POOL32A_FUNC 0xfc00ffff
499#define MM_RDHWR 0x00006b3c
500#define MM_RS 0x001f0000
501#define MM_RT 0x03e00000
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503/*
504 * The ll_bit is cleared by r*_switch.S
505 */
506
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200507unsigned int ll_bit;
508struct task_struct *ll_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100510static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000512 unsigned long value, __user *vaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 /*
516 * analyse the ll instruction that just caused a ri exception
517 * and put the referenced address to addr.
518 */
519
520 /* sign extend offset */
521 offset = opcode & OFFSET;
522 offset <<= 16;
523 offset >>= 16;
524
Ralf Baechlefe00f942005-03-01 19:22:29 +0000525 vaddr = (unsigned long __user *)
Steven J. Hillb9688312013-01-12 23:29:27 +0000526 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100528 if ((unsigned long)vaddr & 3)
529 return SIGBUS;
530 if (get_user(value, vaddr))
531 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 preempt_disable();
534
535 if (ll_task == NULL || ll_task == current) {
536 ll_bit = 1;
537 } else {
538 ll_bit = 0;
539 }
540 ll_task = current;
541
542 preempt_enable();
543
544 regs->regs[(opcode & RT) >> 16] = value;
545
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100546 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
548
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100549static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000551 unsigned long __user *vaddr;
552 unsigned long reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 /*
556 * analyse the sc instruction that just caused a ri exception
557 * and put the referenced address to addr.
558 */
559
560 /* sign extend offset */
561 offset = opcode & OFFSET;
562 offset <<= 16;
563 offset >>= 16;
564
Ralf Baechlefe00f942005-03-01 19:22:29 +0000565 vaddr = (unsigned long __user *)
Steven J. Hillb9688312013-01-12 23:29:27 +0000566 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 reg = (opcode & RT) >> 16;
568
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100569 if ((unsigned long)vaddr & 3)
570 return SIGBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 preempt_disable();
573
574 if (ll_bit == 0 || ll_task != current) {
575 regs->regs[reg] = 0;
576 preempt_enable();
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100577 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579
580 preempt_enable();
581
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100582 if (put_user(regs->regs[reg], vaddr))
583 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 regs->regs[reg] = 1;
586
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100587 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
590/*
591 * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
592 * opcodes are supposed to result in coprocessor unusable exceptions if
593 * executed on ll/sc-less processors. That's the theory. In practice a
594 * few processors such as NEC's VR4100 throw reserved instruction exceptions
595 * instead, so we're doing the emulation thing in both exception handlers.
596 */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100597static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800599 if ((opcode & OPCODE) == LL) {
600 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200601 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100602 return simulate_ll(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800603 }
604 if ((opcode & OPCODE) == SC) {
605 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200606 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100607 return simulate_sc(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100610 return -1; /* Must be something else ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
612
Ralf Baechle3c370262005-04-13 17:43:59 +0000613/*
614 * Simulate trapping 'rdhwr' instructions to provide user accessible
Chris Dearman1f5826b2006-05-08 18:02:16 +0100615 * registers not implemented in hardware.
Ralf Baechle3c370262005-04-13 17:43:59 +0000616 */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500617static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
Ralf Baechle3c370262005-04-13 17:43:59 +0000618{
Al Virodc8f6022006-01-12 01:06:07 -0800619 struct thread_info *ti = task_thread_info(current);
Ralf Baechle3c370262005-04-13 17:43:59 +0000620
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500621 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
622 1, regs, 0);
623 switch (rd) {
624 case 0: /* CPU number */
625 regs->regs[rt] = smp_processor_id();
626 return 0;
627 case 1: /* SYNCI length */
628 regs->regs[rt] = min(current_cpu_data.dcache.linesz,
629 current_cpu_data.icache.linesz);
630 return 0;
631 case 2: /* Read count register */
632 regs->regs[rt] = read_c0_count();
633 return 0;
634 case 3: /* Count register resolution */
Ralf Baechle69f24d12013-09-17 10:25:47 +0200635 switch (current_cpu_type()) {
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500636 case CPU_20KC:
637 case CPU_25KF:
638 regs->regs[rt] = 1;
639 break;
640 default:
641 regs->regs[rt] = 2;
642 }
643 return 0;
644 case 29:
645 regs->regs[rt] = ti->tp_value;
646 return 0;
647 default:
648 return -1;
649 }
650}
651
652static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
653{
Ralf Baechle3c370262005-04-13 17:43:59 +0000654 if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
655 int rd = (opcode & RD) >> 11;
656 int rt = (opcode & RT) >> 16;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500657
658 simulate_rdhwr(regs, rd, rt);
659 return 0;
660 }
661
662 /* Not ours. */
663 return -1;
664}
665
666static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned short opcode)
667{
668 if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
669 int rd = (opcode & MM_RS) >> 16;
670 int rt = (opcode & MM_RT) >> 21;
671 simulate_rdhwr(regs, rd, rt);
672 return 0;
Ralf Baechle3c370262005-04-13 17:43:59 +0000673 }
674
Daniel Jacobowitz56ebd512005-11-26 22:34:41 -0500675 /* Not ours. */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100676 return -1;
677}
Ralf Baechlee5679882006-11-30 01:14:47 +0000678
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100679static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
680{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800681 if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
682 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200683 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100684 return 0;
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800685 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100686
687 return -1; /* Must be something else ... */
Ralf Baechle3c370262005-04-13 17:43:59 +0000688}
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690asmlinkage void do_ov(struct pt_regs *regs)
691{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200692 enum ctx_state prev_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 siginfo_t info;
694
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200695 prev_state = exception_enter();
Ralf Baechle36ccf1c2006-02-14 21:04:54 +0000696 die_if_kernel("Integer overflow", regs);
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 info.si_code = FPE_INTOVF;
699 info.si_signo = SIGFPE;
700 info.si_errno = 0;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000701 info.si_addr = (void __user *) regs->cp0_epc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 force_sig_info(SIGFPE, &info, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200703 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
705
Leonid Yegoshin102cedc2013-03-25 12:09:02 -0500706int process_fpemu_return(int sig, void __user *fault_addr)
David Daney515b0292010-10-21 16:32:26 -0700707{
708 if (sig == SIGSEGV || sig == SIGBUS) {
709 struct siginfo si = {0};
710 si.si_addr = fault_addr;
711 si.si_signo = sig;
712 if (sig == SIGSEGV) {
713 if (find_vma(current->mm, (unsigned long)fault_addr))
714 si.si_code = SEGV_ACCERR;
715 else
716 si.si_code = SEGV_MAPERR;
717 } else {
718 si.si_code = BUS_ADRERR;
719 }
720 force_sig_info(sig, &si, current);
721 return 1;
722 } else if (sig) {
723 force_sig(sig, current);
724 return 1;
725 } else {
726 return 0;
727 }
728}
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/*
731 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
732 */
733asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
734{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200735 enum ctx_state prev_state;
David Daney515b0292010-10-21 16:32:26 -0700736 siginfo_t info = {0};
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100737
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200738 prev_state = exception_enter();
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200739 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs),
740 SIGFPE) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200741 goto out;
Chris Dearman57725f92006-06-30 23:35:28 +0100742 die_if_kernel("FP exception in kernel code", regs);
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 if (fcr31 & FPU_CSR_UNI_X) {
745 int sig;
David Daney515b0292010-10-21 16:32:26 -0700746 void __user *fault_addr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000749 * Unimplemented operation exception. If we've got the full
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 * software emulator on-board, let's use it...
751 *
752 * Force FPU to dump state into task/thread context. We're
753 * moving a lot of data here for what is probably a single
754 * instruction, but the alternative is to pre-decode the FP
755 * register operands before invoking the emulator, which seems
756 * a bit extreme for what should be an infrequent event.
757 */
Ralf Baechlecd21dfc2005-04-28 13:39:10 +0000758 /* Ensure 'resume' not overwrite saved fp context again. */
Atsushi Nemoto53dc8022007-03-10 01:07:45 +0900759 lose_fpu(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /* Run the emulator */
David Daney515b0292010-10-21 16:32:26 -0700762 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
763 &fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /*
766 * We can't allow the emulated instruction to leave any of
767 * the cause bit set in $fcr31.
768 */
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900769 current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 /* Restore the hardware register state */
Ralf Baechle70342282013-01-22 12:59:30 +0100772 own_fpu(1); /* Using the FPU again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 /* If something went wrong, signal */
David Daney515b0292010-10-21 16:32:26 -0700775 process_fpemu_return(sig, fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200777 goto out;
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100778 } else if (fcr31 & FPU_CSR_INV_X)
779 info.si_code = FPE_FLTINV;
780 else if (fcr31 & FPU_CSR_DIV_X)
781 info.si_code = FPE_FLTDIV;
782 else if (fcr31 & FPU_CSR_OVF_X)
783 info.si_code = FPE_FLTOVF;
784 else if (fcr31 & FPU_CSR_UDF_X)
785 info.si_code = FPE_FLTUND;
786 else if (fcr31 & FPU_CSR_INE_X)
787 info.si_code = FPE_FLTRES;
788 else
789 info.si_code = __SI_FAULT;
790 info.si_signo = SIGFPE;
791 info.si_errno = 0;
792 info.si_addr = (void __user *) regs->cp0_epc;
793 force_sig_info(SIGFPE, &info, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200794
795out:
796 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
Ralf Baechledf270052008-04-20 16:28:54 +0100799static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
800 const char *str)
801{
802 siginfo_t info;
803 char b[40];
804
Jason Wessel5dd11d52010-05-20 21:04:26 -0500805#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
David Daney70dc6f02010-08-03 15:44:43 -0700806 if (kgdb_ll_trap(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Jason Wessel5dd11d52010-05-20 21:04:26 -0500807 return;
808#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
809
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200810 if (notify_die(DIE_TRAP, str, regs, code, regs_to_trapnr(regs),
811 SIGTRAP) == NOTIFY_STOP)
Jason Wessel88547002008-07-29 15:58:53 -0500812 return;
813
Ralf Baechledf270052008-04-20 16:28:54 +0100814 /*
815 * A short test says that IRIX 5.3 sends SIGTRAP for all trap
816 * insns, even for trap and break codes that indicate arithmetic
817 * failures. Weird ...
818 * But should we continue the brokenness??? --macro
819 */
820 switch (code) {
821 case BRK_OVERFLOW:
822 case BRK_DIVZERO:
823 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
824 die_if_kernel(b, regs);
825 if (code == BRK_DIVZERO)
826 info.si_code = FPE_INTDIV;
827 else
828 info.si_code = FPE_INTOVF;
829 info.si_signo = SIGFPE;
830 info.si_errno = 0;
831 info.si_addr = (void __user *) regs->cp0_epc;
832 force_sig_info(SIGFPE, &info, current);
833 break;
834 case BRK_BUG:
835 die_if_kernel("Kernel bug detected", regs);
836 force_sig(SIGTRAP, current);
837 break;
Ralf Baechleba3049e2008-10-28 17:38:42 +0000838 case BRK_MEMU:
839 /*
840 * Address errors may be deliberately induced by the FPU
841 * emulator to retake control of the CPU after executing the
842 * instruction in the delay slot of an emulated branch.
843 *
844 * Terminate if exception was recognized as a delay slot return
845 * otherwise handle as normal.
846 */
847 if (do_dsemulret(regs))
848 return;
849
850 die_if_kernel("Math emu break/trap", regs);
851 force_sig(SIGTRAP, current);
852 break;
Ralf Baechledf270052008-04-20 16:28:54 +0100853 default:
854 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
855 die_if_kernel(b, regs);
856 force_sig(SIGTRAP, current);
857 }
858}
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860asmlinkage void do_bp(struct pt_regs *regs)
861{
862 unsigned int opcode, bcode;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200863 enum ctx_state prev_state;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500864 unsigned long epc;
865 u16 instr[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200867 prev_state = exception_enter();
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500868 if (get_isa16_mode(regs->cp0_epc)) {
869 /* Calculate EPC. */
870 epc = exception_epc(regs);
871 if (cpu_has_mmips) {
872 if ((__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)) ||
873 (__get_user(instr[1], (u16 __user *)msk_isa16_mode(epc + 2)))))
874 goto out_sigsegv;
875 opcode = (instr[0] << 16) | instr[1];
876 } else {
877 /* MIPS16e mode */
878 if (__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)))
879 goto out_sigsegv;
880 bcode = (instr[0] >> 6) & 0x3f;
881 do_trap_or_bp(regs, bcode, "Break");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200882 goto out;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500883 }
884 } else {
885 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
886 goto out_sigsegv;
887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 /*
890 * There is the ancient bug in the MIPS assemblers that the break
891 * code starts left to bit 16 instead to bit 6 in the opcode.
892 * Gas is bug-compatible, but not always, grrr...
893 * We handle both cases with a simple heuristics. --macro
894 */
895 bcode = ((opcode >> 6) & ((1 << 20) - 1));
Ralf Baechledf270052008-04-20 16:28:54 +0100896 if (bcode >= (1 << 10))
897 bcode >>= 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
David Daneyc1bf2072010-08-03 11:22:20 -0700899 /*
900 * notify the kprobe handlers, if instruction is likely to
901 * pertain to them.
902 */
903 switch (bcode) {
904 case BRK_KPROBE_BP:
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200905 if (notify_die(DIE_BREAK, "debug", regs, bcode,
906 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200907 goto out;
David Daneyc1bf2072010-08-03 11:22:20 -0700908 else
909 break;
910 case BRK_KPROBE_SSTEPBP:
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200911 if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
912 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200913 goto out;
David Daneyc1bf2072010-08-03 11:22:20 -0700914 else
915 break;
916 default:
917 break;
918 }
919
Ralf Baechledf270052008-04-20 16:28:54 +0100920 do_trap_or_bp(regs, bcode, "Break");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200921
922out:
923 exception_exit(prev_state);
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900924 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000925
926out_sigsegv:
927 force_sig(SIGSEGV, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200928 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
931asmlinkage void do_tr(struct pt_regs *regs)
932{
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000933 u32 opcode, tcode = 0;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200934 enum ctx_state prev_state;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500935 u16 instr[2];
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000936 unsigned long epc = msk_isa16_mode(exception_epc(regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200938 prev_state = exception_enter();
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000939 if (get_isa16_mode(regs->cp0_epc)) {
940 if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
941 __get_user(instr[1], (u16 __user *)(epc + 2)))
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500942 goto out_sigsegv;
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000943 opcode = (instr[0] << 16) | instr[1];
944 /* Immediate versions don't provide a code. */
945 if (!(opcode & OPCODE))
946 tcode = (opcode >> 12) & ((1 << 4) - 1);
947 } else {
948 if (__get_user(opcode, (u32 __user *)epc))
949 goto out_sigsegv;
950 /* Immediate versions don't provide a code. */
951 if (!(opcode & OPCODE))
952 tcode = (opcode >> 6) & ((1 << 10) - 1);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Ralf Baechledf270052008-04-20 16:28:54 +0100955 do_trap_or_bp(regs, tcode, "Trap");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200956
957out:
958 exception_exit(prev_state);
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900959 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000960
961out_sigsegv:
962 force_sig(SIGSEGV, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200963 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964}
965
966asmlinkage void do_ri(struct pt_regs *regs)
967{
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100968 unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
969 unsigned long old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500970 unsigned long old31 = regs->regs[31];
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200971 enum ctx_state prev_state;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100972 unsigned int opcode = 0;
973 int status = -1;
974
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200975 prev_state = exception_enter();
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200976 if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs),
977 SIGILL) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200978 goto out;
Jason Wessel88547002008-07-29 15:58:53 -0500979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 die_if_kernel("Reserved instruction in kernel code", regs);
981
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100982 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200983 goto out;
Ralf Baechle3c370262005-04-13 17:43:59 +0000984
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500985 if (get_isa16_mode(regs->cp0_epc)) {
986 unsigned short mmop[2] = { 0 };
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100987
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500988 if (unlikely(get_user(mmop[0], epc) < 0))
989 status = SIGSEGV;
990 if (unlikely(get_user(mmop[1], epc) < 0))
991 status = SIGSEGV;
992 opcode = (mmop[0] << 16) | mmop[1];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100993
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500994 if (status < 0)
995 status = simulate_rdhwr_mm(regs, opcode);
996 } else {
997 if (unlikely(get_user(opcode, epc) < 0))
998 status = SIGSEGV;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100999
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001000 if (!cpu_has_llsc && status < 0)
1001 status = simulate_llsc(regs, opcode);
1002
1003 if (status < 0)
1004 status = simulate_rdhwr_normal(regs, opcode);
1005
1006 if (status < 0)
1007 status = simulate_sync(regs, opcode);
1008 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001009
1010 if (status < 0)
1011 status = SIGILL;
1012
1013 if (unlikely(status > 0)) {
1014 regs->cp0_epc = old_epc; /* Undo skip-over. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001015 regs->regs[31] = old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001016 force_sig(status, current);
1017 }
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001018
1019out:
1020 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021}
1022
Ralf Baechled223a862007-07-10 17:33:02 +01001023/*
1024 * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
1025 * emulated more than some threshold number of instructions, force migration to
1026 * a "CPU" that has FP support.
1027 */
1028static void mt_ase_fp_affinity(void)
1029{
1030#ifdef CONFIG_MIPS_MT_FPAFF
1031 if (mt_fpemul_threshold > 0 &&
1032 ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
1033 /*
1034 * If there's no FPU present, or if the application has already
1035 * restricted the allowed set to exclude any CPUs with FPUs,
1036 * we'll skip the procedure.
1037 */
1038 if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
1039 cpumask_t tmask;
1040
Kevin D. Kissell9cc12362008-09-09 21:33:36 +02001041 current->thread.user_cpus_allowed
1042 = current->cpus_allowed;
1043 cpus_and(tmask, current->cpus_allowed,
1044 mt_fpu_cpumask);
Julia Lawalled1bbde2010-03-26 23:03:07 +01001045 set_cpus_allowed_ptr(current, &tmask);
Ralf Baechle293c5bd2007-07-25 16:19:33 +01001046 set_thread_flag(TIF_FPUBOUND);
Ralf Baechled223a862007-07-10 17:33:02 +01001047 }
1048 }
1049#endif /* CONFIG_MIPS_MT_FPAFF */
1050}
1051
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001052/*
1053 * No lock; only written during early bootup by CPU 0.
1054 */
1055static RAW_NOTIFIER_HEAD(cu2_chain);
1056
1057int __ref register_cu2_notifier(struct notifier_block *nb)
1058{
1059 return raw_notifier_chain_register(&cu2_chain, nb);
1060}
1061
1062int cu2_notifier_call_chain(unsigned long val, void *v)
1063{
1064 return raw_notifier_call_chain(&cu2_chain, val, v);
1065}
1066
1067static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
Ralf Baechle70342282013-01-22 12:59:30 +01001068 void *data)
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001069{
1070 struct pt_regs *regs = data;
1071
Jayachandran C83bee792013-06-10 06:30:01 +00001072 die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001073 "instruction", regs);
Jayachandran C83bee792013-06-10 06:30:01 +00001074 force_sig(SIGILL, current);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001075
1076 return NOTIFY_OK;
1077}
1078
Paul Burton1db1af82014-01-27 15:23:11 +00001079static int enable_restore_fp_context(int msa)
1080{
1081 int err, was_fpu_owner;
1082
1083 if (!used_math()) {
1084 /* First time FP context user. */
1085 err = init_fpu();
1086 if (msa && !err)
1087 enable_msa();
1088 if (!err)
1089 set_used_math();
1090 return err;
1091 }
1092
1093 /*
1094 * This task has formerly used the FP context.
1095 *
1096 * If this thread has no live MSA vector context then we can simply
1097 * restore the scalar FP context. If it has live MSA vector context
1098 * (that is, it has or may have used MSA since last performing a
1099 * function call) then we'll need to restore the vector context. This
1100 * applies even if we're currently only executing a scalar FP
1101 * instruction. This is because if we were to later execute an MSA
1102 * instruction then we'd either have to:
1103 *
1104 * - Restore the vector context & clobber any registers modified by
1105 * scalar FP instructions between now & then.
1106 *
1107 * or
1108 *
1109 * - Not restore the vector context & lose the most significant bits
1110 * of all vector registers.
1111 *
1112 * Neither of those options is acceptable. We cannot restore the least
1113 * significant bits of the registers now & only restore the most
1114 * significant bits later because the most significant bits of any
1115 * vector registers whose aliased FP register is modified now will have
1116 * been zeroed. We'd have no way to know that when restoring the vector
1117 * context & thus may load an outdated value for the most significant
1118 * bits of a vector register.
1119 */
1120 if (!msa && !thread_msa_context_live())
1121 return own_fpu(1);
1122
1123 /*
1124 * This task is using or has previously used MSA. Thus we require
1125 * that Status.FR == 1.
1126 */
1127 was_fpu_owner = is_fpu_owner();
1128 err = own_fpu(0);
1129 if (err)
1130 return err;
1131
1132 enable_msa();
1133 write_msa_csr(current->thread.fpu.msacsr);
1134 set_thread_flag(TIF_USEDMSA);
1135
1136 /*
1137 * If this is the first time that the task is using MSA and it has
1138 * previously used scalar FP in this time slice then we already nave
1139 * FP context which we shouldn't clobber.
1140 */
1141 if (!test_and_set_thread_flag(TIF_MSA_CTX_LIVE) && was_fpu_owner)
1142 return 0;
1143
1144 /* We need to restore the vector context. */
1145 restore_msa(current);
1146 return 0;
1147}
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149asmlinkage void do_cpu(struct pt_regs *regs)
1150{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001151 enum ctx_state prev_state;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001152 unsigned int __user *epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001153 unsigned long old_epc, old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001154 unsigned int opcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 unsigned int cpid;
Paul Burton597ce172013-11-22 13:12:07 +00001156 int status, err;
David Daneyf9bb4cf2008-12-11 15:33:23 -08001157 unsigned long __maybe_unused flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001159 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
1161
Jayachandran C83bee792013-06-10 06:30:01 +00001162 if (cpid != 2)
1163 die_if_kernel("do_cpu invoked from kernel context!", regs);
1164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 switch (cpid) {
1166 case 0:
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001167 epc = (unsigned int __user *)exception_epc(regs);
1168 old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001169 old31 = regs->regs[31];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001170 opcode = 0;
1171 status = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001173 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001174 goto out;
Ralf Baechle3c370262005-04-13 17:43:59 +00001175
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001176 if (get_isa16_mode(regs->cp0_epc)) {
1177 unsigned short mmop[2] = { 0 };
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001178
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001179 if (unlikely(get_user(mmop[0], epc) < 0))
1180 status = SIGSEGV;
1181 if (unlikely(get_user(mmop[1], epc) < 0))
1182 status = SIGSEGV;
1183 opcode = (mmop[0] << 16) | mmop[1];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001184
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001185 if (status < 0)
1186 status = simulate_rdhwr_mm(regs, opcode);
1187 } else {
1188 if (unlikely(get_user(opcode, epc) < 0))
1189 status = SIGSEGV;
1190
1191 if (!cpu_has_llsc && status < 0)
1192 status = simulate_llsc(regs, opcode);
1193
1194 if (status < 0)
1195 status = simulate_rdhwr_normal(regs, opcode);
1196 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001197
1198 if (status < 0)
1199 status = SIGILL;
1200
1201 if (unlikely(status > 0)) {
1202 regs->cp0_epc = old_epc; /* Undo skip-over. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001203 regs->regs[31] = old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001204 force_sig(status, current);
1205 }
1206
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001207 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001209 case 3:
1210 /*
1211 * Old (MIPS I and MIPS II) processors will set this code
1212 * for COP1X opcode instructions that replaced the original
Ralf Baechle70342282013-01-22 12:59:30 +01001213 * COP3 space. We don't limit COP1 space instructions in
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001214 * the emulator according to the CPU ISA, so we want to
1215 * treat COP1X instructions consistently regardless of which
Ralf Baechle70342282013-01-22 12:59:30 +01001216 * code the CPU chose. Therefore we redirect this trap to
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001217 * the FP emulator too.
1218 *
1219 * Then some newer FPU-less processors use this code
1220 * erroneously too, so they are covered by this choice
1221 * as well.
1222 */
1223 if (raw_cpu_has_fpu)
1224 break;
1225 /* Fall through. */
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 case 1:
Paul Burton1db1af82014-01-27 15:23:11 +00001228 err = enable_restore_fp_context(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Paul Burton597ce172013-11-22 13:12:07 +00001230 if (!raw_cpu_has_fpu || err) {
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001231 int sig;
David Daney515b0292010-10-21 16:32:26 -07001232 void __user *fault_addr = NULL;
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001233 sig = fpu_emulator_cop1Handler(regs,
David Daney515b0292010-10-21 16:32:26 -07001234 &current->thread.fpu,
1235 0, &fault_addr);
Paul Burton597ce172013-11-22 13:12:07 +00001236 if (!process_fpemu_return(sig, fault_addr) && !err)
Ralf Baechled223a862007-07-10 17:33:02 +01001237 mt_ase_fp_affinity();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
1239
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001240 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 case 2:
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001243 raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001244 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 }
1246
1247 force_sig(SIGILL, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001248
1249out:
1250 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251}
1252
Paul Burton1db1af82014-01-27 15:23:11 +00001253asmlinkage void do_msa(struct pt_regs *regs)
1254{
1255 enum ctx_state prev_state;
1256 int err;
1257
1258 prev_state = exception_enter();
1259
1260 if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) {
1261 force_sig(SIGILL, current);
1262 goto out;
1263 }
1264
1265 die_if_kernel("do_msa invoked from kernel context!", regs);
1266
1267 err = enable_restore_fp_context(1);
1268 if (err)
1269 force_sig(SIGILL, current);
1270out:
1271 exception_exit(prev_state);
1272}
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274asmlinkage void do_mdmx(struct pt_regs *regs)
1275{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001276 enum ctx_state prev_state;
1277
1278 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 force_sig(SIGILL, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001280 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
David Daney8bc6d052009-01-05 15:29:58 -08001283/*
1284 * Called with interrupts disabled.
1285 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286asmlinkage void do_watch(struct pt_regs *regs)
1287{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001288 enum ctx_state prev_state;
David Daneyb67b2b72008-09-23 00:08:45 -07001289 u32 cause;
1290
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001291 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 /*
David Daneyb67b2b72008-09-23 00:08:45 -07001293 * Clear WP (bit 22) bit of cause register so we don't loop
1294 * forever.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 */
David Daneyb67b2b72008-09-23 00:08:45 -07001296 cause = read_c0_cause();
1297 cause &= ~(1 << 22);
1298 write_c0_cause(cause);
1299
1300 /*
1301 * If the current thread has the watch registers loaded, save
1302 * their values and send SIGTRAP. Otherwise another thread
1303 * left the registers set, clear them and continue.
1304 */
1305 if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
1306 mips_read_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001307 local_irq_enable();
David Daneyb67b2b72008-09-23 00:08:45 -07001308 force_sig(SIGTRAP, current);
David Daney8bc6d052009-01-05 15:29:58 -08001309 } else {
David Daneyb67b2b72008-09-23 00:08:45 -07001310 mips_clear_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001311 local_irq_enable();
1312 }
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001313 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314}
1315
1316asmlinkage void do_mcheck(struct pt_regs *regs)
1317{
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001318 const int field = 2 * sizeof(unsigned long);
1319 int multi_match = regs->cp0_status & ST0_TS;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001320 enum ctx_state prev_state;
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001321
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001322 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 show_regs(regs);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001324
1325 if (multi_match) {
Ralf Baechle70342282013-01-22 12:59:30 +01001326 printk("Index : %0x\n", read_c0_index());
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001327 printk("Pagemask: %0x\n", read_c0_pagemask());
1328 printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
1329 printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
1330 printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
1331 printk("\n");
1332 dump_tlb_all();
1333 }
1334
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +09001335 show_code((unsigned int __user *) regs->cp0_epc);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 /*
1338 * Some chips may have other causes of machine check (e.g. SB1
1339 * graduation timer)
1340 */
1341 panic("Caught Machine Check exception - %scaused by multiple "
1342 "matching entries in the TLB.",
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001343 (multi_match) ? "" : "not ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001346asmlinkage void do_mt(struct pt_regs *regs)
1347{
Ralf Baechle41c594a2006-04-05 09:45:45 +01001348 int subcode;
1349
Ralf Baechle41c594a2006-04-05 09:45:45 +01001350 subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
1351 >> VPECONTROL_EXCPT_SHIFT;
1352 switch (subcode) {
1353 case 0:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001354 printk(KERN_DEBUG "Thread Underflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001355 break;
1356 case 1:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001357 printk(KERN_DEBUG "Thread Overflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001358 break;
1359 case 2:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001360 printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001361 break;
1362 case 3:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001363 printk(KERN_DEBUG "Gating Storage Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001364 break;
1365 case 4:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001366 printk(KERN_DEBUG "YIELD Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001367 break;
1368 case 5:
Masanari Iidaf232c7e2012-02-08 21:53:14 +09001369 printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001370 break;
1371 default:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001372 printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
Ralf Baechle41c594a2006-04-05 09:45:45 +01001373 subcode);
1374 break;
1375 }
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001376 die_if_kernel("MIPS MT Thread exception in kernel", regs);
1377
1378 force_sig(SIGILL, current);
1379}
1380
1381
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001382asmlinkage void do_dsp(struct pt_regs *regs)
1383{
1384 if (cpu_has_dsp)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001385 panic("Unexpected DSP exception");
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001386
1387 force_sig(SIGILL, current);
1388}
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390asmlinkage void do_reserved(struct pt_regs *regs)
1391{
1392 /*
Ralf Baechle70342282013-01-22 12:59:30 +01001393 * Game over - no way to handle this if it ever occurs. Most probably
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 * caused by a new unknown cpu type or after another deadly
1395 * hard/software error.
1396 */
1397 show_regs(regs);
1398 panic("Caught reserved exception %ld - should not happen.",
1399 (regs->cp0_cause & 0x7f) >> 2);
1400}
1401
Ralf Baechle39b8d522008-04-28 17:14:26 +01001402static int __initdata l1parity = 1;
1403static int __init nol1parity(char *s)
1404{
1405 l1parity = 0;
1406 return 1;
1407}
1408__setup("nol1par", nol1parity);
1409static int __initdata l2parity = 1;
1410static int __init nol2parity(char *s)
1411{
1412 l2parity = 0;
1413 return 1;
1414}
1415__setup("nol2par", nol2parity);
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417/*
1418 * Some MIPS CPUs can enable/disable for cache parity detection, but do
1419 * it different ways.
1420 */
1421static inline void parity_protection_init(void)
1422{
Ralf Baechle10cc3522007-10-11 23:46:15 +01001423 switch (current_cpu_type()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 case CPU_24K:
Nigel Stephens98a41de2006-04-27 15:50:32 +01001425 case CPU_34K:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001426 case CPU_74K:
1427 case CPU_1004K:
Steven J. Hill442e14a2014-01-17 15:03:50 -06001428 case CPU_1074K:
Leonid Yegoshin26ab96d2013-11-27 10:07:53 +00001429 case CPU_INTERAPTIV:
Leonid Yegoshin708ac4b2013-11-14 16:12:27 +00001430 case CPU_PROAPTIV:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001431 {
1432#define ERRCTL_PE 0x80000000
1433#define ERRCTL_L2P 0x00800000
1434 unsigned long errctl;
1435 unsigned int l1parity_present, l2parity_present;
1436
1437 errctl = read_c0_ecc();
1438 errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
1439
1440 /* probe L1 parity support */
1441 write_c0_ecc(errctl | ERRCTL_PE);
1442 back_to_back_c0_hazard();
1443 l1parity_present = (read_c0_ecc() & ERRCTL_PE);
1444
1445 /* probe L2 parity support */
1446 write_c0_ecc(errctl|ERRCTL_L2P);
1447 back_to_back_c0_hazard();
1448 l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
1449
1450 if (l1parity_present && l2parity_present) {
1451 if (l1parity)
1452 errctl |= ERRCTL_PE;
1453 if (l1parity ^ l2parity)
1454 errctl |= ERRCTL_L2P;
1455 } else if (l1parity_present) {
1456 if (l1parity)
1457 errctl |= ERRCTL_PE;
1458 } else if (l2parity_present) {
1459 if (l2parity)
1460 errctl |= ERRCTL_L2P;
1461 } else {
1462 /* No parity available */
1463 }
1464
1465 printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
1466
1467 write_c0_ecc(errctl);
1468 back_to_back_c0_hazard();
1469 errctl = read_c0_ecc();
1470 printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
1471
1472 if (l1parity_present)
1473 printk(KERN_INFO "Cache parity protection %sabled\n",
1474 (errctl & ERRCTL_PE) ? "en" : "dis");
1475
1476 if (l2parity_present) {
1477 if (l1parity_present && l1parity)
1478 errctl ^= ERRCTL_L2P;
1479 printk(KERN_INFO "L2 cache parity protection %sabled\n",
1480 (errctl & ERRCTL_L2P) ? "en" : "dis");
1481 }
1482 }
1483 break;
1484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 case CPU_5KC:
Leonid Yegoshin78d48032012-07-06 21:56:01 +02001486 case CPU_5KE:
Kelvin Cheung2fa36392012-06-20 20:05:32 +01001487 case CPU_LOONGSON1:
Ralf Baechle14f18b72005-03-01 18:15:08 +00001488 write_c0_ecc(0x80000000);
1489 back_to_back_c0_hazard();
1490 /* Set the PE bit (bit 31) in the c0_errctl register. */
1491 printk(KERN_INFO "Cache parity protection %sabled\n",
1492 (read_c0_ecc() & 0x80000000) ? "en" : "dis");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 break;
1494 case CPU_20KC:
1495 case CPU_25KF:
1496 /* Clear the DE bit (bit 16) in the c0_status register. */
1497 printk(KERN_INFO "Enable cache parity protection for "
1498 "MIPS 20KC/25KF CPUs.\n");
1499 clear_c0_status(ST0_DE);
1500 break;
1501 default:
1502 break;
1503 }
1504}
1505
1506asmlinkage void cache_parity_error(void)
1507{
1508 const int field = 2 * sizeof(unsigned long);
1509 unsigned int reg_val;
1510
1511 /* For the moment, report the problem and hang. */
1512 printk("Cache error exception:\n");
1513 printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1514 reg_val = read_c0_cacheerr();
1515 printk("c0_cacheerr == %08x\n", reg_val);
1516
1517 printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1518 reg_val & (1<<30) ? "secondary" : "primary",
1519 reg_val & (1<<31) ? "data" : "insn");
Leonid Yegoshin6de20452013-10-10 09:58:59 +01001520 if (cpu_has_mips_r2 &&
1521 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1522 pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
1523 reg_val & (1<<29) ? "ED " : "",
1524 reg_val & (1<<28) ? "ET " : "",
1525 reg_val & (1<<27) ? "ES " : "",
1526 reg_val & (1<<26) ? "EE " : "",
1527 reg_val & (1<<25) ? "EB " : "",
1528 reg_val & (1<<24) ? "EI " : "",
1529 reg_val & (1<<23) ? "E1 " : "",
1530 reg_val & (1<<22) ? "E0 " : "");
1531 } else {
1532 pr_err("Error bits: %s%s%s%s%s%s%s\n",
1533 reg_val & (1<<29) ? "ED " : "",
1534 reg_val & (1<<28) ? "ET " : "",
1535 reg_val & (1<<26) ? "EE " : "",
1536 reg_val & (1<<25) ? "EB " : "",
1537 reg_val & (1<<24) ? "EI " : "",
1538 reg_val & (1<<23) ? "E1 " : "",
1539 reg_val & (1<<22) ? "E0 " : "");
1540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1542
Ralf Baechleec917c2c2005-10-07 16:58:15 +01001543#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 if (reg_val & (1<<22))
1545 printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
1546
1547 if (reg_val & (1<<23))
1548 printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
1549#endif
1550
1551 panic("Can't handle the cache error!");
1552}
1553
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +00001554asmlinkage void do_ftlb(void)
1555{
1556 const int field = 2 * sizeof(unsigned long);
1557 unsigned int reg_val;
1558
1559 /* For the moment, report the problem and hang. */
1560 if (cpu_has_mips_r2 &&
1561 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1562 pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
1563 read_c0_ecc());
1564 pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1565 reg_val = read_c0_cacheerr();
1566 pr_err("c0_cacheerr == %08x\n", reg_val);
1567
1568 if ((reg_val & 0xc0000000) == 0xc0000000) {
1569 pr_err("Decoded c0_cacheerr: FTLB parity error\n");
1570 } else {
1571 pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1572 reg_val & (1<<30) ? "secondary" : "primary",
1573 reg_val & (1<<31) ? "data" : "insn");
1574 }
1575 } else {
1576 pr_err("FTLB error exception\n");
1577 }
1578 /* Just print the cacheerr bits for now */
1579 cache_parity_error();
1580}
1581
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582/*
1583 * SDBBP EJTAG debug exception handler.
1584 * We skip the instruction and return to the next instruction.
1585 */
1586void ejtag_exception_handler(struct pt_regs *regs)
1587{
1588 const int field = 2 * sizeof(unsigned long);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001589 unsigned long depc, old_epc, old_ra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 unsigned int debug;
1591
Chris Dearman70ae6122006-06-30 12:32:37 +01001592 printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 depc = read_c0_depc();
1594 debug = read_c0_debug();
Chris Dearman70ae6122006-06-30 12:32:37 +01001595 printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 if (debug & 0x80000000) {
1597 /*
1598 * In branch delay slot.
1599 * We cheat a little bit here and use EPC to calculate the
1600 * debug return address (DEPC). EPC is restored after the
1601 * calculation.
1602 */
1603 old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001604 old_ra = regs->regs[31];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 regs->cp0_epc = depc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001606 compute_return_epc(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 depc = regs->cp0_epc;
1608 regs->cp0_epc = old_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001609 regs->regs[31] = old_ra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 } else
1611 depc += 4;
1612 write_c0_depc(depc);
1613
1614#if 0
Chris Dearman70ae6122006-06-30 12:32:37 +01001615 printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 write_c0_debug(debug | 0x100);
1617#endif
1618}
1619
1620/*
1621 * NMI exception handler.
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001622 * No lock; only written during early bootup by CPU 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 */
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001624static RAW_NOTIFIER_HEAD(nmi_chain);
1625
1626int register_nmi_notifier(struct notifier_block *nb)
1627{
1628 return raw_notifier_chain_register(&nmi_chain, nb);
1629}
1630
Joe Perchesff2d8b12012-01-12 17:17:21 -08001631void __noreturn nmi_exception_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +01001633 char str[100];
1634
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001635 raw_notifier_call_chain(&nmi_chain, 0, regs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001636 bust_spinlocks(1);
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +01001637 snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
1638 smp_processor_id(), regs->cp0_epc);
1639 regs->cp0_epc = read_c0_errorepc();
1640 die(str, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Ralf Baechlee01402b2005-07-14 15:57:16 +00001643#define VECTORSPACING 0x100 /* for EI/VI mode */
1644
1645unsigned long ebase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646unsigned long exception_handlers[32];
Ralf Baechlee01402b2005-07-14 15:57:16 +00001647unsigned long vi_handlers[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Florian Fainelli2d1b6e92010-01-28 15:21:42 +01001649void __init *set_except_vector(int n, void *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650{
1651 unsigned long handler = (unsigned long) addr;
Ralf Baechleb22d1b62013-05-09 17:57:30 +02001652 unsigned long old_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001654#ifdef CONFIG_CPU_MICROMIPS
1655 /*
1656 * Only the TLB handlers are cache aligned with an even
1657 * address. All other handlers are on an odd address and
1658 * require no modification. Otherwise, MIPS32 mode will
1659 * be entered when handling any TLB exceptions. That
1660 * would be bad...since we must stay in microMIPS mode.
1661 */
1662 if (!(handler & 0x1))
1663 handler |= 1;
1664#endif
Ralf Baechleb22d1b62013-05-09 17:57:30 +02001665 old_handler = xchg(&exception_handlers[n], handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 if (n == 0 && cpu_has_divec) {
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001668#ifdef CONFIG_CPU_MICROMIPS
1669 unsigned long jump_mask = ~((1 << 27) - 1);
1670#else
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001671 unsigned long jump_mask = ~((1 << 28) - 1);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001672#endif
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001673 u32 *buf = (u32 *)(ebase + 0x200);
1674 unsigned int k0 = 26;
1675 if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
1676 uasm_i_j(&buf, handler & ~jump_mask);
1677 uasm_i_nop(&buf);
1678 } else {
1679 UASM_i_LA(&buf, k0, handler);
1680 uasm_i_jr(&buf, k0);
1681 uasm_i_nop(&buf);
1682 }
1683 local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 }
1685 return (void *)old_handler;
1686}
1687
Ralf Baechle86a17082013-02-08 01:21:34 +01001688static void do_default_vi(void)
Atsushi Nemoto6ba07e52007-05-21 23:45:38 +09001689{
1690 show_regs(get_irq_regs());
1691 panic("Caught unexpected vectored interrupt.");
1692}
1693
Ralf Baechleef300e42007-05-06 18:31:18 +01001694static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001695{
1696 unsigned long handler;
1697 unsigned long old_handler = vi_handlers[n];
Ralf Baechlef6771db2007-11-08 18:02:29 +00001698 int srssets = current_cpu_data.srsets;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001699 u16 *h;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001700 unsigned char *b;
1701
Ralf Baechleb72b7092009-03-30 14:49:44 +02001702 BUG_ON(!cpu_has_veic && !cpu_has_vint);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001703
1704 if (addr == NULL) {
1705 handler = (unsigned long) do_default_vi;
1706 srs = 0;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001707 } else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001708 handler = (unsigned long) addr;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001709 vi_handlers[n] = handler;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001710
1711 b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
1712
Ralf Baechlef6771db2007-11-08 18:02:29 +00001713 if (srs >= srssets)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001714 panic("Shadow register set %d not supported", srs);
1715
1716 if (cpu_has_veic) {
1717 if (board_bind_eic_interrupt)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001718 board_bind_eic_interrupt(n, srs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001719 } else if (cpu_has_vint) {
Ralf Baechlee01402b2005-07-14 15:57:16 +00001720 /* SRSMap is only defined if shadow sets are implemented */
Ralf Baechlef6771db2007-11-08 18:02:29 +00001721 if (srssets > 1)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001722 change_c0_srsmap(0xf << n*4, srs << n*4);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001723 }
1724
1725 if (srs == 0) {
1726 /*
1727 * If no shadow set is selected then use the default handler
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001728 * that does normal register saving and standard interrupt exit
Ralf Baechlee01402b2005-07-14 15:57:16 +00001729 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001730 extern char except_vec_vi, except_vec_vi_lui;
1731 extern char except_vec_vi_ori, except_vec_vi_end;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001732 extern char rollback_except_vec_vi;
Ralf Baechlef94d9a82013-05-21 17:30:36 +02001733 char *vec_start = using_rollback_handler() ?
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001734 &rollback_except_vec_vi : &except_vec_vi;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001735#ifdef CONFIG_MIPS_MT_SMTC
1736 /*
1737 * We need to provide the SMTC vectored interrupt handler
1738 * not only with the address of the handler, but with the
1739 * Status.IM bit to be masked before going there.
1740 */
1741 extern char except_vec_vi_mori;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001742#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1743 const int mori_offset = &except_vec_vi_mori - vec_start + 2;
1744#else
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001745 const int mori_offset = &except_vec_vi_mori - vec_start;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001746#endif
Ralf Baechle41c594a2006-04-05 09:45:45 +01001747#endif /* CONFIG_MIPS_MT_SMTC */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001748#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1749 const int lui_offset = &except_vec_vi_lui - vec_start + 2;
1750 const int ori_offset = &except_vec_vi_ori - vec_start + 2;
1751#else
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001752 const int lui_offset = &except_vec_vi_lui - vec_start;
1753 const int ori_offset = &except_vec_vi_ori - vec_start;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001754#endif
1755 const int handler_len = &except_vec_vi_end - vec_start;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001756
1757 if (handler_len > VECTORSPACING) {
1758 /*
1759 * Sigh... panicing won't help as the console
1760 * is probably not configured :(
1761 */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001762 panic("VECTORSPACING too small");
Ralf Baechlee01402b2005-07-14 15:57:16 +00001763 }
1764
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001765 set_handler(((unsigned long)b - ebase), vec_start,
1766#ifdef CONFIG_CPU_MICROMIPS
1767 (handler_len - 1));
1768#else
1769 handler_len);
1770#endif
Ralf Baechle41c594a2006-04-05 09:45:45 +01001771#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle8e8a52e2007-05-31 14:00:19 +01001772 BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
1773
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001774 h = (u16 *)(b + mori_offset);
1775 *h = (0x100 << n);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001776#endif /* CONFIG_MIPS_MT_SMTC */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001777 h = (u16 *)(b + lui_offset);
1778 *h = (handler >> 16) & 0xffff;
1779 h = (u16 *)(b + ori_offset);
1780 *h = (handler & 0xffff);
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001781 local_flush_icache_range((unsigned long)b,
1782 (unsigned long)(b+handler_len));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001783 }
1784 else {
1785 /*
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001786 * In other cases jump directly to the interrupt handler. It
1787 * is the handler's responsibility to save registers if required
1788 * (eg hi/lo) and return from the exception using "eret".
Ralf Baechlee01402b2005-07-14 15:57:16 +00001789 */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001790 u32 insn;
1791
1792 h = (u16 *)b;
1793 /* j handler */
1794#ifdef CONFIG_CPU_MICROMIPS
1795 insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
1796#else
1797 insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
1798#endif
1799 h[0] = (insn >> 16) & 0xffff;
1800 h[1] = insn & 0xffff;
1801 h[2] = 0;
1802 h[3] = 0;
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001803 local_flush_icache_range((unsigned long)b,
1804 (unsigned long)(b+8));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001805 }
1806
1807 return (void *)old_handler;
1808}
1809
Ralf Baechleef300e42007-05-06 18:31:18 +01001810void *set_vi_handler(int n, vi_handler_t addr)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001811{
Ralf Baechleff3eab22006-03-29 14:12:58 +01001812 return set_vi_srs_handler(n, addr, 0);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001813}
Ralf Baechlef41ae0b2006-06-05 17:24:46 +01001814
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815extern void tlb_init(void);
1816
Ralf Baechle42f77542007-10-18 17:48:11 +01001817/*
1818 * Timer interrupt
1819 */
1820int cp0_compare_irq;
Ralf Baechle68b63522012-07-19 09:13:52 +02001821EXPORT_SYMBOL_GPL(cp0_compare_irq);
David VomLehn010c1082009-12-21 17:49:22 -08001822int cp0_compare_irq_shift;
Ralf Baechle42f77542007-10-18 17:48:11 +01001823
1824/*
1825 * Performance counter IRQ or -1 if shared with timer
1826 */
1827int cp0_perfcount_irq;
1828EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
1829
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001830static int noulri;
Chris Dearmanbdc94eb2007-10-03 10:43:56 +01001831
1832static int __init ulri_disable(char *s)
1833{
1834 pr_info("Disabling ulri\n");
1835 noulri = 1;
1836
1837 return 1;
1838}
1839__setup("noulri", ulri_disable);
1840
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001841void per_cpu_trap_init(bool is_boot_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
1843 unsigned int cpu = smp_processor_id();
1844 unsigned int status_set = ST0_CU0;
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001845 unsigned int hwrena = cpu_hwrena_impl_bits;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001846#ifdef CONFIG_MIPS_MT_SMTC
1847 int secondaryTC = 0;
1848 int bootTC = (cpu == 0);
1849
1850 /*
1851 * Only do per_cpu_trap_init() for first TC of Each VPE.
1852 * Note that this hack assumes that the SMTC init code
1853 * assigns TCs consecutively and in ascending order.
1854 */
1855
1856 if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
1857 ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
1858 secondaryTC = 1;
1859#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 /*
1862 * Disable coprocessors and select 32-bit or 64-bit addressing
1863 * and the 16/32 or 32/32 FPR register model. Reset the BEV
1864 * flag that some firmware may have left set and the TS bit (for
1865 * IP27). Set XX for ISA IV code to work.
1866 */
Ralf Baechle875d43e2005-09-03 15:56:16 -07001867#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
1869#endif
Deng-Cheng Zhuadb37892013-04-01 18:14:28 +00001870 if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 status_set |= ST0_XX;
Chris Dearmanbbaf2382007-12-13 22:42:19 +00001872 if (cpu_has_dsp)
1873 status_set |= ST0_MX;
1874
Ralf Baechleb38c7392006-02-07 01:20:43 +00001875 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 -07001876 status_set);
1877
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001878 if (cpu_has_mips_r2)
1879 hwrena |= 0x0000000f;
Ralf Baechlea3692022007-07-10 17:33:02 +01001880
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001881 if (!noulri && cpu_has_userlocal)
1882 hwrena |= (1 << 29);
Ralf Baechlea3692022007-07-10 17:33:02 +01001883
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001884 if (hwrena)
1885 write_c0_hwrena(hwrena);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001886
Ralf Baechle41c594a2006-04-05 09:45:45 +01001887#ifdef CONFIG_MIPS_MT_SMTC
1888 if (!secondaryTC) {
1889#endif /* CONFIG_MIPS_MT_SMTC */
1890
Ralf Baechlee01402b2005-07-14 15:57:16 +00001891 if (cpu_has_veic || cpu_has_vint) {
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001892 unsigned long sr = set_c0_status(ST0_BEV);
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001893 write_c0_ebase(ebase);
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001894 write_c0_status(sr);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001895 /* Setting vector spacing enables EI/VI mode */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001896 change_c0_intctl(0x3e0, VECTORSPACING);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001897 }
Ralf Baechled03d0a52005-08-17 13:44:26 +00001898 if (cpu_has_divec) {
1899 if (cpu_has_mipsmt) {
1900 unsigned int vpflags = dvpe();
1901 set_c0_cause(CAUSEF_IV);
1902 evpe(vpflags);
1903 } else
1904 set_c0_cause(CAUSEF_IV);
1905 }
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001906
1907 /*
1908 * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
1909 *
1910 * o read IntCtl.IPTI to determine the timer interrupt
1911 * o read IntCtl.IPPCI to determine the performance counter interrupt
1912 */
1913 if (cpu_has_mips_r2) {
David VomLehn010c1082009-12-21 17:49:22 -08001914 cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
1915 cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
1916 cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001917 if (cp0_perfcount_irq == cp0_compare_irq)
1918 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001919 } else {
1920 cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
Ralf Baechlec6a4ebb2012-07-06 23:56:00 +02001921 cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001922 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001923 }
1924
Ralf Baechle41c594a2006-04-05 09:45:45 +01001925#ifdef CONFIG_MIPS_MT_SMTC
1926 }
1927#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
David Daney48c4ac92013-05-13 13:56:44 -07001929 if (!cpu_data[cpu].asid_cache)
1930 cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932 atomic_inc(&init_mm.mm_count);
1933 current->active_mm = &init_mm;
1934 BUG_ON(current->mm);
1935 enter_lazy_tlb(&init_mm, current);
1936
Ralf Baechle41c594a2006-04-05 09:45:45 +01001937#ifdef CONFIG_MIPS_MT_SMTC
1938 if (bootTC) {
1939#endif /* CONFIG_MIPS_MT_SMTC */
David Daney6650df32012-05-15 00:04:50 -07001940 /* Boot CPU's cache setup in setup_arch(). */
1941 if (!is_boot_cpu)
1942 cpu_cache_init();
Ralf Baechle41c594a2006-04-05 09:45:45 +01001943 tlb_init();
1944#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle6a058882007-05-31 14:03:45 +01001945 } else if (!secondaryTC) {
1946 /*
1947 * First TC in non-boot VPE must do subset of tlb_init()
1948 * for MMU countrol registers.
1949 */
1950 write_c0_pagemask(PM_DEFAULT_MASK);
1951 write_c0_wired(0);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001952 }
1953#endif /* CONFIG_MIPS_MT_SMTC */
David Daney3d8bfdd2010-12-21 14:19:11 -08001954 TLBMISS_HANDLER_SETUP();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}
1956
Ralf Baechlee01402b2005-07-14 15:57:16 +00001957/* Install CPU exception handler */
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001958void set_handler(unsigned long offset, void *addr, unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001959{
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001960#ifdef CONFIG_CPU_MICROMIPS
1961 memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
1962#else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001963 memcpy((void *)(ebase + offset), addr, size);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001964#endif
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001965 local_flush_icache_range(ebase + offset, ebase + offset + size);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001966}
1967
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001968static char panic_null_cerr[] =
Ralf Baechle641e97f2007-10-11 23:46:05 +01001969 "Trying to set NULL cache error exception handler";
1970
Ralf Baechle42fe7ee2009-01-28 18:48:23 +00001971/*
1972 * Install uncached CPU exception handler.
1973 * This is suitable only for the cache error exception which is the only
1974 * exception handler that is being run uncached.
1975 */
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001976void set_uncached_handler(unsigned long offset, void *addr,
Ralf Baechle234fcd12008-03-08 09:56:28 +00001977 unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001978{
Sebastian Andrzej Siewior4f81b012010-04-27 22:53:30 +02001979 unsigned long uncached_ebase = CKSEG1ADDR(ebase);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001980
Ralf Baechle641e97f2007-10-11 23:46:05 +01001981 if (!addr)
1982 panic(panic_null_cerr);
1983
Ralf Baechlee01402b2005-07-14 15:57:16 +00001984 memcpy((void *)(uncached_ebase + offset), addr, size);
1985}
1986
Atsushi Nemoto5b104962006-09-11 17:50:29 +09001987static int __initdata rdhwr_noopt;
1988static int __init set_rdhwr_noopt(char *str)
1989{
1990 rdhwr_noopt = 1;
1991 return 1;
1992}
1993
1994__setup("rdhwr_noopt", set_rdhwr_noopt);
1995
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996void __init trap_init(void)
1997{
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001998 extern char except_vec3_generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 extern char except_vec4;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002000 extern char except_vec3_r4000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 unsigned long i;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09002002
2003 check_wait();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Jason Wessel88547002008-07-29 15:58:53 -05002005#if defined(CONFIG_KGDB)
2006 if (kgdb_early_setup)
Ralf Baechle70342282013-01-22 12:59:30 +01002007 return; /* Already done */
Jason Wessel88547002008-07-29 15:58:53 -05002008#endif
2009
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07002010 if (cpu_has_veic || cpu_has_vint) {
2011 unsigned long size = 0x200 + VECTORSPACING*64;
2012 ebase = (unsigned long)
2013 __alloc_bootmem(size, 1 << fls(size), 0);
2014 } else {
Sanjay Lal9843b032012-11-21 18:34:03 -08002015#ifdef CONFIG_KVM_GUEST
2016#define KVM_GUEST_KSEG0 0x40000000
2017 ebase = KVM_GUEST_KSEG0;
2018#else
2019 ebase = CKSEG0;
2020#endif
David Daney566f74f2008-10-23 17:56:35 -07002021 if (cpu_has_mips_r2)
2022 ebase += (read_c0_ebase() & 0x3ffff000);
2023 }
Ralf Baechlee01402b2005-07-14 15:57:16 +00002024
Steven J. Hillc6213c62013-06-05 21:25:17 +00002025 if (cpu_has_mmips) {
2026 unsigned int config3 = read_c0_config3();
2027
2028 if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
2029 write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
2030 else
2031 write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
2032 }
2033
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +00002034 if (board_ebase_setup)
2035 board_ebase_setup();
David Daney6650df32012-05-15 00:04:50 -07002036 per_cpu_trap_init(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 /*
2039 * Copy the generic exception handlers to their final destination.
2040 * This will be overriden later as suitable for a particular
2041 * configuration.
2042 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00002043 set_handler(0x180, &except_vec3_generic, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
2045 /*
2046 * Setup default vectors
2047 */
2048 for (i = 0; i <= 31; i++)
2049 set_except_vector(i, handle_reserved);
2050
2051 /*
2052 * Copy the EJTAG debug exception vector handler code to it's final
2053 * destination.
2054 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00002055 if (cpu_has_ejtag && board_ejtag_handler_setup)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01002056 board_ejtag_handler_setup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
2058 /*
2059 * Only some CPUs have the watch exceptions.
2060 */
2061 if (cpu_has_watch)
2062 set_except_vector(23, handle_watch);
2063
2064 /*
Ralf Baechlee01402b2005-07-14 15:57:16 +00002065 * Initialise interrupt handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00002067 if (cpu_has_veic || cpu_has_vint) {
2068 int nvec = cpu_has_veic ? 64 : 8;
2069 for (i = 0; i < nvec; i++)
Ralf Baechleff3eab22006-03-29 14:12:58 +01002070 set_vi_handler(i, NULL);
Ralf Baechlee01402b2005-07-14 15:57:16 +00002071 }
2072 else if (cpu_has_divec)
2073 set_handler(0x200, &except_vec4, 0x8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 /*
2076 * Some CPUs can enable/disable for cache parity detection, but does
2077 * it different ways.
2078 */
2079 parity_protection_init();
2080
2081 /*
2082 * The Data Bus Errors / Instruction Bus Errors are signaled
2083 * by external hardware. Therefore these two exceptions
2084 * may have board specific handlers.
2085 */
2086 if (board_be_init)
2087 board_be_init();
2088
Ralf Baechlef94d9a82013-05-21 17:30:36 +02002089 set_except_vector(0, using_rollback_handler() ? rollback_handle_int
2090 : handle_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 set_except_vector(1, handle_tlbm);
2092 set_except_vector(2, handle_tlbl);
2093 set_except_vector(3, handle_tlbs);
2094
2095 set_except_vector(4, handle_adel);
2096 set_except_vector(5, handle_ades);
2097
2098 set_except_vector(6, handle_ibe);
2099 set_except_vector(7, handle_dbe);
2100
2101 set_except_vector(8, handle_sys);
2102 set_except_vector(9, handle_bp);
Atsushi Nemoto5b104962006-09-11 17:50:29 +09002103 set_except_vector(10, rdhwr_noopt ? handle_ri :
2104 (cpu_has_vtag_icache ?
2105 handle_ri_rdhwr_vivt : handle_ri_rdhwr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 set_except_vector(11, handle_cpu);
2107 set_except_vector(12, handle_ov);
2108 set_except_vector(13, handle_tr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Ralf Baechle10cc3522007-10-11 23:46:15 +01002110 if (current_cpu_type() == CPU_R6000 ||
2111 current_cpu_type() == CPU_R6000A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 /*
2113 * The R6000 is the only R-series CPU that features a machine
2114 * check exception (similar to the R4000 cache error) and
2115 * unaligned ldc1/sdc1 exception. The handlers have not been
Ralf Baechle70342282013-01-22 12:59:30 +01002116 * written yet. Well, anyway there is no R6000 machine on the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 * current list of targets for Linux/MIPS.
2118 * (Duh, crap, there is someone with a triple R6k machine)
2119 */
2120 //set_except_vector(14, handle_mc);
2121 //set_except_vector(15, handle_ndc);
2122 }
2123
Ralf Baechlee01402b2005-07-14 15:57:16 +00002124
2125 if (board_nmi_handler_setup)
2126 board_nmi_handler_setup();
2127
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002128 if (cpu_has_fpu && !cpu_has_nofpuex)
2129 set_except_vector(15, handle_fpe);
2130
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +00002131 set_except_vector(16, handle_ftlb);
Paul Burton1db1af82014-01-27 15:23:11 +00002132 set_except_vector(21, handle_msa);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002133 set_except_vector(22, handle_mdmx);
2134
2135 if (cpu_has_mcheck)
2136 set_except_vector(24, handle_mcheck);
2137
Ralf Baechle340ee4b2005-08-17 17:44:08 +00002138 if (cpu_has_mipsmt)
2139 set_except_vector(25, handle_mt);
2140
Chris Dearmanacaec422007-05-24 22:30:18 +01002141 set_except_vector(26, handle_dsp);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002142
David Daneyfcbf1df2012-05-15 00:04:46 -07002143 if (board_cache_error_setup)
2144 board_cache_error_setup();
2145
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002146 if (cpu_has_vce)
2147 /* Special exception: R4[04]00 uses also the divec space. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002148 set_handler(0x180, &except_vec3_r4000, 0x100);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002149 else if (cpu_has_4kex)
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002150 set_handler(0x180, &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002151 else
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002152 set_handler(0x080, &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002153
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02002154 local_flush_icache_range(ebase, ebase + 0x400);
Thomas Bogendoerfer05106172008-08-04 19:44:34 +02002155
2156 sort_extable(__start___dbe_table, __stop___dbe_table);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00002157
Ralf Baechle4483b152010-08-05 13:25:59 +01002158 cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159}