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/signal.h>
23 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/user.h>
27 #include <linux/string.h>
28 #include <linux/linkage.h>
29 #include <linux/init.h>
30 #include <linux/ptrace.h>
31 #include <linux/kallsyms.h>
33 #include <asm/setup.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <asm/traps.h>
38 #include <asm/pgalloc.h>
39 #include <asm/machdep.h>
40 #include <asm/siginfo.h>
42 /* assembler routines */
43 asmlinkage void system_call(void);
44 asmlinkage void buserr(void);
45 asmlinkage void trap(void);
46 asmlinkage void nmihandler(void);
47 #ifdef CONFIG_M68KFPU_EMU
48 asmlinkage void fpu_emu(void);
51 e_vector vectors[256] = {
52 [VEC_BUSERR] = buserr,
53 [VEC_SYS] = system_call,
56 /* nmi handler for the Amiga */
62 * this must be called very early as the kernel might
63 * use some instruction that are emulated on the 060
65 void __init base_trap_init(void)
68 extern e_vector *sun3x_prom_vbr;
70 __asm__ volatile ("movec %%vbr, %0" : "=r" (sun3x_prom_vbr));
73 /* setup the exception vector table */
74 __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
77 /* set up ISP entry points */
78 asmlinkage void unimp_vec(void) asm ("_060_isp_unimp");
80 vectors[VEC_UNIMPII] = unimp_vec;
84 void __init trap_init (void)
88 for (i = VEC_SPUR; i <= VEC_INT7; i++)
89 vectors[i] = bad_inthandler;
91 for (i = 0; i < VEC_USER; i++)
95 for (i = VEC_USER; i < 256; i++)
96 vectors[i] = bad_inthandler;
98 #ifdef CONFIG_M68KFPU_EMU
100 vectors[VEC_LINE11] = fpu_emu;
103 if (CPU_IS_040 && !FPU_IS_EMU) {
104 /* set up FPSP entry points */
105 asmlinkage void dz_vec(void) asm ("dz");
106 asmlinkage void inex_vec(void) asm ("inex");
107 asmlinkage void ovfl_vec(void) asm ("ovfl");
108 asmlinkage void unfl_vec(void) asm ("unfl");
109 asmlinkage void snan_vec(void) asm ("snan");
110 asmlinkage void operr_vec(void) asm ("operr");
111 asmlinkage void bsun_vec(void) asm ("bsun");
112 asmlinkage void fline_vec(void) asm ("fline");
113 asmlinkage void unsupp_vec(void) asm ("unsupp");
115 vectors[VEC_FPDIVZ] = dz_vec;
116 vectors[VEC_FPIR] = inex_vec;
117 vectors[VEC_FPOVER] = ovfl_vec;
118 vectors[VEC_FPUNDER] = unfl_vec;
119 vectors[VEC_FPNAN] = snan_vec;
120 vectors[VEC_FPOE] = operr_vec;
121 vectors[VEC_FPBRUC] = bsun_vec;
122 vectors[VEC_LINE11] = fline_vec;
123 vectors[VEC_FPUNSUP] = unsupp_vec;
126 if (CPU_IS_060 && !FPU_IS_EMU) {
127 /* set up IFPSP entry points */
128 asmlinkage void snan_vec6(void) asm ("_060_fpsp_snan");
129 asmlinkage void operr_vec6(void) asm ("_060_fpsp_operr");
130 asmlinkage void ovfl_vec6(void) asm ("_060_fpsp_ovfl");
131 asmlinkage void unfl_vec6(void) asm ("_060_fpsp_unfl");
132 asmlinkage void dz_vec6(void) asm ("_060_fpsp_dz");
133 asmlinkage void inex_vec6(void) asm ("_060_fpsp_inex");
134 asmlinkage void fline_vec6(void) asm ("_060_fpsp_fline");
135 asmlinkage void unsupp_vec6(void) asm ("_060_fpsp_unsupp");
136 asmlinkage void effadd_vec6(void) asm ("_060_fpsp_effadd");
138 vectors[VEC_FPNAN] = snan_vec6;
139 vectors[VEC_FPOE] = operr_vec6;
140 vectors[VEC_FPOVER] = ovfl_vec6;
141 vectors[VEC_FPUNDER] = unfl_vec6;
142 vectors[VEC_FPDIVZ] = dz_vec6;
143 vectors[VEC_FPIR] = inex_vec6;
144 vectors[VEC_LINE11] = fline_vec6;
145 vectors[VEC_FPUNSUP] = unsupp_vec6;
146 vectors[VEC_UNIMPEA] = effadd_vec6;
149 /* if running on an amiga, make the NMI interrupt do nothing */
151 vectors[VEC_INT7] = nmihandler;
156 static const char *vec_names[] = {
157 [VEC_RESETSP] = "RESET SP",
158 [VEC_RESETPC] = "RESET PC",
159 [VEC_BUSERR] = "BUS ERROR",
160 [VEC_ADDRERR] = "ADDRESS ERROR",
161 [VEC_ILLEGAL] = "ILLEGAL INSTRUCTION",
162 [VEC_ZERODIV] = "ZERO DIVIDE",
164 [VEC_TRAP] = "TRAPcc",
165 [VEC_PRIV] = "PRIVILEGE VIOLATION",
166 [VEC_TRACE] = "TRACE",
167 [VEC_LINE10] = "LINE 1010",
168 [VEC_LINE11] = "LINE 1111",
169 [VEC_RESV12] = "UNASSIGNED RESERVED 12",
170 [VEC_COPROC] = "COPROCESSOR PROTOCOL VIOLATION",
171 [VEC_FORMAT] = "FORMAT ERROR",
172 [VEC_UNINT] = "UNINITIALIZED INTERRUPT",
173 [VEC_RESV16] = "UNASSIGNED RESERVED 16",
174 [VEC_RESV17] = "UNASSIGNED RESERVED 17",
175 [VEC_RESV18] = "UNASSIGNED RESERVED 18",
176 [VEC_RESV19] = "UNASSIGNED RESERVED 19",
177 [VEC_RESV20] = "UNASSIGNED RESERVED 20",
178 [VEC_RESV21] = "UNASSIGNED RESERVED 21",
179 [VEC_RESV22] = "UNASSIGNED RESERVED 22",
180 [VEC_RESV23] = "UNASSIGNED RESERVED 23",
181 [VEC_SPUR] = "SPURIOUS INTERRUPT",
182 [VEC_INT1] = "LEVEL 1 INT",
183 [VEC_INT2] = "LEVEL 2 INT",
184 [VEC_INT3] = "LEVEL 3 INT",
185 [VEC_INT4] = "LEVEL 4 INT",
186 [VEC_INT5] = "LEVEL 5 INT",
187 [VEC_INT6] = "LEVEL 6 INT",
188 [VEC_INT7] = "LEVEL 7 INT",
189 [VEC_SYS] = "SYSCALL",
190 [VEC_TRAP1] = "TRAP #1",
191 [VEC_TRAP2] = "TRAP #2",
192 [VEC_TRAP3] = "TRAP #3",
193 [VEC_TRAP4] = "TRAP #4",
194 [VEC_TRAP5] = "TRAP #5",
195 [VEC_TRAP6] = "TRAP #6",
196 [VEC_TRAP7] = "TRAP #7",
197 [VEC_TRAP8] = "TRAP #8",
198 [VEC_TRAP9] = "TRAP #9",
199 [VEC_TRAP10] = "TRAP #10",
200 [VEC_TRAP11] = "TRAP #11",
201 [VEC_TRAP12] = "TRAP #12",
202 [VEC_TRAP13] = "TRAP #13",
203 [VEC_TRAP14] = "TRAP #14",
204 [VEC_TRAP15] = "TRAP #15",
205 [VEC_FPBRUC] = "FPCP BSUN",
206 [VEC_FPIR] = "FPCP INEXACT",
207 [VEC_FPDIVZ] = "FPCP DIV BY 0",
208 [VEC_FPUNDER] = "FPCP UNDERFLOW",
209 [VEC_FPOE] = "FPCP OPERAND ERROR",
210 [VEC_FPOVER] = "FPCP OVERFLOW",
211 [VEC_FPNAN] = "FPCP SNAN",
212 [VEC_FPUNSUP] = "FPCP UNSUPPORTED OPERATION",
213 [VEC_MMUCFG] = "MMU CONFIGURATION ERROR",
214 [VEC_MMUILL] = "MMU ILLEGAL OPERATION ERROR",
215 [VEC_MMUACC] = "MMU ACCESS LEVEL VIOLATION ERROR",
216 [VEC_RESV59] = "UNASSIGNED RESERVED 59",
217 [VEC_UNIMPEA] = "UNASSIGNED RESERVED 60",
218 [VEC_UNIMPII] = "UNASSIGNED RESERVED 61",
219 [VEC_RESV62] = "UNASSIGNED RESERVED 62",
220 [VEC_RESV63] = "UNASSIGNED RESERVED 63",
223 static const char *space_names[] = {
225 [USER_DATA] = "User Data",
226 [USER_PROGRAM] = "User Program",
230 [FC_CONTROL] = "Control",
233 [SUPER_DATA] = "Super Data",
234 [SUPER_PROGRAM] = "Super Program",
238 void die_if_kernel(char *,struct pt_regs *,int);
239 asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
240 unsigned long error_code);
241 int send_fault_sig(struct pt_regs *regs);
243 asmlinkage void trap_c(struct frame *fp);
245 #if defined (CONFIG_M68060)
246 static inline void access_error060 (struct frame *fp)
248 unsigned long fslw = fp->un.fmt4.pc; /* is really FSLW for access error */
251 printk("fslw=%#lx, fa=%#lx\n", fslw, fp->un.fmt4.effaddr);
254 if (fslw & MMU060_BPE) {
255 /* branch prediction error -> clear branch cache */
256 __asm__ __volatile__ ("movec %/cacr,%/d0\n\t"
257 "orl #0x00400000,%/d0\n\t"
260 /* return if there's no other error */
261 if (!(fslw & MMU060_ERR_BITS) && !(fslw & MMU060_SEE))
265 if (fslw & (MMU060_DESC_ERR | MMU060_WP | MMU060_SP)) {
266 unsigned long errorcode;
267 unsigned long addr = fp->un.fmt4.effaddr;
269 if (fslw & MMU060_MA)
270 addr = (addr + PAGE_SIZE - 1) & PAGE_MASK;
273 if (fslw & MMU060_DESC_ERR) {
274 __flush_tlb040_one(addr);
280 printk("errorcode = %d\n", errorcode );
282 do_page_fault(&fp->ptregs, addr, errorcode);
283 } else if (fslw & (MMU060_SEE)){
284 /* Software Emulation Error.
285 * fault during mem_read/mem_write in ifpsp060/os.S
287 send_fault_sig(&fp->ptregs);
288 } else if (!(fslw & (MMU060_RE|MMU060_WE)) ||
289 send_fault_sig(&fp->ptregs) > 0) {
290 printk("pc=%#lx, fa=%#lx\n", fp->ptregs.pc, fp->un.fmt4.effaddr);
291 printk( "68060 access error, fslw=%lx\n", fslw );
295 #endif /* CONFIG_M68060 */
297 #if defined (CONFIG_M68040)
298 static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
301 mm_segment_t old_fs = get_fs();
303 set_fs(MAKE_MM_SEG(wbs));
306 asm volatile (".chip 68040; ptestw (%0); .chip 68k" : : "a" (addr));
308 asm volatile (".chip 68040; ptestr (%0); .chip 68k" : : "a" (addr));
310 asm volatile (".chip 68040; movec %%mmusr,%0; .chip 68k" : "=r" (mmusr));
317 static inline int do_040writeback1(unsigned short wbs, unsigned long wba,
321 mm_segment_t old_fs = get_fs();
323 /* set_fs can not be moved, otherwise put_user() may oops */
324 set_fs(MAKE_MM_SEG(wbs));
326 switch (wbs & WBSIZ_040) {
328 res = put_user(wbd & 0xff, (char __user *)wba);
331 res = put_user(wbd & 0xffff, (short __user *)wba);
334 res = put_user(wbd, (int __user *)wba);
338 /* set_fs can not be moved, otherwise put_user() may oops */
343 printk("do_040writeback1, res=%d\n",res);
349 /* after an exception in a writeback the stack frame corresponding
350 * to that exception is discarded, set a few bits in the old frame
351 * to simulate what it should look like
353 static inline void fix_xframe040(struct frame *fp, unsigned long wba, unsigned short wbs)
355 fp->un.fmt7.faddr = wba;
356 fp->un.fmt7.ssw = wbs & 0xff;
357 if (wba != current->thread.faddr)
358 fp->un.fmt7.ssw |= MA_040;
361 static inline void do_040writebacks(struct frame *fp)
365 if (fp->un.fmt7.wb1s & WBV_040)
366 printk("access_error040: cannot handle 1st writeback. oops.\n");
369 if ((fp->un.fmt7.wb2s & WBV_040) &&
370 !(fp->un.fmt7.wb2s & WBTT_040)) {
371 res = do_040writeback1(fp->un.fmt7.wb2s, fp->un.fmt7.wb2a,
374 fix_xframe040(fp, fp->un.fmt7.wb2a, fp->un.fmt7.wb2s);
376 fp->un.fmt7.wb2s = 0;
379 /* do the 2nd wb only if the first one was successful (except for a kernel wb) */
380 if (fp->un.fmt7.wb3s & WBV_040 && (!res || fp->un.fmt7.wb3s & 4)) {
381 res = do_040writeback1(fp->un.fmt7.wb3s, fp->un.fmt7.wb3a,
385 fix_xframe040(fp, fp->un.fmt7.wb3a, fp->un.fmt7.wb3s);
387 fp->un.fmt7.wb2s = fp->un.fmt7.wb3s;
388 fp->un.fmt7.wb3s &= (~WBV_040);
389 fp->un.fmt7.wb2a = fp->un.fmt7.wb3a;
390 fp->un.fmt7.wb2d = fp->un.fmt7.wb3d;
393 fp->un.fmt7.wb3s = 0;
397 send_fault_sig(&fp->ptregs);
401 * called from sigreturn(), must ensure userspace code didn't
402 * manipulate exception frame to circumvent protection, then complete
404 * we just clear TM2 to turn it into a userspace access
406 asmlinkage void berr_040cleanup(struct frame *fp)
408 fp->un.fmt7.wb2s &= ~4;
409 fp->un.fmt7.wb3s &= ~4;
411 do_040writebacks(fp);
414 static inline void access_error040(struct frame *fp)
416 unsigned short ssw = fp->un.fmt7.ssw;
420 printk("ssw=%#x, fa=%#lx\n", ssw, fp->un.fmt7.faddr);
421 printk("wb1s=%#x, wb2s=%#x, wb3s=%#x\n", fp->un.fmt7.wb1s,
422 fp->un.fmt7.wb2s, fp->un.fmt7.wb3s);
423 printk ("wb2a=%lx, wb3a=%lx, wb2d=%lx, wb3d=%lx\n",
424 fp->un.fmt7.wb2a, fp->un.fmt7.wb3a,
425 fp->un.fmt7.wb2d, fp->un.fmt7.wb3d);
429 unsigned long addr = fp->un.fmt7.faddr;
430 unsigned long errorcode;
433 * The MMU status has to be determined AFTER the address
434 * has been corrected if there was a misaligned access (MA).
437 addr = (addr + 7) & -8;
439 /* MMU error, get the MMUSR info for this access */
440 mmusr = probe040(!(ssw & RW_040), addr, ssw);
442 printk("mmusr = %lx\n", mmusr);
445 if (!(mmusr & MMU_R_040)) {
446 /* clear the invalid atc entry */
447 __flush_tlb040_one(addr);
451 /* despite what documentation seems to say, RMW
452 * accesses have always both the LK and RW bits set */
453 if (!(ssw & RW_040) || (ssw & LK_040))
456 if (do_page_fault(&fp->ptregs, addr, errorcode)) {
458 printk("do_page_fault() !=0 \n");
460 if (user_mode(&fp->ptregs)){
461 /* delay writebacks after signal delivery */
463 printk(".. was usermode - return\n");
467 /* disable writeback into user space from kernel
468 * (if do_page_fault didn't fix the mapping,
469 * the writeback won't do good)
473 printk(".. disabling wb2\n");
475 if (fp->un.fmt7.wb2a == fp->un.fmt7.faddr)
476 fp->un.fmt7.wb2s &= ~WBV_040;
477 if (fp->un.fmt7.wb3a == fp->un.fmt7.faddr)
478 fp->un.fmt7.wb3s &= ~WBV_040;
481 /* In case of a bus error we either kill the process or expect
482 * the kernel to catch the fault, which then is also responsible
483 * for cleaning up the mess.
485 current->thread.signo = SIGBUS;
486 current->thread.faddr = fp->un.fmt7.faddr;
487 if (send_fault_sig(&fp->ptregs) >= 0)
488 printk("68040 bus error (ssw=%x, faddr=%lx)\n", ssw,
493 do_040writebacks(fp);
495 #endif /* CONFIG_M68040 */
497 #if defined(CONFIG_SUN3)
498 #include <asm/sun3mmu.h>
500 extern int mmu_emu_handle_fault (unsigned long, int, int);
502 /* sun3 version of bus_error030 */
504 static inline void bus_error030 (struct frame *fp)
506 unsigned char buserr_type = sun3_get_buserr ();
507 unsigned long addr, errorcode;
508 unsigned short ssw = fp->un.fmtb.ssw;
509 extern unsigned long _sun3_map_test_start, _sun3_map_test_end;
513 printk ("Instruction fault at %#010lx\n",
515 fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
517 fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
519 printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
520 ssw & RW ? "read" : "write",
522 space_names[ssw & DFC], fp->ptregs.pc);
526 * Check if this page should be demand-mapped. This needs to go before
527 * the testing for a bad kernel-space access (demand-mapping applies
528 * to kernel accesses too).
532 && (buserr_type & (SUN3_BUSERR_PROTERR | SUN3_BUSERR_INVALID))) {
533 if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 0))
537 /* Check for kernel-space pagefault (BAD). */
538 if (fp->ptregs.sr & PS_S) {
539 /* kernel fault must be a data fault to user space */
540 if (! ((ssw & DF) && ((ssw & DFC) == USER_DATA))) {
541 // try checking the kernel mappings before surrender
542 if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 1))
544 /* instruction fault or kernel data fault! */
546 printk ("Instruction fault at %#010lx\n",
549 /* was this fault incurred testing bus mappings? */
550 if((fp->ptregs.pc >= (unsigned long)&_sun3_map_test_start) &&
551 (fp->ptregs.pc <= (unsigned long)&_sun3_map_test_end)) {
552 send_fault_sig(&fp->ptregs);
556 printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
557 ssw & RW ? "read" : "write",
559 space_names[ssw & DFC], fp->ptregs.pc);
561 printk ("BAD KERNEL BUSERR\n");
563 die_if_kernel("Oops", &fp->ptregs,0);
564 force_sig(SIGKILL, current);
569 if (!(ssw & (FC | FB)) && !(ssw & DF))
570 /* not an instruction fault or data fault! BAD */
571 panic ("USER BUSERR w/o instruction or data fault");
575 /* First handle the data fault, if any. */
577 addr = fp->un.fmtb.daddr;
579 // errorcode bit 0: 0 -> no page 1 -> protection fault
580 // errorcode bit 1: 0 -> read fault 1 -> write fault
582 // (buserr_type & SUN3_BUSERR_PROTERR) -> protection fault
583 // (buserr_type & SUN3_BUSERR_INVALID) -> invalid page fault
585 if (buserr_type & SUN3_BUSERR_PROTERR)
587 else if (buserr_type & SUN3_BUSERR_INVALID)
591 printk ("*** unexpected busfault type=%#04x\n", buserr_type);
592 printk ("invalid %s access at %#lx from pc %#lx\n",
593 !(ssw & RW) ? "write" : "read", addr,
596 die_if_kernel ("Oops", &fp->ptregs, buserr_type);
597 force_sig (SIGBUS, current);
601 //todo: wtf is RM bit? --m
602 if (!(ssw & RW) || ssw & RM)
605 /* Handle page fault. */
606 do_page_fault (&fp->ptregs, addr, errorcode);
608 /* Retry the data fault now. */
612 /* Now handle the instruction fault. */
614 /* Get the fault address. */
615 if (fp->ptregs.format == 0xA)
616 addr = fp->ptregs.pc + 4;
618 addr = fp->un.fmtb.baddr;
622 if (buserr_type & SUN3_BUSERR_INVALID) {
623 if (!mmu_emu_handle_fault (fp->un.fmtb.daddr, 1, 0))
624 do_page_fault (&fp->ptregs, addr, 0);
627 printk ("protection fault on insn access (segv).\n");
629 force_sig (SIGSEGV, current);
633 #if defined(CPU_M68020_OR_M68030)
634 static inline void bus_error030 (struct frame *fp)
636 volatile unsigned short temp;
637 unsigned short mmusr;
638 unsigned long addr, errorcode;
639 unsigned short ssw = fp->un.fmtb.ssw;
643 printk ("pid = %x ", current->pid);
644 printk ("SSW=%#06x ", ssw);
647 printk ("Instruction fault at %#010lx\n",
649 fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
651 fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
653 printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
654 ssw & RW ? "read" : "write",
656 space_names[ssw & DFC], fp->ptregs.pc);
659 /* ++andreas: If a data fault and an instruction fault happen
660 at the same time map in both pages. */
662 /* First handle the data fault, if any. */
664 addr = fp->un.fmtb.daddr;
667 asm volatile ("ptestr %3,%2@,#7,%0\n\t"
670 : "a" (&temp), "a" (addr), "d" (ssw));
672 asm volatile ("ptestr %2,%1@,#7\n\t"
674 : : "a" (&temp), "a" (addr), "d" (ssw));
679 printk("mmusr is %#x for addr %#lx in task %p\n",
680 mmusr, addr, current);
681 printk("descriptor address is %#lx, contents %#lx\n",
682 __va(desc), *(unsigned long *)__va(desc));
685 errorcode = (mmusr & MMU_I) ? 0 : 1;
686 if (!(ssw & RW) || (ssw & RM))
689 if (mmusr & (MMU_I | MMU_WP)) {
691 printk("Data %s fault at %#010lx in %s (pc=%#lx)\n",
692 ssw & RW ? "read" : "write",
694 space_names[ssw & DFC], fp->ptregs.pc);
697 /* Don't try to do anything further if an exception was
699 if (do_page_fault (&fp->ptregs, addr, errorcode) < 0)
701 } else if (!(mmusr & MMU_I)) {
702 /* probably a 020 cas fault */
703 if (!(ssw & RM) && send_fault_sig(&fp->ptregs) > 0)
704 printk("unexpected bus error (%#x,%#x)\n", ssw, mmusr);
705 } else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
706 printk("invalid %s access at %#lx from pc %#lx\n",
707 !(ssw & RW) ? "write" : "read", addr,
709 die_if_kernel("Oops",&fp->ptregs,mmusr);
710 force_sig(SIGSEGV, current);
714 static volatile long tlong;
717 printk("weird %s access at %#lx from pc %#lx (ssw is %#x)\n",
718 !(ssw & RW) ? "write" : "read", addr,
720 asm volatile ("ptestr #1,%1@,#0\n\t"
723 : "a" (&temp), "a" (addr));
726 printk ("level 0 mmusr is %#x\n", mmusr);
728 asm volatile ("pmove %%tt0,%0@"
731 printk("tt0 is %#lx, ", tlong);
732 asm volatile ("pmove %%tt1,%0@"
735 printk("tt1 is %#lx\n", tlong);
738 printk("Unknown SIGSEGV - 1\n");
740 die_if_kernel("Oops",&fp->ptregs,mmusr);
741 force_sig(SIGSEGV, current);
745 /* setup an ATC entry for the access about to be retried */
746 if (!(ssw & RW) || (ssw & RM))
747 asm volatile ("ploadw %1,%0@" : /* no outputs */
748 : "a" (addr), "d" (ssw));
750 asm volatile ("ploadr %1,%0@" : /* no outputs */
751 : "a" (addr), "d" (ssw));
754 /* Now handle the instruction fault. */
756 if (!(ssw & (FC|FB)))
759 if (fp->ptregs.sr & PS_S) {
760 printk("Instruction fault at %#010lx\n",
763 printk ("BAD KERNEL BUSERR\n");
764 die_if_kernel("Oops",&fp->ptregs,0);
765 force_sig(SIGKILL, current);
769 /* get the fault address */
770 if (fp->ptregs.format == 10)
771 addr = fp->ptregs.pc + 4;
773 addr = fp->un.fmtb.baddr;
777 if ((ssw & DF) && ((addr ^ fp->un.fmtb.daddr) & PAGE_MASK) == 0)
778 /* Insn fault on same page as data fault. But we
779 should still create the ATC entry. */
780 goto create_atc_entry;
783 asm volatile ("ptestr #1,%2@,#7,%0\n\t"
786 : "a" (&temp), "a" (addr));
788 asm volatile ("ptestr #1,%1@,#7\n\t"
790 : : "a" (&temp), "a" (addr));
795 printk ("mmusr is %#x for addr %#lx in task %p\n",
796 mmusr, addr, current);
797 printk ("descriptor address is %#lx, contents %#lx\n",
798 __va(desc), *(unsigned long *)__va(desc));
802 do_page_fault (&fp->ptregs, addr, 0);
803 else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
804 printk ("invalid insn access at %#lx from pc %#lx\n",
805 addr, fp->ptregs.pc);
807 printk("Unknown SIGSEGV - 2\n");
809 die_if_kernel("Oops",&fp->ptregs,mmusr);
810 force_sig(SIGSEGV, current);
815 /* setup an ATC entry for the access about to be retried */
816 asm volatile ("ploadr #2,%0@" : /* no outputs */
819 #endif /* CPU_M68020_OR_M68030 */
820 #endif /* !CONFIG_SUN3 */
822 asmlinkage void buserr_c(struct frame *fp)
824 /* Only set esp0 if coming from user mode */
825 if (user_mode(&fp->ptregs))
826 current->thread.esp0 = (unsigned long) fp;
829 printk ("*** Bus Error *** Format is %x\n", fp->ptregs.format);
832 switch (fp->ptregs.format) {
833 #if defined (CONFIG_M68060)
834 case 4: /* 68060 access error */
835 access_error060 (fp);
838 #if defined (CONFIG_M68040)
839 case 0x7: /* 68040 access error */
840 access_error040 (fp);
843 #if defined (CPU_M68020_OR_M68030)
850 die_if_kernel("bad frame format",&fp->ptregs,0);
852 printk("Unknown SIGSEGV - 4\n");
854 force_sig(SIGSEGV, current);
859 static int kstack_depth_to_print = 48;
861 void show_trace(unsigned long *stack)
863 unsigned long *endstack;
867 printk("Call Trace:");
868 addr = (unsigned long)stack + THREAD_SIZE - 1;
869 endstack = (unsigned long *)(addr & -THREAD_SIZE);
871 while (stack + 1 <= endstack) {
874 * If the address is either in the text segment of the
875 * kernel, or in the region which contains vmalloc'ed
876 * memory, it *may* be the address of a calling
877 * routine; if so, print it so that someone tracing
878 * down the cause of the crash will be able to figure
879 * out the call path that was taken.
881 if (__kernel_text_address(addr)) {
882 #ifndef CONFIG_KALLSYMS
886 printk(" [<%08lx>] %pS\n", addr, (void *)addr);
893 void show_registers(struct pt_regs *regs)
895 struct frame *fp = (struct frame *)regs;
896 mm_segment_t old_fs = get_fs();
902 printk("PC: [<%08lx>] %pS\n", regs->pc, (void *)regs->pc);
903 printk("SR: %04x SP: %p a2: %08lx\n", regs->sr, regs, regs->a2);
904 printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
905 regs->d0, regs->d1, regs->d2, regs->d3);
906 printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
907 regs->d4, regs->d5, regs->a0, regs->a1);
909 printk("Process %s (pid: %d, task=%p)\n",
910 current->comm, task_pid_nr(current), current);
911 addr = (unsigned long)&fp->un;
912 printk("Frame format=%X ", regs->format);
913 switch (regs->format) {
915 printk("instr addr=%08lx\n", fp->un.fmt2.iaddr);
916 addr += sizeof(fp->un.fmt2);
919 printk("eff addr=%08lx\n", fp->un.fmt3.effaddr);
920 addr += sizeof(fp->un.fmt3);
923 printk((CPU_IS_060 ? "fault addr=%08lx fslw=%08lx\n"
924 : "eff addr=%08lx pc=%08lx\n"),
925 fp->un.fmt4.effaddr, fp->un.fmt4.pc);
926 addr += sizeof(fp->un.fmt4);
929 printk("eff addr=%08lx ssw=%04x faddr=%08lx\n",
930 fp->un.fmt7.effaddr, fp->un.fmt7.ssw, fp->un.fmt7.faddr);
931 printk("wb 1 stat/addr/data: %04x %08lx %08lx\n",
932 fp->un.fmt7.wb1s, fp->un.fmt7.wb1a, fp->un.fmt7.wb1dpd0);
933 printk("wb 2 stat/addr/data: %04x %08lx %08lx\n",
934 fp->un.fmt7.wb2s, fp->un.fmt7.wb2a, fp->un.fmt7.wb2d);
935 printk("wb 3 stat/addr/data: %04x %08lx %08lx\n",
936 fp->un.fmt7.wb3s, fp->un.fmt7.wb3a, fp->un.fmt7.wb3d);
937 printk("push data: %08lx %08lx %08lx %08lx\n",
938 fp->un.fmt7.wb1dpd0, fp->un.fmt7.pd1, fp->un.fmt7.pd2,
940 addr += sizeof(fp->un.fmt7);
943 printk("instr addr=%08lx\n", fp->un.fmt9.iaddr);
944 addr += sizeof(fp->un.fmt9);
947 printk("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
948 fp->un.fmta.ssw, fp->un.fmta.isc, fp->un.fmta.isb,
949 fp->un.fmta.daddr, fp->un.fmta.dobuf);
950 addr += sizeof(fp->un.fmta);
953 printk("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
954 fp->un.fmtb.ssw, fp->un.fmtb.isc, fp->un.fmtb.isb,
955 fp->un.fmtb.daddr, fp->un.fmtb.dobuf);
956 printk("baddr=%08lx dibuf=%08lx ver=%x\n",
957 fp->un.fmtb.baddr, fp->un.fmtb.dibuf, fp->un.fmtb.ver);
958 addr += sizeof(fp->un.fmtb);
963 show_stack(NULL, (unsigned long *)addr);
967 cp = (u16 *)regs->pc;
968 for (i = -8; i < 16; i++) {
969 if (get_user(c, cp + i) && i >= 0) {
970 printk(" Bad PC value.");
973 printk(i ? " %04x" : " <%04x>", c);
979 void show_stack(struct task_struct *task, unsigned long *stack)
982 unsigned long *endstack;
987 stack = (unsigned long *)task->thread.esp0;
989 stack = (unsigned long *)&stack;
991 endstack = (unsigned long *)(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
993 printk("Stack from %08lx:", (unsigned long)stack);
995 for (i = 0; i < kstack_depth_to_print; i++) {
996 if (p + 1 > endstack)
1000 printk(" %08lx", *p++);
1007 * The architecture-independent backtrace generator
1009 void dump_stack(void)
1011 unsigned long stack;
1016 EXPORT_SYMBOL(dump_stack);
1018 void bad_super_trap (struct frame *fp)
1021 if (fp->ptregs.vector < 4 * ARRAY_SIZE(vec_names))
1022 printk ("*** %s *** FORMAT=%X\n",
1023 vec_names[(fp->ptregs.vector) >> 2],
1026 printk ("*** Exception %d *** FORMAT=%X\n",
1027 (fp->ptregs.vector) >> 2,
1029 if (fp->ptregs.vector >> 2 == VEC_ADDRERR && CPU_IS_020_OR_030) {
1030 unsigned short ssw = fp->un.fmtb.ssw;
1032 printk ("SSW=%#06x ", ssw);
1035 printk ("Pipe stage C instruction fault at %#010lx\n",
1036 (fp->ptregs.format) == 0xA ?
1037 fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2);
1039 printk ("Pipe stage B instruction fault at %#010lx\n",
1040 (fp->ptregs.format) == 0xA ?
1041 fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
1043 printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
1044 ssw & RW ? "read" : "write",
1045 fp->un.fmtb.daddr, space_names[ssw & DFC],
1048 printk ("Current process id is %d\n", task_pid_nr(current));
1049 die_if_kernel("BAD KERNEL TRAP", &fp->ptregs, 0);
1052 asmlinkage void trap_c(struct frame *fp)
1057 if (fp->ptregs.sr & PS_S) {
1058 if ((fp->ptregs.vector >> 2) == VEC_TRACE) {
1059 /* traced a trapping instruction */
1060 current->ptrace |= PT_DTRACE;
1066 /* send the appropriate signal to the user program */
1067 switch ((fp->ptregs.vector) >> 2) {
1069 info.si_code = BUS_ADRALN;
1075 info.si_code = ILL_ILLOPC;
1079 info.si_code = ILL_PRVOPC;
1083 info.si_code = ILL_COPROC;
1100 info.si_code = ILL_ILLTRP;
1106 info.si_code = FPE_FLTINV;
1110 info.si_code = FPE_FLTRES;
1114 info.si_code = FPE_FLTDIV;
1118 info.si_code = FPE_FLTUND;
1122 info.si_code = FPE_FLTOVF;
1126 info.si_code = FPE_INTDIV;
1131 info.si_code = FPE_INTOVF;
1134 case VEC_TRACE: /* ptrace single step */
1135 info.si_code = TRAP_TRACE;
1138 case VEC_TRAP15: /* breakpoint */
1139 info.si_code = TRAP_BRKPT;
1143 info.si_code = ILL_ILLOPC;
1147 info.si_signo = sig;
1149 switch (fp->ptregs.format) {
1151 info.si_addr = (void *) fp->ptregs.pc;
1154 info.si_addr = (void *) fp->un.fmt2.iaddr;
1157 info.si_addr = (void *) fp->un.fmt7.effaddr;
1160 info.si_addr = (void *) fp->un.fmt9.iaddr;
1163 info.si_addr = (void *) fp->un.fmta.daddr;
1166 info.si_addr = (void *) fp->un.fmtb.daddr;
1169 force_sig_info (sig, &info, current);
1172 void die_if_kernel (char *str, struct pt_regs *fp, int nr)
1174 if (!(fp->sr & PS_S))
1178 printk("%s: %08x\n",str,nr);
1180 add_taint(TAINT_DIE);
1185 * This function is called if an error occur while accessing
1186 * user-space from the fpsp040 code.
1188 asmlinkage void fpsp040_die(void)
1193 #ifdef CONFIG_M68KFPU_EMU
1194 asmlinkage void fpemu_signal(int signal, int code, void *addr)
1198 info.si_signo = signal;
1200 info.si_code = code;
1201 info.si_addr = addr;
1202 force_sig_info(signal, &info, current);