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