2 * linux/arch/m68k/kernel/traps.c
4 * Copyright (C) 1993, 1994 by Hamish Macdonald
6 * 68040 fixes by Michael Rausch
7 * 68040 fixes by Martin Apel
8 * 68040 fixes and writeback by Richard Zidlicky
9 * 68060 fixes by Roman Hodek
10 * 68060 fixes by Jesper Skov
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file COPYING in the main directory of this archive
18 * Sets up all exception vectors
21 #include <linux/sched.h>
22 #include <linux/sched/debug.h>
23 #include <linux/signal.h>
24 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/user.h>
28 #include <linux/string.h>
29 #include <linux/linkage.h>
30 #include <linux/init.h>
31 #include <linux/ptrace.h>
32 #include <linux/kallsyms.h>
34 #include <asm/setup.h>
36 #include <linux/uaccess.h>
37 #include <asm/traps.h>
38 #include <asm/machdep.h>
39 #include <asm/processor.h>
40 #include <asm/siginfo.h>
41 #include <asm/tlbflush.h>
43 static const char *vec_names[] = {
44 [VEC_RESETSP] = "RESET SP",
45 [VEC_RESETPC] = "RESET PC",
46 [VEC_BUSERR] = "BUS ERROR",
47 [VEC_ADDRERR] = "ADDRESS ERROR",
48 [VEC_ILLEGAL] = "ILLEGAL INSTRUCTION",
49 [VEC_ZERODIV] = "ZERO DIVIDE",
51 [VEC_TRAP] = "TRAPcc",
52 [VEC_PRIV] = "PRIVILEGE VIOLATION",
53 [VEC_TRACE] = "TRACE",
54 [VEC_LINE10] = "LINE 1010",
55 [VEC_LINE11] = "LINE 1111",
56 [VEC_RESV12] = "UNASSIGNED RESERVED 12",
57 [VEC_COPROC] = "COPROCESSOR PROTOCOL VIOLATION",
58 [VEC_FORMAT] = "FORMAT ERROR",
59 [VEC_UNINT] = "UNINITIALIZED INTERRUPT",
60 [VEC_RESV16] = "UNASSIGNED RESERVED 16",
61 [VEC_RESV17] = "UNASSIGNED RESERVED 17",
62 [VEC_RESV18] = "UNASSIGNED RESERVED 18",
63 [VEC_RESV19] = "UNASSIGNED RESERVED 19",
64 [VEC_RESV20] = "UNASSIGNED RESERVED 20",
65 [VEC_RESV21] = "UNASSIGNED RESERVED 21",
66 [VEC_RESV22] = "UNASSIGNED RESERVED 22",
67 [VEC_RESV23] = "UNASSIGNED RESERVED 23",
68 [VEC_SPUR] = "SPURIOUS INTERRUPT",
69 [VEC_INT1] = "LEVEL 1 INT",
70 [VEC_INT2] = "LEVEL 2 INT",
71 [VEC_INT3] = "LEVEL 3 INT",
72 [VEC_INT4] = "LEVEL 4 INT",
73 [VEC_INT5] = "LEVEL 5 INT",
74 [VEC_INT6] = "LEVEL 6 INT",
75 [VEC_INT7] = "LEVEL 7 INT",
76 [VEC_SYS] = "SYSCALL",
77 [VEC_TRAP1] = "TRAP #1",
78 [VEC_TRAP2] = "TRAP #2",
79 [VEC_TRAP3] = "TRAP #3",
80 [VEC_TRAP4] = "TRAP #4",
81 [VEC_TRAP5] = "TRAP #5",
82 [VEC_TRAP6] = "TRAP #6",
83 [VEC_TRAP7] = "TRAP #7",
84 [VEC_TRAP8] = "TRAP #8",
85 [VEC_TRAP9] = "TRAP #9",
86 [VEC_TRAP10] = "TRAP #10",
87 [VEC_TRAP11] = "TRAP #11",
88 [VEC_TRAP12] = "TRAP #12",
89 [VEC_TRAP13] = "TRAP #13",
90 [VEC_TRAP14] = "TRAP #14",
91 [VEC_TRAP15] = "TRAP #15",
92 [VEC_FPBRUC] = "FPCP BSUN",
93 [VEC_FPIR] = "FPCP INEXACT",
94 [VEC_FPDIVZ] = "FPCP DIV BY 0",
95 [VEC_FPUNDER] = "FPCP UNDERFLOW",
96 [VEC_FPOE] = "FPCP OPERAND ERROR",
97 [VEC_FPOVER] = "FPCP OVERFLOW",
98 [VEC_FPNAN] = "FPCP SNAN",
99 [VEC_FPUNSUP] = "FPCP UNSUPPORTED OPERATION",
100 [VEC_MMUCFG] = "MMU CONFIGURATION ERROR",
101 [VEC_MMUILL] = "MMU ILLEGAL OPERATION ERROR",
102 [VEC_MMUACC] = "MMU ACCESS LEVEL VIOLATION ERROR",
103 [VEC_RESV59] = "UNASSIGNED RESERVED 59",
104 [VEC_UNIMPEA] = "UNASSIGNED RESERVED 60",
105 [VEC_UNIMPII] = "UNASSIGNED RESERVED 61",
106 [VEC_RESV62] = "UNASSIGNED RESERVED 62",
107 [VEC_RESV63] = "UNASSIGNED RESERVED 63",
110 static const char *space_names[] = {
112 [USER_DATA] = "User Data",
113 [USER_PROGRAM] = "User Program",
117 [FC_CONTROL] = "Control",
120 [SUPER_DATA] = "Super Data",
121 [SUPER_PROGRAM] = "Super Program",
125 void die_if_kernel(char *,struct pt_regs *,int);
126 asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
127 unsigned long error_code);
128 int send_fault_sig(struct pt_regs *regs);
130 asmlinkage void trap_c(struct frame *fp);
132 #if defined (CONFIG_M68060)
133 static inline void access_error060 (struct frame *fp)
135 unsigned long fslw = fp->un.fmt4.pc; /* is really FSLW for access error */
137 pr_debug("fslw=%#lx, fa=%#lx\n", fslw, fp->un.fmt4.effaddr);
139 if (fslw & MMU060_BPE) {
140 /* branch prediction error -> clear branch cache */
141 __asm__ __volatile__ ("movec %/cacr,%/d0\n\t"
142 "orl #0x00400000,%/d0\n\t"
145 /* return if there's no other error */
146 if (!(fslw & MMU060_ERR_BITS) && !(fslw & MMU060_SEE))
150 if (fslw & (MMU060_DESC_ERR | MMU060_WP | MMU060_SP)) {
151 unsigned long errorcode;
152 unsigned long addr = fp->un.fmt4.effaddr;
154 if (fslw & MMU060_MA)
155 addr = (addr + PAGE_SIZE - 1) & PAGE_MASK;
158 if (fslw & MMU060_DESC_ERR) {
159 __flush_tlb040_one(addr);
164 pr_debug("errorcode = %ld\n", errorcode);
165 do_page_fault(&fp->ptregs, addr, errorcode);
166 } else if (fslw & (MMU060_SEE)){
167 /* Software Emulation Error.
168 * fault during mem_read/mem_write in ifpsp060/os.S
170 send_fault_sig(&fp->ptregs);
171 } else if (!(fslw & (MMU060_RE|MMU060_WE)) ||
172 send_fault_sig(&fp->ptregs) > 0) {
173 pr_err("pc=%#lx, fa=%#lx\n", fp->ptregs.pc,
174 fp->un.fmt4.effaddr);
175 pr_err("68060 access error, fslw=%lx\n", fslw);
179 #endif /* CONFIG_M68060 */
181 #if defined (CONFIG_M68040)
182 static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
189 asm volatile (".chip 68040; ptestw (%0); .chip 68k" : : "a" (addr));
191 asm volatile (".chip 68040; ptestr (%0); .chip 68k" : : "a" (addr));
193 asm volatile (".chip 68040; movec %%mmusr,%0; .chip 68k" : "=r" (mmusr));
200 static inline int do_040writeback1(unsigned short wbs, unsigned long wba,
207 switch (wbs & WBSIZ_040) {
209 res = put_user(wbd & 0xff, (char __user *)wba);
212 res = put_user(wbd & 0xffff, (short __user *)wba);
215 res = put_user(wbd, (int __user *)wba);
221 pr_debug("do_040writeback1, res=%d\n", res);
226 /* after an exception in a writeback the stack frame corresponding
227 * to that exception is discarded, set a few bits in the old frame
228 * to simulate what it should look like
230 static inline void fix_xframe040(struct frame *fp, unsigned long wba, unsigned short wbs)
232 fp->un.fmt7.faddr = wba;
233 fp->un.fmt7.ssw = wbs & 0xff;
234 if (wba != current->thread.faddr)
235 fp->un.fmt7.ssw |= MA_040;
238 static inline void do_040writebacks(struct frame *fp)
242 if (fp->un.fmt7.wb1s & WBV_040)
243 pr_err("access_error040: cannot handle 1st writeback. oops.\n");
246 if ((fp->un.fmt7.wb2s & WBV_040) &&
247 !(fp->un.fmt7.wb2s & WBTT_040)) {
248 res = do_040writeback1(fp->un.fmt7.wb2s, fp->un.fmt7.wb2a,
251 fix_xframe040(fp, fp->un.fmt7.wb2a, fp->un.fmt7.wb2s);
253 fp->un.fmt7.wb2s = 0;
256 /* do the 2nd wb only if the first one was successful (except for a kernel wb) */
257 if (fp->un.fmt7.wb3s & WBV_040 && (!res || fp->un.fmt7.wb3s & 4)) {
258 res = do_040writeback1(fp->un.fmt7.wb3s, fp->un.fmt7.wb3a,
262 fix_xframe040(fp, fp->un.fmt7.wb3a, fp->un.fmt7.wb3s);
264 fp->un.fmt7.wb2s = fp->un.fmt7.wb3s;
265 fp->un.fmt7.wb3s &= (~WBV_040);
266 fp->un.fmt7.wb2a = fp->un.fmt7.wb3a;
267 fp->un.fmt7.wb2d = fp->un.fmt7.wb3d;
270 fp->un.fmt7.wb3s = 0;
274 send_fault_sig(&fp->ptregs);
278 * called from sigreturn(), must ensure userspace code didn't
279 * manipulate exception frame to circumvent protection, then complete
281 * we just clear TM2 to turn it into a userspace access
283 asmlinkage void berr_040cleanup(struct frame *fp)
285 fp->un.fmt7.wb2s &= ~4;
286 fp->un.fmt7.wb3s &= ~4;
288 do_040writebacks(fp);
291 static inline void access_error040(struct frame *fp)
293 unsigned short ssw = fp->un.fmt7.ssw;
296 pr_debug("ssw=%#x, fa=%#lx\n", ssw, fp->un.fmt7.faddr);
297 pr_debug("wb1s=%#x, wb2s=%#x, wb3s=%#x\n", fp->un.fmt7.wb1s,
298 fp->un.fmt7.wb2s, fp->un.fmt7.wb3s);
299 pr_debug("wb2a=%lx, wb3a=%lx, wb2d=%lx, wb3d=%lx\n",
300 fp->un.fmt7.wb2a, fp->un.fmt7.wb3a,
301 fp->un.fmt7.wb2d, fp->un.fmt7.wb3d);
304 unsigned long addr = fp->un.fmt7.faddr;
305 unsigned long errorcode;
308 * The MMU status has to be determined AFTER the address
309 * has been corrected if there was a misaligned access (MA).
312 addr = (addr + 7) & -8;
314 /* MMU error, get the MMUSR info for this access */
315 mmusr = probe040(!(ssw & RW_040), addr, ssw);
316 pr_debug("mmusr = %lx\n", mmusr);
318 if (!(mmusr & MMU_R_040)) {
319 /* clear the invalid atc entry */
320 __flush_tlb040_one(addr);
324 /* despite what documentation seems to say, RMW
325 * accesses have always both the LK and RW bits set */
326 if (!(ssw & RW_040) || (ssw & LK_040))
329 if (do_page_fault(&fp->ptregs, addr, errorcode)) {
330 pr_debug("do_page_fault() !=0\n");
331 if (user_mode(&fp->ptregs)){
332 /* delay writebacks after signal delivery */
333 pr_debug(".. was usermode - return\n");
336 /* disable writeback into user space from kernel
337 * (if do_page_fault didn't fix the mapping,
338 * the writeback won't do good)
341 pr_debug(".. disabling wb2\n");
342 if (fp->un.fmt7.wb2a == fp->un.fmt7.faddr)
343 fp->un.fmt7.wb2s &= ~WBV_040;
344 if (fp->un.fmt7.wb3a == fp->un.fmt7.faddr)
345 fp->un.fmt7.wb3s &= ~WBV_040;
348 /* In case of a bus error we either kill the process or expect
349 * the kernel to catch the fault, which then is also responsible
350 * for cleaning up the mess.
352 current->thread.signo = SIGBUS;
353 current->thread.faddr = fp->un.fmt7.faddr;
354 if (send_fault_sig(&fp->ptregs) >= 0)
355 pr_err("68040 bus error (ssw=%x, faddr=%lx)\n", ssw,
360 do_040writebacks(fp);
362 #endif /* CONFIG_M68040 */
364 #if defined(CONFIG_SUN3)
365 #include <asm/sun3mmu.h>
367 extern int mmu_emu_handle_fault (unsigned long, int, int);
369 /* sun3 version of bus_error030 */
371 static inline void bus_error030 (struct frame *fp)
373 unsigned char buserr_type = sun3_get_buserr ();
374 unsigned long addr, errorcode;
375 unsigned short ssw = fp->un.fmtb.ssw;
376 extern unsigned long _sun3_map_test_start, _sun3_map_test_end;
379 pr_debug("Instruction fault at %#010lx\n",
381 fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
383 fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
385 pr_debug("Data %s fault at %#010lx in %s (pc=%#lx)\n",
386 ssw & RW ? "read" : "write",
388 space_names[ssw & DFC], fp->ptregs.pc);
391 * Check if this page should be demand-mapped. This needs to go before
392 * the testing for a bad kernel-space access (demand-mapping applies
393 * to kernel accesses too).
397 && (buserr_type & (SUN3_BUSERR_PROTERR | SUN3_BUSERR_INVALID))) {
398 if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 0))
402 /* Check for kernel-space pagefault (BAD). */
403 if (fp->ptregs.sr & PS_S) {
404 /* kernel fault must be a data fault to user space */
405 if (! ((ssw & DF) && ((ssw & DFC) == USER_DATA))) {
406 // try checking the kernel mappings before surrender
407 if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 1))
409 /* instruction fault or kernel data fault! */
411 pr_err("Instruction fault at %#010lx\n",
414 /* was this fault incurred testing bus mappings? */
415 if((fp->ptregs.pc >= (unsigned long)&_sun3_map_test_start) &&
416 (fp->ptregs.pc <= (unsigned long)&_sun3_map_test_end)) {
417 send_fault_sig(&fp->ptregs);
421 pr_err("Data %s fault at %#010lx in %s (pc=%#lx)\n",
422 ssw & RW ? "read" : "write",
424 space_names[ssw & DFC], fp->ptregs.pc);
426 pr_err("BAD KERNEL BUSERR\n");
428 die_if_kernel("Oops", &fp->ptregs,0);
434 if (!(ssw & (FC | FB)) && !(ssw & DF))
435 /* not an instruction fault or data fault! BAD */
436 panic ("USER BUSERR w/o instruction or data fault");
440 /* First handle the data fault, if any. */
442 addr = fp->un.fmtb.daddr;
444 // errorcode bit 0: 0 -> no page 1 -> protection fault
445 // errorcode bit 1: 0 -> read fault 1 -> write fault
447 // (buserr_type & SUN3_BUSERR_PROTERR) -> protection fault
448 // (buserr_type & SUN3_BUSERR_INVALID) -> invalid page fault
450 if (buserr_type & SUN3_BUSERR_PROTERR)
452 else if (buserr_type & SUN3_BUSERR_INVALID)
455 pr_debug("*** unexpected busfault type=%#04x\n",
457 pr_debug("invalid %s access at %#lx from pc %#lx\n",
458 !(ssw & RW) ? "write" : "read", addr,
460 die_if_kernel ("Oops", &fp->ptregs, buserr_type);
465 //todo: wtf is RM bit? --m
466 if (!(ssw & RW) || ssw & RM)
469 /* Handle page fault. */
470 do_page_fault (&fp->ptregs, addr, errorcode);
472 /* Retry the data fault now. */
476 /* Now handle the instruction fault. */
478 /* Get the fault address. */
479 if (fp->ptregs.format == 0xA)
480 addr = fp->ptregs.pc + 4;
482 addr = fp->un.fmtb.baddr;
486 if (buserr_type & SUN3_BUSERR_INVALID) {
487 if (!mmu_emu_handle_fault(addr, 1, 0))
488 do_page_fault (&fp->ptregs, addr, 0);
490 pr_debug("protection fault on insn access (segv).\n");
495 #if defined(CPU_M68020_OR_M68030)
496 static inline void bus_error030 (struct frame *fp)
498 volatile unsigned short temp;
499 unsigned short mmusr;
500 unsigned long addr, errorcode;
501 unsigned short ssw = fp->un.fmtb.ssw;
506 pr_debug("pid = %x ", current->pid);
507 pr_debug("SSW=%#06x ", ssw);
510 pr_debug("Instruction fault at %#010lx\n",
512 fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
514 fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
516 pr_debug("Data %s fault at %#010lx in %s (pc=%#lx)\n",
517 ssw & RW ? "read" : "write",
519 space_names[ssw & DFC], fp->ptregs.pc);
521 /* ++andreas: If a data fault and an instruction fault happen
522 at the same time map in both pages. */
524 /* First handle the data fault, if any. */
526 addr = fp->un.fmtb.daddr;
529 asm volatile ("ptestr %3,%2@,#7,%0\n\t"
531 : "=a&" (desc), "=m" (temp)
532 : "a" (addr), "d" (ssw));
533 pr_debug("mmusr is %#x for addr %#lx in task %p\n",
534 temp, addr, current);
535 pr_debug("descriptor address is 0x%p, contents %#lx\n",
536 __va(desc), *(unsigned long *)__va(desc));
538 asm volatile ("ptestr %2,%1@,#7\n\t"
540 : "=m" (temp) : "a" (addr), "d" (ssw));
543 errorcode = (mmusr & MMU_I) ? 0 : 1;
544 if (!(ssw & RW) || (ssw & RM))
547 if (mmusr & (MMU_I | MMU_WP)) {
549 pr_err("Data %s fault at %#010lx in %s (pc=%#lx)\n",
550 ssw & RW ? "read" : "write",
552 space_names[ssw & DFC], fp->ptregs.pc);
555 /* Don't try to do anything further if an exception was
557 if (do_page_fault (&fp->ptregs, addr, errorcode) < 0)
559 } else if (!(mmusr & MMU_I)) {
560 /* probably a 020 cas fault */
561 if (!(ssw & RM) && send_fault_sig(&fp->ptregs) > 0)
562 pr_err("unexpected bus error (%#x,%#x)\n", ssw,
564 } else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
565 pr_err("invalid %s access at %#lx from pc %#lx\n",
566 !(ssw & RW) ? "write" : "read", addr,
568 die_if_kernel("Oops",&fp->ptregs,mmusr);
573 static volatile long tlong;
576 pr_err("weird %s access at %#lx from pc %#lx (ssw is %#x)\n",
577 !(ssw & RW) ? "write" : "read", addr,
579 asm volatile ("ptestr #1,%1@,#0\n\t"
585 pr_err("level 0 mmusr is %#x\n", mmusr);
587 asm volatile ("pmove %%tt0,%0"
589 pr_debug("tt0 is %#lx, ", tlong);
590 asm volatile ("pmove %%tt1,%0"
592 pr_debug("tt1 is %#lx\n", tlong);
594 pr_debug("Unknown SIGSEGV - 1\n");
595 die_if_kernel("Oops",&fp->ptregs,mmusr);
600 /* setup an ATC entry for the access about to be retried */
601 if (!(ssw & RW) || (ssw & RM))
602 asm volatile ("ploadw %1,%0@" : /* no outputs */
603 : "a" (addr), "d" (ssw));
605 asm volatile ("ploadr %1,%0@" : /* no outputs */
606 : "a" (addr), "d" (ssw));
609 /* Now handle the instruction fault. */
611 if (!(ssw & (FC|FB)))
614 if (fp->ptregs.sr & PS_S) {
615 pr_err("Instruction fault at %#010lx\n", fp->ptregs.pc);
617 pr_err("BAD KERNEL BUSERR\n");
618 die_if_kernel("Oops",&fp->ptregs,0);
623 /* get the fault address */
624 if (fp->ptregs.format == 10)
625 addr = fp->ptregs.pc + 4;
627 addr = fp->un.fmtb.baddr;
631 if ((ssw & DF) && ((addr ^ fp->un.fmtb.daddr) & PAGE_MASK) == 0)
632 /* Insn fault on same page as data fault. But we
633 should still create the ATC entry. */
634 goto create_atc_entry;
637 asm volatile ("ptestr #1,%2@,#7,%0\n\t"
639 : "=a&" (desc), "=m" (temp)
641 pr_debug("mmusr is %#x for addr %#lx in task %p\n",
642 temp, addr, current);
643 pr_debug("descriptor address is 0x%p, contents %#lx\n",
644 __va(desc), *(unsigned long *)__va(desc));
646 asm volatile ("ptestr #1,%1@,#7\n\t"
648 : "=m" (temp) : "a" (addr));
652 do_page_fault (&fp->ptregs, addr, 0);
653 else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
654 pr_err("invalid insn access at %#lx from pc %#lx\n",
655 addr, fp->ptregs.pc);
656 pr_debug("Unknown SIGSEGV - 2\n");
657 die_if_kernel("Oops",&fp->ptregs,mmusr);
663 /* setup an ATC entry for the access about to be retried */
664 asm volatile ("ploadr #2,%0@" : /* no outputs */
667 #endif /* CPU_M68020_OR_M68030 */
668 #endif /* !CONFIG_SUN3 */
670 #if defined(CONFIG_COLDFIRE) && defined(CONFIG_MMU)
671 #include <asm/mcfmmu.h>
674 * The following table converts the FS encoding of a ColdFire
675 * exception stack frame into the error_code value needed by
678 static const unsigned char fs_err_code[] = {
697 static inline void access_errorcf(unsigned int fs, struct frame *fp)
699 unsigned long mmusr, addr;
700 unsigned int err_code;
703 mmusr = mmu_read(MMUSR);
704 addr = mmu_read(MMUAR);
708 * bit 0 == 0 means no page found, 1 means protection fault
709 * bit 1 == 0 means read, 1 means write
712 case 5: /* 0101 TLB opword X miss */
713 need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 0, 0);
714 addr = fp->ptregs.pc;
716 case 6: /* 0110 TLB extension word X miss */
717 need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 0, 1);
718 addr = fp->ptregs.pc + sizeof(long);
720 case 10: /* 1010 TLB W miss */
721 need_page_fault = cf_tlb_miss(&fp->ptregs, 1, 1, 0);
723 case 14: /* 1110 TLB R miss */
724 need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 1, 0);
729 /* 0010 Interrupt during debug service routine */
731 /* 0100 X Protection */
732 /* 0111 IFP in emulator mode */
733 /* 1000 W Protection*/
734 /* 1001 Write error*/
736 /* 1100 R Protection*/
737 /* 1101 R Protection*/
738 /* 1111 OEP in emulator mode*/
743 if (need_page_fault) {
744 err_code = fs_err_code[fs];
745 if ((fs == 13) && (mmusr & MMUSR_WF)) /* rd-mod-wr access */
746 err_code |= 2; /* bit1 - write, bit0 - protection */
747 do_page_fault(&fp->ptregs, addr, err_code);
750 #endif /* CONFIG_COLDFIRE CONFIG_MMU */
752 asmlinkage void buserr_c(struct frame *fp)
754 /* Only set esp0 if coming from user mode */
755 if (user_mode(&fp->ptregs))
756 current->thread.esp0 = (unsigned long) fp;
758 pr_debug("*** Bus Error *** Format is %x\n", fp->ptregs.format);
760 #if defined(CONFIG_COLDFIRE) && defined(CONFIG_MMU)
761 if (CPU_IS_COLDFIRE) {
763 fs = (fp->ptregs.vector & 0x3) |
764 ((fp->ptregs.vector & 0xc00) >> 8);
774 access_errorcf(fs, fp);
780 #endif /* CONFIG_COLDFIRE && CONFIG_MMU */
782 switch (fp->ptregs.format) {
783 #if defined (CONFIG_M68060)
784 case 4: /* 68060 access error */
785 access_error060 (fp);
788 #if defined (CONFIG_M68040)
789 case 0x7: /* 68040 access error */
790 access_error040 (fp);
793 #if defined (CPU_M68020_OR_M68030)
800 die_if_kernel("bad frame format",&fp->ptregs,0);
801 pr_debug("Unknown SIGSEGV - 4\n");
807 static int kstack_depth_to_print = 48;
809 static void show_trace(unsigned long *stack, const char *loglvl)
811 unsigned long *endstack;
815 printk("%sCall Trace:", loglvl);
816 addr = (unsigned long)stack + THREAD_SIZE - 1;
817 endstack = (unsigned long *)(addr & -THREAD_SIZE);
819 while (stack + 1 <= endstack) {
822 * If the address is either in the text segment of the
823 * kernel, or in the region which contains vmalloc'ed
824 * memory, it *may* be the address of a calling
825 * routine; if so, print it so that someone tracing
826 * down the cause of the crash will be able to figure
827 * out the call path that was taken.
829 if (__kernel_text_address(addr)) {
830 #ifndef CONFIG_KALLSYMS
834 pr_cont(" [<%08lx>] %pS\n", addr, (void *)addr);
841 void show_registers(struct pt_regs *regs)
843 struct frame *fp = (struct frame *)regs;
849 pr_info("PC: [<%08lx>] %pS\n", regs->pc, (void *)regs->pc);
850 pr_info("SR: %04x SP: %p a2: %08lx\n", regs->sr, regs, regs->a2);
851 pr_info("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
852 regs->d0, regs->d1, regs->d2, regs->d3);
853 pr_info("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
854 regs->d4, regs->d5, regs->a0, regs->a1);
856 pr_info("Process %s (pid: %d, task=%p)\n",
857 current->comm, task_pid_nr(current), current);
858 addr = (unsigned long)&fp->un;
859 pr_info("Frame format=%X ", regs->format);
860 switch (regs->format) {
862 pr_cont("instr addr=%08lx\n", fp->un.fmt2.iaddr);
863 addr += sizeof(fp->un.fmt2);
866 pr_cont("eff addr=%08lx\n", fp->un.fmt3.effaddr);
867 addr += sizeof(fp->un.fmt3);
871 pr_cont("fault addr=%08lx fslw=%08lx\n",
872 fp->un.fmt4.effaddr, fp->un.fmt4.pc);
874 pr_cont("eff addr=%08lx pc=%08lx\n",
875 fp->un.fmt4.effaddr, fp->un.fmt4.pc);
876 addr += sizeof(fp->un.fmt4);
879 pr_cont("eff addr=%08lx ssw=%04x faddr=%08lx\n",
880 fp->un.fmt7.effaddr, fp->un.fmt7.ssw, fp->un.fmt7.faddr);
881 pr_info("wb 1 stat/addr/data: %04x %08lx %08lx\n",
882 fp->un.fmt7.wb1s, fp->un.fmt7.wb1a, fp->un.fmt7.wb1dpd0);
883 pr_info("wb 2 stat/addr/data: %04x %08lx %08lx\n",
884 fp->un.fmt7.wb2s, fp->un.fmt7.wb2a, fp->un.fmt7.wb2d);
885 pr_info("wb 3 stat/addr/data: %04x %08lx %08lx\n",
886 fp->un.fmt7.wb3s, fp->un.fmt7.wb3a, fp->un.fmt7.wb3d);
887 pr_info("push data: %08lx %08lx %08lx %08lx\n",
888 fp->un.fmt7.wb1dpd0, fp->un.fmt7.pd1, fp->un.fmt7.pd2,
890 addr += sizeof(fp->un.fmt7);
893 pr_cont("instr addr=%08lx\n", fp->un.fmt9.iaddr);
894 addr += sizeof(fp->un.fmt9);
897 pr_cont("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
898 fp->un.fmta.ssw, fp->un.fmta.isc, fp->un.fmta.isb,
899 fp->un.fmta.daddr, fp->un.fmta.dobuf);
900 addr += sizeof(fp->un.fmta);
903 pr_cont("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
904 fp->un.fmtb.ssw, fp->un.fmtb.isc, fp->un.fmtb.isb,
905 fp->un.fmtb.daddr, fp->un.fmtb.dobuf);
906 pr_info("baddr=%08lx dibuf=%08lx ver=%x\n",
907 fp->un.fmtb.baddr, fp->un.fmtb.dibuf, fp->un.fmtb.ver);
908 addr += sizeof(fp->un.fmtb);
913 show_stack(NULL, (unsigned long *)addr, KERN_INFO);
916 cp = (u16 *)regs->pc;
917 for (i = -8; i < 16; i++) {
918 if (get_kernel_nofault(c, cp + i) && i >= 0) {
919 pr_cont(" Bad PC value.");
925 pr_cont(" <%04x>", c);
930 void show_stack(struct task_struct *task, unsigned long *stack,
934 unsigned long *endstack;
939 stack = (unsigned long *)task->thread.esp0;
941 stack = (unsigned long *)&stack;
943 endstack = (unsigned long *)(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
945 printk("%sStack from %08lx:", loglvl, (unsigned long)stack);
947 for (i = 0; i < kstack_depth_to_print; i++) {
948 if (p + 1 > endstack)
952 pr_cont(" %08lx", *p++);
955 show_trace(stack, loglvl);
959 * The vector number returned in the frame pointer may also contain
960 * the "fs" (Fault Status) bits on ColdFire. These are in the bottom
961 * 2 bits, and upper 2 bits. So we need to mask out the real vector
962 * number before using it in comparisons. You don't need to do this on
963 * real 68k parts, but it won't hurt either.
966 void bad_super_trap (struct frame *fp)
968 int vector = (fp->ptregs.vector >> 2) & 0xff;
971 if (vector < ARRAY_SIZE(vec_names))
972 pr_err("*** %s *** FORMAT=%X\n",
976 pr_err("*** Exception %d *** FORMAT=%X\n",
977 vector, fp->ptregs.format);
978 if (vector == VEC_ADDRERR && CPU_IS_020_OR_030) {
979 unsigned short ssw = fp->un.fmtb.ssw;
981 pr_err("SSW=%#06x ", ssw);
984 pr_err("Pipe stage C instruction fault at %#010lx\n",
985 (fp->ptregs.format) == 0xA ?
986 fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2);
988 pr_err("Pipe stage B instruction fault at %#010lx\n",
989 (fp->ptregs.format) == 0xA ?
990 fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
992 pr_err("Data %s fault at %#010lx in %s (pc=%#lx)\n",
993 ssw & RW ? "read" : "write",
994 fp->un.fmtb.daddr, space_names[ssw & DFC],
997 pr_err("Current process id is %d\n", task_pid_nr(current));
998 die_if_kernel("BAD KERNEL TRAP", &fp->ptregs, 0);
1001 asmlinkage void trap_c(struct frame *fp)
1005 int vector = (fp->ptregs.vector >> 2) & 0xff;
1007 if (fp->ptregs.sr & PS_S) {
1008 if (vector == VEC_TRACE) {
1009 /* traced a trapping instruction on a 68020/30,
1010 * real exception will be executed afterwards.
1015 if (fixup_exception(&fp->ptregs))
1022 /* send the appropriate signal to the user program */
1025 si_code = BUS_ADRALN;
1031 si_code = ILL_ILLOPC;
1035 si_code = ILL_PRVOPC;
1039 si_code = ILL_COPROC;
1056 si_code = ILL_ILLTRP;
1062 si_code = FPE_FLTINV;
1066 si_code = FPE_FLTRES;
1070 si_code = FPE_FLTDIV;
1074 si_code = FPE_FLTUND;
1078 si_code = FPE_FLTOVF;
1082 si_code = FPE_INTDIV;
1087 si_code = FPE_INTOVF;
1090 case VEC_TRACE: /* ptrace single step */
1091 si_code = TRAP_TRACE;
1094 case VEC_TRAP15: /* breakpoint */
1095 si_code = TRAP_BRKPT;
1099 si_code = ILL_ILLOPC;
1103 switch (fp->ptregs.format) {
1105 addr = (void __user *) fp->ptregs.pc;
1108 addr = (void __user *) fp->un.fmt2.iaddr;
1111 addr = (void __user *) fp->un.fmt7.effaddr;
1114 addr = (void __user *) fp->un.fmt9.iaddr;
1117 addr = (void __user *) fp->un.fmta.daddr;
1120 addr = (void __user*) fp->un.fmtb.daddr;
1123 force_sig_fault(sig, si_code, addr);
1126 void die_if_kernel (char *str, struct pt_regs *fp, int nr)
1128 if (!(fp->sr & PS_S))
1132 pr_crit("%s: %08x\n", str, nr);
1134 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
1135 make_task_dead(SIGSEGV);
1138 asmlinkage void set_esp0(unsigned long ssp)
1140 current->thread.esp0 = ssp;
1144 * This function is called if an error occur while accessing
1145 * user-space from the fpsp040 code.
1147 asmlinkage void fpsp040_die(void)
1149 force_exit_sig(SIGSEGV);
1152 #ifdef CONFIG_M68KFPU_EMU
1153 asmlinkage void fpemu_signal(int signal, int code, void *addr)
1155 force_sig_fault(signal, code, addr);