xref: /linux/arch/m68k/kernel/traps.c (revision 3c67075d5df21f6bdb1dade1f2ab7e82ef0c0f6a)
1144077eaSGreg Ungerer /*
2144077eaSGreg Ungerer  *  linux/arch/m68k/kernel/traps.c
3144077eaSGreg Ungerer  *
4144077eaSGreg Ungerer  *  Copyright (C) 1993, 1994 by Hamish Macdonald
5144077eaSGreg Ungerer  *
6144077eaSGreg Ungerer  *  68040 fixes by Michael Rausch
7144077eaSGreg Ungerer  *  68040 fixes by Martin Apel
8144077eaSGreg Ungerer  *  68040 fixes and writeback by Richard Zidlicky
9144077eaSGreg Ungerer  *  68060 fixes by Roman Hodek
10144077eaSGreg Ungerer  *  68060 fixes by Jesper Skov
11144077eaSGreg Ungerer  *
12144077eaSGreg Ungerer  * This file is subject to the terms and conditions of the GNU General Public
13144077eaSGreg Ungerer  * License.  See the file COPYING in the main directory of this archive
14144077eaSGreg Ungerer  * for more details.
15144077eaSGreg Ungerer  */
16144077eaSGreg Ungerer 
17144077eaSGreg Ungerer /*
18144077eaSGreg Ungerer  * Sets up all exception vectors
19144077eaSGreg Ungerer  */
20144077eaSGreg Ungerer 
21144077eaSGreg Ungerer #include <linux/sched.h>
22b17b0153SIngo Molnar #include <linux/sched/debug.h>
23144077eaSGreg Ungerer #include <linux/signal.h>
24144077eaSGreg Ungerer #include <linux/kernel.h>
25144077eaSGreg Ungerer #include <linux/mm.h>
26144077eaSGreg Ungerer #include <linux/module.h>
27144077eaSGreg Ungerer #include <linux/user.h>
28144077eaSGreg Ungerer #include <linux/string.h>
29144077eaSGreg Ungerer #include <linux/linkage.h>
30144077eaSGreg Ungerer #include <linux/init.h>
31144077eaSGreg Ungerer #include <linux/ptrace.h>
32144077eaSGreg Ungerer #include <linux/kallsyms.h>
33144077eaSGreg Ungerer 
34144077eaSGreg Ungerer #include <asm/setup.h>
35144077eaSGreg Ungerer #include <asm/fpu.h>
367c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
37144077eaSGreg Ungerer #include <asm/traps.h>
38144077eaSGreg Ungerer #include <asm/pgalloc.h>
39144077eaSGreg Ungerer #include <asm/machdep.h>
40144077eaSGreg Ungerer #include <asm/siginfo.h>
41144077eaSGreg Ungerer 
42144077eaSGreg Ungerer 
43144077eaSGreg Ungerer static const char *vec_names[] = {
44144077eaSGreg Ungerer 	[VEC_RESETSP]	= "RESET SP",
45144077eaSGreg Ungerer 	[VEC_RESETPC]	= "RESET PC",
46144077eaSGreg Ungerer 	[VEC_BUSERR]	= "BUS ERROR",
47144077eaSGreg Ungerer 	[VEC_ADDRERR]	= "ADDRESS ERROR",
48144077eaSGreg Ungerer 	[VEC_ILLEGAL]	= "ILLEGAL INSTRUCTION",
49144077eaSGreg Ungerer 	[VEC_ZERODIV]	= "ZERO DIVIDE",
50144077eaSGreg Ungerer 	[VEC_CHK]	= "CHK",
51144077eaSGreg Ungerer 	[VEC_TRAP]	= "TRAPcc",
52144077eaSGreg Ungerer 	[VEC_PRIV]	= "PRIVILEGE VIOLATION",
53144077eaSGreg Ungerer 	[VEC_TRACE]	= "TRACE",
54144077eaSGreg Ungerer 	[VEC_LINE10]	= "LINE 1010",
55144077eaSGreg Ungerer 	[VEC_LINE11]	= "LINE 1111",
56144077eaSGreg Ungerer 	[VEC_RESV12]	= "UNASSIGNED RESERVED 12",
57144077eaSGreg Ungerer 	[VEC_COPROC]	= "COPROCESSOR PROTOCOL VIOLATION",
58144077eaSGreg Ungerer 	[VEC_FORMAT]	= "FORMAT ERROR",
59144077eaSGreg Ungerer 	[VEC_UNINT]	= "UNINITIALIZED INTERRUPT",
60144077eaSGreg Ungerer 	[VEC_RESV16]	= "UNASSIGNED RESERVED 16",
61144077eaSGreg Ungerer 	[VEC_RESV17]	= "UNASSIGNED RESERVED 17",
62144077eaSGreg Ungerer 	[VEC_RESV18]	= "UNASSIGNED RESERVED 18",
63144077eaSGreg Ungerer 	[VEC_RESV19]	= "UNASSIGNED RESERVED 19",
64144077eaSGreg Ungerer 	[VEC_RESV20]	= "UNASSIGNED RESERVED 20",
65144077eaSGreg Ungerer 	[VEC_RESV21]	= "UNASSIGNED RESERVED 21",
66144077eaSGreg Ungerer 	[VEC_RESV22]	= "UNASSIGNED RESERVED 22",
67144077eaSGreg Ungerer 	[VEC_RESV23]	= "UNASSIGNED RESERVED 23",
68144077eaSGreg Ungerer 	[VEC_SPUR]	= "SPURIOUS INTERRUPT",
69144077eaSGreg Ungerer 	[VEC_INT1]	= "LEVEL 1 INT",
70144077eaSGreg Ungerer 	[VEC_INT2]	= "LEVEL 2 INT",
71144077eaSGreg Ungerer 	[VEC_INT3]	= "LEVEL 3 INT",
72144077eaSGreg Ungerer 	[VEC_INT4]	= "LEVEL 4 INT",
73144077eaSGreg Ungerer 	[VEC_INT5]	= "LEVEL 5 INT",
74144077eaSGreg Ungerer 	[VEC_INT6]	= "LEVEL 6 INT",
75144077eaSGreg Ungerer 	[VEC_INT7]	= "LEVEL 7 INT",
76144077eaSGreg Ungerer 	[VEC_SYS]	= "SYSCALL",
77144077eaSGreg Ungerer 	[VEC_TRAP1]	= "TRAP #1",
78144077eaSGreg Ungerer 	[VEC_TRAP2]	= "TRAP #2",
79144077eaSGreg Ungerer 	[VEC_TRAP3]	= "TRAP #3",
80144077eaSGreg Ungerer 	[VEC_TRAP4]	= "TRAP #4",
81144077eaSGreg Ungerer 	[VEC_TRAP5]	= "TRAP #5",
82144077eaSGreg Ungerer 	[VEC_TRAP6]	= "TRAP #6",
83144077eaSGreg Ungerer 	[VEC_TRAP7]	= "TRAP #7",
84144077eaSGreg Ungerer 	[VEC_TRAP8]	= "TRAP #8",
85144077eaSGreg Ungerer 	[VEC_TRAP9]	= "TRAP #9",
86144077eaSGreg Ungerer 	[VEC_TRAP10]	= "TRAP #10",
87144077eaSGreg Ungerer 	[VEC_TRAP11]	= "TRAP #11",
88144077eaSGreg Ungerer 	[VEC_TRAP12]	= "TRAP #12",
89144077eaSGreg Ungerer 	[VEC_TRAP13]	= "TRAP #13",
90144077eaSGreg Ungerer 	[VEC_TRAP14]	= "TRAP #14",
91144077eaSGreg Ungerer 	[VEC_TRAP15]	= "TRAP #15",
92144077eaSGreg Ungerer 	[VEC_FPBRUC]	= "FPCP BSUN",
93144077eaSGreg Ungerer 	[VEC_FPIR]	= "FPCP INEXACT",
94144077eaSGreg Ungerer 	[VEC_FPDIVZ]	= "FPCP DIV BY 0",
95144077eaSGreg Ungerer 	[VEC_FPUNDER]	= "FPCP UNDERFLOW",
96144077eaSGreg Ungerer 	[VEC_FPOE]	= "FPCP OPERAND ERROR",
97144077eaSGreg Ungerer 	[VEC_FPOVER]	= "FPCP OVERFLOW",
98144077eaSGreg Ungerer 	[VEC_FPNAN]	= "FPCP SNAN",
99144077eaSGreg Ungerer 	[VEC_FPUNSUP]	= "FPCP UNSUPPORTED OPERATION",
100144077eaSGreg Ungerer 	[VEC_MMUCFG]	= "MMU CONFIGURATION ERROR",
101144077eaSGreg Ungerer 	[VEC_MMUILL]	= "MMU ILLEGAL OPERATION ERROR",
102144077eaSGreg Ungerer 	[VEC_MMUACC]	= "MMU ACCESS LEVEL VIOLATION ERROR",
103144077eaSGreg Ungerer 	[VEC_RESV59]	= "UNASSIGNED RESERVED 59",
104144077eaSGreg Ungerer 	[VEC_UNIMPEA]	= "UNASSIGNED RESERVED 60",
105144077eaSGreg Ungerer 	[VEC_UNIMPII]	= "UNASSIGNED RESERVED 61",
106144077eaSGreg Ungerer 	[VEC_RESV62]	= "UNASSIGNED RESERVED 62",
107144077eaSGreg Ungerer 	[VEC_RESV63]	= "UNASSIGNED RESERVED 63",
108144077eaSGreg Ungerer };
109144077eaSGreg Ungerer 
110144077eaSGreg Ungerer static const char *space_names[] = {
111144077eaSGreg Ungerer 	[0]		= "Space 0",
112144077eaSGreg Ungerer 	[USER_DATA]	= "User Data",
113144077eaSGreg Ungerer 	[USER_PROGRAM]	= "User Program",
114144077eaSGreg Ungerer #ifndef CONFIG_SUN3
115144077eaSGreg Ungerer 	[3]		= "Space 3",
1161da177e4SLinus Torvalds #else
117144077eaSGreg Ungerer 	[FC_CONTROL]	= "Control",
118144077eaSGreg Ungerer #endif
119144077eaSGreg Ungerer 	[4]		= "Space 4",
120144077eaSGreg Ungerer 	[SUPER_DATA]	= "Super Data",
121144077eaSGreg Ungerer 	[SUPER_PROGRAM]	= "Super Program",
122144077eaSGreg Ungerer 	[CPU_SPACE]	= "CPU"
123144077eaSGreg Ungerer };
124144077eaSGreg Ungerer 
125144077eaSGreg Ungerer void die_if_kernel(char *,struct pt_regs *,int);
126144077eaSGreg Ungerer asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
127144077eaSGreg Ungerer                              unsigned long error_code);
128144077eaSGreg Ungerer int send_fault_sig(struct pt_regs *regs);
129144077eaSGreg Ungerer 
130144077eaSGreg Ungerer asmlinkage void trap_c(struct frame *fp);
131144077eaSGreg Ungerer 
132144077eaSGreg Ungerer #if defined (CONFIG_M68060)
133144077eaSGreg Ungerer static inline void access_error060 (struct frame *fp)
134144077eaSGreg Ungerer {
135144077eaSGreg Ungerer 	unsigned long fslw = fp->un.fmt4.pc; /* is really FSLW for access error */
136144077eaSGreg Ungerer 
137245b815cSGeert Uytterhoeven 	pr_debug("fslw=%#lx, fa=%#lx\n", fslw, fp->un.fmt4.effaddr);
138144077eaSGreg Ungerer 
139144077eaSGreg Ungerer 	if (fslw & MMU060_BPE) {
140144077eaSGreg Ungerer 		/* branch prediction error -> clear branch cache */
141144077eaSGreg Ungerer 		__asm__ __volatile__ ("movec %/cacr,%/d0\n\t"
142144077eaSGreg Ungerer 				      "orl   #0x00400000,%/d0\n\t"
143144077eaSGreg Ungerer 				      "movec %/d0,%/cacr"
144144077eaSGreg Ungerer 				      : : : "d0" );
145144077eaSGreg Ungerer 		/* return if there's no other error */
146144077eaSGreg Ungerer 		if (!(fslw & MMU060_ERR_BITS) && !(fslw & MMU060_SEE))
147144077eaSGreg Ungerer 			return;
148144077eaSGreg Ungerer 	}
149144077eaSGreg Ungerer 
150144077eaSGreg Ungerer 	if (fslw & (MMU060_DESC_ERR | MMU060_WP | MMU060_SP)) {
151144077eaSGreg Ungerer 		unsigned long errorcode;
152144077eaSGreg Ungerer 		unsigned long addr = fp->un.fmt4.effaddr;
153144077eaSGreg Ungerer 
154144077eaSGreg Ungerer 		if (fslw & MMU060_MA)
155144077eaSGreg Ungerer 			addr = (addr + PAGE_SIZE - 1) & PAGE_MASK;
156144077eaSGreg Ungerer 
157144077eaSGreg Ungerer 		errorcode = 1;
158144077eaSGreg Ungerer 		if (fslw & MMU060_DESC_ERR) {
159144077eaSGreg Ungerer 			__flush_tlb040_one(addr);
160144077eaSGreg Ungerer 			errorcode = 0;
161144077eaSGreg Ungerer 		}
162144077eaSGreg Ungerer 		if (fslw & MMU060_W)
163144077eaSGreg Ungerer 			errorcode |= 2;
164245b815cSGeert Uytterhoeven 		pr_debug("errorcode = %ld\n", errorcode);
165144077eaSGreg Ungerer 		do_page_fault(&fp->ptregs, addr, errorcode);
166144077eaSGreg Ungerer 	} else if (fslw & (MMU060_SEE)){
167144077eaSGreg Ungerer 		/* Software Emulation Error.
168144077eaSGreg Ungerer 		 * fault during mem_read/mem_write in ifpsp060/os.S
169144077eaSGreg Ungerer 		 */
170144077eaSGreg Ungerer 		send_fault_sig(&fp->ptregs);
171144077eaSGreg Ungerer 	} else if (!(fslw & (MMU060_RE|MMU060_WE)) ||
172144077eaSGreg Ungerer 		   send_fault_sig(&fp->ptregs) > 0) {
173245b815cSGeert Uytterhoeven 		pr_err("pc=%#lx, fa=%#lx\n", fp->ptregs.pc,
174245b815cSGeert Uytterhoeven 		       fp->un.fmt4.effaddr);
175245b815cSGeert Uytterhoeven 		pr_err("68060 access error, fslw=%lx\n", fslw);
176144077eaSGreg Ungerer 		trap_c( fp );
177144077eaSGreg Ungerer 	}
178144077eaSGreg Ungerer }
179144077eaSGreg Ungerer #endif /* CONFIG_M68060 */
180144077eaSGreg Ungerer 
181144077eaSGreg Ungerer #if defined (CONFIG_M68040)
182144077eaSGreg Ungerer static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
183144077eaSGreg Ungerer {
184144077eaSGreg Ungerer 	unsigned long mmusr;
185144077eaSGreg Ungerer 	mm_segment_t old_fs = get_fs();
186144077eaSGreg Ungerer 
187144077eaSGreg Ungerer 	set_fs(MAKE_MM_SEG(wbs));
188144077eaSGreg Ungerer 
189144077eaSGreg Ungerer 	if (iswrite)
190144077eaSGreg Ungerer 		asm volatile (".chip 68040; ptestw (%0); .chip 68k" : : "a" (addr));
191144077eaSGreg Ungerer 	else
192144077eaSGreg Ungerer 		asm volatile (".chip 68040; ptestr (%0); .chip 68k" : : "a" (addr));
193144077eaSGreg Ungerer 
194144077eaSGreg Ungerer 	asm volatile (".chip 68040; movec %%mmusr,%0; .chip 68k" : "=r" (mmusr));
195144077eaSGreg Ungerer 
196144077eaSGreg Ungerer 	set_fs(old_fs);
197144077eaSGreg Ungerer 
198144077eaSGreg Ungerer 	return mmusr;
199144077eaSGreg Ungerer }
200144077eaSGreg Ungerer 
201144077eaSGreg Ungerer static inline int do_040writeback1(unsigned short wbs, unsigned long wba,
202144077eaSGreg Ungerer 				   unsigned long wbd)
203144077eaSGreg Ungerer {
204144077eaSGreg Ungerer 	int res = 0;
205144077eaSGreg Ungerer 	mm_segment_t old_fs = get_fs();
206144077eaSGreg Ungerer 
207144077eaSGreg Ungerer 	/* set_fs can not be moved, otherwise put_user() may oops */
208144077eaSGreg Ungerer 	set_fs(MAKE_MM_SEG(wbs));
209144077eaSGreg Ungerer 
210144077eaSGreg Ungerer 	switch (wbs & WBSIZ_040) {
211144077eaSGreg Ungerer 	case BA_SIZE_BYTE:
212144077eaSGreg Ungerer 		res = put_user(wbd & 0xff, (char __user *)wba);
213144077eaSGreg Ungerer 		break;
214144077eaSGreg Ungerer 	case BA_SIZE_WORD:
215144077eaSGreg Ungerer 		res = put_user(wbd & 0xffff, (short __user *)wba);
216144077eaSGreg Ungerer 		break;
217144077eaSGreg Ungerer 	case BA_SIZE_LONG:
218144077eaSGreg Ungerer 		res = put_user(wbd, (int __user *)wba);
219144077eaSGreg Ungerer 		break;
220144077eaSGreg Ungerer 	}
221144077eaSGreg Ungerer 
222144077eaSGreg Ungerer 	/* set_fs can not be moved, otherwise put_user() may oops */
223144077eaSGreg Ungerer 	set_fs(old_fs);
224144077eaSGreg Ungerer 
225144077eaSGreg Ungerer 
226245b815cSGeert Uytterhoeven 	pr_debug("do_040writeback1, res=%d\n", res);
227144077eaSGreg Ungerer 
228144077eaSGreg Ungerer 	return res;
229144077eaSGreg Ungerer }
230144077eaSGreg Ungerer 
231144077eaSGreg Ungerer /* after an exception in a writeback the stack frame corresponding
232144077eaSGreg Ungerer  * to that exception is discarded, set a few bits in the old frame
233144077eaSGreg Ungerer  * to simulate what it should look like
234144077eaSGreg Ungerer  */
235144077eaSGreg Ungerer static inline void fix_xframe040(struct frame *fp, unsigned long wba, unsigned short wbs)
236144077eaSGreg Ungerer {
237144077eaSGreg Ungerer 	fp->un.fmt7.faddr = wba;
238144077eaSGreg Ungerer 	fp->un.fmt7.ssw = wbs & 0xff;
239144077eaSGreg Ungerer 	if (wba != current->thread.faddr)
240144077eaSGreg Ungerer 	    fp->un.fmt7.ssw |= MA_040;
241144077eaSGreg Ungerer }
242144077eaSGreg Ungerer 
243144077eaSGreg Ungerer static inline void do_040writebacks(struct frame *fp)
244144077eaSGreg Ungerer {
245144077eaSGreg Ungerer 	int res = 0;
246144077eaSGreg Ungerer #if 0
247144077eaSGreg Ungerer 	if (fp->un.fmt7.wb1s & WBV_040)
248245b815cSGeert Uytterhoeven 		pr_err("access_error040: cannot handle 1st writeback. oops.\n");
249144077eaSGreg Ungerer #endif
250144077eaSGreg Ungerer 
251144077eaSGreg Ungerer 	if ((fp->un.fmt7.wb2s & WBV_040) &&
252144077eaSGreg Ungerer 	    !(fp->un.fmt7.wb2s & WBTT_040)) {
253144077eaSGreg Ungerer 		res = do_040writeback1(fp->un.fmt7.wb2s, fp->un.fmt7.wb2a,
254144077eaSGreg Ungerer 				       fp->un.fmt7.wb2d);
255144077eaSGreg Ungerer 		if (res)
256144077eaSGreg Ungerer 			fix_xframe040(fp, fp->un.fmt7.wb2a, fp->un.fmt7.wb2s);
257144077eaSGreg Ungerer 		else
258144077eaSGreg Ungerer 			fp->un.fmt7.wb2s = 0;
259144077eaSGreg Ungerer 	}
260144077eaSGreg Ungerer 
261144077eaSGreg Ungerer 	/* do the 2nd wb only if the first one was successful (except for a kernel wb) */
262144077eaSGreg Ungerer 	if (fp->un.fmt7.wb3s & WBV_040 && (!res || fp->un.fmt7.wb3s & 4)) {
263144077eaSGreg Ungerer 		res = do_040writeback1(fp->un.fmt7.wb3s, fp->un.fmt7.wb3a,
264144077eaSGreg Ungerer 				       fp->un.fmt7.wb3d);
265144077eaSGreg Ungerer 		if (res)
266144077eaSGreg Ungerer 		    {
267144077eaSGreg Ungerer 			fix_xframe040(fp, fp->un.fmt7.wb3a, fp->un.fmt7.wb3s);
268144077eaSGreg Ungerer 
269144077eaSGreg Ungerer 			fp->un.fmt7.wb2s = fp->un.fmt7.wb3s;
270144077eaSGreg Ungerer 			fp->un.fmt7.wb3s &= (~WBV_040);
271144077eaSGreg Ungerer 			fp->un.fmt7.wb2a = fp->un.fmt7.wb3a;
272144077eaSGreg Ungerer 			fp->un.fmt7.wb2d = fp->un.fmt7.wb3d;
273144077eaSGreg Ungerer 		    }
274144077eaSGreg Ungerer 		else
275144077eaSGreg Ungerer 			fp->un.fmt7.wb3s = 0;
276144077eaSGreg Ungerer 	}
277144077eaSGreg Ungerer 
278144077eaSGreg Ungerer 	if (res)
279144077eaSGreg Ungerer 		send_fault_sig(&fp->ptregs);
280144077eaSGreg Ungerer }
281144077eaSGreg Ungerer 
282144077eaSGreg Ungerer /*
283144077eaSGreg Ungerer  * called from sigreturn(), must ensure userspace code didn't
284144077eaSGreg Ungerer  * manipulate exception frame to circumvent protection, then complete
285144077eaSGreg Ungerer  * pending writebacks
286144077eaSGreg Ungerer  * we just clear TM2 to turn it into a userspace access
287144077eaSGreg Ungerer  */
288144077eaSGreg Ungerer asmlinkage void berr_040cleanup(struct frame *fp)
289144077eaSGreg Ungerer {
290144077eaSGreg Ungerer 	fp->un.fmt7.wb2s &= ~4;
291144077eaSGreg Ungerer 	fp->un.fmt7.wb3s &= ~4;
292144077eaSGreg Ungerer 
293144077eaSGreg Ungerer 	do_040writebacks(fp);
294144077eaSGreg Ungerer }
295144077eaSGreg Ungerer 
296144077eaSGreg Ungerer static inline void access_error040(struct frame *fp)
297144077eaSGreg Ungerer {
298144077eaSGreg Ungerer 	unsigned short ssw = fp->un.fmt7.ssw;
299144077eaSGreg Ungerer 	unsigned long mmusr;
300144077eaSGreg Ungerer 
301245b815cSGeert Uytterhoeven 	pr_debug("ssw=%#x, fa=%#lx\n", ssw, fp->un.fmt7.faddr);
302245b815cSGeert Uytterhoeven 	pr_debug("wb1s=%#x, wb2s=%#x, wb3s=%#x\n", fp->un.fmt7.wb1s,
303144077eaSGreg Ungerer 		fp->un.fmt7.wb2s, fp->un.fmt7.wb3s);
304245b815cSGeert Uytterhoeven 	pr_debug("wb2a=%lx, wb3a=%lx, wb2d=%lx, wb3d=%lx\n",
305144077eaSGreg Ungerer 		fp->un.fmt7.wb2a, fp->un.fmt7.wb3a,
306144077eaSGreg Ungerer 		fp->un.fmt7.wb2d, fp->un.fmt7.wb3d);
307144077eaSGreg Ungerer 
308144077eaSGreg Ungerer 	if (ssw & ATC_040) {
309144077eaSGreg Ungerer 		unsigned long addr = fp->un.fmt7.faddr;
310144077eaSGreg Ungerer 		unsigned long errorcode;
311144077eaSGreg Ungerer 
312144077eaSGreg Ungerer 		/*
313144077eaSGreg Ungerer 		 * The MMU status has to be determined AFTER the address
314144077eaSGreg Ungerer 		 * has been corrected if there was a misaligned access (MA).
315144077eaSGreg Ungerer 		 */
316144077eaSGreg Ungerer 		if (ssw & MA_040)
317144077eaSGreg Ungerer 			addr = (addr + 7) & -8;
318144077eaSGreg Ungerer 
319144077eaSGreg Ungerer 		/* MMU error, get the MMUSR info for this access */
320144077eaSGreg Ungerer 		mmusr = probe040(!(ssw & RW_040), addr, ssw);
321245b815cSGeert Uytterhoeven 		pr_debug("mmusr = %lx\n", mmusr);
322144077eaSGreg Ungerer 		errorcode = 1;
323144077eaSGreg Ungerer 		if (!(mmusr & MMU_R_040)) {
324144077eaSGreg Ungerer 			/* clear the invalid atc entry */
325144077eaSGreg Ungerer 			__flush_tlb040_one(addr);
326144077eaSGreg Ungerer 			errorcode = 0;
327144077eaSGreg Ungerer 		}
328144077eaSGreg Ungerer 
329144077eaSGreg Ungerer 		/* despite what documentation seems to say, RMW
330144077eaSGreg Ungerer 		 * accesses have always both the LK and RW bits set */
331144077eaSGreg Ungerer 		if (!(ssw & RW_040) || (ssw & LK_040))
332144077eaSGreg Ungerer 			errorcode |= 2;
333144077eaSGreg Ungerer 
334144077eaSGreg Ungerer 		if (do_page_fault(&fp->ptregs, addr, errorcode)) {
335245b815cSGeert Uytterhoeven 			pr_debug("do_page_fault() !=0\n");
336144077eaSGreg Ungerer 			if (user_mode(&fp->ptregs)){
337144077eaSGreg Ungerer 				/* delay writebacks after signal delivery */
338245b815cSGeert Uytterhoeven 				pr_debug(".. was usermode - return\n");
339144077eaSGreg Ungerer 				return;
340144077eaSGreg Ungerer 			}
341144077eaSGreg Ungerer 			/* disable writeback into user space from kernel
342144077eaSGreg Ungerer 			 * (if do_page_fault didn't fix the mapping,
343144077eaSGreg Ungerer                          * the writeback won't do good)
344144077eaSGreg Ungerer 			 */
345144077eaSGreg Ungerer disable_wb:
346245b815cSGeert Uytterhoeven 			pr_debug(".. disabling wb2\n");
347144077eaSGreg Ungerer 			if (fp->un.fmt7.wb2a == fp->un.fmt7.faddr)
348144077eaSGreg Ungerer 				fp->un.fmt7.wb2s &= ~WBV_040;
349144077eaSGreg Ungerer 			if (fp->un.fmt7.wb3a == fp->un.fmt7.faddr)
350144077eaSGreg Ungerer 				fp->un.fmt7.wb3s &= ~WBV_040;
351144077eaSGreg Ungerer 		}
352144077eaSGreg Ungerer 	} else {
353144077eaSGreg Ungerer 		/* In case of a bus error we either kill the process or expect
354144077eaSGreg Ungerer 		 * the kernel to catch the fault, which then is also responsible
355144077eaSGreg Ungerer 		 * for cleaning up the mess.
356144077eaSGreg Ungerer 		 */
357144077eaSGreg Ungerer 		current->thread.signo = SIGBUS;
358144077eaSGreg Ungerer 		current->thread.faddr = fp->un.fmt7.faddr;
359144077eaSGreg Ungerer 		if (send_fault_sig(&fp->ptregs) >= 0)
360245b815cSGeert Uytterhoeven 			pr_err("68040 bus error (ssw=%x, faddr=%lx)\n", ssw,
361144077eaSGreg Ungerer 			       fp->un.fmt7.faddr);
362144077eaSGreg Ungerer 		goto disable_wb;
363144077eaSGreg Ungerer 	}
364144077eaSGreg Ungerer 
365144077eaSGreg Ungerer 	do_040writebacks(fp);
366144077eaSGreg Ungerer }
367144077eaSGreg Ungerer #endif /* CONFIG_M68040 */
368144077eaSGreg Ungerer 
369144077eaSGreg Ungerer #if defined(CONFIG_SUN3)
370144077eaSGreg Ungerer #include <asm/sun3mmu.h>
371144077eaSGreg Ungerer 
372144077eaSGreg Ungerer extern int mmu_emu_handle_fault (unsigned long, int, int);
373144077eaSGreg Ungerer 
374144077eaSGreg Ungerer /* sun3 version of bus_error030 */
375144077eaSGreg Ungerer 
376144077eaSGreg Ungerer static inline void bus_error030 (struct frame *fp)
377144077eaSGreg Ungerer {
378144077eaSGreg Ungerer 	unsigned char buserr_type = sun3_get_buserr ();
379144077eaSGreg Ungerer 	unsigned long addr, errorcode;
380144077eaSGreg Ungerer 	unsigned short ssw = fp->un.fmtb.ssw;
381144077eaSGreg Ungerer 	extern unsigned long _sun3_map_test_start, _sun3_map_test_end;
382144077eaSGreg Ungerer 
383144077eaSGreg Ungerer 	if (ssw & (FC | FB))
384245b815cSGeert Uytterhoeven 		pr_debug("Instruction fault at %#010lx\n",
385144077eaSGreg Ungerer 			ssw & FC ?
386144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
387144077eaSGreg Ungerer 			:
388144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
389144077eaSGreg Ungerer 	if (ssw & DF)
390245b815cSGeert Uytterhoeven 		pr_debug("Data %s fault at %#010lx in %s (pc=%#lx)\n",
391144077eaSGreg Ungerer 			ssw & RW ? "read" : "write",
392144077eaSGreg Ungerer 			fp->un.fmtb.daddr,
393144077eaSGreg Ungerer 			space_names[ssw & DFC], fp->ptregs.pc);
394144077eaSGreg Ungerer 
395144077eaSGreg Ungerer 	/*
396144077eaSGreg Ungerer 	 * Check if this page should be demand-mapped. This needs to go before
397144077eaSGreg Ungerer 	 * the testing for a bad kernel-space access (demand-mapping applies
398144077eaSGreg Ungerer 	 * to kernel accesses too).
399144077eaSGreg Ungerer 	 */
400144077eaSGreg Ungerer 
401144077eaSGreg Ungerer 	if ((ssw & DF)
402144077eaSGreg Ungerer 	    && (buserr_type & (SUN3_BUSERR_PROTERR | SUN3_BUSERR_INVALID))) {
403144077eaSGreg Ungerer 		if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 0))
404144077eaSGreg Ungerer 			return;
405144077eaSGreg Ungerer 	}
406144077eaSGreg Ungerer 
407144077eaSGreg Ungerer 	/* Check for kernel-space pagefault (BAD). */
408144077eaSGreg Ungerer 	if (fp->ptregs.sr & PS_S) {
409144077eaSGreg Ungerer 		/* kernel fault must be a data fault to user space */
410144077eaSGreg Ungerer 		if (! ((ssw & DF) && ((ssw & DFC) == USER_DATA))) {
411144077eaSGreg Ungerer 		     // try checking the kernel mappings before surrender
412144077eaSGreg Ungerer 		     if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 1))
413144077eaSGreg Ungerer 			  return;
414144077eaSGreg Ungerer 			/* instruction fault or kernel data fault! */
415144077eaSGreg Ungerer 			if (ssw & (FC | FB))
416245b815cSGeert Uytterhoeven 				pr_err("Instruction fault at %#010lx\n",
417144077eaSGreg Ungerer 					fp->ptregs.pc);
418144077eaSGreg Ungerer 			if (ssw & DF) {
419144077eaSGreg Ungerer 				/* was this fault incurred testing bus mappings? */
420144077eaSGreg Ungerer 				if((fp->ptregs.pc >= (unsigned long)&_sun3_map_test_start) &&
421144077eaSGreg Ungerer 				   (fp->ptregs.pc <= (unsigned long)&_sun3_map_test_end)) {
422144077eaSGreg Ungerer 					send_fault_sig(&fp->ptregs);
423144077eaSGreg Ungerer 					return;
424144077eaSGreg Ungerer 				}
425144077eaSGreg Ungerer 
426245b815cSGeert Uytterhoeven 				pr_err("Data %s fault at %#010lx in %s (pc=%#lx)\n",
427144077eaSGreg Ungerer 					ssw & RW ? "read" : "write",
428144077eaSGreg Ungerer 					fp->un.fmtb.daddr,
429144077eaSGreg Ungerer 					space_names[ssw & DFC], fp->ptregs.pc);
430144077eaSGreg Ungerer 			}
431245b815cSGeert Uytterhoeven 			pr_err("BAD KERNEL BUSERR\n");
432144077eaSGreg Ungerer 
433144077eaSGreg Ungerer 			die_if_kernel("Oops", &fp->ptregs,0);
434144077eaSGreg Ungerer 			force_sig(SIGKILL, current);
435144077eaSGreg Ungerer 			return;
436144077eaSGreg Ungerer 		}
437144077eaSGreg Ungerer 	} else {
438144077eaSGreg Ungerer 		/* user fault */
439144077eaSGreg Ungerer 		if (!(ssw & (FC | FB)) && !(ssw & DF))
440144077eaSGreg Ungerer 			/* not an instruction fault or data fault! BAD */
441144077eaSGreg Ungerer 			panic ("USER BUSERR w/o instruction or data fault");
442144077eaSGreg Ungerer 	}
443144077eaSGreg Ungerer 
444144077eaSGreg Ungerer 
445144077eaSGreg Ungerer 	/* First handle the data fault, if any.  */
446144077eaSGreg Ungerer 	if (ssw & DF) {
447144077eaSGreg Ungerer 		addr = fp->un.fmtb.daddr;
448144077eaSGreg Ungerer 
449144077eaSGreg Ungerer // errorcode bit 0:	0 -> no page		1 -> protection fault
450144077eaSGreg Ungerer // errorcode bit 1:	0 -> read fault		1 -> write fault
451144077eaSGreg Ungerer 
452144077eaSGreg Ungerer // (buserr_type & SUN3_BUSERR_PROTERR)	-> protection fault
453144077eaSGreg Ungerer // (buserr_type & SUN3_BUSERR_INVALID)	-> invalid page fault
454144077eaSGreg Ungerer 
455144077eaSGreg Ungerer 		if (buserr_type & SUN3_BUSERR_PROTERR)
456144077eaSGreg Ungerer 			errorcode = 0x01;
457144077eaSGreg Ungerer 		else if (buserr_type & SUN3_BUSERR_INVALID)
458144077eaSGreg Ungerer 			errorcode = 0x00;
459144077eaSGreg Ungerer 		else {
460245b815cSGeert Uytterhoeven 			pr_debug("*** unexpected busfault type=%#04x\n",
461245b815cSGeert Uytterhoeven 				 buserr_type);
462245b815cSGeert Uytterhoeven 			pr_debug("invalid %s access at %#lx from pc %#lx\n",
463144077eaSGreg Ungerer 				 !(ssw & RW) ? "write" : "read", addr,
464144077eaSGreg Ungerer 				 fp->ptregs.pc);
465144077eaSGreg Ungerer 			die_if_kernel ("Oops", &fp->ptregs, buserr_type);
466144077eaSGreg Ungerer 			force_sig (SIGBUS, current);
467144077eaSGreg Ungerer 			return;
468144077eaSGreg Ungerer 		}
469144077eaSGreg Ungerer 
470144077eaSGreg Ungerer //todo: wtf is RM bit? --m
471144077eaSGreg Ungerer 		if (!(ssw & RW) || ssw & RM)
472144077eaSGreg Ungerer 			errorcode |= 0x02;
473144077eaSGreg Ungerer 
474144077eaSGreg Ungerer 		/* Handle page fault. */
475144077eaSGreg Ungerer 		do_page_fault (&fp->ptregs, addr, errorcode);
476144077eaSGreg Ungerer 
477144077eaSGreg Ungerer 		/* Retry the data fault now. */
478144077eaSGreg Ungerer 		return;
479144077eaSGreg Ungerer 	}
480144077eaSGreg Ungerer 
481144077eaSGreg Ungerer 	/* Now handle the instruction fault. */
482144077eaSGreg Ungerer 
483144077eaSGreg Ungerer 	/* Get the fault address. */
484144077eaSGreg Ungerer 	if (fp->ptregs.format == 0xA)
485144077eaSGreg Ungerer 		addr = fp->ptregs.pc + 4;
486144077eaSGreg Ungerer 	else
487144077eaSGreg Ungerer 		addr = fp->un.fmtb.baddr;
488144077eaSGreg Ungerer 	if (ssw & FC)
489144077eaSGreg Ungerer 		addr -= 2;
490144077eaSGreg Ungerer 
491144077eaSGreg Ungerer 	if (buserr_type & SUN3_BUSERR_INVALID) {
4925fec45a2SThomas Bogendoerfer 		if (!mmu_emu_handle_fault(addr, 1, 0))
493144077eaSGreg Ungerer 			do_page_fault (&fp->ptregs, addr, 0);
494144077eaSGreg Ungerer        } else {
495245b815cSGeert Uytterhoeven 		pr_debug("protection fault on insn access (segv).\n");
496144077eaSGreg Ungerer 		force_sig (SIGSEGV, current);
497144077eaSGreg Ungerer        }
498144077eaSGreg Ungerer }
499144077eaSGreg Ungerer #else
500144077eaSGreg Ungerer #if defined(CPU_M68020_OR_M68030)
501144077eaSGreg Ungerer static inline void bus_error030 (struct frame *fp)
502144077eaSGreg Ungerer {
503144077eaSGreg Ungerer 	volatile unsigned short temp;
504144077eaSGreg Ungerer 	unsigned short mmusr;
505144077eaSGreg Ungerer 	unsigned long addr, errorcode;
506144077eaSGreg Ungerer 	unsigned short ssw = fp->un.fmtb.ssw;
507144077eaSGreg Ungerer #ifdef DEBUG
508144077eaSGreg Ungerer 	unsigned long desc;
509245b815cSGeert Uytterhoeven #endif
510144077eaSGreg Ungerer 
511245b815cSGeert Uytterhoeven 	pr_debug("pid = %x  ", current->pid);
512245b815cSGeert Uytterhoeven 	pr_debug("SSW=%#06x  ", ssw);
513144077eaSGreg Ungerer 
514144077eaSGreg Ungerer 	if (ssw & (FC | FB))
515245b815cSGeert Uytterhoeven 		pr_debug("Instruction fault at %#010lx\n",
516144077eaSGreg Ungerer 			ssw & FC ?
517144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
518144077eaSGreg Ungerer 			:
519144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
520144077eaSGreg Ungerer 	if (ssw & DF)
521245b815cSGeert Uytterhoeven 		pr_debug("Data %s fault at %#010lx in %s (pc=%#lx)\n",
522144077eaSGreg Ungerer 			ssw & RW ? "read" : "write",
523144077eaSGreg Ungerer 			fp->un.fmtb.daddr,
524144077eaSGreg Ungerer 			space_names[ssw & DFC], fp->ptregs.pc);
525144077eaSGreg Ungerer 
526144077eaSGreg Ungerer 	/* ++andreas: If a data fault and an instruction fault happen
527144077eaSGreg Ungerer 	   at the same time map in both pages.  */
528144077eaSGreg Ungerer 
529144077eaSGreg Ungerer 	/* First handle the data fault, if any.  */
530144077eaSGreg Ungerer 	if (ssw & DF) {
531144077eaSGreg Ungerer 		addr = fp->un.fmtb.daddr;
532144077eaSGreg Ungerer 
533144077eaSGreg Ungerer #ifdef DEBUG
534144077eaSGreg Ungerer 		asm volatile ("ptestr %3,%2@,#7,%0\n\t"
5352a353506SAndreas Schwab 			      "pmove %%psr,%1"
5362a353506SAndreas Schwab 			      : "=a&" (desc), "=m" (temp)
5372a353506SAndreas Schwab 			      : "a" (addr), "d" (ssw));
538245b815cSGeert Uytterhoeven 		pr_debug("mmusr is %#x for addr %#lx in task %p\n",
539245b815cSGeert Uytterhoeven 			 temp, addr, current);
540245b815cSGeert Uytterhoeven 		pr_debug("descriptor address is 0x%p, contents %#lx\n",
541245b815cSGeert Uytterhoeven 			 __va(desc), *(unsigned long *)__va(desc));
542144077eaSGreg Ungerer #else
543144077eaSGreg Ungerer 		asm volatile ("ptestr %2,%1@,#7\n\t"
5442a353506SAndreas Schwab 			      "pmove %%psr,%0"
5452a353506SAndreas Schwab 			      : "=m" (temp) : "a" (addr), "d" (ssw));
546144077eaSGreg Ungerer #endif
547144077eaSGreg Ungerer 		mmusr = temp;
548144077eaSGreg Ungerer 		errorcode = (mmusr & MMU_I) ? 0 : 1;
549144077eaSGreg Ungerer 		if (!(ssw & RW) || (ssw & RM))
550144077eaSGreg Ungerer 			errorcode |= 2;
551144077eaSGreg Ungerer 
552144077eaSGreg Ungerer 		if (mmusr & (MMU_I | MMU_WP)) {
553144077eaSGreg Ungerer 			if (ssw & 4) {
554245b815cSGeert Uytterhoeven 				pr_err("Data %s fault at %#010lx in %s (pc=%#lx)\n",
555144077eaSGreg Ungerer 				       ssw & RW ? "read" : "write",
556144077eaSGreg Ungerer 				       fp->un.fmtb.daddr,
557144077eaSGreg Ungerer 				       space_names[ssw & DFC], fp->ptregs.pc);
558144077eaSGreg Ungerer 				goto buserr;
559144077eaSGreg Ungerer 			}
560144077eaSGreg Ungerer 			/* Don't try to do anything further if an exception was
561144077eaSGreg Ungerer 			   handled. */
562144077eaSGreg Ungerer 			if (do_page_fault (&fp->ptregs, addr, errorcode) < 0)
563144077eaSGreg Ungerer 				return;
564144077eaSGreg Ungerer 		} else if (!(mmusr & MMU_I)) {
565144077eaSGreg Ungerer 			/* probably a 020 cas fault */
566144077eaSGreg Ungerer 			if (!(ssw & RM) && send_fault_sig(&fp->ptregs) > 0)
567245b815cSGeert Uytterhoeven 				pr_err("unexpected bus error (%#x,%#x)\n", ssw,
568245b815cSGeert Uytterhoeven 				       mmusr);
569144077eaSGreg Ungerer 		} else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
570245b815cSGeert Uytterhoeven 			pr_err("invalid %s access at %#lx from pc %#lx\n",
571144077eaSGreg Ungerer 			       !(ssw & RW) ? "write" : "read", addr,
572144077eaSGreg Ungerer 			       fp->ptregs.pc);
573144077eaSGreg Ungerer 			die_if_kernel("Oops",&fp->ptregs,mmusr);
574144077eaSGreg Ungerer 			force_sig(SIGSEGV, current);
575144077eaSGreg Ungerer 			return;
576144077eaSGreg Ungerer 		} else {
577144077eaSGreg Ungerer #if 0
578144077eaSGreg Ungerer 			static volatile long tlong;
579144077eaSGreg Ungerer #endif
580144077eaSGreg Ungerer 
581245b815cSGeert Uytterhoeven 			pr_err("weird %s access at %#lx from pc %#lx (ssw is %#x)\n",
582144077eaSGreg Ungerer 			       !(ssw & RW) ? "write" : "read", addr,
583144077eaSGreg Ungerer 			       fp->ptregs.pc, ssw);
584144077eaSGreg Ungerer 			asm volatile ("ptestr #1,%1@,#0\n\t"
5852a353506SAndreas Schwab 				      "pmove %%psr,%0"
5862a353506SAndreas Schwab 				      : "=m" (temp)
5872a353506SAndreas Schwab 				      : "a" (addr));
588144077eaSGreg Ungerer 			mmusr = temp;
589144077eaSGreg Ungerer 
590245b815cSGeert Uytterhoeven 			pr_err("level 0 mmusr is %#x\n", mmusr);
591144077eaSGreg Ungerer #if 0
5922a353506SAndreas Schwab 			asm volatile ("pmove %%tt0,%0"
5932a353506SAndreas Schwab 				      : "=m" (tlong));
594245b815cSGeert Uytterhoeven 			pr_debug("tt0 is %#lx, ", tlong);
5952a353506SAndreas Schwab 			asm volatile ("pmove %%tt1,%0"
5962a353506SAndreas Schwab 				      : "=m" (tlong));
597245b815cSGeert Uytterhoeven 			pr_debug("tt1 is %#lx\n", tlong);
598144077eaSGreg Ungerer #endif
599245b815cSGeert Uytterhoeven 			pr_debug("Unknown SIGSEGV - 1\n");
600144077eaSGreg Ungerer 			die_if_kernel("Oops",&fp->ptregs,mmusr);
601144077eaSGreg Ungerer 			force_sig(SIGSEGV, current);
602144077eaSGreg Ungerer 			return;
603144077eaSGreg Ungerer 		}
604144077eaSGreg Ungerer 
605144077eaSGreg Ungerer 		/* setup an ATC entry for the access about to be retried */
606144077eaSGreg Ungerer 		if (!(ssw & RW) || (ssw & RM))
607144077eaSGreg Ungerer 			asm volatile ("ploadw %1,%0@" : /* no outputs */
608144077eaSGreg Ungerer 				      : "a" (addr), "d" (ssw));
609144077eaSGreg Ungerer 		else
610144077eaSGreg Ungerer 			asm volatile ("ploadr %1,%0@" : /* no outputs */
611144077eaSGreg Ungerer 				      : "a" (addr), "d" (ssw));
612144077eaSGreg Ungerer 	}
613144077eaSGreg Ungerer 
614144077eaSGreg Ungerer 	/* Now handle the instruction fault. */
615144077eaSGreg Ungerer 
616144077eaSGreg Ungerer 	if (!(ssw & (FC|FB)))
617144077eaSGreg Ungerer 		return;
618144077eaSGreg Ungerer 
619144077eaSGreg Ungerer 	if (fp->ptregs.sr & PS_S) {
620245b815cSGeert Uytterhoeven 		pr_err("Instruction fault at %#010lx\n", fp->ptregs.pc);
621144077eaSGreg Ungerer 	buserr:
622245b815cSGeert Uytterhoeven 		pr_err("BAD KERNEL BUSERR\n");
623144077eaSGreg Ungerer 		die_if_kernel("Oops",&fp->ptregs,0);
624144077eaSGreg Ungerer 		force_sig(SIGKILL, current);
625144077eaSGreg Ungerer 		return;
626144077eaSGreg Ungerer 	}
627144077eaSGreg Ungerer 
628144077eaSGreg Ungerer 	/* get the fault address */
629144077eaSGreg Ungerer 	if (fp->ptregs.format == 10)
630144077eaSGreg Ungerer 		addr = fp->ptregs.pc + 4;
631144077eaSGreg Ungerer 	else
632144077eaSGreg Ungerer 		addr = fp->un.fmtb.baddr;
633144077eaSGreg Ungerer 	if (ssw & FC)
634144077eaSGreg Ungerer 		addr -= 2;
635144077eaSGreg Ungerer 
636144077eaSGreg Ungerer 	if ((ssw & DF) && ((addr ^ fp->un.fmtb.daddr) & PAGE_MASK) == 0)
637144077eaSGreg Ungerer 		/* Insn fault on same page as data fault.  But we
638144077eaSGreg Ungerer 		   should still create the ATC entry.  */
639144077eaSGreg Ungerer 		goto create_atc_entry;
640144077eaSGreg Ungerer 
641144077eaSGreg Ungerer #ifdef DEBUG
642144077eaSGreg Ungerer 	asm volatile ("ptestr #1,%2@,#7,%0\n\t"
6432a353506SAndreas Schwab 		      "pmove %%psr,%1"
6442a353506SAndreas Schwab 		      : "=a&" (desc), "=m" (temp)
6452a353506SAndreas Schwab 		      : "a" (addr));
646245b815cSGeert Uytterhoeven 	pr_debug("mmusr is %#x for addr %#lx in task %p\n",
647245b815cSGeert Uytterhoeven 		temp, addr, current);
648245b815cSGeert Uytterhoeven 	pr_debug("descriptor address is 0x%p, contents %#lx\n",
649245b815cSGeert Uytterhoeven 		__va(desc), *(unsigned long *)__va(desc));
650144077eaSGreg Ungerer #else
651144077eaSGreg Ungerer 	asm volatile ("ptestr #1,%1@,#7\n\t"
6522a353506SAndreas Schwab 		      "pmove %%psr,%0"
6532a353506SAndreas Schwab 		      : "=m" (temp) : "a" (addr));
654144077eaSGreg Ungerer #endif
655144077eaSGreg Ungerer 	mmusr = temp;
656144077eaSGreg Ungerer 	if (mmusr & MMU_I)
657144077eaSGreg Ungerer 		do_page_fault (&fp->ptregs, addr, 0);
658144077eaSGreg Ungerer 	else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
659245b815cSGeert Uytterhoeven 		pr_err("invalid insn access at %#lx from pc %#lx\n",
660144077eaSGreg Ungerer 			addr, fp->ptregs.pc);
661245b815cSGeert Uytterhoeven 		pr_debug("Unknown SIGSEGV - 2\n");
662144077eaSGreg Ungerer 		die_if_kernel("Oops",&fp->ptregs,mmusr);
663144077eaSGreg Ungerer 		force_sig(SIGSEGV, current);
664144077eaSGreg Ungerer 		return;
665144077eaSGreg Ungerer 	}
666144077eaSGreg Ungerer 
667144077eaSGreg Ungerer create_atc_entry:
668144077eaSGreg Ungerer 	/* setup an ATC entry for the access about to be retried */
669144077eaSGreg Ungerer 	asm volatile ("ploadr #2,%0@" : /* no outputs */
670144077eaSGreg Ungerer 		      : "a" (addr));
671144077eaSGreg Ungerer }
672144077eaSGreg Ungerer #endif /* CPU_M68020_OR_M68030 */
673144077eaSGreg Ungerer #endif /* !CONFIG_SUN3 */
674144077eaSGreg Ungerer 
67578d705e3SGreg Ungerer #if defined(CONFIG_COLDFIRE) && defined(CONFIG_MMU)
67678d705e3SGreg Ungerer #include <asm/mcfmmu.h>
67778d705e3SGreg Ungerer 
67878d705e3SGreg Ungerer /*
67978d705e3SGreg Ungerer  *	The following table converts the FS encoding of a ColdFire
68078d705e3SGreg Ungerer  *	exception stack frame into the error_code value needed by
68178d705e3SGreg Ungerer  *	do_fault.
68278d705e3SGreg Ungerer */
68378d705e3SGreg Ungerer static const unsigned char fs_err_code[] = {
68478d705e3SGreg Ungerer 	0,  /* 0000 */
68578d705e3SGreg Ungerer 	0,  /* 0001 */
68678d705e3SGreg Ungerer 	0,  /* 0010 */
68778d705e3SGreg Ungerer 	0,  /* 0011 */
68878d705e3SGreg Ungerer 	1,  /* 0100 */
68978d705e3SGreg Ungerer 	0,  /* 0101 */
69078d705e3SGreg Ungerer 	0,  /* 0110 */
69178d705e3SGreg Ungerer 	0,  /* 0111 */
69278d705e3SGreg Ungerer 	2,  /* 1000 */
69378d705e3SGreg Ungerer 	3,  /* 1001 */
69478d705e3SGreg Ungerer 	2,  /* 1010 */
69578d705e3SGreg Ungerer 	0,  /* 1011 */
69678d705e3SGreg Ungerer 	1,  /* 1100 */
69778d705e3SGreg Ungerer 	1,  /* 1101 */
69878d705e3SGreg Ungerer 	0,  /* 1110 */
69978d705e3SGreg Ungerer 	0   /* 1111 */
70078d705e3SGreg Ungerer };
70178d705e3SGreg Ungerer 
70278d705e3SGreg Ungerer static inline void access_errorcf(unsigned int fs, struct frame *fp)
70378d705e3SGreg Ungerer {
70478d705e3SGreg Ungerer 	unsigned long mmusr, addr;
70578d705e3SGreg Ungerer 	unsigned int err_code;
70678d705e3SGreg Ungerer 	int need_page_fault;
70778d705e3SGreg Ungerer 
70878d705e3SGreg Ungerer 	mmusr = mmu_read(MMUSR);
70978d705e3SGreg Ungerer 	addr = mmu_read(MMUAR);
71078d705e3SGreg Ungerer 
71178d705e3SGreg Ungerer 	/*
71278d705e3SGreg Ungerer 	 * error_code:
71378d705e3SGreg Ungerer 	 *	bit 0 == 0 means no page found, 1 means protection fault
71478d705e3SGreg Ungerer 	 *	bit 1 == 0 means read, 1 means write
71578d705e3SGreg Ungerer 	 */
71678d705e3SGreg Ungerer 	switch (fs) {
71778d705e3SGreg Ungerer 	case  5:  /* 0101 TLB opword X miss */
71878d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 0, 0);
71978d705e3SGreg Ungerer 		addr = fp->ptregs.pc;
72078d705e3SGreg Ungerer 		break;
72178d705e3SGreg Ungerer 	case  6:  /* 0110 TLB extension word X miss */
72278d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 0, 1);
72378d705e3SGreg Ungerer 		addr = fp->ptregs.pc + sizeof(long);
72478d705e3SGreg Ungerer 		break;
72578d705e3SGreg Ungerer 	case 10:  /* 1010 TLB W miss */
72678d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 1, 1, 0);
72778d705e3SGreg Ungerer 		break;
72878d705e3SGreg Ungerer 	case 14: /* 1110 TLB R miss */
72978d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 1, 0);
73078d705e3SGreg Ungerer 		break;
73178d705e3SGreg Ungerer 	default:
73278d705e3SGreg Ungerer 		/* 0000 Normal  */
73378d705e3SGreg Ungerer 		/* 0001 Reserved */
73478d705e3SGreg Ungerer 		/* 0010 Interrupt during debug service routine */
73578d705e3SGreg Ungerer 		/* 0011 Reserved */
73678d705e3SGreg Ungerer 		/* 0100 X Protection */
73778d705e3SGreg Ungerer 		/* 0111 IFP in emulator mode */
73878d705e3SGreg Ungerer 		/* 1000 W Protection*/
73978d705e3SGreg Ungerer 		/* 1001 Write error*/
74078d705e3SGreg Ungerer 		/* 1011 Reserved*/
74178d705e3SGreg Ungerer 		/* 1100 R Protection*/
74278d705e3SGreg Ungerer 		/* 1101 R Protection*/
74378d705e3SGreg Ungerer 		/* 1111 OEP in emulator mode*/
74478d705e3SGreg Ungerer 		need_page_fault = 1;
74578d705e3SGreg Ungerer 		break;
74678d705e3SGreg Ungerer 	}
74778d705e3SGreg Ungerer 
74878d705e3SGreg Ungerer 	if (need_page_fault) {
74978d705e3SGreg Ungerer 		err_code = fs_err_code[fs];
75078d705e3SGreg Ungerer 		if ((fs == 13) && (mmusr & MMUSR_WF)) /* rd-mod-wr access */
75178d705e3SGreg Ungerer 			err_code |= 2; /* bit1 - write, bit0 - protection */
75278d705e3SGreg Ungerer 		do_page_fault(&fp->ptregs, addr, err_code);
75378d705e3SGreg Ungerer 	}
75478d705e3SGreg Ungerer }
75578d705e3SGreg Ungerer #endif /* CONFIG_COLDFIRE CONFIG_MMU */
75678d705e3SGreg Ungerer 
757144077eaSGreg Ungerer asmlinkage void buserr_c(struct frame *fp)
758144077eaSGreg Ungerer {
759144077eaSGreg Ungerer 	/* Only set esp0 if coming from user mode */
760144077eaSGreg Ungerer 	if (user_mode(&fp->ptregs))
761144077eaSGreg Ungerer 		current->thread.esp0 = (unsigned long) fp;
762144077eaSGreg Ungerer 
763245b815cSGeert Uytterhoeven 	pr_debug("*** Bus Error *** Format is %x\n", fp->ptregs.format);
764144077eaSGreg Ungerer 
76578d705e3SGreg Ungerer #if defined(CONFIG_COLDFIRE) && defined(CONFIG_MMU)
76678d705e3SGreg Ungerer 	if (CPU_IS_COLDFIRE) {
76778d705e3SGreg Ungerer 		unsigned int fs;
76878d705e3SGreg Ungerer 		fs = (fp->ptregs.vector & 0x3) |
76978d705e3SGreg Ungerer 			((fp->ptregs.vector & 0xc00) >> 8);
77078d705e3SGreg Ungerer 		switch (fs) {
77178d705e3SGreg Ungerer 		case 0x5:
77278d705e3SGreg Ungerer 		case 0x6:
77378d705e3SGreg Ungerer 		case 0x7:
77478d705e3SGreg Ungerer 		case 0x9:
77578d705e3SGreg Ungerer 		case 0xa:
77678d705e3SGreg Ungerer 		case 0xd:
77778d705e3SGreg Ungerer 		case 0xe:
77878d705e3SGreg Ungerer 		case 0xf:
77978d705e3SGreg Ungerer 			access_errorcf(fs, fp);
78078d705e3SGreg Ungerer 			return;
78178d705e3SGreg Ungerer 		default:
78278d705e3SGreg Ungerer 			break;
78378d705e3SGreg Ungerer 		}
78478d705e3SGreg Ungerer 	}
78578d705e3SGreg Ungerer #endif /* CONFIG_COLDFIRE && CONFIG_MMU */
78678d705e3SGreg Ungerer 
787144077eaSGreg Ungerer 	switch (fp->ptregs.format) {
788144077eaSGreg Ungerer #if defined (CONFIG_M68060)
789144077eaSGreg Ungerer 	case 4:				/* 68060 access error */
790144077eaSGreg Ungerer 	  access_error060 (fp);
791144077eaSGreg Ungerer 	  break;
792144077eaSGreg Ungerer #endif
793144077eaSGreg Ungerer #if defined (CONFIG_M68040)
794144077eaSGreg Ungerer 	case 0x7:			/* 68040 access error */
795144077eaSGreg Ungerer 	  access_error040 (fp);
796144077eaSGreg Ungerer 	  break;
797144077eaSGreg Ungerer #endif
798144077eaSGreg Ungerer #if defined (CPU_M68020_OR_M68030)
799144077eaSGreg Ungerer 	case 0xa:
800144077eaSGreg Ungerer 	case 0xb:
801144077eaSGreg Ungerer 	  bus_error030 (fp);
802144077eaSGreg Ungerer 	  break;
803144077eaSGreg Ungerer #endif
804144077eaSGreg Ungerer 	default:
805144077eaSGreg Ungerer 	  die_if_kernel("bad frame format",&fp->ptregs,0);
806245b815cSGeert Uytterhoeven 	  pr_debug("Unknown SIGSEGV - 4\n");
807144077eaSGreg Ungerer 	  force_sig(SIGSEGV, current);
808144077eaSGreg Ungerer 	}
809144077eaSGreg Ungerer }
810144077eaSGreg Ungerer 
811144077eaSGreg Ungerer 
812144077eaSGreg Ungerer static int kstack_depth_to_print = 48;
813144077eaSGreg Ungerer 
814144077eaSGreg Ungerer void show_trace(unsigned long *stack)
815144077eaSGreg Ungerer {
816144077eaSGreg Ungerer 	unsigned long *endstack;
817144077eaSGreg Ungerer 	unsigned long addr;
818144077eaSGreg Ungerer 	int i;
819144077eaSGreg Ungerer 
820245b815cSGeert Uytterhoeven 	pr_info("Call Trace:");
821144077eaSGreg Ungerer 	addr = (unsigned long)stack + THREAD_SIZE - 1;
822144077eaSGreg Ungerer 	endstack = (unsigned long *)(addr & -THREAD_SIZE);
823144077eaSGreg Ungerer 	i = 0;
824144077eaSGreg Ungerer 	while (stack + 1 <= endstack) {
825144077eaSGreg Ungerer 		addr = *stack++;
826144077eaSGreg Ungerer 		/*
827144077eaSGreg Ungerer 		 * If the address is either in the text segment of the
828144077eaSGreg Ungerer 		 * kernel, or in the region which contains vmalloc'ed
829144077eaSGreg Ungerer 		 * memory, it *may* be the address of a calling
830144077eaSGreg Ungerer 		 * routine; if so, print it so that someone tracing
831144077eaSGreg Ungerer 		 * down the cause of the crash will be able to figure
832144077eaSGreg Ungerer 		 * out the call path that was taken.
833144077eaSGreg Ungerer 		 */
834144077eaSGreg Ungerer 		if (__kernel_text_address(addr)) {
835144077eaSGreg Ungerer #ifndef CONFIG_KALLSYMS
836144077eaSGreg Ungerer 			if (i % 5 == 0)
837245b815cSGeert Uytterhoeven 				pr_cont("\n       ");
838144077eaSGreg Ungerer #endif
839245b815cSGeert Uytterhoeven 			pr_cont(" [<%08lx>] %pS\n", addr, (void *)addr);
840144077eaSGreg Ungerer 			i++;
841144077eaSGreg Ungerer 		}
842144077eaSGreg Ungerer 	}
843245b815cSGeert Uytterhoeven 	pr_cont("\n");
844144077eaSGreg Ungerer }
845144077eaSGreg Ungerer 
846144077eaSGreg Ungerer void show_registers(struct pt_regs *regs)
847144077eaSGreg Ungerer {
848144077eaSGreg Ungerer 	struct frame *fp = (struct frame *)regs;
849144077eaSGreg Ungerer 	mm_segment_t old_fs = get_fs();
850144077eaSGreg Ungerer 	u16 c, *cp;
851144077eaSGreg Ungerer 	unsigned long addr;
852144077eaSGreg Ungerer 	int i;
853144077eaSGreg Ungerer 
854144077eaSGreg Ungerer 	print_modules();
855245b815cSGeert Uytterhoeven 	pr_info("PC: [<%08lx>] %pS\n", regs->pc, (void *)regs->pc);
856245b815cSGeert Uytterhoeven 	pr_info("SR: %04x  SP: %p  a2: %08lx\n", regs->sr, regs, regs->a2);
857245b815cSGeert Uytterhoeven 	pr_info("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
858144077eaSGreg Ungerer 	       regs->d0, regs->d1, regs->d2, regs->d3);
859245b815cSGeert Uytterhoeven 	pr_info("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
860144077eaSGreg Ungerer 	       regs->d4, regs->d5, regs->a0, regs->a1);
861144077eaSGreg Ungerer 
862245b815cSGeert Uytterhoeven 	pr_info("Process %s (pid: %d, task=%p)\n",
863144077eaSGreg Ungerer 		current->comm, task_pid_nr(current), current);
864144077eaSGreg Ungerer 	addr = (unsigned long)&fp->un;
865245b815cSGeert Uytterhoeven 	pr_info("Frame format=%X ", regs->format);
866144077eaSGreg Ungerer 	switch (regs->format) {
867144077eaSGreg Ungerer 	case 0x2:
868245b815cSGeert Uytterhoeven 		pr_cont("instr addr=%08lx\n", fp->un.fmt2.iaddr);
869144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt2);
870144077eaSGreg Ungerer 		break;
871144077eaSGreg Ungerer 	case 0x3:
872245b815cSGeert Uytterhoeven 		pr_cont("eff addr=%08lx\n", fp->un.fmt3.effaddr);
873144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt3);
874144077eaSGreg Ungerer 		break;
875144077eaSGreg Ungerer 	case 0x4:
876245b815cSGeert Uytterhoeven 		if (CPU_IS_060)
877245b815cSGeert Uytterhoeven 			pr_cont("fault addr=%08lx fslw=%08lx\n",
878245b815cSGeert Uytterhoeven 				fp->un.fmt4.effaddr, fp->un.fmt4.pc);
879245b815cSGeert Uytterhoeven 		else
880245b815cSGeert Uytterhoeven 			pr_cont("eff addr=%08lx pc=%08lx\n",
881144077eaSGreg Ungerer 				fp->un.fmt4.effaddr, fp->un.fmt4.pc);
882144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt4);
883144077eaSGreg Ungerer 		break;
884144077eaSGreg Ungerer 	case 0x7:
885245b815cSGeert Uytterhoeven 		pr_cont("eff addr=%08lx ssw=%04x faddr=%08lx\n",
886144077eaSGreg Ungerer 			fp->un.fmt7.effaddr, fp->un.fmt7.ssw, fp->un.fmt7.faddr);
887245b815cSGeert Uytterhoeven 		pr_info("wb 1 stat/addr/data: %04x %08lx %08lx\n",
888144077eaSGreg Ungerer 			fp->un.fmt7.wb1s, fp->un.fmt7.wb1a, fp->un.fmt7.wb1dpd0);
889245b815cSGeert Uytterhoeven 		pr_info("wb 2 stat/addr/data: %04x %08lx %08lx\n",
890144077eaSGreg Ungerer 			fp->un.fmt7.wb2s, fp->un.fmt7.wb2a, fp->un.fmt7.wb2d);
891245b815cSGeert Uytterhoeven 		pr_info("wb 3 stat/addr/data: %04x %08lx %08lx\n",
892144077eaSGreg Ungerer 			fp->un.fmt7.wb3s, fp->un.fmt7.wb3a, fp->un.fmt7.wb3d);
893245b815cSGeert Uytterhoeven 		pr_info("push data: %08lx %08lx %08lx %08lx\n",
894144077eaSGreg Ungerer 			fp->un.fmt7.wb1dpd0, fp->un.fmt7.pd1, fp->un.fmt7.pd2,
895144077eaSGreg Ungerer 			fp->un.fmt7.pd3);
896144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt7);
897144077eaSGreg Ungerer 		break;
898144077eaSGreg Ungerer 	case 0x9:
899245b815cSGeert Uytterhoeven 		pr_cont("instr addr=%08lx\n", fp->un.fmt9.iaddr);
900144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt9);
901144077eaSGreg Ungerer 		break;
902144077eaSGreg Ungerer 	case 0xa:
903245b815cSGeert Uytterhoeven 		pr_cont("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
904144077eaSGreg Ungerer 			fp->un.fmta.ssw, fp->un.fmta.isc, fp->un.fmta.isb,
905144077eaSGreg Ungerer 			fp->un.fmta.daddr, fp->un.fmta.dobuf);
906144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmta);
907144077eaSGreg Ungerer 		break;
908144077eaSGreg Ungerer 	case 0xb:
909245b815cSGeert Uytterhoeven 		pr_cont("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
910144077eaSGreg Ungerer 			fp->un.fmtb.ssw, fp->un.fmtb.isc, fp->un.fmtb.isb,
911144077eaSGreg Ungerer 			fp->un.fmtb.daddr, fp->un.fmtb.dobuf);
912245b815cSGeert Uytterhoeven 		pr_info("baddr=%08lx dibuf=%08lx ver=%x\n",
913144077eaSGreg Ungerer 			fp->un.fmtb.baddr, fp->un.fmtb.dibuf, fp->un.fmtb.ver);
914144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmtb);
915144077eaSGreg Ungerer 		break;
916144077eaSGreg Ungerer 	default:
917245b815cSGeert Uytterhoeven 		pr_cont("\n");
918144077eaSGreg Ungerer 	}
919144077eaSGreg Ungerer 	show_stack(NULL, (unsigned long *)addr);
920144077eaSGreg Ungerer 
921245b815cSGeert Uytterhoeven 	pr_info("Code:");
922144077eaSGreg Ungerer 	set_fs(KERNEL_DS);
923144077eaSGreg Ungerer 	cp = (u16 *)regs->pc;
924144077eaSGreg Ungerer 	for (i = -8; i < 16; i++) {
925144077eaSGreg Ungerer 		if (get_user(c, cp + i) && i >= 0) {
926245b815cSGeert Uytterhoeven 			pr_cont(" Bad PC value.");
927144077eaSGreg Ungerer 			break;
928144077eaSGreg Ungerer 		}
929245b815cSGeert Uytterhoeven 		if (i)
930245b815cSGeert Uytterhoeven 			pr_cont(" %04x", c);
931245b815cSGeert Uytterhoeven 		else
932245b815cSGeert Uytterhoeven 			pr_cont(" <%04x>", c);
933144077eaSGreg Ungerer 	}
934144077eaSGreg Ungerer 	set_fs(old_fs);
935245b815cSGeert Uytterhoeven 	pr_cont("\n");
936144077eaSGreg Ungerer }
937144077eaSGreg Ungerer 
938144077eaSGreg Ungerer void show_stack(struct task_struct *task, unsigned long *stack)
939144077eaSGreg Ungerer {
940144077eaSGreg Ungerer 	unsigned long *p;
941144077eaSGreg Ungerer 	unsigned long *endstack;
942144077eaSGreg Ungerer 	int i;
943144077eaSGreg Ungerer 
944144077eaSGreg Ungerer 	if (!stack) {
945144077eaSGreg Ungerer 		if (task)
946144077eaSGreg Ungerer 			stack = (unsigned long *)task->thread.esp0;
947144077eaSGreg Ungerer 		else
948144077eaSGreg Ungerer 			stack = (unsigned long *)&stack;
949144077eaSGreg Ungerer 	}
950144077eaSGreg Ungerer 	endstack = (unsigned long *)(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
951144077eaSGreg Ungerer 
952245b815cSGeert Uytterhoeven 	pr_info("Stack from %08lx:", (unsigned long)stack);
953144077eaSGreg Ungerer 	p = stack;
954144077eaSGreg Ungerer 	for (i = 0; i < kstack_depth_to_print; i++) {
955144077eaSGreg Ungerer 		if (p + 1 > endstack)
956144077eaSGreg Ungerer 			break;
957144077eaSGreg Ungerer 		if (i % 8 == 0)
958245b815cSGeert Uytterhoeven 			pr_cont("\n       ");
959245b815cSGeert Uytterhoeven 		pr_cont(" %08lx", *p++);
960144077eaSGreg Ungerer 	}
961245b815cSGeert Uytterhoeven 	pr_cont("\n");
962144077eaSGreg Ungerer 	show_trace(stack);
963144077eaSGreg Ungerer }
964144077eaSGreg Ungerer 
965144077eaSGreg Ungerer /*
966144077eaSGreg Ungerer  * The vector number returned in the frame pointer may also contain
967144077eaSGreg Ungerer  * the "fs" (Fault Status) bits on ColdFire. These are in the bottom
968144077eaSGreg Ungerer  * 2 bits, and upper 2 bits. So we need to mask out the real vector
969144077eaSGreg Ungerer  * number before using it in comparisons. You don't need to do this on
970144077eaSGreg Ungerer  * real 68k parts, but it won't hurt either.
971144077eaSGreg Ungerer  */
972144077eaSGreg Ungerer 
973144077eaSGreg Ungerer void bad_super_trap (struct frame *fp)
974144077eaSGreg Ungerer {
975144077eaSGreg Ungerer 	int vector = (fp->ptregs.vector >> 2) & 0xff;
976144077eaSGreg Ungerer 
977144077eaSGreg Ungerer 	console_verbose();
978144077eaSGreg Ungerer 	if (vector < ARRAY_SIZE(vec_names))
979245b815cSGeert Uytterhoeven 		pr_err("*** %s ***   FORMAT=%X\n",
980144077eaSGreg Ungerer 			vec_names[vector],
981144077eaSGreg Ungerer 			fp->ptregs.format);
982144077eaSGreg Ungerer 	else
983245b815cSGeert Uytterhoeven 		pr_err("*** Exception %d ***   FORMAT=%X\n",
984144077eaSGreg Ungerer 			vector, fp->ptregs.format);
985144077eaSGreg Ungerer 	if (vector == VEC_ADDRERR && CPU_IS_020_OR_030) {
986144077eaSGreg Ungerer 		unsigned short ssw = fp->un.fmtb.ssw;
987144077eaSGreg Ungerer 
988245b815cSGeert Uytterhoeven 		pr_err("SSW=%#06x  ", ssw);
989144077eaSGreg Ungerer 
990144077eaSGreg Ungerer 		if (ssw & RC)
991245b815cSGeert Uytterhoeven 			pr_err("Pipe stage C instruction fault at %#010lx\n",
992144077eaSGreg Ungerer 				(fp->ptregs.format) == 0xA ?
993144077eaSGreg Ungerer 				fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2);
994144077eaSGreg Ungerer 		if (ssw & RB)
995245b815cSGeert Uytterhoeven 			pr_err("Pipe stage B instruction fault at %#010lx\n",
996144077eaSGreg Ungerer 				(fp->ptregs.format) == 0xA ?
997144077eaSGreg Ungerer 				fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
998144077eaSGreg Ungerer 		if (ssw & DF)
999245b815cSGeert Uytterhoeven 			pr_err("Data %s fault at %#010lx in %s (pc=%#lx)\n",
1000144077eaSGreg Ungerer 				ssw & RW ? "read" : "write",
1001144077eaSGreg Ungerer 				fp->un.fmtb.daddr, space_names[ssw & DFC],
1002144077eaSGreg Ungerer 				fp->ptregs.pc);
1003144077eaSGreg Ungerer 	}
1004245b815cSGeert Uytterhoeven 	pr_err("Current process id is %d\n", task_pid_nr(current));
1005144077eaSGreg Ungerer 	die_if_kernel("BAD KERNEL TRAP", &fp->ptregs, 0);
1006144077eaSGreg Ungerer }
1007144077eaSGreg Ungerer 
1008144077eaSGreg Ungerer asmlinkage void trap_c(struct frame *fp)
1009144077eaSGreg Ungerer {
1010*3c67075dSEric W. Biederman 	int sig, si_code;
1011*3c67075dSEric W. Biederman 	void __user *addr;
1012144077eaSGreg Ungerer 	int vector = (fp->ptregs.vector >> 2) & 0xff;
1013144077eaSGreg Ungerer 
1014144077eaSGreg Ungerer 	if (fp->ptregs.sr & PS_S) {
1015144077eaSGreg Ungerer 		if (vector == VEC_TRACE) {
1016144077eaSGreg Ungerer 			/* traced a trapping instruction on a 68020/30,
1017144077eaSGreg Ungerer 			 * real exception will be executed afterwards.
1018144077eaSGreg Ungerer 			 */
101968acfdcbSAl Viro 			return;
102068acfdcbSAl Viro 		}
102168acfdcbSAl Viro #ifdef CONFIG_MMU
102268acfdcbSAl Viro 		if (fixup_exception(&fp->ptregs))
102368acfdcbSAl Viro 			return;
102468acfdcbSAl Viro #endif
1025144077eaSGreg Ungerer 		bad_super_trap(fp);
1026144077eaSGreg Ungerer 		return;
1027144077eaSGreg Ungerer 	}
1028144077eaSGreg Ungerer 
1029144077eaSGreg Ungerer 	/* send the appropriate signal to the user program */
1030144077eaSGreg Ungerer 	switch (vector) {
1031144077eaSGreg Ungerer 	    case VEC_ADDRERR:
1032*3c67075dSEric W. Biederman 		si_code = BUS_ADRALN;
1033144077eaSGreg Ungerer 		sig = SIGBUS;
1034144077eaSGreg Ungerer 		break;
1035144077eaSGreg Ungerer 	    case VEC_ILLEGAL:
1036144077eaSGreg Ungerer 	    case VEC_LINE10:
1037144077eaSGreg Ungerer 	    case VEC_LINE11:
1038*3c67075dSEric W. Biederman 		si_code = ILL_ILLOPC;
1039144077eaSGreg Ungerer 		sig = SIGILL;
1040144077eaSGreg Ungerer 		break;
1041144077eaSGreg Ungerer 	    case VEC_PRIV:
1042*3c67075dSEric W. Biederman 		si_code = ILL_PRVOPC;
1043144077eaSGreg Ungerer 		sig = SIGILL;
1044144077eaSGreg Ungerer 		break;
1045144077eaSGreg Ungerer 	    case VEC_COPROC:
1046*3c67075dSEric W. Biederman 		si_code = ILL_COPROC;
1047144077eaSGreg Ungerer 		sig = SIGILL;
1048144077eaSGreg Ungerer 		break;
1049144077eaSGreg Ungerer 	    case VEC_TRAP1:
1050144077eaSGreg Ungerer 	    case VEC_TRAP2:
1051144077eaSGreg Ungerer 	    case VEC_TRAP3:
1052144077eaSGreg Ungerer 	    case VEC_TRAP4:
1053144077eaSGreg Ungerer 	    case VEC_TRAP5:
1054144077eaSGreg Ungerer 	    case VEC_TRAP6:
1055144077eaSGreg Ungerer 	    case VEC_TRAP7:
1056144077eaSGreg Ungerer 	    case VEC_TRAP8:
1057144077eaSGreg Ungerer 	    case VEC_TRAP9:
1058144077eaSGreg Ungerer 	    case VEC_TRAP10:
1059144077eaSGreg Ungerer 	    case VEC_TRAP11:
1060144077eaSGreg Ungerer 	    case VEC_TRAP12:
1061144077eaSGreg Ungerer 	    case VEC_TRAP13:
1062144077eaSGreg Ungerer 	    case VEC_TRAP14:
1063*3c67075dSEric W. Biederman 		si_code = ILL_ILLTRP;
1064144077eaSGreg Ungerer 		sig = SIGILL;
1065144077eaSGreg Ungerer 		break;
1066144077eaSGreg Ungerer 	    case VEC_FPBRUC:
1067144077eaSGreg Ungerer 	    case VEC_FPOE:
1068144077eaSGreg Ungerer 	    case VEC_FPNAN:
1069*3c67075dSEric W. Biederman 		si_code = FPE_FLTINV;
1070144077eaSGreg Ungerer 		sig = SIGFPE;
1071144077eaSGreg Ungerer 		break;
1072144077eaSGreg Ungerer 	    case VEC_FPIR:
1073*3c67075dSEric W. Biederman 		si_code = FPE_FLTRES;
1074144077eaSGreg Ungerer 		sig = SIGFPE;
1075144077eaSGreg Ungerer 		break;
1076144077eaSGreg Ungerer 	    case VEC_FPDIVZ:
1077*3c67075dSEric W. Biederman 		si_code = FPE_FLTDIV;
1078144077eaSGreg Ungerer 		sig = SIGFPE;
1079144077eaSGreg Ungerer 		break;
1080144077eaSGreg Ungerer 	    case VEC_FPUNDER:
1081*3c67075dSEric W. Biederman 		si_code = FPE_FLTUND;
1082144077eaSGreg Ungerer 		sig = SIGFPE;
1083144077eaSGreg Ungerer 		break;
1084144077eaSGreg Ungerer 	    case VEC_FPOVER:
1085*3c67075dSEric W. Biederman 		si_code = FPE_FLTOVF;
1086144077eaSGreg Ungerer 		sig = SIGFPE;
1087144077eaSGreg Ungerer 		break;
1088144077eaSGreg Ungerer 	    case VEC_ZERODIV:
1089*3c67075dSEric W. Biederman 		si_code = FPE_INTDIV;
1090144077eaSGreg Ungerer 		sig = SIGFPE;
1091144077eaSGreg Ungerer 		break;
1092144077eaSGreg Ungerer 	    case VEC_CHK:
1093144077eaSGreg Ungerer 	    case VEC_TRAP:
1094*3c67075dSEric W. Biederman 		si_code = FPE_INTOVF;
1095144077eaSGreg Ungerer 		sig = SIGFPE;
1096144077eaSGreg Ungerer 		break;
1097144077eaSGreg Ungerer 	    case VEC_TRACE:		/* ptrace single step */
1098*3c67075dSEric W. Biederman 		si_code = TRAP_TRACE;
1099144077eaSGreg Ungerer 		sig = SIGTRAP;
1100144077eaSGreg Ungerer 		break;
1101144077eaSGreg Ungerer 	    case VEC_TRAP15:		/* breakpoint */
1102*3c67075dSEric W. Biederman 		si_code = TRAP_BRKPT;
1103144077eaSGreg Ungerer 		sig = SIGTRAP;
1104144077eaSGreg Ungerer 		break;
1105144077eaSGreg Ungerer 	    default:
1106*3c67075dSEric W. Biederman 		si_code = ILL_ILLOPC;
1107144077eaSGreg Ungerer 		sig = SIGILL;
1108144077eaSGreg Ungerer 		break;
1109144077eaSGreg Ungerer 	}
1110144077eaSGreg Ungerer 	switch (fp->ptregs.format) {
1111144077eaSGreg Ungerer 	    default:
1112*3c67075dSEric W. Biederman 		addr = (void __user *) fp->ptregs.pc;
1113144077eaSGreg Ungerer 		break;
1114144077eaSGreg Ungerer 	    case 2:
1115*3c67075dSEric W. Biederman 		addr = (void __user *) fp->un.fmt2.iaddr;
1116144077eaSGreg Ungerer 		break;
1117144077eaSGreg Ungerer 	    case 7:
1118*3c67075dSEric W. Biederman 		addr = (void __user *) fp->un.fmt7.effaddr;
1119144077eaSGreg Ungerer 		break;
1120144077eaSGreg Ungerer 	    case 9:
1121*3c67075dSEric W. Biederman 		addr = (void __user *) fp->un.fmt9.iaddr;
1122144077eaSGreg Ungerer 		break;
1123144077eaSGreg Ungerer 	    case 10:
1124*3c67075dSEric W. Biederman 		addr = (void __user *) fp->un.fmta.daddr;
1125144077eaSGreg Ungerer 		break;
1126144077eaSGreg Ungerer 	    case 11:
1127*3c67075dSEric W. Biederman 		addr = (void __user*) fp->un.fmtb.daddr;
1128144077eaSGreg Ungerer 		break;
1129144077eaSGreg Ungerer 	}
1130*3c67075dSEric W. Biederman 	force_sig_fault(sig, si_code, addr, current);
1131144077eaSGreg Ungerer }
1132144077eaSGreg Ungerer 
1133144077eaSGreg Ungerer void die_if_kernel (char *str, struct pt_regs *fp, int nr)
1134144077eaSGreg Ungerer {
1135144077eaSGreg Ungerer 	if (!(fp->sr & PS_S))
1136144077eaSGreg Ungerer 		return;
1137144077eaSGreg Ungerer 
1138144077eaSGreg Ungerer 	console_verbose();
1139245b815cSGeert Uytterhoeven 	pr_crit("%s: %08x\n", str, nr);
1140144077eaSGreg Ungerer 	show_registers(fp);
1141373d4d09SRusty Russell 	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
1142144077eaSGreg Ungerer 	do_exit(SIGSEGV);
1143144077eaSGreg Ungerer }
1144144077eaSGreg Ungerer 
1145144077eaSGreg Ungerer asmlinkage void set_esp0(unsigned long ssp)
1146144077eaSGreg Ungerer {
1147144077eaSGreg Ungerer 	current->thread.esp0 = ssp;
1148144077eaSGreg Ungerer }
1149144077eaSGreg Ungerer 
1150144077eaSGreg Ungerer /*
1151144077eaSGreg Ungerer  * This function is called if an error occur while accessing
1152144077eaSGreg Ungerer  * user-space from the fpsp040 code.
1153144077eaSGreg Ungerer  */
1154144077eaSGreg Ungerer asmlinkage void fpsp040_die(void)
1155144077eaSGreg Ungerer {
1156144077eaSGreg Ungerer 	do_exit(SIGSEGV);
1157144077eaSGreg Ungerer }
1158144077eaSGreg Ungerer 
1159144077eaSGreg Ungerer #ifdef CONFIG_M68KFPU_EMU
1160144077eaSGreg Ungerer asmlinkage void fpemu_signal(int signal, int code, void *addr)
1161144077eaSGreg Ungerer {
1162*3c67075dSEric W. Biederman 	force_sig_fault(signal, code, addr, current);
1163144077eaSGreg Ungerer }
11641da177e4SLinus Torvalds #endif
1165