blob: 7ac4d8f44cf0a5aeb028566ec6766fe767463c17 [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);
Paul Burton2bcb3fb2014-01-27 15:23:12 +000081extern asmlinkage void handle_msa_fpe(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern asmlinkage void handle_fpe(void);
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +000083extern asmlinkage void handle_ftlb(void);
Paul Burton1db1af82014-01-27 15:23:11 +000084extern asmlinkage void handle_msa(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085extern asmlinkage void handle_mdmx(void);
86extern asmlinkage void handle_watch(void);
Ralf Baechle340ee4b2005-08-17 17:44:08 +000087extern asmlinkage void handle_mt(void);
Ralf Baechlee50c0a82005-05-31 11:49:19 +000088extern asmlinkage void handle_dsp(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern asmlinkage void handle_mcheck(void);
90extern asmlinkage void handle_reserved(void);
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092void (*board_be_init)(void);
93int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
Ralf Baechlee01402b2005-07-14 15:57:16 +000094void (*board_nmi_handler_setup)(void);
95void (*board_ejtag_handler_setup)(void);
96void (*board_bind_eic_interrupt)(int irq, int regset);
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +000097void (*board_ebase_setup)(void);
Paul Gortmaker078a55f2013-06-18 13:38:59 +000098void(*board_cache_error_setup)(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200100static void show_raw_backtrace(unsigned long reg29)
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900101{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100102 unsigned long *sp = (unsigned long *)(reg29 & ~3);
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900103 unsigned long addr;
104
105 printk("Call Trace:");
106#ifdef CONFIG_KALLSYMS
107 printk("\n");
108#endif
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200109 while (!kstack_end(sp)) {
110 unsigned long __user *p =
111 (unsigned long __user *)(unsigned long)sp++;
112 if (__get_user(addr, p)) {
113 printk(" (Bad stack address)");
114 break;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100115 }
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200116 if (__kernel_text_address(addr))
117 print_ip_sym(addr);
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900118 }
Thomas Bogendoerfer10220c82008-05-12 17:58:48 +0200119 printk("\n");
Atsushi Nemotoe889d782006-07-25 23:51:36 +0900120}
121
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900122#ifdef CONFIG_KALLSYMS
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +0900123int raw_show_trace;
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900124static int __init set_raw_show_trace(char *str)
125{
126 raw_show_trace = 1;
127 return 1;
128}
129__setup("raw_show_trace", set_raw_show_trace);
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +0900130#endif
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200131
Ralf Baechleeae23f22007-10-14 23:27:21 +0100132static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900133{
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200134 unsigned long sp = regs->regs[29];
135 unsigned long ra = regs->regs[31];
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900136 unsigned long pc = regs->cp0_epc;
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900137
Vincent Wene909be82012-07-19 09:11:16 +0200138 if (!task)
139 task = current;
140
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900141 if (raw_show_trace || !__kernel_text_address(pc)) {
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200142 show_raw_backtrace(sp);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900143 return;
144 }
145 printk("Call Trace:\n");
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200146 do {
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200147 print_ip_sym(pc);
Atsushi Nemoto19246002006-09-29 18:02:51 +0900148 pc = unwind_stack(task, &sp, pc, &ra);
Franck Bui-Huu4d157d52006-08-03 09:29:21 +0200149 } while (pc);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900150 printk("\n");
151}
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/*
154 * This routine abuses get_user()/put_user() to reference pointers
155 * with at least a bit of error checking ...
156 */
Ralf Baechleeae23f22007-10-14 23:27:21 +0100157static void show_stacktrace(struct task_struct *task,
158 const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 const int field = 2 * sizeof(unsigned long);
161 long stackdata;
162 int i;
Atsushi Nemoto5e0373b2007-07-13 23:02:42 +0900163 unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 printk("Stack :");
166 i = 0;
167 while ((unsigned long) sp & (PAGE_SIZE - 1)) {
168 if (i && ((i % (64 / field)) == 0))
Ralf Baechle70342282013-01-22 12:59:30 +0100169 printk("\n ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 if (i > 39) {
171 printk(" ...");
172 break;
173 }
174
175 if (__get_user(stackdata, sp++)) {
176 printk(" (Bad stack address)");
177 break;
178 }
179
180 printk(" %0*lx", field, stackdata);
181 i++;
182 }
183 printk("\n");
Franck Bui-Huu87151ae2006-08-03 09:29:17 +0200184 show_backtrace(task, regs);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900185}
186
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900187void show_stack(struct task_struct *task, unsigned long *sp)
188{
189 struct pt_regs regs;
190 if (sp) {
191 regs.regs[29] = (unsigned long)sp;
192 regs.regs[31] = 0;
193 regs.cp0_epc = 0;
194 } else {
195 if (task && task != current) {
196 regs.regs[29] = task->thread.reg29;
197 regs.regs[31] = 0;
198 regs.cp0_epc = task->thread.reg31;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500199#ifdef CONFIG_KGDB_KDB
200 } else if (atomic_read(&kgdb_active) != -1 &&
201 kdb_current_regs) {
202 memcpy(&regs, kdb_current_regs, sizeof(regs));
203#endif /* CONFIG_KGDB_KDB */
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900204 } else {
205 prepare_frametrace(&regs);
206 }
207 }
208 show_stacktrace(task, &regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
210
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900211static void show_code(unsigned int __user *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 long i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100214 unsigned short __user *pc16 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 printk("\nCode:");
217
Ralf Baechle39b8d522008-04-28 17:14:26 +0100218 if ((unsigned long)pc & 1)
219 pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 for(i = -3 ; i < 6 ; i++) {
221 unsigned int insn;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100222 if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 printk(" (Bad address in epc)\n");
224 break;
225 }
Ralf Baechle39b8d522008-04-28 17:14:26 +0100226 printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228}
229
Ralf Baechleeae23f22007-10-14 23:27:21 +0100230static void __show_regs(const struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 const int field = 2 * sizeof(unsigned long);
233 unsigned int cause = regs->cp0_cause;
234 int i;
235
Tejun Heoa43cb952013-04-30 15:27:17 -0700236 show_regs_print_info(KERN_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 /*
239 * Saved main processor registers
240 */
241 for (i = 0; i < 32; ) {
242 if ((i % 4) == 0)
243 printk("$%2d :", i);
244 if (i == 0)
245 printk(" %0*lx", field, 0UL);
246 else if (i == 26 || i == 27)
247 printk(" %*s", field, "");
248 else
249 printk(" %0*lx", field, regs->regs[i]);
250
251 i++;
252 if ((i % 4) == 0)
253 printk("\n");
254 }
255
Franck Bui-Huu9693a852007-02-02 17:41:47 +0100256#ifdef CONFIG_CPU_HAS_SMARTMIPS
257 printk("Acx : %0*lx\n", field, regs->acx);
258#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 printk("Hi : %0*lx\n", field, regs->hi);
260 printk("Lo : %0*lx\n", field, regs->lo);
261
262 /*
263 * Saved cp0 registers
264 */
Ralf Baechleb012cff2008-07-15 18:44:33 +0100265 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
266 (void *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 printk(" %s\n", print_tainted());
Ralf Baechleb012cff2008-07-15 18:44:33 +0100268 printk("ra : %0*lx %pS\n", field, regs->regs[31],
269 (void *) regs->regs[31]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Ralf Baechle70342282013-01-22 12:59:30 +0100271 printk("Status: %08x ", (uint32_t) regs->cp0_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Ralf Baechle1990e542013-06-26 17:06:34 +0200273 if (cpu_has_3kex) {
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000274 if (regs->cp0_status & ST0_KUO)
275 printk("KUo ");
276 if (regs->cp0_status & ST0_IEO)
277 printk("IEo ");
278 if (regs->cp0_status & ST0_KUP)
279 printk("KUp ");
280 if (regs->cp0_status & ST0_IEP)
281 printk("IEp ");
282 if (regs->cp0_status & ST0_KUC)
283 printk("KUc ");
284 if (regs->cp0_status & ST0_IEC)
285 printk("IEc ");
Ralf Baechle1990e542013-06-26 17:06:34 +0200286 } else if (cpu_has_4kex) {
Maciej W. Rozycki3b2396d2005-06-22 20:43:29 +0000287 if (regs->cp0_status & ST0_KX)
288 printk("KX ");
289 if (regs->cp0_status & ST0_SX)
290 printk("SX ");
291 if (regs->cp0_status & ST0_UX)
292 printk("UX ");
293 switch (regs->cp0_status & ST0_KSU) {
294 case KSU_USER:
295 printk("USER ");
296 break;
297 case KSU_SUPERVISOR:
298 printk("SUPERVISOR ");
299 break;
300 case KSU_KERNEL:
301 printk("KERNEL ");
302 break;
303 default:
304 printk("BAD_MODE ");
305 break;
306 }
307 if (regs->cp0_status & ST0_ERL)
308 printk("ERL ");
309 if (regs->cp0_status & ST0_EXL)
310 printk("EXL ");
311 if (regs->cp0_status & ST0_IE)
312 printk("IE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 printk("\n");
315
316 printk("Cause : %08x\n", cause);
317
318 cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
319 if (1 <= cause && cause <= 5)
320 printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
321
Ralf Baechle9966db252007-10-11 23:46:17 +0100322 printk("PrId : %08x (%s)\n", read_c0_prid(),
323 cpu_name_string());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
Ralf Baechleeae23f22007-10-14 23:27:21 +0100326/*
327 * FIXME: really the generic show_regs should take a const pointer argument.
328 */
329void show_regs(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
Ralf Baechleeae23f22007-10-14 23:27:21 +0100331 __show_regs((struct pt_regs *)regs);
332}
333
David Daneyc1bf2072010-08-03 11:22:20 -0700334void show_registers(struct pt_regs *regs)
Ralf Baechleeae23f22007-10-14 23:27:21 +0100335{
Ralf Baechle39b8d522008-04-28 17:14:26 +0100336 const int field = 2 * sizeof(unsigned long);
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100337 mm_segment_t old_fs = get_fs();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100338
Ralf Baechleeae23f22007-10-14 23:27:21 +0100339 __show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 print_modules();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100341 printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
342 current->comm, current->pid, current_thread_info(), current,
343 field, current_thread_info()->tp_value);
344 if (cpu_has_userlocal) {
345 unsigned long tls;
346
347 tls = read_c0_userlocal();
348 if (tls != current_thread_info()->tp_value)
349 printk("*HwTLS: %0*lx\n", field, tls);
350 }
351
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100352 if (!user_mode(regs))
353 /* Necessary for getting the correct stack content */
354 set_fs(KERNEL_DS);
Atsushi Nemotof66686f2006-07-29 23:27:20 +0900355 show_stacktrace(current, regs);
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +0900356 show_code((unsigned int __user *) regs->cp0_epc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 printk("\n");
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +0100358 set_fs(old_fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
David Daney70dc6f02010-08-03 15:44:43 -0700361static int regs_to_trapnr(struct pt_regs *regs)
362{
363 return (regs->cp0_cause >> 2) & 0x1f;
364}
365
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000366static DEFINE_RAW_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
David Daney70dc6f02010-08-03 15:44:43 -0700368void __noreturn die(const char *str, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370 static int die_counter;
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400371 int sig = SIGSEGV;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100372#ifdef CONFIG_MIPS_MT_SMTC
Nathan Lynch8742cd22011-09-30 13:49:35 -0500373 unsigned long dvpret;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100374#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Nathan Lynch8742cd22011-09-30 13:49:35 -0500376 oops_enter();
377
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200378 if (notify_die(DIE_OOPS, str, regs, 0, regs_to_trapnr(regs),
379 SIGSEGV) == NOTIFY_STOP)
Ralf Baechle10423c92011-05-13 10:33:28 +0100380 sig = 0;
Jason Wessel5dd11d52010-05-20 21:04:26 -0500381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 console_verbose();
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000383 raw_spin_lock_irq(&die_lock);
Nathan Lynch8742cd22011-09-30 13:49:35 -0500384#ifdef CONFIG_MIPS_MT_SMTC
385 dvpret = dvpe();
386#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100387 bust_spinlocks(1);
388#ifdef CONFIG_MIPS_MT_SMTC
389 mips_mt_regdump(dvpret);
390#endif /* CONFIG_MIPS_MT_SMTC */
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400391
Ralf Baechle178086c2005-10-13 17:07:54 +0100392 printk("%s[#%d]:\n", str, ++die_counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 show_registers(regs);
Rusty Russell373d4d02013-01-21 17:17:39 +1030394 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
Wu Zhangjin4d85f6a2011-07-23 12:41:24 +0000395 raw_spin_unlock_irq(&die_lock);
Maxime Bizond4fd1982006-07-20 18:52:02 +0200396
Nathan Lynch8742cd22011-09-30 13:49:35 -0500397 oops_exit();
398
Maxime Bizond4fd1982006-07-20 18:52:02 +0200399 if (in_interrupt())
400 panic("Fatal exception in interrupt");
401
402 if (panic_on_oops) {
Ralf Baechleab75dc02011-11-17 15:07:31 +0000403 printk(KERN_EMERG "Fatal exception: panic in 5 seconds");
Maxime Bizond4fd1982006-07-20 18:52:02 +0200404 ssleep(5);
405 panic("Fatal exception");
406 }
407
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +0200408 if (regs && kexec_should_crash(current))
409 crash_kexec(regs);
410
Yury Polyanskiyce384d82010-04-26 00:53:10 -0400411 do_exit(sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Thomas Bogendoerfer05106172008-08-04 19:44:34 +0200414extern struct exception_table_entry __start___dbe_table[];
415extern struct exception_table_entry __stop___dbe_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Ralf Baechleb6dcec92007-02-18 15:57:09 +0000417__asm__(
418" .section __dbe_table, \"a\"\n"
419" .previous \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421/* Given an address, look for it in the exception tables. */
422static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
423{
424 const struct exception_table_entry *e;
425
426 e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
427 if (!e)
428 e = search_module_dbetables(addr);
429 return e;
430}
431
432asmlinkage void do_be(struct pt_regs *regs)
433{
434 const int field = 2 * sizeof(unsigned long);
435 const struct exception_table_entry *fixup = NULL;
436 int data = regs->cp0_cause & 4;
437 int action = MIPS_BE_FATAL;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200438 enum ctx_state prev_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200440 prev_state = exception_enter();
Ralf Baechle70342282013-01-22 12:59:30 +0100441 /* XXX For now. Fixme, this searches the wrong table ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (data && !user_mode(regs))
443 fixup = search_dbe_tables(exception_epc(regs));
444
445 if (fixup)
446 action = MIPS_BE_FIXUP;
447
448 if (board_be_handler)
Atsushi Nemoto28fc5822007-07-13 01:49:49 +0900449 action = board_be_handler(regs, fixup != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 switch (action) {
452 case MIPS_BE_DISCARD:
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200453 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 case MIPS_BE_FIXUP:
455 if (fixup) {
456 regs->cp0_epc = fixup->nextinsn;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200457 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459 break;
460 default:
461 break;
462 }
463
464 /*
465 * Assume it would be too dangerous to continue ...
466 */
467 printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
468 data ? "Data" : "Instruction",
469 field, regs->cp0_epc, field, regs->regs[31]);
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200470 if (notify_die(DIE_OOPS, "bus error", regs, 0, regs_to_trapnr(regs),
471 SIGBUS) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200472 goto out;
Jason Wessel88547002008-07-29 15:58:53 -0500473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 die_if_kernel("Oops", regs);
475 force_sig(SIGBUS, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200476
477out:
478 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481/*
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100482 * ll/sc, rdhwr, sync emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 */
484
485#define OPCODE 0xfc000000
486#define BASE 0x03e00000
487#define RT 0x001f0000
488#define OFFSET 0x0000ffff
489#define LL 0xc0000000
490#define SC 0xe0000000
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100491#define SPEC0 0x00000000
Ralf Baechle3c370262005-04-13 17:43:59 +0000492#define SPEC3 0x7c000000
493#define RD 0x0000f800
494#define FUNC 0x0000003f
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100495#define SYNC 0x0000000f
Ralf Baechle3c370262005-04-13 17:43:59 +0000496#define RDHWR 0x0000003b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500498/* microMIPS definitions */
499#define MM_POOL32A_FUNC 0xfc00ffff
500#define MM_RDHWR 0x00006b3c
501#define MM_RS 0x001f0000
502#define MM_RT 0x03e00000
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504/*
505 * The ll_bit is cleared by r*_switch.S
506 */
507
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200508unsigned int ll_bit;
509struct task_struct *ll_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100511static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000513 unsigned long value, __user *vaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 /*
517 * analyse the ll instruction that just caused a ri exception
518 * and put the referenced address to addr.
519 */
520
521 /* sign extend offset */
522 offset = opcode & OFFSET;
523 offset <<= 16;
524 offset >>= 16;
525
Ralf Baechlefe00f942005-03-01 19:22:29 +0000526 vaddr = (unsigned long __user *)
Steven J. Hillb9688312013-01-12 23:29:27 +0000527 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100529 if ((unsigned long)vaddr & 3)
530 return SIGBUS;
531 if (get_user(value, vaddr))
532 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 preempt_disable();
535
536 if (ll_task == NULL || ll_task == current) {
537 ll_bit = 1;
538 } else {
539 ll_bit = 0;
540 }
541 ll_task = current;
542
543 preempt_enable();
544
545 regs->regs[(opcode & RT) >> 16] = value;
546
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100547 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100550static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000552 unsigned long __user *vaddr;
553 unsigned long reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 /*
557 * analyse the sc instruction that just caused a ri exception
558 * and put the referenced address to addr.
559 */
560
561 /* sign extend offset */
562 offset = opcode & OFFSET;
563 offset <<= 16;
564 offset >>= 16;
565
Ralf Baechlefe00f942005-03-01 19:22:29 +0000566 vaddr = (unsigned long __user *)
Steven J. Hillb9688312013-01-12 23:29:27 +0000567 ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 reg = (opcode & RT) >> 16;
569
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100570 if ((unsigned long)vaddr & 3)
571 return SIGBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 preempt_disable();
574
575 if (ll_bit == 0 || ll_task != current) {
576 regs->regs[reg] = 0;
577 preempt_enable();
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100578 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 preempt_enable();
582
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100583 if (put_user(regs->regs[reg], vaddr))
584 return SIGSEGV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 regs->regs[reg] = 1;
587
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591/*
592 * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
593 * opcodes are supposed to result in coprocessor unusable exceptions if
594 * executed on ll/sc-less processors. That's the theory. In practice a
595 * few processors such as NEC's VR4100 throw reserved instruction exceptions
596 * instead, so we're doing the emulation thing in both exception handlers.
597 */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100598static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800600 if ((opcode & OPCODE) == LL) {
601 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200602 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100603 return simulate_ll(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800604 }
605 if ((opcode & OPCODE) == SC) {
606 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200607 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100608 return simulate_sc(regs, opcode);
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100611 return -1; /* Must be something else ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Ralf Baechle3c370262005-04-13 17:43:59 +0000614/*
615 * Simulate trapping 'rdhwr' instructions to provide user accessible
Chris Dearman1f5826b2006-05-08 18:02:16 +0100616 * registers not implemented in hardware.
Ralf Baechle3c370262005-04-13 17:43:59 +0000617 */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500618static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
Ralf Baechle3c370262005-04-13 17:43:59 +0000619{
Al Virodc8f6022006-01-12 01:06:07 -0800620 struct thread_info *ti = task_thread_info(current);
Ralf Baechle3c370262005-04-13 17:43:59 +0000621
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500622 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
623 1, regs, 0);
624 switch (rd) {
625 case 0: /* CPU number */
626 regs->regs[rt] = smp_processor_id();
627 return 0;
628 case 1: /* SYNCI length */
629 regs->regs[rt] = min(current_cpu_data.dcache.linesz,
630 current_cpu_data.icache.linesz);
631 return 0;
632 case 2: /* Read count register */
633 regs->regs[rt] = read_c0_count();
634 return 0;
635 case 3: /* Count register resolution */
Ralf Baechle69f24d12013-09-17 10:25:47 +0200636 switch (current_cpu_type()) {
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500637 case CPU_20KC:
638 case CPU_25KF:
639 regs->regs[rt] = 1;
640 break;
641 default:
642 regs->regs[rt] = 2;
643 }
644 return 0;
645 case 29:
646 regs->regs[rt] = ti->tp_value;
647 return 0;
648 default:
649 return -1;
650 }
651}
652
653static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
654{
Ralf Baechle3c370262005-04-13 17:43:59 +0000655 if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
656 int rd = (opcode & RD) >> 11;
657 int rt = (opcode & RT) >> 16;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500658
659 simulate_rdhwr(regs, rd, rt);
660 return 0;
661 }
662
663 /* Not ours. */
664 return -1;
665}
666
667static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned short opcode)
668{
669 if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
670 int rd = (opcode & MM_RS) >> 16;
671 int rt = (opcode & MM_RT) >> 21;
672 simulate_rdhwr(regs, rd, rt);
673 return 0;
Ralf Baechle3c370262005-04-13 17:43:59 +0000674 }
675
Daniel Jacobowitz56ebd512005-11-26 22:34:41 -0500676 /* Not ours. */
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100677 return -1;
678}
Ralf Baechlee5679882006-11-30 01:14:47 +0000679
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100680static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
681{
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800682 if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
683 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200684 1, regs, 0);
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100685 return 0;
Deng-Cheng Zhu7f788d22010-10-12 19:37:21 +0800686 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100687
688 return -1; /* Must be something else ... */
Ralf Baechle3c370262005-04-13 17:43:59 +0000689}
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691asmlinkage void do_ov(struct pt_regs *regs)
692{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200693 enum ctx_state prev_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 siginfo_t info;
695
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200696 prev_state = exception_enter();
Ralf Baechle36ccf1c2006-02-14 21:04:54 +0000697 die_if_kernel("Integer overflow", regs);
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 info.si_code = FPE_INTOVF;
700 info.si_signo = SIGFPE;
701 info.si_errno = 0;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000702 info.si_addr = (void __user *) regs->cp0_epc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 force_sig_info(SIGFPE, &info, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200704 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
Leonid Yegoshin102cedc2013-03-25 12:09:02 -0500707int process_fpemu_return(int sig, void __user *fault_addr)
David Daney515b0292010-10-21 16:32:26 -0700708{
709 if (sig == SIGSEGV || sig == SIGBUS) {
710 struct siginfo si = {0};
711 si.si_addr = fault_addr;
712 si.si_signo = sig;
713 if (sig == SIGSEGV) {
714 if (find_vma(current->mm, (unsigned long)fault_addr))
715 si.si_code = SEGV_ACCERR;
716 else
717 si.si_code = SEGV_MAPERR;
718 } else {
719 si.si_code = BUS_ADRERR;
720 }
721 force_sig_info(sig, &si, current);
722 return 1;
723 } else if (sig) {
724 force_sig(sig, current);
725 return 1;
726 } else {
727 return 0;
728 }
729}
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731/*
732 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
733 */
734asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
735{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200736 enum ctx_state prev_state;
David Daney515b0292010-10-21 16:32:26 -0700737 siginfo_t info = {0};
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100738
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200739 prev_state = exception_enter();
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200740 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs),
741 SIGFPE) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200742 goto out;
Chris Dearman57725f92006-06-30 23:35:28 +0100743 die_if_kernel("FP exception in kernel code", regs);
744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 if (fcr31 & FPU_CSR_UNI_X) {
746 int sig;
David Daney515b0292010-10-21 16:32:26 -0700747 void __user *fault_addr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 /*
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000750 * Unimplemented operation exception. If we've got the full
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 * software emulator on-board, let's use it...
752 *
753 * Force FPU to dump state into task/thread context. We're
754 * moving a lot of data here for what is probably a single
755 * instruction, but the alternative is to pre-decode the FP
756 * register operands before invoking the emulator, which seems
757 * a bit extreme for what should be an infrequent event.
758 */
Ralf Baechlecd21dfc2005-04-28 13:39:10 +0000759 /* Ensure 'resume' not overwrite saved fp context again. */
Atsushi Nemoto53dc8022007-03-10 01:07:45 +0900760 lose_fpu(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /* Run the emulator */
David Daney515b0292010-10-21 16:32:26 -0700763 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
764 &fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 /*
767 * We can't allow the emulated instruction to leave any of
768 * the cause bit set in $fcr31.
769 */
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900770 current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 /* Restore the hardware register state */
Ralf Baechle70342282013-01-22 12:59:30 +0100773 own_fpu(1); /* Using the FPU again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 /* If something went wrong, signal */
David Daney515b0292010-10-21 16:32:26 -0700776 process_fpemu_return(sig, fault_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200778 goto out;
Thiemo Seufer948a34c2007-08-22 01:42:04 +0100779 } else if (fcr31 & FPU_CSR_INV_X)
780 info.si_code = FPE_FLTINV;
781 else if (fcr31 & FPU_CSR_DIV_X)
782 info.si_code = FPE_FLTDIV;
783 else if (fcr31 & FPU_CSR_OVF_X)
784 info.si_code = FPE_FLTOVF;
785 else if (fcr31 & FPU_CSR_UDF_X)
786 info.si_code = FPE_FLTUND;
787 else if (fcr31 & FPU_CSR_INE_X)
788 info.si_code = FPE_FLTRES;
789 else
790 info.si_code = __SI_FAULT;
791 info.si_signo = SIGFPE;
792 info.si_errno = 0;
793 info.si_addr = (void __user *) regs->cp0_epc;
794 force_sig_info(SIGFPE, &info, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200795
796out:
797 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Ralf Baechledf270052008-04-20 16:28:54 +0100800static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
801 const char *str)
802{
803 siginfo_t info;
804 char b[40];
805
Jason Wessel5dd11d52010-05-20 21:04:26 -0500806#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
David Daney70dc6f02010-08-03 15:44:43 -0700807 if (kgdb_ll_trap(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Jason Wessel5dd11d52010-05-20 21:04:26 -0500808 return;
809#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
810
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200811 if (notify_die(DIE_TRAP, str, regs, code, regs_to_trapnr(regs),
812 SIGTRAP) == NOTIFY_STOP)
Jason Wessel88547002008-07-29 15:58:53 -0500813 return;
814
Ralf Baechledf270052008-04-20 16:28:54 +0100815 /*
816 * A short test says that IRIX 5.3 sends SIGTRAP for all trap
817 * insns, even for trap and break codes that indicate arithmetic
818 * failures. Weird ...
819 * But should we continue the brokenness??? --macro
820 */
821 switch (code) {
822 case BRK_OVERFLOW:
823 case BRK_DIVZERO:
824 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
825 die_if_kernel(b, regs);
826 if (code == BRK_DIVZERO)
827 info.si_code = FPE_INTDIV;
828 else
829 info.si_code = FPE_INTOVF;
830 info.si_signo = SIGFPE;
831 info.si_errno = 0;
832 info.si_addr = (void __user *) regs->cp0_epc;
833 force_sig_info(SIGFPE, &info, current);
834 break;
835 case BRK_BUG:
836 die_if_kernel("Kernel bug detected", regs);
837 force_sig(SIGTRAP, current);
838 break;
Ralf Baechleba3049e2008-10-28 17:38:42 +0000839 case BRK_MEMU:
840 /*
841 * Address errors may be deliberately induced by the FPU
842 * emulator to retake control of the CPU after executing the
843 * instruction in the delay slot of an emulated branch.
844 *
845 * Terminate if exception was recognized as a delay slot return
846 * otherwise handle as normal.
847 */
848 if (do_dsemulret(regs))
849 return;
850
851 die_if_kernel("Math emu break/trap", regs);
852 force_sig(SIGTRAP, current);
853 break;
Ralf Baechledf270052008-04-20 16:28:54 +0100854 default:
855 scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
856 die_if_kernel(b, regs);
857 force_sig(SIGTRAP, current);
858 }
859}
860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861asmlinkage void do_bp(struct pt_regs *regs)
862{
863 unsigned int opcode, bcode;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200864 enum ctx_state prev_state;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500865 unsigned long epc;
866 u16 instr[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200868 prev_state = exception_enter();
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500869 if (get_isa16_mode(regs->cp0_epc)) {
870 /* Calculate EPC. */
871 epc = exception_epc(regs);
872 if (cpu_has_mmips) {
873 if ((__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)) ||
874 (__get_user(instr[1], (u16 __user *)msk_isa16_mode(epc + 2)))))
875 goto out_sigsegv;
876 opcode = (instr[0] << 16) | instr[1];
877 } else {
878 /* MIPS16e mode */
879 if (__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)))
880 goto out_sigsegv;
881 bcode = (instr[0] >> 6) & 0x3f;
882 do_trap_or_bp(regs, bcode, "Break");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200883 goto out;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500884 }
885 } else {
886 if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
887 goto out_sigsegv;
888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /*
891 * There is the ancient bug in the MIPS assemblers that the break
892 * code starts left to bit 16 instead to bit 6 in the opcode.
893 * Gas is bug-compatible, but not always, grrr...
894 * We handle both cases with a simple heuristics. --macro
895 */
896 bcode = ((opcode >> 6) & ((1 << 20) - 1));
Ralf Baechledf270052008-04-20 16:28:54 +0100897 if (bcode >= (1 << 10))
898 bcode >>= 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
David Daneyc1bf2072010-08-03 11:22:20 -0700900 /*
901 * notify the kprobe handlers, if instruction is likely to
902 * pertain to them.
903 */
904 switch (bcode) {
905 case BRK_KPROBE_BP:
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200906 if (notify_die(DIE_BREAK, "debug", regs, bcode,
907 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200908 goto out;
David Daneyc1bf2072010-08-03 11:22:20 -0700909 else
910 break;
911 case BRK_KPROBE_SSTEPBP:
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200912 if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
913 regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200914 goto out;
David Daneyc1bf2072010-08-03 11:22:20 -0700915 else
916 break;
917 default:
918 break;
919 }
920
Ralf Baechledf270052008-04-20 16:28:54 +0100921 do_trap_or_bp(regs, bcode, "Break");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200922
923out:
924 exception_exit(prev_state);
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900925 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000926
927out_sigsegv:
928 force_sig(SIGSEGV, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200929 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
932asmlinkage void do_tr(struct pt_regs *regs)
933{
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000934 u32 opcode, tcode = 0;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200935 enum ctx_state prev_state;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500936 u16 instr[2];
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000937 unsigned long epc = msk_isa16_mode(exception_epc(regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200939 prev_state = exception_enter();
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000940 if (get_isa16_mode(regs->cp0_epc)) {
941 if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
942 __get_user(instr[1], (u16 __user *)(epc + 2)))
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500943 goto out_sigsegv;
Maciej W. Rozyckia9a6e7a2013-05-23 14:31:23 +0000944 opcode = (instr[0] << 16) | instr[1];
945 /* Immediate versions don't provide a code. */
946 if (!(opcode & OPCODE))
947 tcode = (opcode >> 12) & ((1 << 4) - 1);
948 } else {
949 if (__get_user(opcode, (u32 __user *)epc))
950 goto out_sigsegv;
951 /* Immediate versions don't provide a code. */
952 if (!(opcode & OPCODE))
953 tcode = (opcode >> 6) & ((1 << 10) - 1);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Ralf Baechledf270052008-04-20 16:28:54 +0100956 do_trap_or_bp(regs, tcode, "Trap");
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200957
958out:
959 exception_exit(prev_state);
Atsushi Nemoto90fccb12007-02-06 16:02:21 +0900960 return;
Ralf Baechlee5679882006-11-30 01:14:47 +0000961
962out_sigsegv:
963 force_sig(SIGSEGV, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200964 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
967asmlinkage void do_ri(struct pt_regs *regs)
968{
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100969 unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
970 unsigned long old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500971 unsigned long old31 = regs->regs[31];
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200972 enum ctx_state prev_state;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100973 unsigned int opcode = 0;
974 int status = -1;
975
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200976 prev_state = exception_enter();
Ralf Baechledc73e4c2013-10-09 08:54:15 +0200977 if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs),
978 SIGILL) == NOTIFY_STOP)
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200979 goto out;
Jason Wessel88547002008-07-29 15:58:53 -0500980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 die_if_kernel("Reserved instruction in kernel code", regs);
982
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100983 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +0200984 goto out;
Ralf Baechle3c370262005-04-13 17:43:59 +0000985
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500986 if (get_isa16_mode(regs->cp0_epc)) {
987 unsigned short mmop[2] = { 0 };
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100988
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500989 if (unlikely(get_user(mmop[0], epc) < 0))
990 status = SIGSEGV;
991 if (unlikely(get_user(mmop[1], epc) < 0))
992 status = SIGSEGV;
993 opcode = (mmop[0] << 16) | mmop[1];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +0100994
Steven J. Hill2a0b24f2013-03-25 12:15:55 -0500995 if (status < 0)
996 status = simulate_rdhwr_mm(regs, opcode);
997 } else {
998 if (unlikely(get_user(opcode, epc) < 0))
999 status = SIGSEGV;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001000
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001001 if (!cpu_has_llsc && status < 0)
1002 status = simulate_llsc(regs, opcode);
1003
1004 if (status < 0)
1005 status = simulate_rdhwr_normal(regs, opcode);
1006
1007 if (status < 0)
1008 status = simulate_sync(regs, opcode);
1009 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001010
1011 if (status < 0)
1012 status = SIGILL;
1013
1014 if (unlikely(status > 0)) {
1015 regs->cp0_epc = old_epc; /* Undo skip-over. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001016 regs->regs[31] = old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001017 force_sig(status, current);
1018 }
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001019
1020out:
1021 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
Ralf Baechled223a862007-07-10 17:33:02 +01001024/*
1025 * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
1026 * emulated more than some threshold number of instructions, force migration to
1027 * a "CPU" that has FP support.
1028 */
1029static void mt_ase_fp_affinity(void)
1030{
1031#ifdef CONFIG_MIPS_MT_FPAFF
1032 if (mt_fpemul_threshold > 0 &&
1033 ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
1034 /*
1035 * If there's no FPU present, or if the application has already
1036 * restricted the allowed set to exclude any CPUs with FPUs,
1037 * we'll skip the procedure.
1038 */
1039 if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
1040 cpumask_t tmask;
1041
Kevin D. Kissell9cc12362008-09-09 21:33:36 +02001042 current->thread.user_cpus_allowed
1043 = current->cpus_allowed;
1044 cpus_and(tmask, current->cpus_allowed,
1045 mt_fpu_cpumask);
Julia Lawalled1bbde2010-03-26 23:03:07 +01001046 set_cpus_allowed_ptr(current, &tmask);
Ralf Baechle293c5bd2007-07-25 16:19:33 +01001047 set_thread_flag(TIF_FPUBOUND);
Ralf Baechled223a862007-07-10 17:33:02 +01001048 }
1049 }
1050#endif /* CONFIG_MIPS_MT_FPAFF */
1051}
1052
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001053/*
1054 * No lock; only written during early bootup by CPU 0.
1055 */
1056static RAW_NOTIFIER_HEAD(cu2_chain);
1057
1058int __ref register_cu2_notifier(struct notifier_block *nb)
1059{
1060 return raw_notifier_chain_register(&cu2_chain, nb);
1061}
1062
1063int cu2_notifier_call_chain(unsigned long val, void *v)
1064{
1065 return raw_notifier_call_chain(&cu2_chain, val, v);
1066}
1067
1068static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
Ralf Baechle70342282013-01-22 12:59:30 +01001069 void *data)
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001070{
1071 struct pt_regs *regs = data;
1072
Jayachandran C83bee792013-06-10 06:30:01 +00001073 die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001074 "instruction", regs);
Jayachandran C83bee792013-06-10 06:30:01 +00001075 force_sig(SIGILL, current);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001076
1077 return NOTIFY_OK;
1078}
1079
Paul Burton1db1af82014-01-27 15:23:11 +00001080static int enable_restore_fp_context(int msa)
1081{
1082 int err, was_fpu_owner;
1083
1084 if (!used_math()) {
1085 /* First time FP context user. */
1086 err = init_fpu();
1087 if (msa && !err)
1088 enable_msa();
1089 if (!err)
1090 set_used_math();
1091 return err;
1092 }
1093
1094 /*
1095 * This task has formerly used the FP context.
1096 *
1097 * If this thread has no live MSA vector context then we can simply
1098 * restore the scalar FP context. If it has live MSA vector context
1099 * (that is, it has or may have used MSA since last performing a
1100 * function call) then we'll need to restore the vector context. This
1101 * applies even if we're currently only executing a scalar FP
1102 * instruction. This is because if we were to later execute an MSA
1103 * instruction then we'd either have to:
1104 *
1105 * - Restore the vector context & clobber any registers modified by
1106 * scalar FP instructions between now & then.
1107 *
1108 * or
1109 *
1110 * - Not restore the vector context & lose the most significant bits
1111 * of all vector registers.
1112 *
1113 * Neither of those options is acceptable. We cannot restore the least
1114 * significant bits of the registers now & only restore the most
1115 * significant bits later because the most significant bits of any
1116 * vector registers whose aliased FP register is modified now will have
1117 * been zeroed. We'd have no way to know that when restoring the vector
1118 * context & thus may load an outdated value for the most significant
1119 * bits of a vector register.
1120 */
1121 if (!msa && !thread_msa_context_live())
1122 return own_fpu(1);
1123
1124 /*
1125 * This task is using or has previously used MSA. Thus we require
1126 * that Status.FR == 1.
1127 */
1128 was_fpu_owner = is_fpu_owner();
1129 err = own_fpu(0);
1130 if (err)
1131 return err;
1132
1133 enable_msa();
1134 write_msa_csr(current->thread.fpu.msacsr);
1135 set_thread_flag(TIF_USEDMSA);
1136
1137 /*
1138 * If this is the first time that the task is using MSA and it has
1139 * previously used scalar FP in this time slice then we already nave
1140 * FP context which we shouldn't clobber.
1141 */
1142 if (!test_and_set_thread_flag(TIF_MSA_CTX_LIVE) && was_fpu_owner)
1143 return 0;
1144
1145 /* We need to restore the vector context. */
1146 restore_msa(current);
1147 return 0;
1148}
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150asmlinkage void do_cpu(struct pt_regs *regs)
1151{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001152 enum ctx_state prev_state;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001153 unsigned int __user *epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001154 unsigned long old_epc, old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001155 unsigned int opcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 unsigned int cpid;
Paul Burton597ce172013-11-22 13:12:07 +00001157 int status, err;
David Daneyf9bb4cf2008-12-11 15:33:23 -08001158 unsigned long __maybe_unused flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001160 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
1162
Jayachandran C83bee792013-06-10 06:30:01 +00001163 if (cpid != 2)
1164 die_if_kernel("do_cpu invoked from kernel context!", regs);
1165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 switch (cpid) {
1167 case 0:
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001168 epc = (unsigned int __user *)exception_epc(regs);
1169 old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001170 old31 = regs->regs[31];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001171 opcode = 0;
1172 status = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001174 if (unlikely(compute_return_epc(regs) < 0))
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001175 goto out;
Ralf Baechle3c370262005-04-13 17:43:59 +00001176
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001177 if (get_isa16_mode(regs->cp0_epc)) {
1178 unsigned short mmop[2] = { 0 };
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001179
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001180 if (unlikely(get_user(mmop[0], epc) < 0))
1181 status = SIGSEGV;
1182 if (unlikely(get_user(mmop[1], epc) < 0))
1183 status = SIGSEGV;
1184 opcode = (mmop[0] << 16) | mmop[1];
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001185
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001186 if (status < 0)
1187 status = simulate_rdhwr_mm(regs, opcode);
1188 } else {
1189 if (unlikely(get_user(opcode, epc) < 0))
1190 status = SIGSEGV;
1191
1192 if (!cpu_has_llsc && status < 0)
1193 status = simulate_llsc(regs, opcode);
1194
1195 if (status < 0)
1196 status = simulate_rdhwr_normal(regs, opcode);
1197 }
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001198
1199 if (status < 0)
1200 status = SIGILL;
1201
1202 if (unlikely(status > 0)) {
1203 regs->cp0_epc = old_epc; /* Undo skip-over. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001204 regs->regs[31] = old31;
Maciej W. Rozycki60b0d652007-10-16 18:43:26 +01001205 force_sig(status, current);
1206 }
1207
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001208 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001210 case 3:
1211 /*
1212 * Old (MIPS I and MIPS II) processors will set this code
1213 * for COP1X opcode instructions that replaced the original
Ralf Baechle70342282013-01-22 12:59:30 +01001214 * COP3 space. We don't limit COP1 space instructions in
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001215 * the emulator according to the CPU ISA, so we want to
1216 * treat COP1X instructions consistently regardless of which
Ralf Baechle70342282013-01-22 12:59:30 +01001217 * code the CPU chose. Therefore we redirect this trap to
Maciej W. Rozycki051ff442012-03-06 20:28:54 +00001218 * the FP emulator too.
1219 *
1220 * Then some newer FPU-less processors use this code
1221 * erroneously too, so they are covered by this choice
1222 * as well.
1223 */
1224 if (raw_cpu_has_fpu)
1225 break;
1226 /* Fall through. */
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 case 1:
Paul Burton1db1af82014-01-27 15:23:11 +00001229 err = enable_restore_fp_context(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Paul Burton597ce172013-11-22 13:12:07 +00001231 if (!raw_cpu_has_fpu || err) {
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001232 int sig;
David Daney515b0292010-10-21 16:32:26 -07001233 void __user *fault_addr = NULL;
Atsushi Nemotoe04582b2006-10-09 00:10:01 +09001234 sig = fpu_emulator_cop1Handler(regs,
David Daney515b0292010-10-21 16:32:26 -07001235 &current->thread.fpu,
1236 0, &fault_addr);
Paul Burton597ce172013-11-22 13:12:07 +00001237 if (!process_fpemu_return(sig, fault_addr) && !err)
Ralf Baechled223a862007-07-10 17:33:02 +01001238 mt_ase_fp_affinity();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 }
1240
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001241 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 case 2:
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00001244 raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001245 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 }
1247
1248 force_sig(SIGILL, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001249
1250out:
1251 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Paul Burton2bcb3fb2014-01-27 15:23:12 +00001254asmlinkage void do_msa_fpe(struct pt_regs *regs)
1255{
1256 enum ctx_state prev_state;
1257
1258 prev_state = exception_enter();
1259 die_if_kernel("do_msa_fpe invoked from kernel context!", regs);
1260 force_sig(SIGFPE, current);
1261 exception_exit(prev_state);
1262}
1263
Paul Burton1db1af82014-01-27 15:23:11 +00001264asmlinkage void do_msa(struct pt_regs *regs)
1265{
1266 enum ctx_state prev_state;
1267 int err;
1268
1269 prev_state = exception_enter();
1270
1271 if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) {
1272 force_sig(SIGILL, current);
1273 goto out;
1274 }
1275
1276 die_if_kernel("do_msa invoked from kernel context!", regs);
1277
1278 err = enable_restore_fp_context(1);
1279 if (err)
1280 force_sig(SIGILL, current);
1281out:
1282 exception_exit(prev_state);
1283}
1284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285asmlinkage void do_mdmx(struct pt_regs *regs)
1286{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001287 enum ctx_state prev_state;
1288
1289 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 force_sig(SIGILL, current);
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001291 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
David Daney8bc6d052009-01-05 15:29:58 -08001294/*
1295 * Called with interrupts disabled.
1296 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297asmlinkage void do_watch(struct pt_regs *regs)
1298{
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001299 enum ctx_state prev_state;
David Daneyb67b2b72008-09-23 00:08:45 -07001300 u32 cause;
1301
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001302 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 /*
David Daneyb67b2b72008-09-23 00:08:45 -07001304 * Clear WP (bit 22) bit of cause register so we don't loop
1305 * forever.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 */
David Daneyb67b2b72008-09-23 00:08:45 -07001307 cause = read_c0_cause();
1308 cause &= ~(1 << 22);
1309 write_c0_cause(cause);
1310
1311 /*
1312 * If the current thread has the watch registers loaded, save
1313 * their values and send SIGTRAP. Otherwise another thread
1314 * left the registers set, clear them and continue.
1315 */
1316 if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
1317 mips_read_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001318 local_irq_enable();
David Daneyb67b2b72008-09-23 00:08:45 -07001319 force_sig(SIGTRAP, current);
David Daney8bc6d052009-01-05 15:29:58 -08001320 } else {
David Daneyb67b2b72008-09-23 00:08:45 -07001321 mips_clear_watch_registers();
David Daney8bc6d052009-01-05 15:29:58 -08001322 local_irq_enable();
1323 }
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001324 exception_exit(prev_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
1327asmlinkage void do_mcheck(struct pt_regs *regs)
1328{
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001329 const int field = 2 * sizeof(unsigned long);
1330 int multi_match = regs->cp0_status & ST0_TS;
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001331 enum ctx_state prev_state;
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001332
Ralf Baechlec3fc5cd2013-05-29 01:07:19 +02001333 prev_state = exception_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 show_regs(regs);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001335
1336 if (multi_match) {
Ralf Baechle70342282013-01-22 12:59:30 +01001337 printk("Index : %0x\n", read_c0_index());
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001338 printk("Pagemask: %0x\n", read_c0_pagemask());
1339 printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
1340 printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
1341 printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
1342 printk("\n");
1343 dump_tlb_all();
1344 }
1345
Atsushi Nemotoe1bb82892007-07-13 23:51:46 +09001346 show_code((unsigned int __user *) regs->cp0_epc);
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 /*
1349 * Some chips may have other causes of machine check (e.g. SB1
1350 * graduation timer)
1351 */
1352 panic("Caught Machine Check exception - %scaused by multiple "
1353 "matching entries in the TLB.",
Ralf Baechlecac4bcb2006-05-24 16:51:02 +01001354 (multi_match) ? "" : "not ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001357asmlinkage void do_mt(struct pt_regs *regs)
1358{
Ralf Baechle41c594a2006-04-05 09:45:45 +01001359 int subcode;
1360
Ralf Baechle41c594a2006-04-05 09:45:45 +01001361 subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
1362 >> VPECONTROL_EXCPT_SHIFT;
1363 switch (subcode) {
1364 case 0:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001365 printk(KERN_DEBUG "Thread Underflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001366 break;
1367 case 1:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001368 printk(KERN_DEBUG "Thread Overflow\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001369 break;
1370 case 2:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001371 printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001372 break;
1373 case 3:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001374 printk(KERN_DEBUG "Gating Storage Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001375 break;
1376 case 4:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001377 printk(KERN_DEBUG "YIELD Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001378 break;
1379 case 5:
Masanari Iidaf232c7e2012-02-08 21:53:14 +09001380 printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001381 break;
1382 default:
Chris Dearmane35a5e32006-06-30 14:19:45 +01001383 printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
Ralf Baechle41c594a2006-04-05 09:45:45 +01001384 subcode);
1385 break;
1386 }
Ralf Baechle340ee4b2005-08-17 17:44:08 +00001387 die_if_kernel("MIPS MT Thread exception in kernel", regs);
1388
1389 force_sig(SIGILL, current);
1390}
1391
1392
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001393asmlinkage void do_dsp(struct pt_regs *regs)
1394{
1395 if (cpu_has_dsp)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001396 panic("Unexpected DSP exception");
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001397
1398 force_sig(SIGILL, current);
1399}
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401asmlinkage void do_reserved(struct pt_regs *regs)
1402{
1403 /*
Ralf Baechle70342282013-01-22 12:59:30 +01001404 * Game over - no way to handle this if it ever occurs. Most probably
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 * caused by a new unknown cpu type or after another deadly
1406 * hard/software error.
1407 */
1408 show_regs(regs);
1409 panic("Caught reserved exception %ld - should not happen.",
1410 (regs->cp0_cause & 0x7f) >> 2);
1411}
1412
Ralf Baechle39b8d522008-04-28 17:14:26 +01001413static int __initdata l1parity = 1;
1414static int __init nol1parity(char *s)
1415{
1416 l1parity = 0;
1417 return 1;
1418}
1419__setup("nol1par", nol1parity);
1420static int __initdata l2parity = 1;
1421static int __init nol2parity(char *s)
1422{
1423 l2parity = 0;
1424 return 1;
1425}
1426__setup("nol2par", nol2parity);
1427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428/*
1429 * Some MIPS CPUs can enable/disable for cache parity detection, but do
1430 * it different ways.
1431 */
1432static inline void parity_protection_init(void)
1433{
Ralf Baechle10cc3522007-10-11 23:46:15 +01001434 switch (current_cpu_type()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 case CPU_24K:
Nigel Stephens98a41de2006-04-27 15:50:32 +01001436 case CPU_34K:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001437 case CPU_74K:
1438 case CPU_1004K:
Steven J. Hill442e14a2014-01-17 15:03:50 -06001439 case CPU_1074K:
Leonid Yegoshin26ab96d2013-11-27 10:07:53 +00001440 case CPU_INTERAPTIV:
Leonid Yegoshin708ac4b2013-11-14 16:12:27 +00001441 case CPU_PROAPTIV:
Ralf Baechle39b8d522008-04-28 17:14:26 +01001442 {
1443#define ERRCTL_PE 0x80000000
1444#define ERRCTL_L2P 0x00800000
1445 unsigned long errctl;
1446 unsigned int l1parity_present, l2parity_present;
1447
1448 errctl = read_c0_ecc();
1449 errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
1450
1451 /* probe L1 parity support */
1452 write_c0_ecc(errctl | ERRCTL_PE);
1453 back_to_back_c0_hazard();
1454 l1parity_present = (read_c0_ecc() & ERRCTL_PE);
1455
1456 /* probe L2 parity support */
1457 write_c0_ecc(errctl|ERRCTL_L2P);
1458 back_to_back_c0_hazard();
1459 l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
1460
1461 if (l1parity_present && l2parity_present) {
1462 if (l1parity)
1463 errctl |= ERRCTL_PE;
1464 if (l1parity ^ l2parity)
1465 errctl |= ERRCTL_L2P;
1466 } else if (l1parity_present) {
1467 if (l1parity)
1468 errctl |= ERRCTL_PE;
1469 } else if (l2parity_present) {
1470 if (l2parity)
1471 errctl |= ERRCTL_L2P;
1472 } else {
1473 /* No parity available */
1474 }
1475
1476 printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
1477
1478 write_c0_ecc(errctl);
1479 back_to_back_c0_hazard();
1480 errctl = read_c0_ecc();
1481 printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
1482
1483 if (l1parity_present)
1484 printk(KERN_INFO "Cache parity protection %sabled\n",
1485 (errctl & ERRCTL_PE) ? "en" : "dis");
1486
1487 if (l2parity_present) {
1488 if (l1parity_present && l1parity)
1489 errctl ^= ERRCTL_L2P;
1490 printk(KERN_INFO "L2 cache parity protection %sabled\n",
1491 (errctl & ERRCTL_L2P) ? "en" : "dis");
1492 }
1493 }
1494 break;
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 case CPU_5KC:
Leonid Yegoshin78d48032012-07-06 21:56:01 +02001497 case CPU_5KE:
Kelvin Cheung2fa36392012-06-20 20:05:32 +01001498 case CPU_LOONGSON1:
Ralf Baechle14f18b72005-03-01 18:15:08 +00001499 write_c0_ecc(0x80000000);
1500 back_to_back_c0_hazard();
1501 /* Set the PE bit (bit 31) in the c0_errctl register. */
1502 printk(KERN_INFO "Cache parity protection %sabled\n",
1503 (read_c0_ecc() & 0x80000000) ? "en" : "dis");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 break;
1505 case CPU_20KC:
1506 case CPU_25KF:
1507 /* Clear the DE bit (bit 16) in the c0_status register. */
1508 printk(KERN_INFO "Enable cache parity protection for "
1509 "MIPS 20KC/25KF CPUs.\n");
1510 clear_c0_status(ST0_DE);
1511 break;
1512 default:
1513 break;
1514 }
1515}
1516
1517asmlinkage void cache_parity_error(void)
1518{
1519 const int field = 2 * sizeof(unsigned long);
1520 unsigned int reg_val;
1521
1522 /* For the moment, report the problem and hang. */
1523 printk("Cache error exception:\n");
1524 printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1525 reg_val = read_c0_cacheerr();
1526 printk("c0_cacheerr == %08x\n", reg_val);
1527
1528 printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1529 reg_val & (1<<30) ? "secondary" : "primary",
1530 reg_val & (1<<31) ? "data" : "insn");
Leonid Yegoshin6de20452013-10-10 09:58:59 +01001531 if (cpu_has_mips_r2 &&
1532 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1533 pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
1534 reg_val & (1<<29) ? "ED " : "",
1535 reg_val & (1<<28) ? "ET " : "",
1536 reg_val & (1<<27) ? "ES " : "",
1537 reg_val & (1<<26) ? "EE " : "",
1538 reg_val & (1<<25) ? "EB " : "",
1539 reg_val & (1<<24) ? "EI " : "",
1540 reg_val & (1<<23) ? "E1 " : "",
1541 reg_val & (1<<22) ? "E0 " : "");
1542 } else {
1543 pr_err("Error bits: %s%s%s%s%s%s%s\n",
1544 reg_val & (1<<29) ? "ED " : "",
1545 reg_val & (1<<28) ? "ET " : "",
1546 reg_val & (1<<26) ? "EE " : "",
1547 reg_val & (1<<25) ? "EB " : "",
1548 reg_val & (1<<24) ? "EI " : "",
1549 reg_val & (1<<23) ? "E1 " : "",
1550 reg_val & (1<<22) ? "E0 " : "");
1551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1553
Ralf Baechleec917c2c2005-10-07 16:58:15 +01001554#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 if (reg_val & (1<<22))
1556 printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
1557
1558 if (reg_val & (1<<23))
1559 printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
1560#endif
1561
1562 panic("Can't handle the cache error!");
1563}
1564
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +00001565asmlinkage void do_ftlb(void)
1566{
1567 const int field = 2 * sizeof(unsigned long);
1568 unsigned int reg_val;
1569
1570 /* For the moment, report the problem and hang. */
1571 if (cpu_has_mips_r2 &&
1572 ((current_cpu_data.processor_id && 0xff0000) == PRID_COMP_MIPS)) {
1573 pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
1574 read_c0_ecc());
1575 pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
1576 reg_val = read_c0_cacheerr();
1577 pr_err("c0_cacheerr == %08x\n", reg_val);
1578
1579 if ((reg_val & 0xc0000000) == 0xc0000000) {
1580 pr_err("Decoded c0_cacheerr: FTLB parity error\n");
1581 } else {
1582 pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1583 reg_val & (1<<30) ? "secondary" : "primary",
1584 reg_val & (1<<31) ? "data" : "insn");
1585 }
1586 } else {
1587 pr_err("FTLB error exception\n");
1588 }
1589 /* Just print the cacheerr bits for now */
1590 cache_parity_error();
1591}
1592
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593/*
1594 * SDBBP EJTAG debug exception handler.
1595 * We skip the instruction and return to the next instruction.
1596 */
1597void ejtag_exception_handler(struct pt_regs *regs)
1598{
1599 const int field = 2 * sizeof(unsigned long);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001600 unsigned long depc, old_epc, old_ra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 unsigned int debug;
1602
Chris Dearman70ae6122006-06-30 12:32:37 +01001603 printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 depc = read_c0_depc();
1605 debug = read_c0_debug();
Chris Dearman70ae6122006-06-30 12:32:37 +01001606 printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 if (debug & 0x80000000) {
1608 /*
1609 * In branch delay slot.
1610 * We cheat a little bit here and use EPC to calculate the
1611 * debug return address (DEPC). EPC is restored after the
1612 * calculation.
1613 */
1614 old_epc = regs->cp0_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001615 old_ra = regs->regs[31];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 regs->cp0_epc = depc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001617 compute_return_epc(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 depc = regs->cp0_epc;
1619 regs->cp0_epc = old_epc;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001620 regs->regs[31] = old_ra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 } else
1622 depc += 4;
1623 write_c0_depc(depc);
1624
1625#if 0
Chris Dearman70ae6122006-06-30 12:32:37 +01001626 printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 write_c0_debug(debug | 0x100);
1628#endif
1629}
1630
1631/*
1632 * NMI exception handler.
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001633 * No lock; only written during early bootup by CPU 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 */
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001635static RAW_NOTIFIER_HEAD(nmi_chain);
1636
1637int register_nmi_notifier(struct notifier_block *nb)
1638{
1639 return raw_notifier_chain_register(&nmi_chain, nb);
1640}
1641
Joe Perchesff2d8b12012-01-12 17:17:21 -08001642void __noreturn nmi_exception_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +01001644 char str[100];
1645
Kevin Cernekee34bd92e2011-11-16 01:25:44 +00001646 raw_notifier_call_chain(&nmi_chain, 0, regs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001647 bust_spinlocks(1);
Leonid Yegoshin83e4da1e2013-10-08 12:39:31 +01001648 snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
1649 smp_processor_id(), regs->cp0_epc);
1650 regs->cp0_epc = read_c0_errorepc();
1651 die(str, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652}
1653
Ralf Baechlee01402b2005-07-14 15:57:16 +00001654#define VECTORSPACING 0x100 /* for EI/VI mode */
1655
1656unsigned long ebase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657unsigned long exception_handlers[32];
Ralf Baechlee01402b2005-07-14 15:57:16 +00001658unsigned long vi_handlers[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Florian Fainelli2d1b6e92010-01-28 15:21:42 +01001660void __init *set_except_vector(int n, void *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
1662 unsigned long handler = (unsigned long) addr;
Ralf Baechleb22d1b62013-05-09 17:57:30 +02001663 unsigned long old_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001665#ifdef CONFIG_CPU_MICROMIPS
1666 /*
1667 * Only the TLB handlers are cache aligned with an even
1668 * address. All other handlers are on an odd address and
1669 * require no modification. Otherwise, MIPS32 mode will
1670 * be entered when handling any TLB exceptions. That
1671 * would be bad...since we must stay in microMIPS mode.
1672 */
1673 if (!(handler & 0x1))
1674 handler |= 1;
1675#endif
Ralf Baechleb22d1b62013-05-09 17:57:30 +02001676 old_handler = xchg(&exception_handlers[n], handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 if (n == 0 && cpu_has_divec) {
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001679#ifdef CONFIG_CPU_MICROMIPS
1680 unsigned long jump_mask = ~((1 << 27) - 1);
1681#else
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001682 unsigned long jump_mask = ~((1 << 28) - 1);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001683#endif
Florian Fainelli92bbe1b2010-01-28 15:22:37 +01001684 u32 *buf = (u32 *)(ebase + 0x200);
1685 unsigned int k0 = 26;
1686 if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
1687 uasm_i_j(&buf, handler & ~jump_mask);
1688 uasm_i_nop(&buf);
1689 } else {
1690 UASM_i_LA(&buf, k0, handler);
1691 uasm_i_jr(&buf, k0);
1692 uasm_i_nop(&buf);
1693 }
1694 local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 }
1696 return (void *)old_handler;
1697}
1698
Ralf Baechle86a17082013-02-08 01:21:34 +01001699static void do_default_vi(void)
Atsushi Nemoto6ba07e52007-05-21 23:45:38 +09001700{
1701 show_regs(get_irq_regs());
1702 panic("Caught unexpected vectored interrupt.");
1703}
1704
Ralf Baechleef300e42007-05-06 18:31:18 +01001705static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001706{
1707 unsigned long handler;
1708 unsigned long old_handler = vi_handlers[n];
Ralf Baechlef6771db2007-11-08 18:02:29 +00001709 int srssets = current_cpu_data.srsets;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001710 u16 *h;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001711 unsigned char *b;
1712
Ralf Baechleb72b7092009-03-30 14:49:44 +02001713 BUG_ON(!cpu_has_veic && !cpu_has_vint);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001714
1715 if (addr == NULL) {
1716 handler = (unsigned long) do_default_vi;
1717 srs = 0;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001718 } else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001719 handler = (unsigned long) addr;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001720 vi_handlers[n] = handler;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001721
1722 b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
1723
Ralf Baechlef6771db2007-11-08 18:02:29 +00001724 if (srs >= srssets)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001725 panic("Shadow register set %d not supported", srs);
1726
1727 if (cpu_has_veic) {
1728 if (board_bind_eic_interrupt)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001729 board_bind_eic_interrupt(n, srs);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001730 } else if (cpu_has_vint) {
Ralf Baechlee01402b2005-07-14 15:57:16 +00001731 /* SRSMap is only defined if shadow sets are implemented */
Ralf Baechlef6771db2007-11-08 18:02:29 +00001732 if (srssets > 1)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001733 change_c0_srsmap(0xf << n*4, srs << n*4);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001734 }
1735
1736 if (srs == 0) {
1737 /*
1738 * If no shadow set is selected then use the default handler
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001739 * that does normal register saving and standard interrupt exit
Ralf Baechlee01402b2005-07-14 15:57:16 +00001740 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00001741 extern char except_vec_vi, except_vec_vi_lui;
1742 extern char except_vec_vi_ori, except_vec_vi_end;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001743 extern char rollback_except_vec_vi;
Ralf Baechlef94d9a82013-05-21 17:30:36 +02001744 char *vec_start = using_rollback_handler() ?
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001745 &rollback_except_vec_vi : &except_vec_vi;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001746#ifdef CONFIG_MIPS_MT_SMTC
1747 /*
1748 * We need to provide the SMTC vectored interrupt handler
1749 * not only with the address of the handler, but with the
1750 * Status.IM bit to be masked before going there.
1751 */
1752 extern char except_vec_vi_mori;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001753#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1754 const int mori_offset = &except_vec_vi_mori - vec_start + 2;
1755#else
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001756 const int mori_offset = &except_vec_vi_mori - vec_start;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001757#endif
Ralf Baechle41c594a2006-04-05 09:45:45 +01001758#endif /* CONFIG_MIPS_MT_SMTC */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001759#if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
1760 const int lui_offset = &except_vec_vi_lui - vec_start + 2;
1761 const int ori_offset = &except_vec_vi_ori - vec_start + 2;
1762#else
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09001763 const int lui_offset = &except_vec_vi_lui - vec_start;
1764 const int ori_offset = &except_vec_vi_ori - vec_start;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001765#endif
1766 const int handler_len = &except_vec_vi_end - vec_start;
Ralf Baechlee01402b2005-07-14 15:57:16 +00001767
1768 if (handler_len > VECTORSPACING) {
1769 /*
1770 * Sigh... panicing won't help as the console
1771 * is probably not configured :(
1772 */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001773 panic("VECTORSPACING too small");
Ralf Baechlee01402b2005-07-14 15:57:16 +00001774 }
1775
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001776 set_handler(((unsigned long)b - ebase), vec_start,
1777#ifdef CONFIG_CPU_MICROMIPS
1778 (handler_len - 1));
1779#else
1780 handler_len);
1781#endif
Ralf Baechle41c594a2006-04-05 09:45:45 +01001782#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle8e8a52e2007-05-31 14:00:19 +01001783 BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
1784
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001785 h = (u16 *)(b + mori_offset);
1786 *h = (0x100 << n);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001787#endif /* CONFIG_MIPS_MT_SMTC */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001788 h = (u16 *)(b + lui_offset);
1789 *h = (handler >> 16) & 0xffff;
1790 h = (u16 *)(b + ori_offset);
1791 *h = (handler & 0xffff);
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001792 local_flush_icache_range((unsigned long)b,
1793 (unsigned long)(b+handler_len));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001794 }
1795 else {
1796 /*
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001797 * In other cases jump directly to the interrupt handler. It
1798 * is the handler's responsibility to save registers if required
1799 * (eg hi/lo) and return from the exception using "eret".
Ralf Baechlee01402b2005-07-14 15:57:16 +00001800 */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001801 u32 insn;
1802
1803 h = (u16 *)b;
1804 /* j handler */
1805#ifdef CONFIG_CPU_MICROMIPS
1806 insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
1807#else
1808 insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
1809#endif
1810 h[0] = (insn >> 16) & 0xffff;
1811 h[1] = insn & 0xffff;
1812 h[2] = 0;
1813 h[3] = 0;
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001814 local_flush_icache_range((unsigned long)b,
1815 (unsigned long)(b+8));
Ralf Baechlee01402b2005-07-14 15:57:16 +00001816 }
1817
1818 return (void *)old_handler;
1819}
1820
Ralf Baechleef300e42007-05-06 18:31:18 +01001821void *set_vi_handler(int n, vi_handler_t addr)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001822{
Ralf Baechleff3eab22006-03-29 14:12:58 +01001823 return set_vi_srs_handler(n, addr, 0);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001824}
Ralf Baechlef41ae0b2006-06-05 17:24:46 +01001825
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826extern void tlb_init(void);
1827
Ralf Baechle42f77542007-10-18 17:48:11 +01001828/*
1829 * Timer interrupt
1830 */
1831int cp0_compare_irq;
Ralf Baechle68b63522012-07-19 09:13:52 +02001832EXPORT_SYMBOL_GPL(cp0_compare_irq);
David VomLehn010c1082009-12-21 17:49:22 -08001833int cp0_compare_irq_shift;
Ralf Baechle42f77542007-10-18 17:48:11 +01001834
1835/*
1836 * Performance counter IRQ or -1 if shared with timer
1837 */
1838int cp0_perfcount_irq;
1839EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
1840
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001841static int noulri;
Chris Dearmanbdc94eb2007-10-03 10:43:56 +01001842
1843static int __init ulri_disable(char *s)
1844{
1845 pr_info("Disabling ulri\n");
1846 noulri = 1;
1847
1848 return 1;
1849}
1850__setup("noulri", ulri_disable);
1851
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001852void per_cpu_trap_init(bool is_boot_cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
1854 unsigned int cpu = smp_processor_id();
1855 unsigned int status_set = ST0_CU0;
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001856 unsigned int hwrena = cpu_hwrena_impl_bits;
Ralf Baechle41c594a2006-04-05 09:45:45 +01001857#ifdef CONFIG_MIPS_MT_SMTC
1858 int secondaryTC = 0;
1859 int bootTC = (cpu == 0);
1860
1861 /*
1862 * Only do per_cpu_trap_init() for first TC of Each VPE.
1863 * Note that this hack assumes that the SMTC init code
1864 * assigns TCs consecutively and in ascending order.
1865 */
1866
1867 if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
1868 ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
1869 secondaryTC = 1;
1870#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 /*
1873 * Disable coprocessors and select 32-bit or 64-bit addressing
1874 * and the 16/32 or 32/32 FPR register model. Reset the BEV
1875 * flag that some firmware may have left set and the TS bit (for
1876 * IP27). Set XX for ISA IV code to work.
1877 */
Ralf Baechle875d43e2005-09-03 15:56:16 -07001878#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
1880#endif
Deng-Cheng Zhuadb37892013-04-01 18:14:28 +00001881 if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 status_set |= ST0_XX;
Chris Dearmanbbaf2382007-12-13 22:42:19 +00001883 if (cpu_has_dsp)
1884 status_set |= ST0_MX;
1885
Ralf Baechleb38c7392006-02-07 01:20:43 +00001886 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 -07001887 status_set);
1888
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001889 if (cpu_has_mips_r2)
1890 hwrena |= 0x0000000f;
Ralf Baechlea3692022007-07-10 17:33:02 +01001891
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001892 if (!noulri && cpu_has_userlocal)
1893 hwrena |= (1 << 29);
Ralf Baechlea3692022007-07-10 17:33:02 +01001894
Kevin Cernekee18d693b2010-10-16 14:22:38 -07001895 if (hwrena)
1896 write_c0_hwrena(hwrena);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001897
Ralf Baechle41c594a2006-04-05 09:45:45 +01001898#ifdef CONFIG_MIPS_MT_SMTC
1899 if (!secondaryTC) {
1900#endif /* CONFIG_MIPS_MT_SMTC */
1901
Ralf Baechlee01402b2005-07-14 15:57:16 +00001902 if (cpu_has_veic || cpu_has_vint) {
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001903 unsigned long sr = set_c0_status(ST0_BEV);
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001904 write_c0_ebase(ebase);
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07001905 write_c0_status(sr);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001906 /* Setting vector spacing enables EI/VI mode */
Ralf Baechle49a89ef2007-10-11 23:46:15 +01001907 change_c0_intctl(0x3e0, VECTORSPACING);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001908 }
Ralf Baechled03d0a52005-08-17 13:44:26 +00001909 if (cpu_has_divec) {
1910 if (cpu_has_mipsmt) {
1911 unsigned int vpflags = dvpe();
1912 set_c0_cause(CAUSEF_IV);
1913 evpe(vpflags);
1914 } else
1915 set_c0_cause(CAUSEF_IV);
1916 }
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001917
1918 /*
1919 * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
1920 *
1921 * o read IntCtl.IPTI to determine the timer interrupt
1922 * o read IntCtl.IPPCI to determine the performance counter interrupt
1923 */
1924 if (cpu_has_mips_r2) {
David VomLehn010c1082009-12-21 17:49:22 -08001925 cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
1926 cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
1927 cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001928 if (cp0_perfcount_irq == cp0_compare_irq)
1929 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001930 } else {
1931 cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
Ralf Baechlec6a4ebb2012-07-06 23:56:00 +02001932 cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
Chris Dearmanc3e838a2007-06-21 12:59:57 +01001933 cp0_perfcount_irq = -1;
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +01001934 }
1935
Ralf Baechle41c594a2006-04-05 09:45:45 +01001936#ifdef CONFIG_MIPS_MT_SMTC
1937 }
1938#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
David Daney48c4ac92013-05-13 13:56:44 -07001940 if (!cpu_data[cpu].asid_cache)
1941 cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 atomic_inc(&init_mm.mm_count);
1944 current->active_mm = &init_mm;
1945 BUG_ON(current->mm);
1946 enter_lazy_tlb(&init_mm, current);
1947
Ralf Baechle41c594a2006-04-05 09:45:45 +01001948#ifdef CONFIG_MIPS_MT_SMTC
1949 if (bootTC) {
1950#endif /* CONFIG_MIPS_MT_SMTC */
David Daney6650df32012-05-15 00:04:50 -07001951 /* Boot CPU's cache setup in setup_arch(). */
1952 if (!is_boot_cpu)
1953 cpu_cache_init();
Ralf Baechle41c594a2006-04-05 09:45:45 +01001954 tlb_init();
1955#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle6a058882007-05-31 14:03:45 +01001956 } else if (!secondaryTC) {
1957 /*
1958 * First TC in non-boot VPE must do subset of tlb_init()
1959 * for MMU countrol registers.
1960 */
1961 write_c0_pagemask(PM_DEFAULT_MASK);
1962 write_c0_wired(0);
Ralf Baechle41c594a2006-04-05 09:45:45 +01001963 }
1964#endif /* CONFIG_MIPS_MT_SMTC */
David Daney3d8bfdd2010-12-21 14:19:11 -08001965 TLBMISS_HANDLER_SETUP();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966}
1967
Ralf Baechlee01402b2005-07-14 15:57:16 +00001968/* Install CPU exception handler */
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001969void set_handler(unsigned long offset, void *addr, unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001970{
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001971#ifdef CONFIG_CPU_MICROMIPS
1972 memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
1973#else
Ralf Baechlee01402b2005-07-14 15:57:16 +00001974 memcpy((void *)(ebase + offset), addr, size);
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05001975#endif
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02001976 local_flush_icache_range(ebase + offset, ebase + offset + size);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001977}
1978
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001979static char panic_null_cerr[] =
Ralf Baechle641e97f2007-10-11 23:46:05 +01001980 "Trying to set NULL cache error exception handler";
1981
Ralf Baechle42fe7ee2009-01-28 18:48:23 +00001982/*
1983 * Install uncached CPU exception handler.
1984 * This is suitable only for the cache error exception which is the only
1985 * exception handler that is being run uncached.
1986 */
Paul Gortmaker078a55f2013-06-18 13:38:59 +00001987void set_uncached_handler(unsigned long offset, void *addr,
Ralf Baechle234fcd12008-03-08 09:56:28 +00001988 unsigned long size)
Ralf Baechlee01402b2005-07-14 15:57:16 +00001989{
Sebastian Andrzej Siewior4f81b012010-04-27 22:53:30 +02001990 unsigned long uncached_ebase = CKSEG1ADDR(ebase);
Ralf Baechlee01402b2005-07-14 15:57:16 +00001991
Ralf Baechle641e97f2007-10-11 23:46:05 +01001992 if (!addr)
1993 panic(panic_null_cerr);
1994
Ralf Baechlee01402b2005-07-14 15:57:16 +00001995 memcpy((void *)(uncached_ebase + offset), addr, size);
1996}
1997
Atsushi Nemoto5b104962006-09-11 17:50:29 +09001998static int __initdata rdhwr_noopt;
1999static int __init set_rdhwr_noopt(char *str)
2000{
2001 rdhwr_noopt = 1;
2002 return 1;
2003}
2004
2005__setup("rdhwr_noopt", set_rdhwr_noopt);
2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007void __init trap_init(void)
2008{
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002009 extern char except_vec3_generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 extern char except_vec4;
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002011 extern char except_vec3_r4000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 unsigned long i;
Atsushi Nemotoc65a5482007-11-12 02:05:18 +09002013
2014 check_wait();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Jason Wessel88547002008-07-29 15:58:53 -05002016#if defined(CONFIG_KGDB)
2017 if (kgdb_early_setup)
Ralf Baechle70342282013-01-22 12:59:30 +01002018 return; /* Already done */
Jason Wessel88547002008-07-29 15:58:53 -05002019#endif
2020
Chris Dearman9fb4c2b92009-03-20 15:33:55 -07002021 if (cpu_has_veic || cpu_has_vint) {
2022 unsigned long size = 0x200 + VECTORSPACING*64;
2023 ebase = (unsigned long)
2024 __alloc_bootmem(size, 1 << fls(size), 0);
2025 } else {
Sanjay Lal9843b032012-11-21 18:34:03 -08002026#ifdef CONFIG_KVM_GUEST
2027#define KVM_GUEST_KSEG0 0x40000000
2028 ebase = KVM_GUEST_KSEG0;
2029#else
2030 ebase = CKSEG0;
2031#endif
David Daney566f74f2008-10-23 17:56:35 -07002032 if (cpu_has_mips_r2)
2033 ebase += (read_c0_ebase() & 0x3ffff000);
2034 }
Ralf Baechlee01402b2005-07-14 15:57:16 +00002035
Steven J. Hillc6213c62013-06-05 21:25:17 +00002036 if (cpu_has_mmips) {
2037 unsigned int config3 = read_c0_config3();
2038
2039 if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
2040 write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
2041 else
2042 write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
2043 }
2044
Kevin Cernekee6fb97ef2011-11-16 01:25:45 +00002045 if (board_ebase_setup)
2046 board_ebase_setup();
David Daney6650df32012-05-15 00:04:50 -07002047 per_cpu_trap_init(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 /*
2050 * Copy the generic exception handlers to their final destination.
2051 * This will be overriden later as suitable for a particular
2052 * configuration.
2053 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00002054 set_handler(0x180, &except_vec3_generic, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
2056 /*
2057 * Setup default vectors
2058 */
2059 for (i = 0; i <= 31; i++)
2060 set_except_vector(i, handle_reserved);
2061
2062 /*
2063 * Copy the EJTAG debug exception vector handler code to it's final
2064 * destination.
2065 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00002066 if (cpu_has_ejtag && board_ejtag_handler_setup)
Ralf Baechle49a89ef2007-10-11 23:46:15 +01002067 board_ejtag_handler_setup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 /*
2070 * Only some CPUs have the watch exceptions.
2071 */
2072 if (cpu_has_watch)
2073 set_except_vector(23, handle_watch);
2074
2075 /*
Ralf Baechlee01402b2005-07-14 15:57:16 +00002076 * Initialise interrupt handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 */
Ralf Baechlee01402b2005-07-14 15:57:16 +00002078 if (cpu_has_veic || cpu_has_vint) {
2079 int nvec = cpu_has_veic ? 64 : 8;
2080 for (i = 0; i < nvec; i++)
Ralf Baechleff3eab22006-03-29 14:12:58 +01002081 set_vi_handler(i, NULL);
Ralf Baechlee01402b2005-07-14 15:57:16 +00002082 }
2083 else if (cpu_has_divec)
2084 set_handler(0x200, &except_vec4, 0x8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 /*
2087 * Some CPUs can enable/disable for cache parity detection, but does
2088 * it different ways.
2089 */
2090 parity_protection_init();
2091
2092 /*
2093 * The Data Bus Errors / Instruction Bus Errors are signaled
2094 * by external hardware. Therefore these two exceptions
2095 * may have board specific handlers.
2096 */
2097 if (board_be_init)
2098 board_be_init();
2099
Ralf Baechlef94d9a82013-05-21 17:30:36 +02002100 set_except_vector(0, using_rollback_handler() ? rollback_handle_int
2101 : handle_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 set_except_vector(1, handle_tlbm);
2103 set_except_vector(2, handle_tlbl);
2104 set_except_vector(3, handle_tlbs);
2105
2106 set_except_vector(4, handle_adel);
2107 set_except_vector(5, handle_ades);
2108
2109 set_except_vector(6, handle_ibe);
2110 set_except_vector(7, handle_dbe);
2111
2112 set_except_vector(8, handle_sys);
2113 set_except_vector(9, handle_bp);
Atsushi Nemoto5b104962006-09-11 17:50:29 +09002114 set_except_vector(10, rdhwr_noopt ? handle_ri :
2115 (cpu_has_vtag_icache ?
2116 handle_ri_rdhwr_vivt : handle_ri_rdhwr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 set_except_vector(11, handle_cpu);
2118 set_except_vector(12, handle_ov);
2119 set_except_vector(13, handle_tr);
Paul Burton2bcb3fb2014-01-27 15:23:12 +00002120 set_except_vector(14, handle_msa_fpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Ralf Baechle10cc3522007-10-11 23:46:15 +01002122 if (current_cpu_type() == CPU_R6000 ||
2123 current_cpu_type() == CPU_R6000A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 /*
2125 * The R6000 is the only R-series CPU that features a machine
2126 * check exception (similar to the R4000 cache error) and
2127 * unaligned ldc1/sdc1 exception. The handlers have not been
Ralf Baechle70342282013-01-22 12:59:30 +01002128 * written yet. Well, anyway there is no R6000 machine on the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 * current list of targets for Linux/MIPS.
2130 * (Duh, crap, there is someone with a triple R6k machine)
2131 */
2132 //set_except_vector(14, handle_mc);
2133 //set_except_vector(15, handle_ndc);
2134 }
2135
Ralf Baechlee01402b2005-07-14 15:57:16 +00002136
2137 if (board_nmi_handler_setup)
2138 board_nmi_handler_setup();
2139
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002140 if (cpu_has_fpu && !cpu_has_nofpuex)
2141 set_except_vector(15, handle_fpe);
2142
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +00002143 set_except_vector(16, handle_ftlb);
Paul Burton1db1af82014-01-27 15:23:11 +00002144 set_except_vector(21, handle_msa);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002145 set_except_vector(22, handle_mdmx);
2146
2147 if (cpu_has_mcheck)
2148 set_except_vector(24, handle_mcheck);
2149
Ralf Baechle340ee4b2005-08-17 17:44:08 +00002150 if (cpu_has_mipsmt)
2151 set_except_vector(25, handle_mt);
2152
Chris Dearmanacaec422007-05-24 22:30:18 +01002153 set_except_vector(26, handle_dsp);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002154
David Daneyfcbf1df2012-05-15 00:04:46 -07002155 if (board_cache_error_setup)
2156 board_cache_error_setup();
2157
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002158 if (cpu_has_vce)
2159 /* Special exception: R4[04]00 uses also the divec space. */
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002160 set_handler(0x180, &except_vec3_r4000, 0x100);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002161 else if (cpu_has_4kex)
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002162 set_handler(0x180, &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002163 else
Steven J. Hill2a0b24f2013-03-25 12:15:55 -05002164 set_handler(0x080, &except_vec3_generic, 0x80);
Ralf Baechlee50c0a82005-05-31 11:49:19 +00002165
Thomas Bogendoerfere0cee3e2008-08-04 20:53:57 +02002166 local_flush_icache_range(ebase, ebase + 0x400);
Thomas Bogendoerfer05106172008-08-04 19:44:34 +02002167
2168 sort_extable(__start___dbe_table, __stop___dbe_table);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +00002169
Ralf Baechle4483b152010-08-05 13:25:59 +01002170 cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}