15 #include <linux/compiler.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/sched.h>
26 #include <linux/ptrace.h>
33 #include <linux/perf_event.h>
35 #include <asm/bootinfo.h>
37 #include <asm/break.h>
45 #include <asm/module.h>
46 #include <asm/pgtable.h>
47 #include <asm/ptrace.h>
48 #include <asm/sections.h>
50 #include <asm/traps.h>
51 #include <asm/uaccess.h>
53 #include <asm/mmu_context.h>
54 #include <asm/types.h>
55 #include <asm/stacktrace.h>
87 void *__user *fault_addr);
97 static void show_raw_backtrace(
unsigned long reg29)
99 unsigned long *
sp = (
unsigned long *)(reg29 & ~3);
103 #ifdef CONFIG_KALLSYMS
106 while (!kstack_end(sp)) {
108 (
unsigned long __user *)(
unsigned long)sp++;
110 printk(
" (Bad stack address)");
119 #ifdef CONFIG_KALLSYMS
121 static int __init set_raw_show_trace(
char *
str)
126 __setup(
"raw_show_trace", set_raw_show_trace);
131 unsigned long sp = regs->
regs[29];
132 unsigned long ra = regs->
regs[31];
139 show_raw_backtrace(sp);
154 static void show_stacktrace(
struct task_struct *task,
157 const int field = 2 *
sizeof(
unsigned long);
164 while ((
unsigned long) sp & (
PAGE_SIZE - 1)) {
165 if (i && ((i % (64 / field)) == 0))
173 printk(
" (Bad stack address)");
177 printk(
" %0*lx", field, stackdata);
196 #ifdef CONFIG_KGDB_KDB
202 prepare_frametrace(®s);
205 show_stacktrace(task, ®s);
215 prepare_frametrace(®s);
221 static void show_code(
unsigned int __user *pc)
228 if ((
unsigned long)pc & 1)
229 pc16 = (
unsigned short __user *)((
unsigned long)pc & ~1);
230 for(i = -3 ; i < 6 ; i++) {
233 printk(
" (Bad address in epc)\n");
236 printk(
"%c%0*x%c", (i?
' ':
'<'), pc16 ? 4 : 8, insn, (i?
' ':
'>'));
242 const int field = 2 *
sizeof(
unsigned long);
251 for (i = 0; i < 32; ) {
256 else if (i == 26 || i == 27)
257 printk(
" %*s", field,
"");
266 #ifdef CONFIG_CPU_HAS_SMARTMIPS
267 printk(
"Acx : %0*lx\n", field, regs->acx);
269 printk(
"Hi : %0*lx\n", field, regs->
hi);
270 printk(
"Lo : %0*lx\n", field, regs->
lo);
278 printk(
"ra : %0*lx %pS\n", field, regs->
regs[31],
279 (
void *) regs->
regs[31]);
326 printk(
"Cause : %08x\n", cause);
329 if (1 <= cause && cause <= 5)
346 const int field = 2 *
sizeof(
unsigned long);
350 printk(
"Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
358 printk(
"*HwTLS: %0*lx\n", field, tls);
361 show_stacktrace(
current, regs);
366 static int regs_to_trapnr(
struct pt_regs *regs)
375 static int die_counter;
377 #ifdef CONFIG_MIPS_MT_SMTC
378 unsigned long dvpret;
388 #ifdef CONFIG_MIPS_MT_SMTC
392 #ifdef CONFIG_MIPS_MT_SMTC
396 printk(
"%s[#%d]:\n", str, ++die_counter);
404 panic(
"Fatal exception in interrupt");
409 panic(
"Fatal exception");
419 " .section __dbe_table, \"a\"\n"
427 e =
search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
435 const int field = 2 *
sizeof(
unsigned long);
442 fixup = search_dbe_tables(exception_epc(regs));
467 data ?
"Data" :
"Instruction",
481 #define OPCODE 0xfc000000
482 #define BASE 0x03e00000
483 #define RT 0x001f0000
484 #define OFFSET 0x0000ffff
485 #define LL 0xc0000000
486 #define SC 0xe0000000
487 #define SPEC0 0x00000000
488 #define SPEC3 0x7c000000
489 #define RD 0x0000f800
490 #define FUNC 0x0000003f
491 #define SYNC 0x0000000f
492 #define RDHWR 0x0000003b
501 static inline int simulate_ll(
struct pt_regs *regs,
unsigned int opcode)
516 vaddr = (
unsigned long __user *)
519 if ((
unsigned long)vaddr & 3)
535 regs->
regs[(opcode &
RT) >> 16] = value;
540 static inline int simulate_sc(
struct pt_regs *regs,
unsigned int opcode)
556 vaddr = (
unsigned long __user *)
558 reg = (opcode &
RT) >> 16;
560 if ((
unsigned long)vaddr & 3)
565 if (ll_bit == 0 || ll_task !=
current) {
588 static int simulate_llsc(
struct pt_regs *regs,
unsigned int opcode)
593 return simulate_ll(regs, opcode);
595 if ((opcode & OPCODE) ==
SC) {
598 return simulate_sc(regs, opcode);
608 static int simulate_rdhwr(
struct pt_regs *regs,
unsigned int opcode)
613 int rd = (opcode &
RD) >> 11;
614 int rt = (opcode &
RT) >> 16;
650 static int simulate_sync(
struct pt_regs *regs,
unsigned int opcode)
652 if ((opcode & OPCODE) ==
SPEC0 && (opcode & FUNC) ==
SYNC) {
674 static int process_fpemu_return(
int sig,
void __user *fault_addr)
678 si.si_addr = fault_addr;
741 process_fpemu_return(sig, fault_addr);
762 static void do_trap_or_bp(
struct pt_regs *regs,
unsigned int code,
768 #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
785 scnprintf(b,
sizeof(b),
"%s instruction in kernel code", str);
816 scnprintf(b,
sizeof(b),
"%s instruction in kernel code", str);
824 unsigned int opcode, bcode;
835 bcode = ((opcode >> 6) & ((1 << 20) - 1));
836 if (bcode >= (1 << 10))
858 do_trap_or_bp(regs, bcode,
"Break");
867 unsigned int opcode, tcode = 0;
873 if (!(opcode & OPCODE))
874 tcode = ((opcode >> 6) & ((1 << 10) - 1));
876 do_trap_or_bp(regs, tcode,
"Trap");
886 unsigned long old_epc = regs->
cp0_epc;
887 unsigned int opcode = 0;
896 if (
unlikely(compute_return_epc(regs) < 0))
903 status = simulate_llsc(regs, opcode);
906 status = simulate_rdhwr(regs, opcode);
909 status = simulate_sync(regs, opcode);
925 static void mt_ase_fp_affinity(
void)
927 #ifdef CONFIG_MIPS_MT_FPAFF
938 current->thread.user_cpus_allowed
942 set_cpus_allowed_ptr(
current, &tmask);
943 set_thread_flag(TIF_FPUBOUND);
971 die_if_kernel(
"Unhandled kernel unaligned access or invalid "
972 "instruction", regs);
985 unsigned long old_epc;
997 epc = (
unsigned int __user *)exception_epc(regs);
1002 if (
unlikely(compute_return_epc(regs) < 0))
1009 status = simulate_llsc(regs, opcode);
1012 status = simulate_rdhwr(regs, opcode);
1038 if (!process_fpemu_return(sig, fault_addr))
1039 mt_ase_fp_affinity();
1072 cause &= ~(1 << 22);
1080 if (test_tsk_thread_flag(
current, TIF_LOAD_WATCH)) {
1092 const int field = 2 *
sizeof(
unsigned long);
1113 panic(
"Caught Machine Check exception - %scaused by multiple "
1114 "matching entries in the TLB.",
1115 (multi_match) ?
"" :
"not ");
1157 panic(
"Unexpected DSP exception");
1170 panic(
"Caught reserved exception %ld - should not happen.",
1175 static int __init nol1parity(
char *
s)
1180 __setup(
"nol1par", nol1parity);
1182 static int __init nol2parity(
char *
s)
1187 __setup(
"nol2par", nol2parity);
1193 static inline void parity_protection_init(
void)
1201 #define ERRCTL_PE 0x80000000
1202 #define ERRCTL_L2P 0x00800000
1203 unsigned long errctl;
1204 unsigned int l1parity_present, l2parity_present;
1211 back_to_back_c0_hazard();
1216 back_to_back_c0_hazard();
1219 if (l1parity_present && l2parity_present) {
1222 if (l1parity ^ l2parity)
1224 }
else if (l1parity_present) {
1227 }
else if (l2parity_present) {
1237 back_to_back_c0_hazard();
1241 if (l1parity_present)
1243 (errctl & ERRCTL_PE) ?
"en" :
"dis");
1245 if (l2parity_present) {
1246 if (l1parity_present && l1parity)
1249 (errctl & ERRCTL_L2P) ?
"en" :
"dis");
1258 back_to_back_c0_hazard();
1267 "MIPS 20KC/25KF CPUs.\n");
1277 const int field = 2 *
sizeof(
unsigned long);
1281 printk(
"Cache error exception:\n");
1284 printk(
"c0_cacheerr == %08x\n", reg_val);
1286 printk(
"Decoded c0_cacheerr: %s cache fault in %s reference.\n",
1287 reg_val & (1<<30) ?
"secondary" :
"primary",
1288 reg_val & (1<<31) ?
"data" :
"insn");
1289 printk(
"Error bits: %s%s%s%s%s%s%s\n",
1290 reg_val & (1<<29) ?
"ED " :
"",
1291 reg_val & (1<<28) ?
"ET " :
"",
1292 reg_val & (1<<26) ?
"EE " :
"",
1293 reg_val & (1<<25) ?
"EB " :
"",
1294 reg_val & (1<<24) ?
"EI " :
"",
1295 reg_val & (1<<23) ?
"E1 " :
"",
1296 reg_val & (1<<22) ?
"E0 " :
"");
1297 printk(
"IDX: 0x%08x\n", reg_val & ((1<<22)-1));
1299 #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
1300 if (reg_val & (1<<22))
1303 if (reg_val & (1<<23))
1307 panic(
"Can't handle the cache error!");
1316 const int field = 2 *
sizeof(
unsigned long);
1317 unsigned long depc, old_epc;
1320 printk(
KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
1324 if (debug & 0x80000000) {
1361 printk(
"NMI taken!!!!\n");
1365 #define VECTORSPACING 0x100
1374 unsigned long old_handler = exception_handlers[
n];
1376 exception_handlers[
n] = handler;
1378 unsigned long jump_mask = ~((1 << 28) - 1);
1380 unsigned int k0 = 26;
1381 if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
1382 uasm_i_j(&buf, handler & ~jump_mask);
1386 uasm_i_jr(&buf, k0);
1391 return (
void *)old_handler;
1397 panic(
"Caught unexpected vectored interrupt.");
1403 unsigned long old_handler = vi_handlers[
n];
1411 handler = (
unsigned long) do_default_vi;
1414 handler = (
unsigned long) addr;
1415 vi_handlers[
n] = (
unsigned long) addr;
1420 panic(
"Shadow register set %d not supported", srs);
1428 change_c0_srsmap(0xf << n*4, srs << n*4);
1437 extern char except_vec_vi, except_vec_vi_lui;
1438 extern char except_vec_vi_ori, except_vec_vi_end;
1439 extern char rollback_except_vec_vi;
1441 &rollback_except_vec_vi : &except_vec_vi;
1442 #ifdef CONFIG_MIPS_MT_SMTC
1448 extern char except_vec_vi_mori;
1449 const int mori_offset = &except_vec_vi_mori - vec_start;
1451 const int handler_len = &except_vec_vi_end - vec_start;
1452 const int lui_offset = &except_vec_vi_lui - vec_start;
1453 const int ori_offset = &except_vec_vi_ori - vec_start;
1455 if (handler_len > VECTORSPACING) {
1460 panic(
"VECTORSPACING too small");
1463 memcpy(b, vec_start, handler_len);
1464 #ifdef CONFIG_MIPS_MT_SMTC
1467 w = (
u32 *)(b + mori_offset);
1468 *w = (*w & 0xffff0000) | (0x100 << n);
1470 w = (
u32 *)(b + lui_offset);
1471 *w = (*w & 0xffff0000) | (((
u32)handler >> 16) & 0xffff);
1472 w = (
u32 *)(b + ori_offset);
1473 *w = (*w & 0xffff0000) | ((
u32)handler & 0xffff);
1475 (
unsigned long)(b+handler_len));
1485 *w++ = 0x08000000 | (((
u32)handler >> 2) & 0x03fffff);
1488 (
unsigned long)(b+8));
1491 return (
void *)old_handler;
1496 return set_vi_srs_handler(n, addr, 0);
1517 static int __init ulri_disable(
char *
s)
1524 __setup(
"noulri", ulri_disable);
1529 unsigned int status_set =
ST0_CU0;
1531 #ifdef CONFIG_MIPS_MT_SMTC
1532 int secondaryTC = 0;
1533 int bootTC = (cpu == 0);
1564 hwrena |= 0x0000000f;
1567 hwrena |= (1 << 29);
1572 #ifdef CONFIG_MIPS_MT_SMTC
1577 unsigned long sr = set_c0_status(
ST0_BEV);
1581 change_c0_intctl(0x3e0, VECTORSPACING);
1585 unsigned int vpflags = dvpe();
1602 if (cp0_perfcount_irq == cp0_compare_irq)
1603 cp0_perfcount_irq = -1;
1607 cp0_perfcount_irq = -1;
1610 #ifdef CONFIG_MIPS_MT_SMTC
1622 #ifdef CONFIG_MIPS_MT_SMTC
1629 #ifdef CONFIG_MIPS_MT_SMTC
1630 }
else if (!secondaryTC) {
1645 memcpy((
void *)(ebase + offset), addr, size);
1650 "Trying to set NULL cache error exception handler";
1660 unsigned long uncached_ebase =
CKSEG1ADDR(ebase);
1663 panic(panic_null_cerr);
1665 memcpy((
void *)(uncached_ebase + offset), addr, size);
1669 static int __init set_rdhwr_noopt(
char *str)
1675 __setup(
"rdhwr_noopt", set_rdhwr_noopt);
1679 extern char except_vec3_generic, except_vec3_r4000;
1680 extern char except_vec4;
1687 #if defined(CONFIG_KGDB)
1688 if (kgdb_early_setup)
1693 unsigned long size = 0x200 + VECTORSPACING*64;
1694 ebase = (
unsigned long)
1716 for (i = 0; i <= 31; i++)
1737 for (i = 0; i < nvec; i++)
1747 parity_protection_init();
1813 memcpy((
void *)(ebase + 0x180), &except_vec3_r4000, 0x100);
1815 memcpy((
void *)(ebase + 0x180), &except_vec3_generic, 0x80);
1817 memcpy((
void *)(ebase + 0x080), &except_vec3_generic, 0x80);