Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Ralf Baechle | 36ccf1c | 2006-02-14 21:04:54 +0000 | [diff] [blame] | 6 | * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright (C) 1995, 1996 Paul M. Antoine |
| 8 | * Copyright (C) 1998 Ulf Carlsson |
| 9 | * Copyright (C) 1999 Silicon Graphics, Inc. |
| 10 | * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com |
| 11 | * Copyright (C) 2000, 01 MIPS Technologies, Inc. |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 12 | * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Ralf Baechle | 8e8a52e | 2007-05-31 14:00:19 +0100 | [diff] [blame] | 14 | #include <linux/bug.h> |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 15 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/spinlock.h> |
| 22 | #include <linux/kallsyms.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 23 | #include <linux/bootmem.h> |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 25 | #include <linux/ptrace.h> |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 26 | #include <linux/kgdb.h> |
| 27 | #include <linux/kdebug.h> |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 28 | #include <linux/notifier.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <asm/bootinfo.h> |
| 31 | #include <asm/branch.h> |
| 32 | #include <asm/break.h> |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 33 | #include <asm/cop2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/cpu.h> |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 35 | #include <asm/dsp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/fpu.h> |
Ralf Baechle | ba3049e | 2008-10-28 17:38:42 +0000 | [diff] [blame] | 37 | #include <asm/fpu_emulator.h> |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 38 | #include <asm/mipsregs.h> |
| 39 | #include <asm/mipsmtregs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/module.h> |
| 41 | #include <asm/pgtable.h> |
| 42 | #include <asm/ptrace.h> |
| 43 | #include <asm/sections.h> |
| 44 | #include <asm/system.h> |
| 45 | #include <asm/tlbdebug.h> |
| 46 | #include <asm/traps.h> |
| 47 | #include <asm/uaccess.h> |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 48 | #include <asm/watch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <asm/types.h> |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 51 | #include <asm/stacktrace.h> |
David Daney | f9bb4cf | 2008-12-11 15:33:23 -0800 | [diff] [blame] | 52 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 54 | extern void check_wait(void); |
| 55 | extern asmlinkage void r4k_wait(void); |
| 56 | extern asmlinkage void rollback_handle_int(void); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 57 | extern asmlinkage void handle_int(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | extern asmlinkage void handle_tlbm(void); |
| 59 | extern asmlinkage void handle_tlbl(void); |
| 60 | extern asmlinkage void handle_tlbs(void); |
| 61 | extern asmlinkage void handle_adel(void); |
| 62 | extern asmlinkage void handle_ades(void); |
| 63 | extern asmlinkage void handle_ibe(void); |
| 64 | extern asmlinkage void handle_dbe(void); |
| 65 | extern asmlinkage void handle_sys(void); |
| 66 | extern asmlinkage void handle_bp(void); |
| 67 | extern asmlinkage void handle_ri(void); |
Atsushi Nemoto | 5b10496 | 2006-09-11 17:50:29 +0900 | [diff] [blame] | 68 | extern asmlinkage void handle_ri_rdhwr_vivt(void); |
| 69 | extern asmlinkage void handle_ri_rdhwr(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | extern asmlinkage void handle_cpu(void); |
| 71 | extern asmlinkage void handle_ov(void); |
| 72 | extern asmlinkage void handle_tr(void); |
| 73 | extern asmlinkage void handle_fpe(void); |
| 74 | extern asmlinkage void handle_mdmx(void); |
| 75 | extern asmlinkage void handle_watch(void); |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 76 | extern asmlinkage void handle_mt(void); |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 77 | extern asmlinkage void handle_dsp(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | extern asmlinkage void handle_mcheck(void); |
| 79 | extern asmlinkage void handle_reserved(void); |
| 80 | |
Ralf Baechle | 12616ed | 2005-10-18 10:26:46 +0100 | [diff] [blame] | 81 | extern int fpu_emulator_cop1Handler(struct pt_regs *xcp, |
Atsushi Nemoto | e04582b | 2006-10-09 00:10:01 +0900 | [diff] [blame] | 82 | struct mips_fpu_struct *ctx, int has_fpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | void (*board_be_init)(void); |
| 85 | int (*board_be_handler)(struct pt_regs *regs, int is_fixup); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 86 | void (*board_nmi_handler_setup)(void); |
| 87 | void (*board_ejtag_handler_setup)(void); |
| 88 | void (*board_bind_eic_interrupt)(int irq, int regset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 91 | static void show_raw_backtrace(unsigned long reg29) |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 92 | { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 93 | unsigned long *sp = (unsigned long *)(reg29 & ~3); |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 94 | unsigned long addr; |
| 95 | |
| 96 | printk("Call Trace:"); |
| 97 | #ifdef CONFIG_KALLSYMS |
| 98 | printk("\n"); |
| 99 | #endif |
Thomas Bogendoerfer | 10220c8 | 2008-05-12 17:58:48 +0200 | [diff] [blame] | 100 | while (!kstack_end(sp)) { |
| 101 | unsigned long __user *p = |
| 102 | (unsigned long __user *)(unsigned long)sp++; |
| 103 | if (__get_user(addr, p)) { |
| 104 | printk(" (Bad stack address)"); |
| 105 | break; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 106 | } |
Thomas Bogendoerfer | 10220c8 | 2008-05-12 17:58:48 +0200 | [diff] [blame] | 107 | if (__kernel_text_address(addr)) |
| 108 | print_ip_sym(addr); |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 109 | } |
Thomas Bogendoerfer | 10220c8 | 2008-05-12 17:58:48 +0200 | [diff] [blame] | 110 | printk("\n"); |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 111 | } |
| 112 | |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 113 | #ifdef CONFIG_KALLSYMS |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 114 | int raw_show_trace; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 115 | static int __init set_raw_show_trace(char *str) |
| 116 | { |
| 117 | raw_show_trace = 1; |
| 118 | return 1; |
| 119 | } |
| 120 | __setup("raw_show_trace", set_raw_show_trace); |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 121 | #endif |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 122 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 123 | static void show_backtrace(struct task_struct *task, const struct pt_regs *regs) |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 124 | { |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 125 | unsigned long sp = regs->regs[29]; |
| 126 | unsigned long ra = regs->regs[31]; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 127 | unsigned long pc = regs->cp0_epc; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 128 | |
| 129 | if (raw_show_trace || !__kernel_text_address(pc)) { |
Franck Bui-Huu | 87151ae | 2006-08-03 09:29:17 +0200 | [diff] [blame] | 130 | show_raw_backtrace(sp); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | printk("Call Trace:\n"); |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 134 | do { |
Franck Bui-Huu | 87151ae | 2006-08-03 09:29:17 +0200 | [diff] [blame] | 135 | print_ip_sym(pc); |
Atsushi Nemoto | 1924600 | 2006-09-29 18:02:51 +0900 | [diff] [blame] | 136 | pc = unwind_stack(task, &sp, pc, &ra); |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 137 | } while (pc); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 138 | printk("\n"); |
| 139 | } |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* |
| 142 | * This routine abuses get_user()/put_user() to reference pointers |
| 143 | * with at least a bit of error checking ... |
| 144 | */ |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 145 | static void show_stacktrace(struct task_struct *task, |
| 146 | const struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | const int field = 2 * sizeof(unsigned long); |
| 149 | long stackdata; |
| 150 | int i; |
Atsushi Nemoto | 5e0373b | 2007-07-13 23:02:42 +0900 | [diff] [blame] | 151 | unsigned long __user *sp = (unsigned long __user *)regs->regs[29]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | printk("Stack :"); |
| 154 | i = 0; |
| 155 | while ((unsigned long) sp & (PAGE_SIZE - 1)) { |
| 156 | if (i && ((i % (64 / field)) == 0)) |
| 157 | printk("\n "); |
| 158 | if (i > 39) { |
| 159 | printk(" ..."); |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | if (__get_user(stackdata, sp++)) { |
| 164 | printk(" (Bad stack address)"); |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | printk(" %0*lx", field, stackdata); |
| 169 | i++; |
| 170 | } |
| 171 | printk("\n"); |
Franck Bui-Huu | 87151ae | 2006-08-03 09:29:17 +0200 | [diff] [blame] | 172 | show_backtrace(task, regs); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 173 | } |
| 174 | |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 175 | void show_stack(struct task_struct *task, unsigned long *sp) |
| 176 | { |
| 177 | struct pt_regs regs; |
| 178 | if (sp) { |
| 179 | regs.regs[29] = (unsigned long)sp; |
| 180 | regs.regs[31] = 0; |
| 181 | regs.cp0_epc = 0; |
| 182 | } else { |
| 183 | if (task && task != current) { |
| 184 | regs.regs[29] = task->thread.reg29; |
| 185 | regs.regs[31] = 0; |
| 186 | regs.cp0_epc = task->thread.reg31; |
| 187 | } else { |
| 188 | prepare_frametrace(®s); |
| 189 | } |
| 190 | } |
| 191 | show_stacktrace(task, ®s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
| 195 | * The architecture-independent dump_stack generator |
| 196 | */ |
| 197 | void dump_stack(void) |
| 198 | { |
Franck Bui-Huu | 1666a6f | 2006-08-03 09:29:19 +0200 | [diff] [blame] | 199 | struct pt_regs regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Franck Bui-Huu | 1666a6f | 2006-08-03 09:29:19 +0200 | [diff] [blame] | 201 | prepare_frametrace(®s); |
| 202 | show_backtrace(current, ®s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | EXPORT_SYMBOL(dump_stack); |
| 206 | |
Atsushi Nemoto | e1bb828 | 2007-07-13 23:51:46 +0900 | [diff] [blame] | 207 | static void show_code(unsigned int __user *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
| 209 | long i; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 210 | unsigned short __user *pc16 = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | printk("\nCode:"); |
| 213 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 214 | if ((unsigned long)pc & 1) |
| 215 | pc16 = (unsigned short __user *)((unsigned long)pc & ~1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | for(i = -3 ; i < 6 ; i++) { |
| 217 | unsigned int insn; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 218 | if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | printk(" (Bad address in epc)\n"); |
| 220 | break; |
| 221 | } |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 222 | printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>')); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 226 | static void __show_regs(const struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | const int field = 2 * sizeof(unsigned long); |
| 229 | unsigned int cause = regs->cp0_cause; |
| 230 | int i; |
| 231 | |
| 232 | printk("Cpu %d\n", smp_processor_id()); |
| 233 | |
| 234 | /* |
| 235 | * Saved main processor registers |
| 236 | */ |
| 237 | for (i = 0; i < 32; ) { |
| 238 | if ((i % 4) == 0) |
| 239 | printk("$%2d :", i); |
| 240 | if (i == 0) |
| 241 | printk(" %0*lx", field, 0UL); |
| 242 | else if (i == 26 || i == 27) |
| 243 | printk(" %*s", field, ""); |
| 244 | else |
| 245 | printk(" %0*lx", field, regs->regs[i]); |
| 246 | |
| 247 | i++; |
| 248 | if ((i % 4) == 0) |
| 249 | printk("\n"); |
| 250 | } |
| 251 | |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 252 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 253 | printk("Acx : %0*lx\n", field, regs->acx); |
| 254 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | printk("Hi : %0*lx\n", field, regs->hi); |
| 256 | printk("Lo : %0*lx\n", field, regs->lo); |
| 257 | |
| 258 | /* |
| 259 | * Saved cp0 registers |
| 260 | */ |
Ralf Baechle | b012cff | 2008-07-15 18:44:33 +0100 | [diff] [blame] | 261 | printk("epc : %0*lx %pS\n", field, regs->cp0_epc, |
| 262 | (void *) regs->cp0_epc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | printk(" %s\n", print_tainted()); |
Ralf Baechle | b012cff | 2008-07-15 18:44:33 +0100 | [diff] [blame] | 264 | printk("ra : %0*lx %pS\n", field, regs->regs[31], |
| 265 | (void *) regs->regs[31]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | printk("Status: %08x ", (uint32_t) regs->cp0_status); |
| 268 | |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 269 | if (current_cpu_data.isa_level == MIPS_CPU_ISA_I) { |
| 270 | if (regs->cp0_status & ST0_KUO) |
| 271 | printk("KUo "); |
| 272 | if (regs->cp0_status & ST0_IEO) |
| 273 | printk("IEo "); |
| 274 | if (regs->cp0_status & ST0_KUP) |
| 275 | printk("KUp "); |
| 276 | if (regs->cp0_status & ST0_IEP) |
| 277 | printk("IEp "); |
| 278 | if (regs->cp0_status & ST0_KUC) |
| 279 | printk("KUc "); |
| 280 | if (regs->cp0_status & ST0_IEC) |
| 281 | printk("IEc "); |
| 282 | } else { |
| 283 | if (regs->cp0_status & ST0_KX) |
| 284 | printk("KX "); |
| 285 | if (regs->cp0_status & ST0_SX) |
| 286 | printk("SX "); |
| 287 | if (regs->cp0_status & ST0_UX) |
| 288 | printk("UX "); |
| 289 | switch (regs->cp0_status & ST0_KSU) { |
| 290 | case KSU_USER: |
| 291 | printk("USER "); |
| 292 | break; |
| 293 | case KSU_SUPERVISOR: |
| 294 | printk("SUPERVISOR "); |
| 295 | break; |
| 296 | case KSU_KERNEL: |
| 297 | printk("KERNEL "); |
| 298 | break; |
| 299 | default: |
| 300 | printk("BAD_MODE "); |
| 301 | break; |
| 302 | } |
| 303 | if (regs->cp0_status & ST0_ERL) |
| 304 | printk("ERL "); |
| 305 | if (regs->cp0_status & ST0_EXL) |
| 306 | printk("EXL "); |
| 307 | if (regs->cp0_status & ST0_IE) |
| 308 | printk("IE "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | printk("\n"); |
| 311 | |
| 312 | printk("Cause : %08x\n", cause); |
| 313 | |
| 314 | cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE; |
| 315 | if (1 <= cause && cause <= 5) |
| 316 | printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr); |
| 317 | |
Ralf Baechle | 9966db25 | 2007-10-11 23:46:17 +0100 | [diff] [blame] | 318 | printk("PrId : %08x (%s)\n", read_c0_prid(), |
| 319 | cpu_name_string()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 322 | /* |
| 323 | * FIXME: really the generic show_regs should take a const pointer argument. |
| 324 | */ |
| 325 | void show_regs(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 327 | __show_regs((struct pt_regs *)regs); |
| 328 | } |
| 329 | |
| 330 | void show_registers(const struct pt_regs *regs) |
| 331 | { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 332 | const int field = 2 * sizeof(unsigned long); |
| 333 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 334 | __show_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | print_modules(); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 336 | printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n", |
| 337 | current->comm, current->pid, current_thread_info(), current, |
| 338 | field, current_thread_info()->tp_value); |
| 339 | if (cpu_has_userlocal) { |
| 340 | unsigned long tls; |
| 341 | |
| 342 | tls = read_c0_userlocal(); |
| 343 | if (tls != current_thread_info()->tp_value) |
| 344 | printk("*HwTLS: %0*lx\n", field, tls); |
| 345 | } |
| 346 | |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 347 | show_stacktrace(current, regs); |
Atsushi Nemoto | e1bb828 | 2007-07-13 23:51:46 +0900 | [diff] [blame] | 348 | show_code((unsigned int __user *) regs->cp0_epc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | printk("\n"); |
| 350 | } |
| 351 | |
| 352 | static DEFINE_SPINLOCK(die_lock); |
| 353 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 354 | void __noreturn die(const char * str, const struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
| 356 | static int die_counter; |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 357 | #ifdef CONFIG_MIPS_MT_SMTC |
| 358 | unsigned long dvpret = dvpe(); |
| 359 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | console_verbose(); |
| 362 | spin_lock_irq(&die_lock); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 363 | bust_spinlocks(1); |
| 364 | #ifdef CONFIG_MIPS_MT_SMTC |
| 365 | mips_mt_regdump(dvpret); |
| 366 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Ralf Baechle | 178086c | 2005-10-13 17:07:54 +0100 | [diff] [blame] | 367 | printk("%s[#%d]:\n", str, ++die_counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | show_registers(regs); |
Pavel Emelianov | bcdcd8e | 2007-07-17 04:03:42 -0700 | [diff] [blame] | 369 | add_taint(TAINT_DIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | spin_unlock_irq(&die_lock); |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 371 | |
| 372 | if (in_interrupt()) |
| 373 | panic("Fatal exception in interrupt"); |
| 374 | |
| 375 | if (panic_on_oops) { |
| 376 | printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n"); |
| 377 | ssleep(5); |
| 378 | panic("Fatal exception"); |
| 379 | } |
| 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | do_exit(SIGSEGV); |
| 382 | } |
| 383 | |
Thomas Bogendoerfer | 0510617 | 2008-08-04 19:44:34 +0200 | [diff] [blame] | 384 | extern struct exception_table_entry __start___dbe_table[]; |
| 385 | extern struct exception_table_entry __stop___dbe_table[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Ralf Baechle | b6dcec9 | 2007-02-18 15:57:09 +0000 | [diff] [blame] | 387 | __asm__( |
| 388 | " .section __dbe_table, \"a\"\n" |
| 389 | " .previous \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* Given an address, look for it in the exception tables. */ |
| 392 | static const struct exception_table_entry *search_dbe_tables(unsigned long addr) |
| 393 | { |
| 394 | const struct exception_table_entry *e; |
| 395 | |
| 396 | e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr); |
| 397 | if (!e) |
| 398 | e = search_module_dbetables(addr); |
| 399 | return e; |
| 400 | } |
| 401 | |
| 402 | asmlinkage void do_be(struct pt_regs *regs) |
| 403 | { |
| 404 | const int field = 2 * sizeof(unsigned long); |
| 405 | const struct exception_table_entry *fixup = NULL; |
| 406 | int data = regs->cp0_cause & 4; |
| 407 | int action = MIPS_BE_FATAL; |
| 408 | |
| 409 | /* XXX For now. Fixme, this searches the wrong table ... */ |
| 410 | if (data && !user_mode(regs)) |
| 411 | fixup = search_dbe_tables(exception_epc(regs)); |
| 412 | |
| 413 | if (fixup) |
| 414 | action = MIPS_BE_FIXUP; |
| 415 | |
| 416 | if (board_be_handler) |
Atsushi Nemoto | 28fc582 | 2007-07-13 01:49:49 +0900 | [diff] [blame] | 417 | action = board_be_handler(regs, fixup != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | switch (action) { |
| 420 | case MIPS_BE_DISCARD: |
| 421 | return; |
| 422 | case MIPS_BE_FIXUP: |
| 423 | if (fixup) { |
| 424 | regs->cp0_epc = fixup->nextinsn; |
| 425 | return; |
| 426 | } |
| 427 | break; |
| 428 | default: |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * Assume it would be too dangerous to continue ... |
| 434 | */ |
| 435 | printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n", |
| 436 | data ? "Data" : "Instruction", |
| 437 | field, regs->cp0_epc, field, regs->regs[31]); |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 438 | if (notify_die(DIE_OOPS, "bus error", regs, SIGBUS, 0, 0) |
| 439 | == NOTIFY_STOP) |
| 440 | return; |
| 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | die_if_kernel("Oops", regs); |
| 443 | force_sig(SIGBUS, current); |
| 444 | } |
| 445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | /* |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 447 | * ll/sc, rdhwr, sync emulation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | */ |
| 449 | |
| 450 | #define OPCODE 0xfc000000 |
| 451 | #define BASE 0x03e00000 |
| 452 | #define RT 0x001f0000 |
| 453 | #define OFFSET 0x0000ffff |
| 454 | #define LL 0xc0000000 |
| 455 | #define SC 0xe0000000 |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 456 | #define SPEC0 0x00000000 |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 457 | #define SPEC3 0x7c000000 |
| 458 | #define RD 0x0000f800 |
| 459 | #define FUNC 0x0000003f |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 460 | #define SYNC 0x0000000f |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 461 | #define RDHWR 0x0000003b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | /* |
| 464 | * The ll_bit is cleared by r*_switch.S |
| 465 | */ |
| 466 | |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 467 | unsigned int ll_bit; |
| 468 | struct task_struct *ll_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 470 | static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 472 | unsigned long value, __user *vaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * analyse the ll instruction that just caused a ri exception |
| 477 | * and put the referenced address to addr. |
| 478 | */ |
| 479 | |
| 480 | /* sign extend offset */ |
| 481 | offset = opcode & OFFSET; |
| 482 | offset <<= 16; |
| 483 | offset >>= 16; |
| 484 | |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 485 | vaddr = (unsigned long __user *) |
| 486 | ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 488 | if ((unsigned long)vaddr & 3) |
| 489 | return SIGBUS; |
| 490 | if (get_user(value, vaddr)) |
| 491 | return SIGSEGV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | preempt_disable(); |
| 494 | |
| 495 | if (ll_task == NULL || ll_task == current) { |
| 496 | ll_bit = 1; |
| 497 | } else { |
| 498 | ll_bit = 0; |
| 499 | } |
| 500 | ll_task = current; |
| 501 | |
| 502 | preempt_enable(); |
| 503 | |
| 504 | regs->regs[(opcode & RT) >> 16] = value; |
| 505 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 506 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 509 | static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 511 | unsigned long __user *vaddr; |
| 512 | unsigned long reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* |
| 516 | * analyse the sc instruction that just caused a ri exception |
| 517 | * and put the referenced address to addr. |
| 518 | */ |
| 519 | |
| 520 | /* sign extend offset */ |
| 521 | offset = opcode & OFFSET; |
| 522 | offset <<= 16; |
| 523 | offset >>= 16; |
| 524 | |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 525 | vaddr = (unsigned long __user *) |
| 526 | ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | reg = (opcode & RT) >> 16; |
| 528 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 529 | if ((unsigned long)vaddr & 3) |
| 530 | return SIGBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | preempt_disable(); |
| 533 | |
| 534 | if (ll_bit == 0 || ll_task != current) { |
| 535 | regs->regs[reg] = 0; |
| 536 | preempt_enable(); |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 537 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | preempt_enable(); |
| 541 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 542 | if (put_user(regs->regs[reg], vaddr)) |
| 543 | return SIGSEGV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | regs->regs[reg] = 1; |
| 546 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 547 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | /* |
| 551 | * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both |
| 552 | * opcodes are supposed to result in coprocessor unusable exceptions if |
| 553 | * executed on ll/sc-less processors. That's the theory. In practice a |
| 554 | * few processors such as NEC's VR4100 throw reserved instruction exceptions |
| 555 | * instead, so we're doing the emulation thing in both exception handlers. |
| 556 | */ |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 557 | static int simulate_llsc(struct pt_regs *regs, unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 559 | if ((opcode & OPCODE) == LL) |
| 560 | return simulate_ll(regs, opcode); |
| 561 | if ((opcode & OPCODE) == SC) |
| 562 | return simulate_sc(regs, opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 564 | return -1; /* Must be something else ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 567 | /* |
| 568 | * Simulate trapping 'rdhwr' instructions to provide user accessible |
Chris Dearman | 1f5826b | 2006-05-08 18:02:16 +0100 | [diff] [blame] | 569 | * registers not implemented in hardware. |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 570 | */ |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 571 | static int simulate_rdhwr(struct pt_regs *regs, unsigned int opcode) |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 572 | { |
Al Viro | dc8f602 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 573 | struct thread_info *ti = task_thread_info(current); |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 574 | |
| 575 | if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) { |
| 576 | int rd = (opcode & RD) >> 11; |
| 577 | int rt = (opcode & RT) >> 16; |
| 578 | switch (rd) { |
Chris Dearman | 1f5826b | 2006-05-08 18:02:16 +0100 | [diff] [blame] | 579 | case 0: /* CPU number */ |
| 580 | regs->regs[rt] = smp_processor_id(); |
| 581 | return 0; |
| 582 | case 1: /* SYNCI length */ |
| 583 | regs->regs[rt] = min(current_cpu_data.dcache.linesz, |
| 584 | current_cpu_data.icache.linesz); |
| 585 | return 0; |
| 586 | case 2: /* Read count register */ |
| 587 | regs->regs[rt] = read_c0_count(); |
| 588 | return 0; |
| 589 | case 3: /* Count register resolution */ |
| 590 | switch (current_cpu_data.cputype) { |
| 591 | case CPU_20KC: |
| 592 | case CPU_25KF: |
| 593 | regs->regs[rt] = 1; |
| 594 | break; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 595 | default: |
Chris Dearman | 1f5826b | 2006-05-08 18:02:16 +0100 | [diff] [blame] | 596 | regs->regs[rt] = 2; |
| 597 | } |
| 598 | return 0; |
| 599 | case 29: |
| 600 | regs->regs[rt] = ti->tp_value; |
| 601 | return 0; |
| 602 | default: |
| 603 | return -1; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | |
Daniel Jacobowitz | 56ebd51 | 2005-11-26 22:34:41 -0500 | [diff] [blame] | 607 | /* Not ours. */ |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 608 | return -1; |
| 609 | } |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 610 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 611 | static int simulate_sync(struct pt_regs *regs, unsigned int opcode) |
| 612 | { |
| 613 | if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) |
| 614 | return 0; |
| 615 | |
| 616 | return -1; /* Must be something else ... */ |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | asmlinkage void do_ov(struct pt_regs *regs) |
| 620 | { |
| 621 | siginfo_t info; |
| 622 | |
Ralf Baechle | 36ccf1c | 2006-02-14 21:04:54 +0000 | [diff] [blame] | 623 | die_if_kernel("Integer overflow", regs); |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | info.si_code = FPE_INTOVF; |
| 626 | info.si_signo = SIGFPE; |
| 627 | info.si_errno = 0; |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 628 | info.si_addr = (void __user *) regs->cp0_epc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | force_sig_info(SIGFPE, &info, current); |
| 630 | } |
| 631 | |
| 632 | /* |
| 633 | * XXX Delayed fp exceptions when doing a lazy ctx switch XXX |
| 634 | */ |
| 635 | asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31) |
| 636 | { |
Thiemo Seufer | 948a34c | 2007-08-22 01:42:04 +0100 | [diff] [blame] | 637 | siginfo_t info; |
| 638 | |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 639 | if (notify_die(DIE_FP, "FP exception", regs, SIGFPE, 0, 0) |
| 640 | == NOTIFY_STOP) |
| 641 | return; |
Chris Dearman | 57725f9 | 2006-06-30 23:35:28 +0100 | [diff] [blame] | 642 | die_if_kernel("FP exception in kernel code", regs); |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | if (fcr31 & FPU_CSR_UNI_X) { |
| 645 | int sig; |
| 646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | /* |
Ralf Baechle | a3dddd5 | 2006-03-11 08:18:41 +0000 | [diff] [blame] | 648 | * Unimplemented operation exception. If we've got the full |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | * software emulator on-board, let's use it... |
| 650 | * |
| 651 | * Force FPU to dump state into task/thread context. We're |
| 652 | * moving a lot of data here for what is probably a single |
| 653 | * instruction, but the alternative is to pre-decode the FP |
| 654 | * register operands before invoking the emulator, which seems |
| 655 | * a bit extreme for what should be an infrequent event. |
| 656 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 657 | /* Ensure 'resume' not overwrite saved fp context again. */ |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 658 | lose_fpu(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | /* Run the emulator */ |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 661 | sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * We can't allow the emulated instruction to leave any of |
| 665 | * the cause bit set in $fcr31. |
| 666 | */ |
Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 667 | current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | /* Restore the hardware register state */ |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 670 | own_fpu(1); /* Using the FPU again. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | /* If something went wrong, signal */ |
| 673 | if (sig) |
| 674 | force_sig(sig, current); |
| 675 | |
| 676 | return; |
Thiemo Seufer | 948a34c | 2007-08-22 01:42:04 +0100 | [diff] [blame] | 677 | } else if (fcr31 & FPU_CSR_INV_X) |
| 678 | info.si_code = FPE_FLTINV; |
| 679 | else if (fcr31 & FPU_CSR_DIV_X) |
| 680 | info.si_code = FPE_FLTDIV; |
| 681 | else if (fcr31 & FPU_CSR_OVF_X) |
| 682 | info.si_code = FPE_FLTOVF; |
| 683 | else if (fcr31 & FPU_CSR_UDF_X) |
| 684 | info.si_code = FPE_FLTUND; |
| 685 | else if (fcr31 & FPU_CSR_INE_X) |
| 686 | info.si_code = FPE_FLTRES; |
| 687 | else |
| 688 | info.si_code = __SI_FAULT; |
| 689 | info.si_signo = SIGFPE; |
| 690 | info.si_errno = 0; |
| 691 | info.si_addr = (void __user *) regs->cp0_epc; |
| 692 | force_sig_info(SIGFPE, &info, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 695 | static void do_trap_or_bp(struct pt_regs *regs, unsigned int code, |
| 696 | const char *str) |
| 697 | { |
| 698 | siginfo_t info; |
| 699 | char b[40]; |
| 700 | |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 701 | if (notify_die(DIE_TRAP, str, regs, code, 0, 0) == NOTIFY_STOP) |
| 702 | return; |
| 703 | |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 704 | /* |
| 705 | * A short test says that IRIX 5.3 sends SIGTRAP for all trap |
| 706 | * insns, even for trap and break codes that indicate arithmetic |
| 707 | * failures. Weird ... |
| 708 | * But should we continue the brokenness??? --macro |
| 709 | */ |
| 710 | switch (code) { |
| 711 | case BRK_OVERFLOW: |
| 712 | case BRK_DIVZERO: |
| 713 | scnprintf(b, sizeof(b), "%s instruction in kernel code", str); |
| 714 | die_if_kernel(b, regs); |
| 715 | if (code == BRK_DIVZERO) |
| 716 | info.si_code = FPE_INTDIV; |
| 717 | else |
| 718 | info.si_code = FPE_INTOVF; |
| 719 | info.si_signo = SIGFPE; |
| 720 | info.si_errno = 0; |
| 721 | info.si_addr = (void __user *) regs->cp0_epc; |
| 722 | force_sig_info(SIGFPE, &info, current); |
| 723 | break; |
| 724 | case BRK_BUG: |
| 725 | die_if_kernel("Kernel bug detected", regs); |
| 726 | force_sig(SIGTRAP, current); |
| 727 | break; |
Ralf Baechle | ba3049e | 2008-10-28 17:38:42 +0000 | [diff] [blame] | 728 | case BRK_MEMU: |
| 729 | /* |
| 730 | * Address errors may be deliberately induced by the FPU |
| 731 | * emulator to retake control of the CPU after executing the |
| 732 | * instruction in the delay slot of an emulated branch. |
| 733 | * |
| 734 | * Terminate if exception was recognized as a delay slot return |
| 735 | * otherwise handle as normal. |
| 736 | */ |
| 737 | if (do_dsemulret(regs)) |
| 738 | return; |
| 739 | |
| 740 | die_if_kernel("Math emu break/trap", regs); |
| 741 | force_sig(SIGTRAP, current); |
| 742 | break; |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 743 | default: |
| 744 | scnprintf(b, sizeof(b), "%s instruction in kernel code", str); |
| 745 | die_if_kernel(b, regs); |
| 746 | force_sig(SIGTRAP, current); |
| 747 | } |
| 748 | } |
| 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | asmlinkage void do_bp(struct pt_regs *regs) |
| 751 | { |
| 752 | unsigned int opcode, bcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
Atsushi Nemoto | ba755f8 | 2007-04-12 20:02:54 +0900 | [diff] [blame] | 754 | if (__get_user(opcode, (unsigned int __user *) exception_epc(regs))) |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 755 | goto out_sigsegv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | /* |
| 758 | * There is the ancient bug in the MIPS assemblers that the break |
| 759 | * code starts left to bit 16 instead to bit 6 in the opcode. |
| 760 | * Gas is bug-compatible, but not always, grrr... |
| 761 | * We handle both cases with a simple heuristics. --macro |
| 762 | */ |
| 763 | bcode = ((opcode >> 6) & ((1 << 20) - 1)); |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 764 | if (bcode >= (1 << 10)) |
| 765 | bcode >>= 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 767 | do_trap_or_bp(regs, bcode, "Break"); |
Atsushi Nemoto | 90fccb1 | 2007-02-06 16:02:21 +0900 | [diff] [blame] | 768 | return; |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 769 | |
| 770 | out_sigsegv: |
| 771 | force_sig(SIGSEGV, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | asmlinkage void do_tr(struct pt_regs *regs) |
| 775 | { |
| 776 | unsigned int opcode, tcode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Atsushi Nemoto | ba755f8 | 2007-04-12 20:02:54 +0900 | [diff] [blame] | 778 | if (__get_user(opcode, (unsigned int __user *) exception_epc(regs))) |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 779 | goto out_sigsegv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | /* Immediate versions don't provide a code. */ |
| 782 | if (!(opcode & OPCODE)) |
| 783 | tcode = ((opcode >> 6) & ((1 << 10) - 1)); |
| 784 | |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 785 | do_trap_or_bp(regs, tcode, "Trap"); |
Atsushi Nemoto | 90fccb1 | 2007-02-06 16:02:21 +0900 | [diff] [blame] | 786 | return; |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 787 | |
| 788 | out_sigsegv: |
| 789 | force_sig(SIGSEGV, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | asmlinkage void do_ri(struct pt_regs *regs) |
| 793 | { |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 794 | unsigned int __user *epc = (unsigned int __user *)exception_epc(regs); |
| 795 | unsigned long old_epc = regs->cp0_epc; |
| 796 | unsigned int opcode = 0; |
| 797 | int status = -1; |
| 798 | |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 799 | if (notify_die(DIE_RI, "RI Fault", regs, SIGSEGV, 0, 0) |
| 800 | == NOTIFY_STOP) |
| 801 | return; |
| 802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | die_if_kernel("Reserved instruction in kernel code", regs); |
| 804 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 805 | if (unlikely(compute_return_epc(regs) < 0)) |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 806 | return; |
| 807 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 808 | if (unlikely(get_user(opcode, epc) < 0)) |
| 809 | status = SIGSEGV; |
| 810 | |
| 811 | if (!cpu_has_llsc && status < 0) |
| 812 | status = simulate_llsc(regs, opcode); |
| 813 | |
| 814 | if (status < 0) |
| 815 | status = simulate_rdhwr(regs, opcode); |
| 816 | |
| 817 | if (status < 0) |
| 818 | status = simulate_sync(regs, opcode); |
| 819 | |
| 820 | if (status < 0) |
| 821 | status = SIGILL; |
| 822 | |
| 823 | if (unlikely(status > 0)) { |
| 824 | regs->cp0_epc = old_epc; /* Undo skip-over. */ |
| 825 | force_sig(status, current); |
| 826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 829 | /* |
| 830 | * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've |
| 831 | * emulated more than some threshold number of instructions, force migration to |
| 832 | * a "CPU" that has FP support. |
| 833 | */ |
| 834 | static void mt_ase_fp_affinity(void) |
| 835 | { |
| 836 | #ifdef CONFIG_MIPS_MT_FPAFF |
| 837 | if (mt_fpemul_threshold > 0 && |
| 838 | ((current->thread.emulated_fp++ > mt_fpemul_threshold))) { |
| 839 | /* |
| 840 | * If there's no FPU present, or if the application has already |
| 841 | * restricted the allowed set to exclude any CPUs with FPUs, |
| 842 | * we'll skip the procedure. |
| 843 | */ |
| 844 | if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) { |
| 845 | cpumask_t tmask; |
| 846 | |
Kevin D. Kissell | 9cc1236 | 2008-09-09 21:33:36 +0200 | [diff] [blame] | 847 | current->thread.user_cpus_allowed |
| 848 | = current->cpus_allowed; |
| 849 | cpus_and(tmask, current->cpus_allowed, |
| 850 | mt_fpu_cpumask); |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 851 | set_cpus_allowed(current, tmask); |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 852 | set_thread_flag(TIF_FPUBOUND); |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | #endif /* CONFIG_MIPS_MT_FPAFF */ |
| 856 | } |
| 857 | |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 858 | /* |
| 859 | * No lock; only written during early bootup by CPU 0. |
| 860 | */ |
| 861 | static RAW_NOTIFIER_HEAD(cu2_chain); |
| 862 | |
| 863 | int __ref register_cu2_notifier(struct notifier_block *nb) |
| 864 | { |
| 865 | return raw_notifier_chain_register(&cu2_chain, nb); |
| 866 | } |
| 867 | |
| 868 | int cu2_notifier_call_chain(unsigned long val, void *v) |
| 869 | { |
| 870 | return raw_notifier_call_chain(&cu2_chain, val, v); |
| 871 | } |
| 872 | |
| 873 | static int default_cu2_call(struct notifier_block *nfb, unsigned long action, |
| 874 | void *data) |
| 875 | { |
| 876 | struct pt_regs *regs = data; |
| 877 | |
| 878 | switch (action) { |
| 879 | default: |
| 880 | die_if_kernel("Unhandled kernel unaligned access or invalid " |
| 881 | "instruction", regs); |
| 882 | /* Fall through */ |
| 883 | |
| 884 | case CU2_EXCEPTION: |
| 885 | force_sig(SIGILL, current); |
| 886 | } |
| 887 | |
| 888 | return NOTIFY_OK; |
| 889 | } |
| 890 | |
| 891 | static struct notifier_block default_cu2_notifier = { |
| 892 | .notifier_call = default_cu2_call, |
| 893 | .priority = 0x80000000, /* Run last */ |
| 894 | }; |
| 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | asmlinkage void do_cpu(struct pt_regs *regs) |
| 897 | { |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 898 | unsigned int __user *epc; |
| 899 | unsigned long old_epc; |
| 900 | unsigned int opcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | unsigned int cpid; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 902 | int status; |
David Daney | f9bb4cf | 2008-12-11 15:33:23 -0800 | [diff] [blame] | 903 | unsigned long __maybe_unused flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
Atsushi Nemoto | 5323180 | 2007-04-14 02:37:26 +0900 | [diff] [blame] | 905 | die_if_kernel("do_cpu invoked from kernel context!", regs); |
| 906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | cpid = (regs->cp0_cause >> CAUSEB_CE) & 3; |
| 908 | |
| 909 | switch (cpid) { |
| 910 | case 0: |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 911 | epc = (unsigned int __user *)exception_epc(regs); |
| 912 | old_epc = regs->cp0_epc; |
| 913 | opcode = 0; |
| 914 | status = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 916 | if (unlikely(compute_return_epc(regs) < 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | return; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 918 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 919 | if (unlikely(get_user(opcode, epc) < 0)) |
| 920 | status = SIGSEGV; |
| 921 | |
| 922 | if (!cpu_has_llsc && status < 0) |
| 923 | status = simulate_llsc(regs, opcode); |
| 924 | |
| 925 | if (status < 0) |
| 926 | status = simulate_rdhwr(regs, opcode); |
| 927 | |
| 928 | if (status < 0) |
| 929 | status = SIGILL; |
| 930 | |
| 931 | if (unlikely(status > 0)) { |
| 932 | regs->cp0_epc = old_epc; /* Undo skip-over. */ |
| 933 | force_sig(status, current); |
| 934 | } |
| 935 | |
| 936 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
| 938 | case 1: |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 939 | if (used_math()) /* Using the FPU again. */ |
| 940 | own_fpu(1); |
| 941 | else { /* First time FPU user. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | init_fpu(); |
| 943 | set_used_math(); |
| 944 | } |
| 945 | |
Atsushi Nemoto | 5323180 | 2007-04-14 02:37:26 +0900 | [diff] [blame] | 946 | if (!raw_cpu_has_fpu) { |
Atsushi Nemoto | e04582b | 2006-10-09 00:10:01 +0900 | [diff] [blame] | 947 | int sig; |
Atsushi Nemoto | e04582b | 2006-10-09 00:10:01 +0900 | [diff] [blame] | 948 | sig = fpu_emulator_cop1Handler(regs, |
| 949 | ¤t->thread.fpu, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | if (sig) |
| 951 | force_sig(sig, current); |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 952 | else |
| 953 | mt_ase_fp_affinity(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | return; |
| 957 | |
| 958 | case 2: |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 959 | raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs); |
| 960 | break; |
| 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | case 3: |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | force_sig(SIGILL, current); |
| 967 | } |
| 968 | |
| 969 | asmlinkage void do_mdmx(struct pt_regs *regs) |
| 970 | { |
| 971 | force_sig(SIGILL, current); |
| 972 | } |
| 973 | |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 974 | /* |
| 975 | * Called with interrupts disabled. |
| 976 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | asmlinkage void do_watch(struct pt_regs *regs) |
| 978 | { |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 979 | u32 cause; |
| 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | /* |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 982 | * Clear WP (bit 22) bit of cause register so we don't loop |
| 983 | * forever. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | */ |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 985 | cause = read_c0_cause(); |
| 986 | cause &= ~(1 << 22); |
| 987 | write_c0_cause(cause); |
| 988 | |
| 989 | /* |
| 990 | * If the current thread has the watch registers loaded, save |
| 991 | * their values and send SIGTRAP. Otherwise another thread |
| 992 | * left the registers set, clear them and continue. |
| 993 | */ |
| 994 | if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) { |
| 995 | mips_read_watch_registers(); |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 996 | local_irq_enable(); |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 997 | force_sig(SIGTRAP, current); |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 998 | } else { |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 999 | mips_clear_watch_registers(); |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 1000 | local_irq_enable(); |
| 1001 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | asmlinkage void do_mcheck(struct pt_regs *regs) |
| 1005 | { |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1006 | const int field = 2 * sizeof(unsigned long); |
| 1007 | int multi_match = regs->cp0_status & ST0_TS; |
| 1008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | show_regs(regs); |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1010 | |
| 1011 | if (multi_match) { |
| 1012 | printk("Index : %0x\n", read_c0_index()); |
| 1013 | printk("Pagemask: %0x\n", read_c0_pagemask()); |
| 1014 | printk("EntryHi : %0*lx\n", field, read_c0_entryhi()); |
| 1015 | printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0()); |
| 1016 | printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1()); |
| 1017 | printk("\n"); |
| 1018 | dump_tlb_all(); |
| 1019 | } |
| 1020 | |
Atsushi Nemoto | e1bb828 | 2007-07-13 23:51:46 +0900 | [diff] [blame] | 1021 | show_code((unsigned int __user *) regs->cp0_epc); |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | /* |
| 1024 | * Some chips may have other causes of machine check (e.g. SB1 |
| 1025 | * graduation timer) |
| 1026 | */ |
| 1027 | panic("Caught Machine Check exception - %scaused by multiple " |
| 1028 | "matching entries in the TLB.", |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1029 | (multi_match) ? "" : "not "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 1032 | asmlinkage void do_mt(struct pt_regs *regs) |
| 1033 | { |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1034 | int subcode; |
| 1035 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1036 | subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT) |
| 1037 | >> VPECONTROL_EXCPT_SHIFT; |
| 1038 | switch (subcode) { |
| 1039 | case 0: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1040 | printk(KERN_DEBUG "Thread Underflow\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1041 | break; |
| 1042 | case 1: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1043 | printk(KERN_DEBUG "Thread Overflow\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1044 | break; |
| 1045 | case 2: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1046 | printk(KERN_DEBUG "Invalid YIELD Qualifier\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1047 | break; |
| 1048 | case 3: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1049 | printk(KERN_DEBUG "Gating Storage Exception\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1050 | break; |
| 1051 | case 4: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1052 | printk(KERN_DEBUG "YIELD Scheduler Exception\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1053 | break; |
| 1054 | case 5: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1055 | printk(KERN_DEBUG "Gating Storage Schedulier Exception\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1056 | break; |
| 1057 | default: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1058 | printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n", |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1059 | subcode); |
| 1060 | break; |
| 1061 | } |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 1062 | die_if_kernel("MIPS MT Thread exception in kernel", regs); |
| 1063 | |
| 1064 | force_sig(SIGILL, current); |
| 1065 | } |
| 1066 | |
| 1067 | |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1068 | asmlinkage void do_dsp(struct pt_regs *regs) |
| 1069 | { |
| 1070 | if (cpu_has_dsp) |
| 1071 | panic("Unexpected DSP exception\n"); |
| 1072 | |
| 1073 | force_sig(SIGILL, current); |
| 1074 | } |
| 1075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | asmlinkage void do_reserved(struct pt_regs *regs) |
| 1077 | { |
| 1078 | /* |
| 1079 | * Game over - no way to handle this if it ever occurs. Most probably |
| 1080 | * caused by a new unknown cpu type or after another deadly |
| 1081 | * hard/software error. |
| 1082 | */ |
| 1083 | show_regs(regs); |
| 1084 | panic("Caught reserved exception %ld - should not happen.", |
| 1085 | (regs->cp0_cause & 0x7f) >> 2); |
| 1086 | } |
| 1087 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1088 | static int __initdata l1parity = 1; |
| 1089 | static int __init nol1parity(char *s) |
| 1090 | { |
| 1091 | l1parity = 0; |
| 1092 | return 1; |
| 1093 | } |
| 1094 | __setup("nol1par", nol1parity); |
| 1095 | static int __initdata l2parity = 1; |
| 1096 | static int __init nol2parity(char *s) |
| 1097 | { |
| 1098 | l2parity = 0; |
| 1099 | return 1; |
| 1100 | } |
| 1101 | __setup("nol2par", nol2parity); |
| 1102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | /* |
| 1104 | * Some MIPS CPUs can enable/disable for cache parity detection, but do |
| 1105 | * it different ways. |
| 1106 | */ |
| 1107 | static inline void parity_protection_init(void) |
| 1108 | { |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1109 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | case CPU_24K: |
Nigel Stephens | 98a41de | 2006-04-27 15:50:32 +0100 | [diff] [blame] | 1111 | case CPU_34K: |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1112 | case CPU_74K: |
| 1113 | case CPU_1004K: |
| 1114 | { |
| 1115 | #define ERRCTL_PE 0x80000000 |
| 1116 | #define ERRCTL_L2P 0x00800000 |
| 1117 | unsigned long errctl; |
| 1118 | unsigned int l1parity_present, l2parity_present; |
| 1119 | |
| 1120 | errctl = read_c0_ecc(); |
| 1121 | errctl &= ~(ERRCTL_PE|ERRCTL_L2P); |
| 1122 | |
| 1123 | /* probe L1 parity support */ |
| 1124 | write_c0_ecc(errctl | ERRCTL_PE); |
| 1125 | back_to_back_c0_hazard(); |
| 1126 | l1parity_present = (read_c0_ecc() & ERRCTL_PE); |
| 1127 | |
| 1128 | /* probe L2 parity support */ |
| 1129 | write_c0_ecc(errctl|ERRCTL_L2P); |
| 1130 | back_to_back_c0_hazard(); |
| 1131 | l2parity_present = (read_c0_ecc() & ERRCTL_L2P); |
| 1132 | |
| 1133 | if (l1parity_present && l2parity_present) { |
| 1134 | if (l1parity) |
| 1135 | errctl |= ERRCTL_PE; |
| 1136 | if (l1parity ^ l2parity) |
| 1137 | errctl |= ERRCTL_L2P; |
| 1138 | } else if (l1parity_present) { |
| 1139 | if (l1parity) |
| 1140 | errctl |= ERRCTL_PE; |
| 1141 | } else if (l2parity_present) { |
| 1142 | if (l2parity) |
| 1143 | errctl |= ERRCTL_L2P; |
| 1144 | } else { |
| 1145 | /* No parity available */ |
| 1146 | } |
| 1147 | |
| 1148 | printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl); |
| 1149 | |
| 1150 | write_c0_ecc(errctl); |
| 1151 | back_to_back_c0_hazard(); |
| 1152 | errctl = read_c0_ecc(); |
| 1153 | printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl); |
| 1154 | |
| 1155 | if (l1parity_present) |
| 1156 | printk(KERN_INFO "Cache parity protection %sabled\n", |
| 1157 | (errctl & ERRCTL_PE) ? "en" : "dis"); |
| 1158 | |
| 1159 | if (l2parity_present) { |
| 1160 | if (l1parity_present && l1parity) |
| 1161 | errctl ^= ERRCTL_L2P; |
| 1162 | printk(KERN_INFO "L2 cache parity protection %sabled\n", |
| 1163 | (errctl & ERRCTL_L2P) ? "en" : "dis"); |
| 1164 | } |
| 1165 | } |
| 1166 | break; |
| 1167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | case CPU_5KC: |
Ralf Baechle | 14f18b7 | 2005-03-01 18:15:08 +0000 | [diff] [blame] | 1169 | write_c0_ecc(0x80000000); |
| 1170 | back_to_back_c0_hazard(); |
| 1171 | /* Set the PE bit (bit 31) in the c0_errctl register. */ |
| 1172 | printk(KERN_INFO "Cache parity protection %sabled\n", |
| 1173 | (read_c0_ecc() & 0x80000000) ? "en" : "dis"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | break; |
| 1175 | case CPU_20KC: |
| 1176 | case CPU_25KF: |
| 1177 | /* Clear the DE bit (bit 16) in the c0_status register. */ |
| 1178 | printk(KERN_INFO "Enable cache parity protection for " |
| 1179 | "MIPS 20KC/25KF CPUs.\n"); |
| 1180 | clear_c0_status(ST0_DE); |
| 1181 | break; |
| 1182 | default: |
| 1183 | break; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | asmlinkage void cache_parity_error(void) |
| 1188 | { |
| 1189 | const int field = 2 * sizeof(unsigned long); |
| 1190 | unsigned int reg_val; |
| 1191 | |
| 1192 | /* For the moment, report the problem and hang. */ |
| 1193 | printk("Cache error exception:\n"); |
| 1194 | printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc()); |
| 1195 | reg_val = read_c0_cacheerr(); |
| 1196 | printk("c0_cacheerr == %08x\n", reg_val); |
| 1197 | |
| 1198 | printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n", |
| 1199 | reg_val & (1<<30) ? "secondary" : "primary", |
| 1200 | reg_val & (1<<31) ? "data" : "insn"); |
| 1201 | printk("Error bits: %s%s%s%s%s%s%s\n", |
| 1202 | reg_val & (1<<29) ? "ED " : "", |
| 1203 | reg_val & (1<<28) ? "ET " : "", |
| 1204 | reg_val & (1<<26) ? "EE " : "", |
| 1205 | reg_val & (1<<25) ? "EB " : "", |
| 1206 | reg_val & (1<<24) ? "EI " : "", |
| 1207 | reg_val & (1<<23) ? "E1 " : "", |
| 1208 | reg_val & (1<<22) ? "E0 " : ""); |
| 1209 | printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1)); |
| 1210 | |
Ralf Baechle | ec917c2c | 2005-10-07 16:58:15 +0100 | [diff] [blame] | 1211 | #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | if (reg_val & (1<<22)) |
| 1213 | printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0()); |
| 1214 | |
| 1215 | if (reg_val & (1<<23)) |
| 1216 | printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1()); |
| 1217 | #endif |
| 1218 | |
| 1219 | panic("Can't handle the cache error!"); |
| 1220 | } |
| 1221 | |
| 1222 | /* |
| 1223 | * SDBBP EJTAG debug exception handler. |
| 1224 | * We skip the instruction and return to the next instruction. |
| 1225 | */ |
| 1226 | void ejtag_exception_handler(struct pt_regs *regs) |
| 1227 | { |
| 1228 | const int field = 2 * sizeof(unsigned long); |
| 1229 | unsigned long depc, old_epc; |
| 1230 | unsigned int debug; |
| 1231 | |
Chris Dearman | 70ae612 | 2006-06-30 12:32:37 +0100 | [diff] [blame] | 1232 | printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | depc = read_c0_depc(); |
| 1234 | debug = read_c0_debug(); |
Chris Dearman | 70ae612 | 2006-06-30 12:32:37 +0100 | [diff] [blame] | 1235 | printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | if (debug & 0x80000000) { |
| 1237 | /* |
| 1238 | * In branch delay slot. |
| 1239 | * We cheat a little bit here and use EPC to calculate the |
| 1240 | * debug return address (DEPC). EPC is restored after the |
| 1241 | * calculation. |
| 1242 | */ |
| 1243 | old_epc = regs->cp0_epc; |
| 1244 | regs->cp0_epc = depc; |
| 1245 | __compute_return_epc(regs); |
| 1246 | depc = regs->cp0_epc; |
| 1247 | regs->cp0_epc = old_epc; |
| 1248 | } else |
| 1249 | depc += 4; |
| 1250 | write_c0_depc(depc); |
| 1251 | |
| 1252 | #if 0 |
Chris Dearman | 70ae612 | 2006-06-30 12:32:37 +0100 | [diff] [blame] | 1253 | printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | write_c0_debug(debug | 0x100); |
| 1255 | #endif |
| 1256 | } |
| 1257 | |
| 1258 | /* |
| 1259 | * NMI exception handler. |
| 1260 | */ |
Thiemo Seufer | 34412c7 | 2007-08-20 23:43:49 +0100 | [diff] [blame] | 1261 | NORET_TYPE void ATTRIB_NORET nmi_exception_handler(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | { |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1263 | bust_spinlocks(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | printk("NMI taken!!!!\n"); |
| 1265 | die("NMI", regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1268 | #define VECTORSPACING 0x100 /* for EI/VI mode */ |
| 1269 | |
| 1270 | unsigned long ebase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | unsigned long exception_handlers[32]; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1272 | unsigned long vi_handlers[64]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | |
| 1274 | /* |
| 1275 | * As a side effect of the way this is implemented we're limited |
| 1276 | * to interrupt handlers in the address range from |
| 1277 | * KSEG0 <= x < KSEG0 + 256mb on the Nevada. Oh well ... |
| 1278 | */ |
| 1279 | void *set_except_vector(int n, void *addr) |
| 1280 | { |
| 1281 | unsigned long handler = (unsigned long) addr; |
| 1282 | unsigned long old_handler = exception_handlers[n]; |
| 1283 | |
| 1284 | exception_handlers[n] = handler; |
| 1285 | if (n == 0 && cpu_has_divec) { |
Ralf Baechle | ec70f65 | 2007-10-11 23:46:03 +0100 | [diff] [blame] | 1286 | *(u32 *)(ebase + 0x200) = 0x08000000 | |
| 1287 | (0x03ffffff & (handler >> 2)); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1288 | local_flush_icache_range(ebase + 0x200, ebase + 0x204); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | return (void *)old_handler; |
| 1291 | } |
| 1292 | |
Atsushi Nemoto | 6ba07e5 | 2007-05-21 23:45:38 +0900 | [diff] [blame] | 1293 | static asmlinkage void do_default_vi(void) |
| 1294 | { |
| 1295 | show_regs(get_irq_regs()); |
| 1296 | panic("Caught unexpected vectored interrupt."); |
| 1297 | } |
| 1298 | |
Ralf Baechle | ef300e4 | 2007-05-06 18:31:18 +0100 | [diff] [blame] | 1299 | static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1300 | { |
| 1301 | unsigned long handler; |
| 1302 | unsigned long old_handler = vi_handlers[n]; |
Ralf Baechle | f6771db | 2007-11-08 18:02:29 +0000 | [diff] [blame] | 1303 | int srssets = current_cpu_data.srsets; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1304 | u32 *w; |
| 1305 | unsigned char *b; |
| 1306 | |
Ralf Baechle | b72b709 | 2009-03-30 14:49:44 +0200 | [diff] [blame] | 1307 | BUG_ON(!cpu_has_veic && !cpu_has_vint); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1308 | |
| 1309 | if (addr == NULL) { |
| 1310 | handler = (unsigned long) do_default_vi; |
| 1311 | srs = 0; |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1312 | } else |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1313 | handler = (unsigned long) addr; |
| 1314 | vi_handlers[n] = (unsigned long) addr; |
| 1315 | |
| 1316 | b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING); |
| 1317 | |
Ralf Baechle | f6771db | 2007-11-08 18:02:29 +0000 | [diff] [blame] | 1318 | if (srs >= srssets) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1319 | panic("Shadow register set %d not supported", srs); |
| 1320 | |
| 1321 | if (cpu_has_veic) { |
| 1322 | if (board_bind_eic_interrupt) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1323 | board_bind_eic_interrupt(n, srs); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1324 | } else if (cpu_has_vint) { |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1325 | /* SRSMap is only defined if shadow sets are implemented */ |
Ralf Baechle | f6771db | 2007-11-08 18:02:29 +0000 | [diff] [blame] | 1326 | if (srssets > 1) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1327 | change_c0_srsmap(0xf << n*4, srs << n*4); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | if (srs == 0) { |
| 1331 | /* |
| 1332 | * If no shadow set is selected then use the default handler |
| 1333 | * that does normal register saving and a standard interrupt exit |
| 1334 | */ |
| 1335 | |
| 1336 | extern char except_vec_vi, except_vec_vi_lui; |
| 1337 | extern char except_vec_vi_ori, except_vec_vi_end; |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1338 | extern char rollback_except_vec_vi; |
| 1339 | char *vec_start = (cpu_wait == r4k_wait) ? |
| 1340 | &rollback_except_vec_vi : &except_vec_vi; |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1341 | #ifdef CONFIG_MIPS_MT_SMTC |
| 1342 | /* |
| 1343 | * We need to provide the SMTC vectored interrupt handler |
| 1344 | * not only with the address of the handler, but with the |
| 1345 | * Status.IM bit to be masked before going there. |
| 1346 | */ |
| 1347 | extern char except_vec_vi_mori; |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1348 | const int mori_offset = &except_vec_vi_mori - vec_start; |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1349 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1350 | const int handler_len = &except_vec_vi_end - vec_start; |
| 1351 | const int lui_offset = &except_vec_vi_lui - vec_start; |
| 1352 | const int ori_offset = &except_vec_vi_ori - vec_start; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1353 | |
| 1354 | if (handler_len > VECTORSPACING) { |
| 1355 | /* |
| 1356 | * Sigh... panicing won't help as the console |
| 1357 | * is probably not configured :( |
| 1358 | */ |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1359 | panic("VECTORSPACING too small"); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1362 | memcpy(b, vec_start, handler_len); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1363 | #ifdef CONFIG_MIPS_MT_SMTC |
Ralf Baechle | 8e8a52e | 2007-05-31 14:00:19 +0100 | [diff] [blame] | 1364 | BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */ |
| 1365 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1366 | w = (u32 *)(b + mori_offset); |
| 1367 | *w = (*w & 0xffff0000) | (0x100 << n); |
| 1368 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1369 | w = (u32 *)(b + lui_offset); |
| 1370 | *w = (*w & 0xffff0000) | (((u32)handler >> 16) & 0xffff); |
| 1371 | w = (u32 *)(b + ori_offset); |
| 1372 | *w = (*w & 0xffff0000) | ((u32)handler & 0xffff); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1373 | local_flush_icache_range((unsigned long)b, |
| 1374 | (unsigned long)(b+handler_len)); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1375 | } |
| 1376 | else { |
| 1377 | /* |
| 1378 | * In other cases jump directly to the interrupt handler |
| 1379 | * |
| 1380 | * It is the handlers responsibility to save registers if required |
| 1381 | * (eg hi/lo) and return from the exception using "eret" |
| 1382 | */ |
| 1383 | w = (u32 *)b; |
| 1384 | *w++ = 0x08000000 | (((u32)handler >> 2) & 0x03fffff); /* j handler */ |
| 1385 | *w = 0; |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1386 | local_flush_icache_range((unsigned long)b, |
| 1387 | (unsigned long)(b+8)); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | return (void *)old_handler; |
| 1391 | } |
| 1392 | |
Ralf Baechle | ef300e4 | 2007-05-06 18:31:18 +0100 | [diff] [blame] | 1393 | void *set_vi_handler(int n, vi_handler_t addr) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1394 | { |
Ralf Baechle | ff3eab2 | 2006-03-29 14:12:58 +0100 | [diff] [blame] | 1395 | return set_vi_srs_handler(n, addr, 0); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1396 | } |
Ralf Baechle | f41ae0b | 2006-06-05 17:24:46 +0100 | [diff] [blame] | 1397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | extern void cpu_cache_init(void); |
| 1399 | extern void tlb_init(void); |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1400 | extern void flush_tlb_handlers(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | |
Ralf Baechle | 42f7754 | 2007-10-18 17:48:11 +0100 | [diff] [blame] | 1402 | /* |
| 1403 | * Timer interrupt |
| 1404 | */ |
| 1405 | int cp0_compare_irq; |
David VomLehn | 010c108 | 2009-12-21 17:49:22 -0800 | [diff] [blame] | 1406 | int cp0_compare_irq_shift; |
Ralf Baechle | 42f7754 | 2007-10-18 17:48:11 +0100 | [diff] [blame] | 1407 | |
| 1408 | /* |
| 1409 | * Performance counter IRQ or -1 if shared with timer |
| 1410 | */ |
| 1411 | int cp0_perfcount_irq; |
| 1412 | EXPORT_SYMBOL_GPL(cp0_perfcount_irq); |
| 1413 | |
Chris Dearman | bdc94eb | 2007-10-03 10:43:56 +0100 | [diff] [blame] | 1414 | static int __cpuinitdata noulri; |
| 1415 | |
| 1416 | static int __init ulri_disable(char *s) |
| 1417 | { |
| 1418 | pr_info("Disabling ulri\n"); |
| 1419 | noulri = 1; |
| 1420 | |
| 1421 | return 1; |
| 1422 | } |
| 1423 | __setup("noulri", ulri_disable); |
| 1424 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1425 | void __cpuinit per_cpu_trap_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | { |
| 1427 | unsigned int cpu = smp_processor_id(); |
| 1428 | unsigned int status_set = ST0_CU0; |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1429 | #ifdef CONFIG_MIPS_MT_SMTC |
| 1430 | int secondaryTC = 0; |
| 1431 | int bootTC = (cpu == 0); |
| 1432 | |
| 1433 | /* |
| 1434 | * Only do per_cpu_trap_init() for first TC of Each VPE. |
| 1435 | * Note that this hack assumes that the SMTC init code |
| 1436 | * assigns TCs consecutively and in ascending order. |
| 1437 | */ |
| 1438 | |
| 1439 | if (((read_c0_tcbind() & TCBIND_CURTC) != 0) && |
| 1440 | ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id)) |
| 1441 | secondaryTC = 1; |
| 1442 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
| 1444 | /* |
| 1445 | * Disable coprocessors and select 32-bit or 64-bit addressing |
| 1446 | * and the 16/32 or 32/32 FPR register model. Reset the BEV |
| 1447 | * flag that some firmware may have left set and the TS bit (for |
| 1448 | * IP27). Set XX for ISA IV code to work. |
| 1449 | */ |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 1450 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX; |
| 1452 | #endif |
| 1453 | if (current_cpu_data.isa_level == MIPS_CPU_ISA_IV) |
| 1454 | status_set |= ST0_XX; |
Chris Dearman | bbaf238 | 2007-12-13 22:42:19 +0000 | [diff] [blame] | 1455 | if (cpu_has_dsp) |
| 1456 | status_set |= ST0_MX; |
| 1457 | |
Ralf Baechle | b38c739 | 2006-02-07 01:20:43 +0000 | [diff] [blame] | 1458 | change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | status_set); |
| 1460 | |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 1461 | if (cpu_has_mips_r2) { |
David Daney | fbeda19 | 2009-05-13 15:59:55 -0700 | [diff] [blame] | 1462 | unsigned int enable = 0x0000000f | cpu_hwrena_impl_bits; |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 1463 | |
Chris Dearman | bdc94eb | 2007-10-03 10:43:56 +0100 | [diff] [blame] | 1464 | if (!noulri && cpu_has_userlocal) |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 1465 | enable |= (1 << 29); |
| 1466 | |
| 1467 | write_c0_hwrena(enable); |
| 1468 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1469 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1470 | #ifdef CONFIG_MIPS_MT_SMTC |
| 1471 | if (!secondaryTC) { |
| 1472 | #endif /* CONFIG_MIPS_MT_SMTC */ |
| 1473 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1474 | if (cpu_has_veic || cpu_has_vint) { |
Chris Dearman | 9fb4c2b | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 1475 | unsigned long sr = set_c0_status(ST0_BEV); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1476 | write_c0_ebase(ebase); |
Chris Dearman | 9fb4c2b | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 1477 | write_c0_status(sr); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1478 | /* Setting vector spacing enables EI/VI mode */ |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1479 | change_c0_intctl(0x3e0, VECTORSPACING); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1480 | } |
Ralf Baechle | d03d0a5 | 2005-08-17 13:44:26 +0000 | [diff] [blame] | 1481 | if (cpu_has_divec) { |
| 1482 | if (cpu_has_mipsmt) { |
| 1483 | unsigned int vpflags = dvpe(); |
| 1484 | set_c0_cause(CAUSEF_IV); |
| 1485 | evpe(vpflags); |
| 1486 | } else |
| 1487 | set_c0_cause(CAUSEF_IV); |
| 1488 | } |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 1489 | |
| 1490 | /* |
| 1491 | * Before R2 both interrupt numbers were fixed to 7, so on R2 only: |
| 1492 | * |
| 1493 | * o read IntCtl.IPTI to determine the timer interrupt |
| 1494 | * o read IntCtl.IPPCI to determine the performance counter interrupt |
| 1495 | */ |
| 1496 | if (cpu_has_mips_r2) { |
David VomLehn | 010c108 | 2009-12-21 17:49:22 -0800 | [diff] [blame] | 1497 | cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP; |
| 1498 | cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7; |
| 1499 | cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7; |
Chris Dearman | c3e838a | 2007-06-21 12:59:57 +0100 | [diff] [blame] | 1500 | if (cp0_perfcount_irq == cp0_compare_irq) |
| 1501 | cp0_perfcount_irq = -1; |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 1502 | } else { |
| 1503 | cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ; |
Wu Zhangjin | f4fc580 | 2010-02-01 17:10:55 +0800 | [diff] [blame^] | 1504 | cp0_compare_irq_shift = cp0_compare_irq; |
Chris Dearman | c3e838a | 2007-06-21 12:59:57 +0100 | [diff] [blame] | 1505 | cp0_perfcount_irq = -1; |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1508 | #ifdef CONFIG_MIPS_MT_SMTC |
| 1509 | } |
| 1510 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
| 1512 | cpu_data[cpu].asid_cache = ASID_FIRST_VERSION; |
| 1513 | TLBMISS_HANDLER_SETUP(); |
| 1514 | |
| 1515 | atomic_inc(&init_mm.mm_count); |
| 1516 | current->active_mm = &init_mm; |
| 1517 | BUG_ON(current->mm); |
| 1518 | enter_lazy_tlb(&init_mm, current); |
| 1519 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1520 | #ifdef CONFIG_MIPS_MT_SMTC |
| 1521 | if (bootTC) { |
| 1522 | #endif /* CONFIG_MIPS_MT_SMTC */ |
| 1523 | cpu_cache_init(); |
| 1524 | tlb_init(); |
| 1525 | #ifdef CONFIG_MIPS_MT_SMTC |
Ralf Baechle | 6a05888 | 2007-05-31 14:03:45 +0100 | [diff] [blame] | 1526 | } else if (!secondaryTC) { |
| 1527 | /* |
| 1528 | * First TC in non-boot VPE must do subset of tlb_init() |
| 1529 | * for MMU countrol registers. |
| 1530 | */ |
| 1531 | write_c0_pagemask(PM_DEFAULT_MASK); |
| 1532 | write_c0_wired(0); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1533 | } |
| 1534 | #endif /* CONFIG_MIPS_MT_SMTC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1537 | /* Install CPU exception handler */ |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1538 | void __init set_handler(unsigned long offset, void *addr, unsigned long size) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1539 | { |
| 1540 | memcpy((void *)(ebase + offset), addr, size); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1541 | local_flush_icache_range(ebase + offset, ebase + offset + size); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1544 | static char panic_null_cerr[] __cpuinitdata = |
Ralf Baechle | 641e97f | 2007-10-11 23:46:05 +0100 | [diff] [blame] | 1545 | "Trying to set NULL cache error exception handler"; |
| 1546 | |
Ralf Baechle | 42fe7ee | 2009-01-28 18:48:23 +0000 | [diff] [blame] | 1547 | /* |
| 1548 | * Install uncached CPU exception handler. |
| 1549 | * This is suitable only for the cache error exception which is the only |
| 1550 | * exception handler that is being run uncached. |
| 1551 | */ |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 1552 | void __cpuinit set_uncached_handler(unsigned long offset, void *addr, |
| 1553 | unsigned long size) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1554 | { |
| 1555 | #ifdef CONFIG_32BIT |
| 1556 | unsigned long uncached_ebase = KSEG1ADDR(ebase); |
| 1557 | #endif |
| 1558 | #ifdef CONFIG_64BIT |
| 1559 | unsigned long uncached_ebase = TO_UNCAC(ebase); |
| 1560 | #endif |
| 1561 | |
Ralf Baechle | 641e97f | 2007-10-11 23:46:05 +0100 | [diff] [blame] | 1562 | if (!addr) |
| 1563 | panic(panic_null_cerr); |
| 1564 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1565 | memcpy((void *)(uncached_ebase + offset), addr, size); |
| 1566 | } |
| 1567 | |
Atsushi Nemoto | 5b10496 | 2006-09-11 17:50:29 +0900 | [diff] [blame] | 1568 | static int __initdata rdhwr_noopt; |
| 1569 | static int __init set_rdhwr_noopt(char *str) |
| 1570 | { |
| 1571 | rdhwr_noopt = 1; |
| 1572 | return 1; |
| 1573 | } |
| 1574 | |
| 1575 | __setup("rdhwr_noopt", set_rdhwr_noopt); |
| 1576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | void __init trap_init(void) |
| 1578 | { |
| 1579 | extern char except_vec3_generic, except_vec3_r4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | extern char except_vec4; |
| 1581 | unsigned long i; |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1582 | int rollback; |
| 1583 | |
| 1584 | check_wait(); |
| 1585 | rollback = (cpu_wait == r4k_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 1587 | #if defined(CONFIG_KGDB) |
| 1588 | if (kgdb_early_setup) |
| 1589 | return; /* Already done */ |
| 1590 | #endif |
| 1591 | |
Chris Dearman | 9fb4c2b | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 1592 | if (cpu_has_veic || cpu_has_vint) { |
| 1593 | unsigned long size = 0x200 + VECTORSPACING*64; |
| 1594 | ebase = (unsigned long) |
| 1595 | __alloc_bootmem(size, 1 << fls(size), 0); |
| 1596 | } else { |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1597 | ebase = CAC_BASE; |
David Daney | 566f74f | 2008-10-23 17:56:35 -0700 | [diff] [blame] | 1598 | if (cpu_has_mips_r2) |
| 1599 | ebase += (read_c0_ebase() & 0x3ffff000); |
| 1600 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | per_cpu_trap_init(); |
| 1603 | |
| 1604 | /* |
| 1605 | * Copy the generic exception handlers to their final destination. |
| 1606 | * This will be overriden later as suitable for a particular |
| 1607 | * configuration. |
| 1608 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1609 | set_handler(0x180, &except_vec3_generic, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
| 1611 | /* |
| 1612 | * Setup default vectors |
| 1613 | */ |
| 1614 | for (i = 0; i <= 31; i++) |
| 1615 | set_except_vector(i, handle_reserved); |
| 1616 | |
| 1617 | /* |
| 1618 | * Copy the EJTAG debug exception vector handler code to it's final |
| 1619 | * destination. |
| 1620 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1621 | if (cpu_has_ejtag && board_ejtag_handler_setup) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1622 | board_ejtag_handler_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | |
| 1624 | /* |
| 1625 | * Only some CPUs have the watch exceptions. |
| 1626 | */ |
| 1627 | if (cpu_has_watch) |
| 1628 | set_except_vector(23, handle_watch); |
| 1629 | |
| 1630 | /* |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1631 | * Initialise interrupt handlers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1633 | if (cpu_has_veic || cpu_has_vint) { |
| 1634 | int nvec = cpu_has_veic ? 64 : 8; |
| 1635 | for (i = 0; i < nvec; i++) |
Ralf Baechle | ff3eab2 | 2006-03-29 14:12:58 +0100 | [diff] [blame] | 1636 | set_vi_handler(i, NULL); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1637 | } |
| 1638 | else if (cpu_has_divec) |
| 1639 | set_handler(0x200, &except_vec4, 0x8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | |
| 1641 | /* |
| 1642 | * Some CPUs can enable/disable for cache parity detection, but does |
| 1643 | * it different ways. |
| 1644 | */ |
| 1645 | parity_protection_init(); |
| 1646 | |
| 1647 | /* |
| 1648 | * The Data Bus Errors / Instruction Bus Errors are signaled |
| 1649 | * by external hardware. Therefore these two exceptions |
| 1650 | * may have board specific handlers. |
| 1651 | */ |
| 1652 | if (board_be_init) |
| 1653 | board_be_init(); |
| 1654 | |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1655 | set_except_vector(0, rollback ? rollback_handle_int : handle_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | set_except_vector(1, handle_tlbm); |
| 1657 | set_except_vector(2, handle_tlbl); |
| 1658 | set_except_vector(3, handle_tlbs); |
| 1659 | |
| 1660 | set_except_vector(4, handle_adel); |
| 1661 | set_except_vector(5, handle_ades); |
| 1662 | |
| 1663 | set_except_vector(6, handle_ibe); |
| 1664 | set_except_vector(7, handle_dbe); |
| 1665 | |
| 1666 | set_except_vector(8, handle_sys); |
| 1667 | set_except_vector(9, handle_bp); |
Atsushi Nemoto | 5b10496 | 2006-09-11 17:50:29 +0900 | [diff] [blame] | 1668 | set_except_vector(10, rdhwr_noopt ? handle_ri : |
| 1669 | (cpu_has_vtag_icache ? |
| 1670 | handle_ri_rdhwr_vivt : handle_ri_rdhwr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | set_except_vector(11, handle_cpu); |
| 1672 | set_except_vector(12, handle_ov); |
| 1673 | set_except_vector(13, handle_tr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1675 | if (current_cpu_type() == CPU_R6000 || |
| 1676 | current_cpu_type() == CPU_R6000A) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | /* |
| 1678 | * The R6000 is the only R-series CPU that features a machine |
| 1679 | * check exception (similar to the R4000 cache error) and |
| 1680 | * unaligned ldc1/sdc1 exception. The handlers have not been |
| 1681 | * written yet. Well, anyway there is no R6000 machine on the |
| 1682 | * current list of targets for Linux/MIPS. |
| 1683 | * (Duh, crap, there is someone with a triple R6k machine) |
| 1684 | */ |
| 1685 | //set_except_vector(14, handle_mc); |
| 1686 | //set_except_vector(15, handle_ndc); |
| 1687 | } |
| 1688 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1689 | |
| 1690 | if (board_nmi_handler_setup) |
| 1691 | board_nmi_handler_setup(); |
| 1692 | |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1693 | if (cpu_has_fpu && !cpu_has_nofpuex) |
| 1694 | set_except_vector(15, handle_fpe); |
| 1695 | |
| 1696 | set_except_vector(22, handle_mdmx); |
| 1697 | |
| 1698 | if (cpu_has_mcheck) |
| 1699 | set_except_vector(24, handle_mcheck); |
| 1700 | |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 1701 | if (cpu_has_mipsmt) |
| 1702 | set_except_vector(25, handle_mt); |
| 1703 | |
Chris Dearman | acaec42 | 2007-05-24 22:30:18 +0100 | [diff] [blame] | 1704 | set_except_vector(26, handle_dsp); |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1705 | |
| 1706 | if (cpu_has_vce) |
| 1707 | /* Special exception: R4[04]00 uses also the divec space. */ |
David Daney | 566f74f | 2008-10-23 17:56:35 -0700 | [diff] [blame] | 1708 | memcpy((void *)(ebase + 0x180), &except_vec3_r4000, 0x100); |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1709 | else if (cpu_has_4kex) |
David Daney | 566f74f | 2008-10-23 17:56:35 -0700 | [diff] [blame] | 1710 | memcpy((void *)(ebase + 0x180), &except_vec3_generic, 0x80); |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1711 | else |
David Daney | 566f74f | 2008-10-23 17:56:35 -0700 | [diff] [blame] | 1712 | memcpy((void *)(ebase + 0x080), &except_vec3_generic, 0x80); |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1713 | |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 1714 | local_flush_icache_range(ebase, ebase + 0x400); |
Ralf Baechle | 1d40cfc | 2005-07-15 15:23:23 +0000 | [diff] [blame] | 1715 | flush_tlb_handlers(); |
Thomas Bogendoerfer | 0510617 | 2008-08-04 19:44:34 +0200 | [diff] [blame] | 1716 | |
| 1717 | sort_extable(__start___dbe_table, __stop___dbe_table); |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 1718 | |
| 1719 | register_cu2_notifier(&default_cu2_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | } |