xref: /linux/arch/m68k/kernel/traps.c (revision 5fec45a20db3656ce36fac24639aac76c6641215)
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>
22144077eaSGreg Ungerer #include <linux/signal.h>
23144077eaSGreg Ungerer #include <linux/kernel.h>
24144077eaSGreg Ungerer #include <linux/mm.h>
25144077eaSGreg Ungerer #include <linux/module.h>
26144077eaSGreg Ungerer #include <linux/user.h>
27144077eaSGreg Ungerer #include <linux/string.h>
28144077eaSGreg Ungerer #include <linux/linkage.h>
29144077eaSGreg Ungerer #include <linux/init.h>
30144077eaSGreg Ungerer #include <linux/ptrace.h>
31144077eaSGreg Ungerer #include <linux/kallsyms.h>
32144077eaSGreg Ungerer 
33144077eaSGreg Ungerer #include <asm/setup.h>
34144077eaSGreg Ungerer #include <asm/fpu.h>
35144077eaSGreg Ungerer #include <asm/uaccess.h>
36144077eaSGreg Ungerer #include <asm/traps.h>
37144077eaSGreg Ungerer #include <asm/pgalloc.h>
38144077eaSGreg Ungerer #include <asm/machdep.h>
39144077eaSGreg Ungerer #include <asm/siginfo.h>
40144077eaSGreg Ungerer 
41144077eaSGreg Ungerer 
42144077eaSGreg Ungerer static const char *vec_names[] = {
43144077eaSGreg Ungerer 	[VEC_RESETSP]	= "RESET SP",
44144077eaSGreg Ungerer 	[VEC_RESETPC]	= "RESET PC",
45144077eaSGreg Ungerer 	[VEC_BUSERR]	= "BUS ERROR",
46144077eaSGreg Ungerer 	[VEC_ADDRERR]	= "ADDRESS ERROR",
47144077eaSGreg Ungerer 	[VEC_ILLEGAL]	= "ILLEGAL INSTRUCTION",
48144077eaSGreg Ungerer 	[VEC_ZERODIV]	= "ZERO DIVIDE",
49144077eaSGreg Ungerer 	[VEC_CHK]	= "CHK",
50144077eaSGreg Ungerer 	[VEC_TRAP]	= "TRAPcc",
51144077eaSGreg Ungerer 	[VEC_PRIV]	= "PRIVILEGE VIOLATION",
52144077eaSGreg Ungerer 	[VEC_TRACE]	= "TRACE",
53144077eaSGreg Ungerer 	[VEC_LINE10]	= "LINE 1010",
54144077eaSGreg Ungerer 	[VEC_LINE11]	= "LINE 1111",
55144077eaSGreg Ungerer 	[VEC_RESV12]	= "UNASSIGNED RESERVED 12",
56144077eaSGreg Ungerer 	[VEC_COPROC]	= "COPROCESSOR PROTOCOL VIOLATION",
57144077eaSGreg Ungerer 	[VEC_FORMAT]	= "FORMAT ERROR",
58144077eaSGreg Ungerer 	[VEC_UNINT]	= "UNINITIALIZED INTERRUPT",
59144077eaSGreg Ungerer 	[VEC_RESV16]	= "UNASSIGNED RESERVED 16",
60144077eaSGreg Ungerer 	[VEC_RESV17]	= "UNASSIGNED RESERVED 17",
61144077eaSGreg Ungerer 	[VEC_RESV18]	= "UNASSIGNED RESERVED 18",
62144077eaSGreg Ungerer 	[VEC_RESV19]	= "UNASSIGNED RESERVED 19",
63144077eaSGreg Ungerer 	[VEC_RESV20]	= "UNASSIGNED RESERVED 20",
64144077eaSGreg Ungerer 	[VEC_RESV21]	= "UNASSIGNED RESERVED 21",
65144077eaSGreg Ungerer 	[VEC_RESV22]	= "UNASSIGNED RESERVED 22",
66144077eaSGreg Ungerer 	[VEC_RESV23]	= "UNASSIGNED RESERVED 23",
67144077eaSGreg Ungerer 	[VEC_SPUR]	= "SPURIOUS INTERRUPT",
68144077eaSGreg Ungerer 	[VEC_INT1]	= "LEVEL 1 INT",
69144077eaSGreg Ungerer 	[VEC_INT2]	= "LEVEL 2 INT",
70144077eaSGreg Ungerer 	[VEC_INT3]	= "LEVEL 3 INT",
71144077eaSGreg Ungerer 	[VEC_INT4]	= "LEVEL 4 INT",
72144077eaSGreg Ungerer 	[VEC_INT5]	= "LEVEL 5 INT",
73144077eaSGreg Ungerer 	[VEC_INT6]	= "LEVEL 6 INT",
74144077eaSGreg Ungerer 	[VEC_INT7]	= "LEVEL 7 INT",
75144077eaSGreg Ungerer 	[VEC_SYS]	= "SYSCALL",
76144077eaSGreg Ungerer 	[VEC_TRAP1]	= "TRAP #1",
77144077eaSGreg Ungerer 	[VEC_TRAP2]	= "TRAP #2",
78144077eaSGreg Ungerer 	[VEC_TRAP3]	= "TRAP #3",
79144077eaSGreg Ungerer 	[VEC_TRAP4]	= "TRAP #4",
80144077eaSGreg Ungerer 	[VEC_TRAP5]	= "TRAP #5",
81144077eaSGreg Ungerer 	[VEC_TRAP6]	= "TRAP #6",
82144077eaSGreg Ungerer 	[VEC_TRAP7]	= "TRAP #7",
83144077eaSGreg Ungerer 	[VEC_TRAP8]	= "TRAP #8",
84144077eaSGreg Ungerer 	[VEC_TRAP9]	= "TRAP #9",
85144077eaSGreg Ungerer 	[VEC_TRAP10]	= "TRAP #10",
86144077eaSGreg Ungerer 	[VEC_TRAP11]	= "TRAP #11",
87144077eaSGreg Ungerer 	[VEC_TRAP12]	= "TRAP #12",
88144077eaSGreg Ungerer 	[VEC_TRAP13]	= "TRAP #13",
89144077eaSGreg Ungerer 	[VEC_TRAP14]	= "TRAP #14",
90144077eaSGreg Ungerer 	[VEC_TRAP15]	= "TRAP #15",
91144077eaSGreg Ungerer 	[VEC_FPBRUC]	= "FPCP BSUN",
92144077eaSGreg Ungerer 	[VEC_FPIR]	= "FPCP INEXACT",
93144077eaSGreg Ungerer 	[VEC_FPDIVZ]	= "FPCP DIV BY 0",
94144077eaSGreg Ungerer 	[VEC_FPUNDER]	= "FPCP UNDERFLOW",
95144077eaSGreg Ungerer 	[VEC_FPOE]	= "FPCP OPERAND ERROR",
96144077eaSGreg Ungerer 	[VEC_FPOVER]	= "FPCP OVERFLOW",
97144077eaSGreg Ungerer 	[VEC_FPNAN]	= "FPCP SNAN",
98144077eaSGreg Ungerer 	[VEC_FPUNSUP]	= "FPCP UNSUPPORTED OPERATION",
99144077eaSGreg Ungerer 	[VEC_MMUCFG]	= "MMU CONFIGURATION ERROR",
100144077eaSGreg Ungerer 	[VEC_MMUILL]	= "MMU ILLEGAL OPERATION ERROR",
101144077eaSGreg Ungerer 	[VEC_MMUACC]	= "MMU ACCESS LEVEL VIOLATION ERROR",
102144077eaSGreg Ungerer 	[VEC_RESV59]	= "UNASSIGNED RESERVED 59",
103144077eaSGreg Ungerer 	[VEC_UNIMPEA]	= "UNASSIGNED RESERVED 60",
104144077eaSGreg Ungerer 	[VEC_UNIMPII]	= "UNASSIGNED RESERVED 61",
105144077eaSGreg Ungerer 	[VEC_RESV62]	= "UNASSIGNED RESERVED 62",
106144077eaSGreg Ungerer 	[VEC_RESV63]	= "UNASSIGNED RESERVED 63",
107144077eaSGreg Ungerer };
108144077eaSGreg Ungerer 
109144077eaSGreg Ungerer static const char *space_names[] = {
110144077eaSGreg Ungerer 	[0]		= "Space 0",
111144077eaSGreg Ungerer 	[USER_DATA]	= "User Data",
112144077eaSGreg Ungerer 	[USER_PROGRAM]	= "User Program",
113144077eaSGreg Ungerer #ifndef CONFIG_SUN3
114144077eaSGreg Ungerer 	[3]		= "Space 3",
1151da177e4SLinus Torvalds #else
116144077eaSGreg Ungerer 	[FC_CONTROL]	= "Control",
117144077eaSGreg Ungerer #endif
118144077eaSGreg Ungerer 	[4]		= "Space 4",
119144077eaSGreg Ungerer 	[SUPER_DATA]	= "Super Data",
120144077eaSGreg Ungerer 	[SUPER_PROGRAM]	= "Super Program",
121144077eaSGreg Ungerer 	[CPU_SPACE]	= "CPU"
122144077eaSGreg Ungerer };
123144077eaSGreg Ungerer 
124144077eaSGreg Ungerer void die_if_kernel(char *,struct pt_regs *,int);
125144077eaSGreg Ungerer asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
126144077eaSGreg Ungerer                              unsigned long error_code);
127144077eaSGreg Ungerer int send_fault_sig(struct pt_regs *regs);
128144077eaSGreg Ungerer 
129144077eaSGreg Ungerer asmlinkage void trap_c(struct frame *fp);
130144077eaSGreg Ungerer 
131144077eaSGreg Ungerer #if defined (CONFIG_M68060)
132144077eaSGreg Ungerer static inline void access_error060 (struct frame *fp)
133144077eaSGreg Ungerer {
134144077eaSGreg Ungerer 	unsigned long fslw = fp->un.fmt4.pc; /* is really FSLW for access error */
135144077eaSGreg Ungerer 
136144077eaSGreg Ungerer #ifdef DEBUG
137144077eaSGreg Ungerer 	printk("fslw=%#lx, fa=%#lx\n", fslw, fp->un.fmt4.effaddr);
138144077eaSGreg Ungerer #endif
139144077eaSGreg Ungerer 
140144077eaSGreg Ungerer 	if (fslw & MMU060_BPE) {
141144077eaSGreg Ungerer 		/* branch prediction error -> clear branch cache */
142144077eaSGreg Ungerer 		__asm__ __volatile__ ("movec %/cacr,%/d0\n\t"
143144077eaSGreg Ungerer 				      "orl   #0x00400000,%/d0\n\t"
144144077eaSGreg Ungerer 				      "movec %/d0,%/cacr"
145144077eaSGreg Ungerer 				      : : : "d0" );
146144077eaSGreg Ungerer 		/* return if there's no other error */
147144077eaSGreg Ungerer 		if (!(fslw & MMU060_ERR_BITS) && !(fslw & MMU060_SEE))
148144077eaSGreg Ungerer 			return;
149144077eaSGreg Ungerer 	}
150144077eaSGreg Ungerer 
151144077eaSGreg Ungerer 	if (fslw & (MMU060_DESC_ERR | MMU060_WP | MMU060_SP)) {
152144077eaSGreg Ungerer 		unsigned long errorcode;
153144077eaSGreg Ungerer 		unsigned long addr = fp->un.fmt4.effaddr;
154144077eaSGreg Ungerer 
155144077eaSGreg Ungerer 		if (fslw & MMU060_MA)
156144077eaSGreg Ungerer 			addr = (addr + PAGE_SIZE - 1) & PAGE_MASK;
157144077eaSGreg Ungerer 
158144077eaSGreg Ungerer 		errorcode = 1;
159144077eaSGreg Ungerer 		if (fslw & MMU060_DESC_ERR) {
160144077eaSGreg Ungerer 			__flush_tlb040_one(addr);
161144077eaSGreg Ungerer 			errorcode = 0;
162144077eaSGreg Ungerer 		}
163144077eaSGreg Ungerer 		if (fslw & MMU060_W)
164144077eaSGreg Ungerer 			errorcode |= 2;
165144077eaSGreg Ungerer #ifdef DEBUG
166144077eaSGreg Ungerer 		printk("errorcode = %d\n", errorcode );
167144077eaSGreg Ungerer #endif
168144077eaSGreg Ungerer 		do_page_fault(&fp->ptregs, addr, errorcode);
169144077eaSGreg Ungerer 	} else if (fslw & (MMU060_SEE)){
170144077eaSGreg Ungerer 		/* Software Emulation Error.
171144077eaSGreg Ungerer 		 * fault during mem_read/mem_write in ifpsp060/os.S
172144077eaSGreg Ungerer 		 */
173144077eaSGreg Ungerer 		send_fault_sig(&fp->ptregs);
174144077eaSGreg Ungerer 	} else if (!(fslw & (MMU060_RE|MMU060_WE)) ||
175144077eaSGreg Ungerer 		   send_fault_sig(&fp->ptregs) > 0) {
176144077eaSGreg Ungerer 		printk("pc=%#lx, fa=%#lx\n", fp->ptregs.pc, fp->un.fmt4.effaddr);
177144077eaSGreg Ungerer 		printk( "68060 access error, fslw=%lx\n", fslw );
178144077eaSGreg Ungerer 		trap_c( fp );
179144077eaSGreg Ungerer 	}
180144077eaSGreg Ungerer }
181144077eaSGreg Ungerer #endif /* CONFIG_M68060 */
182144077eaSGreg Ungerer 
183144077eaSGreg Ungerer #if defined (CONFIG_M68040)
184144077eaSGreg Ungerer static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
185144077eaSGreg Ungerer {
186144077eaSGreg Ungerer 	unsigned long mmusr;
187144077eaSGreg Ungerer 	mm_segment_t old_fs = get_fs();
188144077eaSGreg Ungerer 
189144077eaSGreg Ungerer 	set_fs(MAKE_MM_SEG(wbs));
190144077eaSGreg Ungerer 
191144077eaSGreg Ungerer 	if (iswrite)
192144077eaSGreg Ungerer 		asm volatile (".chip 68040; ptestw (%0); .chip 68k" : : "a" (addr));
193144077eaSGreg Ungerer 	else
194144077eaSGreg Ungerer 		asm volatile (".chip 68040; ptestr (%0); .chip 68k" : : "a" (addr));
195144077eaSGreg Ungerer 
196144077eaSGreg Ungerer 	asm volatile (".chip 68040; movec %%mmusr,%0; .chip 68k" : "=r" (mmusr));
197144077eaSGreg Ungerer 
198144077eaSGreg Ungerer 	set_fs(old_fs);
199144077eaSGreg Ungerer 
200144077eaSGreg Ungerer 	return mmusr;
201144077eaSGreg Ungerer }
202144077eaSGreg Ungerer 
203144077eaSGreg Ungerer static inline int do_040writeback1(unsigned short wbs, unsigned long wba,
204144077eaSGreg Ungerer 				   unsigned long wbd)
205144077eaSGreg Ungerer {
206144077eaSGreg Ungerer 	int res = 0;
207144077eaSGreg Ungerer 	mm_segment_t old_fs = get_fs();
208144077eaSGreg Ungerer 
209144077eaSGreg Ungerer 	/* set_fs can not be moved, otherwise put_user() may oops */
210144077eaSGreg Ungerer 	set_fs(MAKE_MM_SEG(wbs));
211144077eaSGreg Ungerer 
212144077eaSGreg Ungerer 	switch (wbs & WBSIZ_040) {
213144077eaSGreg Ungerer 	case BA_SIZE_BYTE:
214144077eaSGreg Ungerer 		res = put_user(wbd & 0xff, (char __user *)wba);
215144077eaSGreg Ungerer 		break;
216144077eaSGreg Ungerer 	case BA_SIZE_WORD:
217144077eaSGreg Ungerer 		res = put_user(wbd & 0xffff, (short __user *)wba);
218144077eaSGreg Ungerer 		break;
219144077eaSGreg Ungerer 	case BA_SIZE_LONG:
220144077eaSGreg Ungerer 		res = put_user(wbd, (int __user *)wba);
221144077eaSGreg Ungerer 		break;
222144077eaSGreg Ungerer 	}
223144077eaSGreg Ungerer 
224144077eaSGreg Ungerer 	/* set_fs can not be moved, otherwise put_user() may oops */
225144077eaSGreg Ungerer 	set_fs(old_fs);
226144077eaSGreg Ungerer 
227144077eaSGreg Ungerer 
228144077eaSGreg Ungerer #ifdef DEBUG
229144077eaSGreg Ungerer 	printk("do_040writeback1, res=%d\n",res);
230144077eaSGreg Ungerer #endif
231144077eaSGreg Ungerer 
232144077eaSGreg Ungerer 	return res;
233144077eaSGreg Ungerer }
234144077eaSGreg Ungerer 
235144077eaSGreg Ungerer /* after an exception in a writeback the stack frame corresponding
236144077eaSGreg Ungerer  * to that exception is discarded, set a few bits in the old frame
237144077eaSGreg Ungerer  * to simulate what it should look like
238144077eaSGreg Ungerer  */
239144077eaSGreg Ungerer static inline void fix_xframe040(struct frame *fp, unsigned long wba, unsigned short wbs)
240144077eaSGreg Ungerer {
241144077eaSGreg Ungerer 	fp->un.fmt7.faddr = wba;
242144077eaSGreg Ungerer 	fp->un.fmt7.ssw = wbs & 0xff;
243144077eaSGreg Ungerer 	if (wba != current->thread.faddr)
244144077eaSGreg Ungerer 	    fp->un.fmt7.ssw |= MA_040;
245144077eaSGreg Ungerer }
246144077eaSGreg Ungerer 
247144077eaSGreg Ungerer static inline void do_040writebacks(struct frame *fp)
248144077eaSGreg Ungerer {
249144077eaSGreg Ungerer 	int res = 0;
250144077eaSGreg Ungerer #if 0
251144077eaSGreg Ungerer 	if (fp->un.fmt7.wb1s & WBV_040)
252144077eaSGreg Ungerer 		printk("access_error040: cannot handle 1st writeback. oops.\n");
253144077eaSGreg Ungerer #endif
254144077eaSGreg Ungerer 
255144077eaSGreg Ungerer 	if ((fp->un.fmt7.wb2s & WBV_040) &&
256144077eaSGreg Ungerer 	    !(fp->un.fmt7.wb2s & WBTT_040)) {
257144077eaSGreg Ungerer 		res = do_040writeback1(fp->un.fmt7.wb2s, fp->un.fmt7.wb2a,
258144077eaSGreg Ungerer 				       fp->un.fmt7.wb2d);
259144077eaSGreg Ungerer 		if (res)
260144077eaSGreg Ungerer 			fix_xframe040(fp, fp->un.fmt7.wb2a, fp->un.fmt7.wb2s);
261144077eaSGreg Ungerer 		else
262144077eaSGreg Ungerer 			fp->un.fmt7.wb2s = 0;
263144077eaSGreg Ungerer 	}
264144077eaSGreg Ungerer 
265144077eaSGreg Ungerer 	/* do the 2nd wb only if the first one was successful (except for a kernel wb) */
266144077eaSGreg Ungerer 	if (fp->un.fmt7.wb3s & WBV_040 && (!res || fp->un.fmt7.wb3s & 4)) {
267144077eaSGreg Ungerer 		res = do_040writeback1(fp->un.fmt7.wb3s, fp->un.fmt7.wb3a,
268144077eaSGreg Ungerer 				       fp->un.fmt7.wb3d);
269144077eaSGreg Ungerer 		if (res)
270144077eaSGreg Ungerer 		    {
271144077eaSGreg Ungerer 			fix_xframe040(fp, fp->un.fmt7.wb3a, fp->un.fmt7.wb3s);
272144077eaSGreg Ungerer 
273144077eaSGreg Ungerer 			fp->un.fmt7.wb2s = fp->un.fmt7.wb3s;
274144077eaSGreg Ungerer 			fp->un.fmt7.wb3s &= (~WBV_040);
275144077eaSGreg Ungerer 			fp->un.fmt7.wb2a = fp->un.fmt7.wb3a;
276144077eaSGreg Ungerer 			fp->un.fmt7.wb2d = fp->un.fmt7.wb3d;
277144077eaSGreg Ungerer 		    }
278144077eaSGreg Ungerer 		else
279144077eaSGreg Ungerer 			fp->un.fmt7.wb3s = 0;
280144077eaSGreg Ungerer 	}
281144077eaSGreg Ungerer 
282144077eaSGreg Ungerer 	if (res)
283144077eaSGreg Ungerer 		send_fault_sig(&fp->ptregs);
284144077eaSGreg Ungerer }
285144077eaSGreg Ungerer 
286144077eaSGreg Ungerer /*
287144077eaSGreg Ungerer  * called from sigreturn(), must ensure userspace code didn't
288144077eaSGreg Ungerer  * manipulate exception frame to circumvent protection, then complete
289144077eaSGreg Ungerer  * pending writebacks
290144077eaSGreg Ungerer  * we just clear TM2 to turn it into a userspace access
291144077eaSGreg Ungerer  */
292144077eaSGreg Ungerer asmlinkage void berr_040cleanup(struct frame *fp)
293144077eaSGreg Ungerer {
294144077eaSGreg Ungerer 	fp->un.fmt7.wb2s &= ~4;
295144077eaSGreg Ungerer 	fp->un.fmt7.wb3s &= ~4;
296144077eaSGreg Ungerer 
297144077eaSGreg Ungerer 	do_040writebacks(fp);
298144077eaSGreg Ungerer }
299144077eaSGreg Ungerer 
300144077eaSGreg Ungerer static inline void access_error040(struct frame *fp)
301144077eaSGreg Ungerer {
302144077eaSGreg Ungerer 	unsigned short ssw = fp->un.fmt7.ssw;
303144077eaSGreg Ungerer 	unsigned long mmusr;
304144077eaSGreg Ungerer 
305144077eaSGreg Ungerer #ifdef DEBUG
306144077eaSGreg Ungerer 	printk("ssw=%#x, fa=%#lx\n", ssw, fp->un.fmt7.faddr);
307144077eaSGreg Ungerer         printk("wb1s=%#x, wb2s=%#x, wb3s=%#x\n", fp->un.fmt7.wb1s,
308144077eaSGreg Ungerer 		fp->un.fmt7.wb2s, fp->un.fmt7.wb3s);
309144077eaSGreg Ungerer 	printk ("wb2a=%lx, wb3a=%lx, wb2d=%lx, wb3d=%lx\n",
310144077eaSGreg Ungerer 		fp->un.fmt7.wb2a, fp->un.fmt7.wb3a,
311144077eaSGreg Ungerer 		fp->un.fmt7.wb2d, fp->un.fmt7.wb3d);
312144077eaSGreg Ungerer #endif
313144077eaSGreg Ungerer 
314144077eaSGreg Ungerer 	if (ssw & ATC_040) {
315144077eaSGreg Ungerer 		unsigned long addr = fp->un.fmt7.faddr;
316144077eaSGreg Ungerer 		unsigned long errorcode;
317144077eaSGreg Ungerer 
318144077eaSGreg Ungerer 		/*
319144077eaSGreg Ungerer 		 * The MMU status has to be determined AFTER the address
320144077eaSGreg Ungerer 		 * has been corrected if there was a misaligned access (MA).
321144077eaSGreg Ungerer 		 */
322144077eaSGreg Ungerer 		if (ssw & MA_040)
323144077eaSGreg Ungerer 			addr = (addr + 7) & -8;
324144077eaSGreg Ungerer 
325144077eaSGreg Ungerer 		/* MMU error, get the MMUSR info for this access */
326144077eaSGreg Ungerer 		mmusr = probe040(!(ssw & RW_040), addr, ssw);
327144077eaSGreg Ungerer #ifdef DEBUG
328144077eaSGreg Ungerer 		printk("mmusr = %lx\n", mmusr);
329144077eaSGreg Ungerer #endif
330144077eaSGreg Ungerer 		errorcode = 1;
331144077eaSGreg Ungerer 		if (!(mmusr & MMU_R_040)) {
332144077eaSGreg Ungerer 			/* clear the invalid atc entry */
333144077eaSGreg Ungerer 			__flush_tlb040_one(addr);
334144077eaSGreg Ungerer 			errorcode = 0;
335144077eaSGreg Ungerer 		}
336144077eaSGreg Ungerer 
337144077eaSGreg Ungerer 		/* despite what documentation seems to say, RMW
338144077eaSGreg Ungerer 		 * accesses have always both the LK and RW bits set */
339144077eaSGreg Ungerer 		if (!(ssw & RW_040) || (ssw & LK_040))
340144077eaSGreg Ungerer 			errorcode |= 2;
341144077eaSGreg Ungerer 
342144077eaSGreg Ungerer 		if (do_page_fault(&fp->ptregs, addr, errorcode)) {
343144077eaSGreg Ungerer #ifdef DEBUG
344144077eaSGreg Ungerer 			printk("do_page_fault() !=0\n");
345144077eaSGreg Ungerer #endif
346144077eaSGreg Ungerer 			if (user_mode(&fp->ptregs)){
347144077eaSGreg Ungerer 				/* delay writebacks after signal delivery */
348144077eaSGreg Ungerer #ifdef DEBUG
349144077eaSGreg Ungerer 			        printk(".. was usermode - return\n");
350144077eaSGreg Ungerer #endif
351144077eaSGreg Ungerer 				return;
352144077eaSGreg Ungerer 			}
353144077eaSGreg Ungerer 			/* disable writeback into user space from kernel
354144077eaSGreg Ungerer 			 * (if do_page_fault didn't fix the mapping,
355144077eaSGreg Ungerer                          * the writeback won't do good)
356144077eaSGreg Ungerer 			 */
357144077eaSGreg Ungerer disable_wb:
358144077eaSGreg Ungerer #ifdef DEBUG
359144077eaSGreg Ungerer 			printk(".. disabling wb2\n");
360144077eaSGreg Ungerer #endif
361144077eaSGreg Ungerer 			if (fp->un.fmt7.wb2a == fp->un.fmt7.faddr)
362144077eaSGreg Ungerer 				fp->un.fmt7.wb2s &= ~WBV_040;
363144077eaSGreg Ungerer 			if (fp->un.fmt7.wb3a == fp->un.fmt7.faddr)
364144077eaSGreg Ungerer 				fp->un.fmt7.wb3s &= ~WBV_040;
365144077eaSGreg Ungerer 		}
366144077eaSGreg Ungerer 	} else {
367144077eaSGreg Ungerer 		/* In case of a bus error we either kill the process or expect
368144077eaSGreg Ungerer 		 * the kernel to catch the fault, which then is also responsible
369144077eaSGreg Ungerer 		 * for cleaning up the mess.
370144077eaSGreg Ungerer 		 */
371144077eaSGreg Ungerer 		current->thread.signo = SIGBUS;
372144077eaSGreg Ungerer 		current->thread.faddr = fp->un.fmt7.faddr;
373144077eaSGreg Ungerer 		if (send_fault_sig(&fp->ptregs) >= 0)
374144077eaSGreg Ungerer 			printk("68040 bus error (ssw=%x, faddr=%lx)\n", ssw,
375144077eaSGreg Ungerer 			       fp->un.fmt7.faddr);
376144077eaSGreg Ungerer 		goto disable_wb;
377144077eaSGreg Ungerer 	}
378144077eaSGreg Ungerer 
379144077eaSGreg Ungerer 	do_040writebacks(fp);
380144077eaSGreg Ungerer }
381144077eaSGreg Ungerer #endif /* CONFIG_M68040 */
382144077eaSGreg Ungerer 
383144077eaSGreg Ungerer #if defined(CONFIG_SUN3)
384144077eaSGreg Ungerer #include <asm/sun3mmu.h>
385144077eaSGreg Ungerer 
386144077eaSGreg Ungerer extern int mmu_emu_handle_fault (unsigned long, int, int);
387144077eaSGreg Ungerer 
388144077eaSGreg Ungerer /* sun3 version of bus_error030 */
389144077eaSGreg Ungerer 
390144077eaSGreg Ungerer static inline void bus_error030 (struct frame *fp)
391144077eaSGreg Ungerer {
392144077eaSGreg Ungerer 	unsigned char buserr_type = sun3_get_buserr ();
393144077eaSGreg Ungerer 	unsigned long addr, errorcode;
394144077eaSGreg Ungerer 	unsigned short ssw = fp->un.fmtb.ssw;
395144077eaSGreg Ungerer 	extern unsigned long _sun3_map_test_start, _sun3_map_test_end;
396144077eaSGreg Ungerer 
397144077eaSGreg Ungerer #ifdef DEBUG
398144077eaSGreg Ungerer 	if (ssw & (FC | FB))
399144077eaSGreg Ungerer 		printk ("Instruction fault at %#010lx\n",
400144077eaSGreg Ungerer 			ssw & FC ?
401144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
402144077eaSGreg Ungerer 			:
403144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
404144077eaSGreg Ungerer 	if (ssw & DF)
405144077eaSGreg Ungerer 		printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
406144077eaSGreg Ungerer 			ssw & RW ? "read" : "write",
407144077eaSGreg Ungerer 			fp->un.fmtb.daddr,
408144077eaSGreg Ungerer 			space_names[ssw & DFC], fp->ptregs.pc);
409144077eaSGreg Ungerer #endif
410144077eaSGreg Ungerer 
411144077eaSGreg Ungerer 	/*
412144077eaSGreg Ungerer 	 * Check if this page should be demand-mapped. This needs to go before
413144077eaSGreg Ungerer 	 * the testing for a bad kernel-space access (demand-mapping applies
414144077eaSGreg Ungerer 	 * to kernel accesses too).
415144077eaSGreg Ungerer 	 */
416144077eaSGreg Ungerer 
417144077eaSGreg Ungerer 	if ((ssw & DF)
418144077eaSGreg Ungerer 	    && (buserr_type & (SUN3_BUSERR_PROTERR | SUN3_BUSERR_INVALID))) {
419144077eaSGreg Ungerer 		if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 0))
420144077eaSGreg Ungerer 			return;
421144077eaSGreg Ungerer 	}
422144077eaSGreg Ungerer 
423144077eaSGreg Ungerer 	/* Check for kernel-space pagefault (BAD). */
424144077eaSGreg Ungerer 	if (fp->ptregs.sr & PS_S) {
425144077eaSGreg Ungerer 		/* kernel fault must be a data fault to user space */
426144077eaSGreg Ungerer 		if (! ((ssw & DF) && ((ssw & DFC) == USER_DATA))) {
427144077eaSGreg Ungerer 		     // try checking the kernel mappings before surrender
428144077eaSGreg Ungerer 		     if (mmu_emu_handle_fault (fp->un.fmtb.daddr, ssw & RW, 1))
429144077eaSGreg Ungerer 			  return;
430144077eaSGreg Ungerer 			/* instruction fault or kernel data fault! */
431144077eaSGreg Ungerer 			if (ssw & (FC | FB))
432144077eaSGreg Ungerer 				printk ("Instruction fault at %#010lx\n",
433144077eaSGreg Ungerer 					fp->ptregs.pc);
434144077eaSGreg Ungerer 			if (ssw & DF) {
435144077eaSGreg Ungerer 				/* was this fault incurred testing bus mappings? */
436144077eaSGreg Ungerer 				if((fp->ptregs.pc >= (unsigned long)&_sun3_map_test_start) &&
437144077eaSGreg Ungerer 				   (fp->ptregs.pc <= (unsigned long)&_sun3_map_test_end)) {
438144077eaSGreg Ungerer 					send_fault_sig(&fp->ptregs);
439144077eaSGreg Ungerer 					return;
440144077eaSGreg Ungerer 				}
441144077eaSGreg Ungerer 
442144077eaSGreg Ungerer 				printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
443144077eaSGreg Ungerer 					ssw & RW ? "read" : "write",
444144077eaSGreg Ungerer 					fp->un.fmtb.daddr,
445144077eaSGreg Ungerer 					space_names[ssw & DFC], fp->ptregs.pc);
446144077eaSGreg Ungerer 			}
447144077eaSGreg Ungerer 			printk ("BAD KERNEL BUSERR\n");
448144077eaSGreg Ungerer 
449144077eaSGreg Ungerer 			die_if_kernel("Oops", &fp->ptregs,0);
450144077eaSGreg Ungerer 			force_sig(SIGKILL, current);
451144077eaSGreg Ungerer 			return;
452144077eaSGreg Ungerer 		}
453144077eaSGreg Ungerer 	} else {
454144077eaSGreg Ungerer 		/* user fault */
455144077eaSGreg Ungerer 		if (!(ssw & (FC | FB)) && !(ssw & DF))
456144077eaSGreg Ungerer 			/* not an instruction fault or data fault! BAD */
457144077eaSGreg Ungerer 			panic ("USER BUSERR w/o instruction or data fault");
458144077eaSGreg Ungerer 	}
459144077eaSGreg Ungerer 
460144077eaSGreg Ungerer 
461144077eaSGreg Ungerer 	/* First handle the data fault, if any.  */
462144077eaSGreg Ungerer 	if (ssw & DF) {
463144077eaSGreg Ungerer 		addr = fp->un.fmtb.daddr;
464144077eaSGreg Ungerer 
465144077eaSGreg Ungerer // errorcode bit 0:	0 -> no page		1 -> protection fault
466144077eaSGreg Ungerer // errorcode bit 1:	0 -> read fault		1 -> write fault
467144077eaSGreg Ungerer 
468144077eaSGreg Ungerer // (buserr_type & SUN3_BUSERR_PROTERR)	-> protection fault
469144077eaSGreg Ungerer // (buserr_type & SUN3_BUSERR_INVALID)	-> invalid page fault
470144077eaSGreg Ungerer 
471144077eaSGreg Ungerer 		if (buserr_type & SUN3_BUSERR_PROTERR)
472144077eaSGreg Ungerer 			errorcode = 0x01;
473144077eaSGreg Ungerer 		else if (buserr_type & SUN3_BUSERR_INVALID)
474144077eaSGreg Ungerer 			errorcode = 0x00;
475144077eaSGreg Ungerer 		else {
476144077eaSGreg Ungerer #ifdef DEBUG
477144077eaSGreg Ungerer 			printk ("*** unexpected busfault type=%#04x\n", buserr_type);
478144077eaSGreg Ungerer 			printk ("invalid %s access at %#lx from pc %#lx\n",
479144077eaSGreg Ungerer 				!(ssw & RW) ? "write" : "read", addr,
480144077eaSGreg Ungerer 				fp->ptregs.pc);
481144077eaSGreg Ungerer #endif
482144077eaSGreg Ungerer 			die_if_kernel ("Oops", &fp->ptregs, buserr_type);
483144077eaSGreg Ungerer 			force_sig (SIGBUS, current);
484144077eaSGreg Ungerer 			return;
485144077eaSGreg Ungerer 		}
486144077eaSGreg Ungerer 
487144077eaSGreg Ungerer //todo: wtf is RM bit? --m
488144077eaSGreg Ungerer 		if (!(ssw & RW) || ssw & RM)
489144077eaSGreg Ungerer 			errorcode |= 0x02;
490144077eaSGreg Ungerer 
491144077eaSGreg Ungerer 		/* Handle page fault. */
492144077eaSGreg Ungerer 		do_page_fault (&fp->ptregs, addr, errorcode);
493144077eaSGreg Ungerer 
494144077eaSGreg Ungerer 		/* Retry the data fault now. */
495144077eaSGreg Ungerer 		return;
496144077eaSGreg Ungerer 	}
497144077eaSGreg Ungerer 
498144077eaSGreg Ungerer 	/* Now handle the instruction fault. */
499144077eaSGreg Ungerer 
500144077eaSGreg Ungerer 	/* Get the fault address. */
501144077eaSGreg Ungerer 	if (fp->ptregs.format == 0xA)
502144077eaSGreg Ungerer 		addr = fp->ptregs.pc + 4;
503144077eaSGreg Ungerer 	else
504144077eaSGreg Ungerer 		addr = fp->un.fmtb.baddr;
505144077eaSGreg Ungerer 	if (ssw & FC)
506144077eaSGreg Ungerer 		addr -= 2;
507144077eaSGreg Ungerer 
508144077eaSGreg Ungerer 	if (buserr_type & SUN3_BUSERR_INVALID) {
509*5fec45a2SThomas Bogendoerfer 		if (!mmu_emu_handle_fault(addr, 1, 0))
510144077eaSGreg Ungerer 			do_page_fault (&fp->ptregs, addr, 0);
511144077eaSGreg Ungerer        } else {
512144077eaSGreg Ungerer #ifdef DEBUG
513144077eaSGreg Ungerer 		printk ("protection fault on insn access (segv).\n");
514144077eaSGreg Ungerer #endif
515144077eaSGreg Ungerer 		force_sig (SIGSEGV, current);
516144077eaSGreg Ungerer        }
517144077eaSGreg Ungerer }
518144077eaSGreg Ungerer #else
519144077eaSGreg Ungerer #if defined(CPU_M68020_OR_M68030)
520144077eaSGreg Ungerer static inline void bus_error030 (struct frame *fp)
521144077eaSGreg Ungerer {
522144077eaSGreg Ungerer 	volatile unsigned short temp;
523144077eaSGreg Ungerer 	unsigned short mmusr;
524144077eaSGreg Ungerer 	unsigned long addr, errorcode;
525144077eaSGreg Ungerer 	unsigned short ssw = fp->un.fmtb.ssw;
526144077eaSGreg Ungerer #ifdef DEBUG
527144077eaSGreg Ungerer 	unsigned long desc;
528144077eaSGreg Ungerer 
529144077eaSGreg Ungerer 	printk ("pid = %x  ", current->pid);
530144077eaSGreg Ungerer 	printk ("SSW=%#06x  ", ssw);
531144077eaSGreg Ungerer 
532144077eaSGreg Ungerer 	if (ssw & (FC | FB))
533144077eaSGreg Ungerer 		printk ("Instruction fault at %#010lx\n",
534144077eaSGreg Ungerer 			ssw & FC ?
535144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2
536144077eaSGreg Ungerer 			:
537144077eaSGreg Ungerer 			fp->ptregs.format == 0xa ? fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
538144077eaSGreg Ungerer 	if (ssw & DF)
539144077eaSGreg Ungerer 		printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
540144077eaSGreg Ungerer 			ssw & RW ? "read" : "write",
541144077eaSGreg Ungerer 			fp->un.fmtb.daddr,
542144077eaSGreg Ungerer 			space_names[ssw & DFC], fp->ptregs.pc);
543144077eaSGreg Ungerer #endif
544144077eaSGreg Ungerer 
545144077eaSGreg Ungerer 	/* ++andreas: If a data fault and an instruction fault happen
546144077eaSGreg Ungerer 	   at the same time map in both pages.  */
547144077eaSGreg Ungerer 
548144077eaSGreg Ungerer 	/* First handle the data fault, if any.  */
549144077eaSGreg Ungerer 	if (ssw & DF) {
550144077eaSGreg Ungerer 		addr = fp->un.fmtb.daddr;
551144077eaSGreg Ungerer 
552144077eaSGreg Ungerer #ifdef DEBUG
553144077eaSGreg Ungerer 		asm volatile ("ptestr %3,%2@,#7,%0\n\t"
5542a353506SAndreas Schwab 			      "pmove %%psr,%1"
5552a353506SAndreas Schwab 			      : "=a&" (desc), "=m" (temp)
5562a353506SAndreas Schwab 			      : "a" (addr), "d" (ssw));
557144077eaSGreg Ungerer #else
558144077eaSGreg Ungerer 		asm volatile ("ptestr %2,%1@,#7\n\t"
5592a353506SAndreas Schwab 			      "pmove %%psr,%0"
5602a353506SAndreas Schwab 			      : "=m" (temp) : "a" (addr), "d" (ssw));
561144077eaSGreg Ungerer #endif
562144077eaSGreg Ungerer 		mmusr = temp;
563144077eaSGreg Ungerer 
564144077eaSGreg Ungerer #ifdef DEBUG
565144077eaSGreg Ungerer 		printk("mmusr is %#x for addr %#lx in task %p\n",
566144077eaSGreg Ungerer 		       mmusr, addr, current);
567144077eaSGreg Ungerer 		printk("descriptor address is %#lx, contents %#lx\n",
568144077eaSGreg Ungerer 		       __va(desc), *(unsigned long *)__va(desc));
569144077eaSGreg Ungerer #endif
570144077eaSGreg Ungerer 
571144077eaSGreg Ungerer 		errorcode = (mmusr & MMU_I) ? 0 : 1;
572144077eaSGreg Ungerer 		if (!(ssw & RW) || (ssw & RM))
573144077eaSGreg Ungerer 			errorcode |= 2;
574144077eaSGreg Ungerer 
575144077eaSGreg Ungerer 		if (mmusr & (MMU_I | MMU_WP)) {
576144077eaSGreg Ungerer 			if (ssw & 4) {
577144077eaSGreg Ungerer 				printk("Data %s fault at %#010lx in %s (pc=%#lx)\n",
578144077eaSGreg Ungerer 				       ssw & RW ? "read" : "write",
579144077eaSGreg Ungerer 				       fp->un.fmtb.daddr,
580144077eaSGreg Ungerer 				       space_names[ssw & DFC], fp->ptregs.pc);
581144077eaSGreg Ungerer 				goto buserr;
582144077eaSGreg Ungerer 			}
583144077eaSGreg Ungerer 			/* Don't try to do anything further if an exception was
584144077eaSGreg Ungerer 			   handled. */
585144077eaSGreg Ungerer 			if (do_page_fault (&fp->ptregs, addr, errorcode) < 0)
586144077eaSGreg Ungerer 				return;
587144077eaSGreg Ungerer 		} else if (!(mmusr & MMU_I)) {
588144077eaSGreg Ungerer 			/* probably a 020 cas fault */
589144077eaSGreg Ungerer 			if (!(ssw & RM) && send_fault_sig(&fp->ptregs) > 0)
590144077eaSGreg Ungerer 				printk("unexpected bus error (%#x,%#x)\n", ssw, mmusr);
591144077eaSGreg Ungerer 		} else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
592144077eaSGreg Ungerer 			printk("invalid %s access at %#lx from pc %#lx\n",
593144077eaSGreg Ungerer 			       !(ssw & RW) ? "write" : "read", addr,
594144077eaSGreg Ungerer 			       fp->ptregs.pc);
595144077eaSGreg Ungerer 			die_if_kernel("Oops",&fp->ptregs,mmusr);
596144077eaSGreg Ungerer 			force_sig(SIGSEGV, current);
597144077eaSGreg Ungerer 			return;
598144077eaSGreg Ungerer 		} else {
599144077eaSGreg Ungerer #if 0
600144077eaSGreg Ungerer 			static volatile long tlong;
601144077eaSGreg Ungerer #endif
602144077eaSGreg Ungerer 
603144077eaSGreg Ungerer 			printk("weird %s access at %#lx from pc %#lx (ssw is %#x)\n",
604144077eaSGreg Ungerer 			       !(ssw & RW) ? "write" : "read", addr,
605144077eaSGreg Ungerer 			       fp->ptregs.pc, ssw);
606144077eaSGreg Ungerer 			asm volatile ("ptestr #1,%1@,#0\n\t"
6072a353506SAndreas Schwab 				      "pmove %%psr,%0"
6082a353506SAndreas Schwab 				      : "=m" (temp)
6092a353506SAndreas Schwab 				      : "a" (addr));
610144077eaSGreg Ungerer 			mmusr = temp;
611144077eaSGreg Ungerer 
612144077eaSGreg Ungerer 			printk ("level 0 mmusr is %#x\n", mmusr);
613144077eaSGreg Ungerer #if 0
6142a353506SAndreas Schwab 			asm volatile ("pmove %%tt0,%0"
6152a353506SAndreas Schwab 				      : "=m" (tlong));
616144077eaSGreg Ungerer 			printk("tt0 is %#lx, ", tlong);
6172a353506SAndreas Schwab 			asm volatile ("pmove %%tt1,%0"
6182a353506SAndreas Schwab 				      : "=m" (tlong));
619144077eaSGreg Ungerer 			printk("tt1 is %#lx\n", tlong);
620144077eaSGreg Ungerer #endif
621144077eaSGreg Ungerer #ifdef DEBUG
622144077eaSGreg Ungerer 			printk("Unknown SIGSEGV - 1\n");
623144077eaSGreg Ungerer #endif
624144077eaSGreg Ungerer 			die_if_kernel("Oops",&fp->ptregs,mmusr);
625144077eaSGreg Ungerer 			force_sig(SIGSEGV, current);
626144077eaSGreg Ungerer 			return;
627144077eaSGreg Ungerer 		}
628144077eaSGreg Ungerer 
629144077eaSGreg Ungerer 		/* setup an ATC entry for the access about to be retried */
630144077eaSGreg Ungerer 		if (!(ssw & RW) || (ssw & RM))
631144077eaSGreg Ungerer 			asm volatile ("ploadw %1,%0@" : /* no outputs */
632144077eaSGreg Ungerer 				      : "a" (addr), "d" (ssw));
633144077eaSGreg Ungerer 		else
634144077eaSGreg Ungerer 			asm volatile ("ploadr %1,%0@" : /* no outputs */
635144077eaSGreg Ungerer 				      : "a" (addr), "d" (ssw));
636144077eaSGreg Ungerer 	}
637144077eaSGreg Ungerer 
638144077eaSGreg Ungerer 	/* Now handle the instruction fault. */
639144077eaSGreg Ungerer 
640144077eaSGreg Ungerer 	if (!(ssw & (FC|FB)))
641144077eaSGreg Ungerer 		return;
642144077eaSGreg Ungerer 
643144077eaSGreg Ungerer 	if (fp->ptregs.sr & PS_S) {
644144077eaSGreg Ungerer 		printk("Instruction fault at %#010lx\n",
645144077eaSGreg Ungerer 			fp->ptregs.pc);
646144077eaSGreg Ungerer 	buserr:
647144077eaSGreg Ungerer 		printk ("BAD KERNEL BUSERR\n");
648144077eaSGreg Ungerer 		die_if_kernel("Oops",&fp->ptregs,0);
649144077eaSGreg Ungerer 		force_sig(SIGKILL, current);
650144077eaSGreg Ungerer 		return;
651144077eaSGreg Ungerer 	}
652144077eaSGreg Ungerer 
653144077eaSGreg Ungerer 	/* get the fault address */
654144077eaSGreg Ungerer 	if (fp->ptregs.format == 10)
655144077eaSGreg Ungerer 		addr = fp->ptregs.pc + 4;
656144077eaSGreg Ungerer 	else
657144077eaSGreg Ungerer 		addr = fp->un.fmtb.baddr;
658144077eaSGreg Ungerer 	if (ssw & FC)
659144077eaSGreg Ungerer 		addr -= 2;
660144077eaSGreg Ungerer 
661144077eaSGreg Ungerer 	if ((ssw & DF) && ((addr ^ fp->un.fmtb.daddr) & PAGE_MASK) == 0)
662144077eaSGreg Ungerer 		/* Insn fault on same page as data fault.  But we
663144077eaSGreg Ungerer 		   should still create the ATC entry.  */
664144077eaSGreg Ungerer 		goto create_atc_entry;
665144077eaSGreg Ungerer 
666144077eaSGreg Ungerer #ifdef DEBUG
667144077eaSGreg Ungerer 	asm volatile ("ptestr #1,%2@,#7,%0\n\t"
6682a353506SAndreas Schwab 		      "pmove %%psr,%1"
6692a353506SAndreas Schwab 		      : "=a&" (desc), "=m" (temp)
6702a353506SAndreas Schwab 		      : "a" (addr));
671144077eaSGreg Ungerer #else
672144077eaSGreg Ungerer 	asm volatile ("ptestr #1,%1@,#7\n\t"
6732a353506SAndreas Schwab 		      "pmove %%psr,%0"
6742a353506SAndreas Schwab 		      : "=m" (temp) : "a" (addr));
675144077eaSGreg Ungerer #endif
676144077eaSGreg Ungerer 	mmusr = temp;
677144077eaSGreg Ungerer 
678144077eaSGreg Ungerer #ifdef DEBUG
679144077eaSGreg Ungerer 	printk ("mmusr is %#x for addr %#lx in task %p\n",
680144077eaSGreg Ungerer 		mmusr, addr, current);
681144077eaSGreg Ungerer 	printk ("descriptor address is %#lx, contents %#lx\n",
682144077eaSGreg Ungerer 		__va(desc), *(unsigned long *)__va(desc));
683144077eaSGreg Ungerer #endif
684144077eaSGreg Ungerer 
685144077eaSGreg Ungerer 	if (mmusr & MMU_I)
686144077eaSGreg Ungerer 		do_page_fault (&fp->ptregs, addr, 0);
687144077eaSGreg Ungerer 	else if (mmusr & (MMU_B|MMU_L|MMU_S)) {
688144077eaSGreg Ungerer 		printk ("invalid insn access at %#lx from pc %#lx\n",
689144077eaSGreg Ungerer 			addr, fp->ptregs.pc);
690144077eaSGreg Ungerer #ifdef DEBUG
691144077eaSGreg Ungerer 		printk("Unknown SIGSEGV - 2\n");
692144077eaSGreg Ungerer #endif
693144077eaSGreg Ungerer 		die_if_kernel("Oops",&fp->ptregs,mmusr);
694144077eaSGreg Ungerer 		force_sig(SIGSEGV, current);
695144077eaSGreg Ungerer 		return;
696144077eaSGreg Ungerer 	}
697144077eaSGreg Ungerer 
698144077eaSGreg Ungerer create_atc_entry:
699144077eaSGreg Ungerer 	/* setup an ATC entry for the access about to be retried */
700144077eaSGreg Ungerer 	asm volatile ("ploadr #2,%0@" : /* no outputs */
701144077eaSGreg Ungerer 		      : "a" (addr));
702144077eaSGreg Ungerer }
703144077eaSGreg Ungerer #endif /* CPU_M68020_OR_M68030 */
704144077eaSGreg Ungerer #endif /* !CONFIG_SUN3 */
705144077eaSGreg Ungerer 
70678d705e3SGreg Ungerer #if defined(CONFIG_COLDFIRE) && defined(CONFIG_MMU)
70778d705e3SGreg Ungerer #include <asm/mcfmmu.h>
70878d705e3SGreg Ungerer 
70978d705e3SGreg Ungerer /*
71078d705e3SGreg Ungerer  *	The following table converts the FS encoding of a ColdFire
71178d705e3SGreg Ungerer  *	exception stack frame into the error_code value needed by
71278d705e3SGreg Ungerer  *	do_fault.
71378d705e3SGreg Ungerer */
71478d705e3SGreg Ungerer static const unsigned char fs_err_code[] = {
71578d705e3SGreg Ungerer 	0,  /* 0000 */
71678d705e3SGreg Ungerer 	0,  /* 0001 */
71778d705e3SGreg Ungerer 	0,  /* 0010 */
71878d705e3SGreg Ungerer 	0,  /* 0011 */
71978d705e3SGreg Ungerer 	1,  /* 0100 */
72078d705e3SGreg Ungerer 	0,  /* 0101 */
72178d705e3SGreg Ungerer 	0,  /* 0110 */
72278d705e3SGreg Ungerer 	0,  /* 0111 */
72378d705e3SGreg Ungerer 	2,  /* 1000 */
72478d705e3SGreg Ungerer 	3,  /* 1001 */
72578d705e3SGreg Ungerer 	2,  /* 1010 */
72678d705e3SGreg Ungerer 	0,  /* 1011 */
72778d705e3SGreg Ungerer 	1,  /* 1100 */
72878d705e3SGreg Ungerer 	1,  /* 1101 */
72978d705e3SGreg Ungerer 	0,  /* 1110 */
73078d705e3SGreg Ungerer 	0   /* 1111 */
73178d705e3SGreg Ungerer };
73278d705e3SGreg Ungerer 
73378d705e3SGreg Ungerer static inline void access_errorcf(unsigned int fs, struct frame *fp)
73478d705e3SGreg Ungerer {
73578d705e3SGreg Ungerer 	unsigned long mmusr, addr;
73678d705e3SGreg Ungerer 	unsigned int err_code;
73778d705e3SGreg Ungerer 	int need_page_fault;
73878d705e3SGreg Ungerer 
73978d705e3SGreg Ungerer 	mmusr = mmu_read(MMUSR);
74078d705e3SGreg Ungerer 	addr = mmu_read(MMUAR);
74178d705e3SGreg Ungerer 
74278d705e3SGreg Ungerer 	/*
74378d705e3SGreg Ungerer 	 * error_code:
74478d705e3SGreg Ungerer 	 *	bit 0 == 0 means no page found, 1 means protection fault
74578d705e3SGreg Ungerer 	 *	bit 1 == 0 means read, 1 means write
74678d705e3SGreg Ungerer 	 */
74778d705e3SGreg Ungerer 	switch (fs) {
74878d705e3SGreg Ungerer 	case  5:  /* 0101 TLB opword X miss */
74978d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 0, 0);
75078d705e3SGreg Ungerer 		addr = fp->ptregs.pc;
75178d705e3SGreg Ungerer 		break;
75278d705e3SGreg Ungerer 	case  6:  /* 0110 TLB extension word X miss */
75378d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 0, 1);
75478d705e3SGreg Ungerer 		addr = fp->ptregs.pc + sizeof(long);
75578d705e3SGreg Ungerer 		break;
75678d705e3SGreg Ungerer 	case 10:  /* 1010 TLB W miss */
75778d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 1, 1, 0);
75878d705e3SGreg Ungerer 		break;
75978d705e3SGreg Ungerer 	case 14: /* 1110 TLB R miss */
76078d705e3SGreg Ungerer 		need_page_fault = cf_tlb_miss(&fp->ptregs, 0, 1, 0);
76178d705e3SGreg Ungerer 		break;
76278d705e3SGreg Ungerer 	default:
76378d705e3SGreg Ungerer 		/* 0000 Normal  */
76478d705e3SGreg Ungerer 		/* 0001 Reserved */
76578d705e3SGreg Ungerer 		/* 0010 Interrupt during debug service routine */
76678d705e3SGreg Ungerer 		/* 0011 Reserved */
76778d705e3SGreg Ungerer 		/* 0100 X Protection */
76878d705e3SGreg Ungerer 		/* 0111 IFP in emulator mode */
76978d705e3SGreg Ungerer 		/* 1000 W Protection*/
77078d705e3SGreg Ungerer 		/* 1001 Write error*/
77178d705e3SGreg Ungerer 		/* 1011 Reserved*/
77278d705e3SGreg Ungerer 		/* 1100 R Protection*/
77378d705e3SGreg Ungerer 		/* 1101 R Protection*/
77478d705e3SGreg Ungerer 		/* 1111 OEP in emulator mode*/
77578d705e3SGreg Ungerer 		need_page_fault = 1;
77678d705e3SGreg Ungerer 		break;
77778d705e3SGreg Ungerer 	}
77878d705e3SGreg Ungerer 
77978d705e3SGreg Ungerer 	if (need_page_fault) {
78078d705e3SGreg Ungerer 		err_code = fs_err_code[fs];
78178d705e3SGreg Ungerer 		if ((fs == 13) && (mmusr & MMUSR_WF)) /* rd-mod-wr access */
78278d705e3SGreg Ungerer 			err_code |= 2; /* bit1 - write, bit0 - protection */
78378d705e3SGreg Ungerer 		do_page_fault(&fp->ptregs, addr, err_code);
78478d705e3SGreg Ungerer 	}
78578d705e3SGreg Ungerer }
78678d705e3SGreg Ungerer #endif /* CONFIG_COLDFIRE CONFIG_MMU */
78778d705e3SGreg Ungerer 
788144077eaSGreg Ungerer asmlinkage void buserr_c(struct frame *fp)
789144077eaSGreg Ungerer {
790144077eaSGreg Ungerer 	/* Only set esp0 if coming from user mode */
791144077eaSGreg Ungerer 	if (user_mode(&fp->ptregs))
792144077eaSGreg Ungerer 		current->thread.esp0 = (unsigned long) fp;
793144077eaSGreg Ungerer 
794144077eaSGreg Ungerer #ifdef DEBUG
795144077eaSGreg Ungerer 	printk ("*** Bus Error *** Format is %x\n", fp->ptregs.format);
796144077eaSGreg Ungerer #endif
797144077eaSGreg Ungerer 
79878d705e3SGreg Ungerer #if defined(CONFIG_COLDFIRE) && defined(CONFIG_MMU)
79978d705e3SGreg Ungerer 	if (CPU_IS_COLDFIRE) {
80078d705e3SGreg Ungerer 		unsigned int fs;
80178d705e3SGreg Ungerer 		fs = (fp->ptregs.vector & 0x3) |
80278d705e3SGreg Ungerer 			((fp->ptregs.vector & 0xc00) >> 8);
80378d705e3SGreg Ungerer 		switch (fs) {
80478d705e3SGreg Ungerer 		case 0x5:
80578d705e3SGreg Ungerer 		case 0x6:
80678d705e3SGreg Ungerer 		case 0x7:
80778d705e3SGreg Ungerer 		case 0x9:
80878d705e3SGreg Ungerer 		case 0xa:
80978d705e3SGreg Ungerer 		case 0xd:
81078d705e3SGreg Ungerer 		case 0xe:
81178d705e3SGreg Ungerer 		case 0xf:
81278d705e3SGreg Ungerer 			access_errorcf(fs, fp);
81378d705e3SGreg Ungerer 			return;
81478d705e3SGreg Ungerer 		default:
81578d705e3SGreg Ungerer 			break;
81678d705e3SGreg Ungerer 		}
81778d705e3SGreg Ungerer 	}
81878d705e3SGreg Ungerer #endif /* CONFIG_COLDFIRE && CONFIG_MMU */
81978d705e3SGreg Ungerer 
820144077eaSGreg Ungerer 	switch (fp->ptregs.format) {
821144077eaSGreg Ungerer #if defined (CONFIG_M68060)
822144077eaSGreg Ungerer 	case 4:				/* 68060 access error */
823144077eaSGreg Ungerer 	  access_error060 (fp);
824144077eaSGreg Ungerer 	  break;
825144077eaSGreg Ungerer #endif
826144077eaSGreg Ungerer #if defined (CONFIG_M68040)
827144077eaSGreg Ungerer 	case 0x7:			/* 68040 access error */
828144077eaSGreg Ungerer 	  access_error040 (fp);
829144077eaSGreg Ungerer 	  break;
830144077eaSGreg Ungerer #endif
831144077eaSGreg Ungerer #if defined (CPU_M68020_OR_M68030)
832144077eaSGreg Ungerer 	case 0xa:
833144077eaSGreg Ungerer 	case 0xb:
834144077eaSGreg Ungerer 	  bus_error030 (fp);
835144077eaSGreg Ungerer 	  break;
836144077eaSGreg Ungerer #endif
837144077eaSGreg Ungerer 	default:
838144077eaSGreg Ungerer 	  die_if_kernel("bad frame format",&fp->ptregs,0);
839144077eaSGreg Ungerer #ifdef DEBUG
840144077eaSGreg Ungerer 	  printk("Unknown SIGSEGV - 4\n");
841144077eaSGreg Ungerer #endif
842144077eaSGreg Ungerer 	  force_sig(SIGSEGV, current);
843144077eaSGreg Ungerer 	}
844144077eaSGreg Ungerer }
845144077eaSGreg Ungerer 
846144077eaSGreg Ungerer 
847144077eaSGreg Ungerer static int kstack_depth_to_print = 48;
848144077eaSGreg Ungerer 
849144077eaSGreg Ungerer void show_trace(unsigned long *stack)
850144077eaSGreg Ungerer {
851144077eaSGreg Ungerer 	unsigned long *endstack;
852144077eaSGreg Ungerer 	unsigned long addr;
853144077eaSGreg Ungerer 	int i;
854144077eaSGreg Ungerer 
855144077eaSGreg Ungerer 	printk("Call Trace:");
856144077eaSGreg Ungerer 	addr = (unsigned long)stack + THREAD_SIZE - 1;
857144077eaSGreg Ungerer 	endstack = (unsigned long *)(addr & -THREAD_SIZE);
858144077eaSGreg Ungerer 	i = 0;
859144077eaSGreg Ungerer 	while (stack + 1 <= endstack) {
860144077eaSGreg Ungerer 		addr = *stack++;
861144077eaSGreg Ungerer 		/*
862144077eaSGreg Ungerer 		 * If the address is either in the text segment of the
863144077eaSGreg Ungerer 		 * kernel, or in the region which contains vmalloc'ed
864144077eaSGreg Ungerer 		 * memory, it *may* be the address of a calling
865144077eaSGreg Ungerer 		 * routine; if so, print it so that someone tracing
866144077eaSGreg Ungerer 		 * down the cause of the crash will be able to figure
867144077eaSGreg Ungerer 		 * out the call path that was taken.
868144077eaSGreg Ungerer 		 */
869144077eaSGreg Ungerer 		if (__kernel_text_address(addr)) {
870144077eaSGreg Ungerer #ifndef CONFIG_KALLSYMS
871144077eaSGreg Ungerer 			if (i % 5 == 0)
872144077eaSGreg Ungerer 				printk("\n       ");
873144077eaSGreg Ungerer #endif
874144077eaSGreg Ungerer 			printk(" [<%08lx>] %pS\n", addr, (void *)addr);
875144077eaSGreg Ungerer 			i++;
876144077eaSGreg Ungerer 		}
877144077eaSGreg Ungerer 	}
878144077eaSGreg Ungerer 	printk("\n");
879144077eaSGreg Ungerer }
880144077eaSGreg Ungerer 
881144077eaSGreg Ungerer void show_registers(struct pt_regs *regs)
882144077eaSGreg Ungerer {
883144077eaSGreg Ungerer 	struct frame *fp = (struct frame *)regs;
884144077eaSGreg Ungerer 	mm_segment_t old_fs = get_fs();
885144077eaSGreg Ungerer 	u16 c, *cp;
886144077eaSGreg Ungerer 	unsigned long addr;
887144077eaSGreg Ungerer 	int i;
888144077eaSGreg Ungerer 
889144077eaSGreg Ungerer 	print_modules();
890144077eaSGreg Ungerer 	printk("PC: [<%08lx>] %pS\n", regs->pc, (void *)regs->pc);
891144077eaSGreg Ungerer 	printk("SR: %04x  SP: %p  a2: %08lx\n", regs->sr, regs, regs->a2);
892144077eaSGreg Ungerer 	printk("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
893144077eaSGreg Ungerer 	       regs->d0, regs->d1, regs->d2, regs->d3);
894144077eaSGreg Ungerer 	printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
895144077eaSGreg Ungerer 	       regs->d4, regs->d5, regs->a0, regs->a1);
896144077eaSGreg Ungerer 
897144077eaSGreg Ungerer 	printk("Process %s (pid: %d, task=%p)\n",
898144077eaSGreg Ungerer 		current->comm, task_pid_nr(current), current);
899144077eaSGreg Ungerer 	addr = (unsigned long)&fp->un;
900144077eaSGreg Ungerer 	printk("Frame format=%X ", regs->format);
901144077eaSGreg Ungerer 	switch (regs->format) {
902144077eaSGreg Ungerer 	case 0x2:
903144077eaSGreg Ungerer 		printk("instr addr=%08lx\n", fp->un.fmt2.iaddr);
904144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt2);
905144077eaSGreg Ungerer 		break;
906144077eaSGreg Ungerer 	case 0x3:
907144077eaSGreg Ungerer 		printk("eff addr=%08lx\n", fp->un.fmt3.effaddr);
908144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt3);
909144077eaSGreg Ungerer 		break;
910144077eaSGreg Ungerer 	case 0x4:
911144077eaSGreg Ungerer 		printk((CPU_IS_060 ? "fault addr=%08lx fslw=%08lx\n"
912144077eaSGreg Ungerer 			: "eff addr=%08lx pc=%08lx\n"),
913144077eaSGreg Ungerer 			fp->un.fmt4.effaddr, fp->un.fmt4.pc);
914144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt4);
915144077eaSGreg Ungerer 		break;
916144077eaSGreg Ungerer 	case 0x7:
917144077eaSGreg Ungerer 		printk("eff addr=%08lx ssw=%04x faddr=%08lx\n",
918144077eaSGreg Ungerer 			fp->un.fmt7.effaddr, fp->un.fmt7.ssw, fp->un.fmt7.faddr);
919144077eaSGreg Ungerer 		printk("wb 1 stat/addr/data: %04x %08lx %08lx\n",
920144077eaSGreg Ungerer 			fp->un.fmt7.wb1s, fp->un.fmt7.wb1a, fp->un.fmt7.wb1dpd0);
921144077eaSGreg Ungerer 		printk("wb 2 stat/addr/data: %04x %08lx %08lx\n",
922144077eaSGreg Ungerer 			fp->un.fmt7.wb2s, fp->un.fmt7.wb2a, fp->un.fmt7.wb2d);
923144077eaSGreg Ungerer 		printk("wb 3 stat/addr/data: %04x %08lx %08lx\n",
924144077eaSGreg Ungerer 			fp->un.fmt7.wb3s, fp->un.fmt7.wb3a, fp->un.fmt7.wb3d);
925144077eaSGreg Ungerer 		printk("push data: %08lx %08lx %08lx %08lx\n",
926144077eaSGreg Ungerer 			fp->un.fmt7.wb1dpd0, fp->un.fmt7.pd1, fp->un.fmt7.pd2,
927144077eaSGreg Ungerer 			fp->un.fmt7.pd3);
928144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt7);
929144077eaSGreg Ungerer 		break;
930144077eaSGreg Ungerer 	case 0x9:
931144077eaSGreg Ungerer 		printk("instr addr=%08lx\n", fp->un.fmt9.iaddr);
932144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmt9);
933144077eaSGreg Ungerer 		break;
934144077eaSGreg Ungerer 	case 0xa:
935144077eaSGreg Ungerer 		printk("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
936144077eaSGreg Ungerer 			fp->un.fmta.ssw, fp->un.fmta.isc, fp->un.fmta.isb,
937144077eaSGreg Ungerer 			fp->un.fmta.daddr, fp->un.fmta.dobuf);
938144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmta);
939144077eaSGreg Ungerer 		break;
940144077eaSGreg Ungerer 	case 0xb:
941144077eaSGreg Ungerer 		printk("ssw=%04x isc=%04x isb=%04x daddr=%08lx dobuf=%08lx\n",
942144077eaSGreg Ungerer 			fp->un.fmtb.ssw, fp->un.fmtb.isc, fp->un.fmtb.isb,
943144077eaSGreg Ungerer 			fp->un.fmtb.daddr, fp->un.fmtb.dobuf);
944144077eaSGreg Ungerer 		printk("baddr=%08lx dibuf=%08lx ver=%x\n",
945144077eaSGreg Ungerer 			fp->un.fmtb.baddr, fp->un.fmtb.dibuf, fp->un.fmtb.ver);
946144077eaSGreg Ungerer 		addr += sizeof(fp->un.fmtb);
947144077eaSGreg Ungerer 		break;
948144077eaSGreg Ungerer 	default:
949144077eaSGreg Ungerer 		printk("\n");
950144077eaSGreg Ungerer 	}
951144077eaSGreg Ungerer 	show_stack(NULL, (unsigned long *)addr);
952144077eaSGreg Ungerer 
953144077eaSGreg Ungerer 	printk("Code:");
954144077eaSGreg Ungerer 	set_fs(KERNEL_DS);
955144077eaSGreg Ungerer 	cp = (u16 *)regs->pc;
956144077eaSGreg Ungerer 	for (i = -8; i < 16; i++) {
957144077eaSGreg Ungerer 		if (get_user(c, cp + i) && i >= 0) {
958144077eaSGreg Ungerer 			printk(" Bad PC value.");
959144077eaSGreg Ungerer 			break;
960144077eaSGreg Ungerer 		}
961144077eaSGreg Ungerer 		printk(i ? " %04x" : " <%04x>", c);
962144077eaSGreg Ungerer 	}
963144077eaSGreg Ungerer 	set_fs(old_fs);
964144077eaSGreg Ungerer 	printk ("\n");
965144077eaSGreg Ungerer }
966144077eaSGreg Ungerer 
967144077eaSGreg Ungerer void show_stack(struct task_struct *task, unsigned long *stack)
968144077eaSGreg Ungerer {
969144077eaSGreg Ungerer 	unsigned long *p;
970144077eaSGreg Ungerer 	unsigned long *endstack;
971144077eaSGreg Ungerer 	int i;
972144077eaSGreg Ungerer 
973144077eaSGreg Ungerer 	if (!stack) {
974144077eaSGreg Ungerer 		if (task)
975144077eaSGreg Ungerer 			stack = (unsigned long *)task->thread.esp0;
976144077eaSGreg Ungerer 		else
977144077eaSGreg Ungerer 			stack = (unsigned long *)&stack;
978144077eaSGreg Ungerer 	}
979144077eaSGreg Ungerer 	endstack = (unsigned long *)(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
980144077eaSGreg Ungerer 
981144077eaSGreg Ungerer 	printk("Stack from %08lx:", (unsigned long)stack);
982144077eaSGreg Ungerer 	p = stack;
983144077eaSGreg Ungerer 	for (i = 0; i < kstack_depth_to_print; i++) {
984144077eaSGreg Ungerer 		if (p + 1 > endstack)
985144077eaSGreg Ungerer 			break;
986144077eaSGreg Ungerer 		if (i % 8 == 0)
987144077eaSGreg Ungerer 			printk("\n       ");
988144077eaSGreg Ungerer 		printk(" %08lx", *p++);
989144077eaSGreg Ungerer 	}
990144077eaSGreg Ungerer 	printk("\n");
991144077eaSGreg Ungerer 	show_trace(stack);
992144077eaSGreg Ungerer }
993144077eaSGreg Ungerer 
994144077eaSGreg Ungerer /*
995144077eaSGreg Ungerer  * The architecture-independent backtrace generator
996144077eaSGreg Ungerer  */
997144077eaSGreg Ungerer void dump_stack(void)
998144077eaSGreg Ungerer {
999144077eaSGreg Ungerer 	unsigned long stack;
1000144077eaSGreg Ungerer 
1001144077eaSGreg Ungerer 	show_trace(&stack);
1002144077eaSGreg Ungerer }
1003144077eaSGreg Ungerer 
1004144077eaSGreg Ungerer EXPORT_SYMBOL(dump_stack);
1005144077eaSGreg Ungerer 
1006144077eaSGreg Ungerer /*
1007144077eaSGreg Ungerer  * The vector number returned in the frame pointer may also contain
1008144077eaSGreg Ungerer  * the "fs" (Fault Status) bits on ColdFire. These are in the bottom
1009144077eaSGreg Ungerer  * 2 bits, and upper 2 bits. So we need to mask out the real vector
1010144077eaSGreg Ungerer  * number before using it in comparisons. You don't need to do this on
1011144077eaSGreg Ungerer  * real 68k parts, but it won't hurt either.
1012144077eaSGreg Ungerer  */
1013144077eaSGreg Ungerer 
1014144077eaSGreg Ungerer void bad_super_trap (struct frame *fp)
1015144077eaSGreg Ungerer {
1016144077eaSGreg Ungerer 	int vector = (fp->ptregs.vector >> 2) & 0xff;
1017144077eaSGreg Ungerer 
1018144077eaSGreg Ungerer 	console_verbose();
1019144077eaSGreg Ungerer 	if (vector < ARRAY_SIZE(vec_names))
1020144077eaSGreg Ungerer 		printk ("*** %s ***   FORMAT=%X\n",
1021144077eaSGreg Ungerer 			vec_names[vector],
1022144077eaSGreg Ungerer 			fp->ptregs.format);
1023144077eaSGreg Ungerer 	else
1024144077eaSGreg Ungerer 		printk ("*** Exception %d ***   FORMAT=%X\n",
1025144077eaSGreg Ungerer 			vector, fp->ptregs.format);
1026144077eaSGreg Ungerer 	if (vector == VEC_ADDRERR && CPU_IS_020_OR_030) {
1027144077eaSGreg Ungerer 		unsigned short ssw = fp->un.fmtb.ssw;
1028144077eaSGreg Ungerer 
1029144077eaSGreg Ungerer 		printk ("SSW=%#06x  ", ssw);
1030144077eaSGreg Ungerer 
1031144077eaSGreg Ungerer 		if (ssw & RC)
1032144077eaSGreg Ungerer 			printk ("Pipe stage C instruction fault at %#010lx\n",
1033144077eaSGreg Ungerer 				(fp->ptregs.format) == 0xA ?
1034144077eaSGreg Ungerer 				fp->ptregs.pc + 2 : fp->un.fmtb.baddr - 2);
1035144077eaSGreg Ungerer 		if (ssw & RB)
1036144077eaSGreg Ungerer 			printk ("Pipe stage B instruction fault at %#010lx\n",
1037144077eaSGreg Ungerer 				(fp->ptregs.format) == 0xA ?
1038144077eaSGreg Ungerer 				fp->ptregs.pc + 4 : fp->un.fmtb.baddr);
1039144077eaSGreg Ungerer 		if (ssw & DF)
1040144077eaSGreg Ungerer 			printk ("Data %s fault at %#010lx in %s (pc=%#lx)\n",
1041144077eaSGreg Ungerer 				ssw & RW ? "read" : "write",
1042144077eaSGreg Ungerer 				fp->un.fmtb.daddr, space_names[ssw & DFC],
1043144077eaSGreg Ungerer 				fp->ptregs.pc);
1044144077eaSGreg Ungerer 	}
1045144077eaSGreg Ungerer 	printk ("Current process id is %d\n", task_pid_nr(current));
1046144077eaSGreg Ungerer 	die_if_kernel("BAD KERNEL TRAP", &fp->ptregs, 0);
1047144077eaSGreg Ungerer }
1048144077eaSGreg Ungerer 
1049144077eaSGreg Ungerer asmlinkage void trap_c(struct frame *fp)
1050144077eaSGreg Ungerer {
1051144077eaSGreg Ungerer 	int sig;
1052144077eaSGreg Ungerer 	int vector = (fp->ptregs.vector >> 2) & 0xff;
1053144077eaSGreg Ungerer 	siginfo_t info;
1054144077eaSGreg Ungerer 
1055144077eaSGreg Ungerer 	if (fp->ptregs.sr & PS_S) {
1056144077eaSGreg Ungerer 		if (vector == VEC_TRACE) {
1057144077eaSGreg Ungerer 			/* traced a trapping instruction on a 68020/30,
1058144077eaSGreg Ungerer 			 * real exception will be executed afterwards.
1059144077eaSGreg Ungerer 			 */
1060144077eaSGreg Ungerer 		} else if (!handle_kernel_fault(&fp->ptregs))
1061144077eaSGreg Ungerer 			bad_super_trap(fp);
1062144077eaSGreg Ungerer 		return;
1063144077eaSGreg Ungerer 	}
1064144077eaSGreg Ungerer 
1065144077eaSGreg Ungerer 	/* send the appropriate signal to the user program */
1066144077eaSGreg Ungerer 	switch (vector) {
1067144077eaSGreg Ungerer 	    case VEC_ADDRERR:
1068144077eaSGreg Ungerer 		info.si_code = BUS_ADRALN;
1069144077eaSGreg Ungerer 		sig = SIGBUS;
1070144077eaSGreg Ungerer 		break;
1071144077eaSGreg Ungerer 	    case VEC_ILLEGAL:
1072144077eaSGreg Ungerer 	    case VEC_LINE10:
1073144077eaSGreg Ungerer 	    case VEC_LINE11:
1074144077eaSGreg Ungerer 		info.si_code = ILL_ILLOPC;
1075144077eaSGreg Ungerer 		sig = SIGILL;
1076144077eaSGreg Ungerer 		break;
1077144077eaSGreg Ungerer 	    case VEC_PRIV:
1078144077eaSGreg Ungerer 		info.si_code = ILL_PRVOPC;
1079144077eaSGreg Ungerer 		sig = SIGILL;
1080144077eaSGreg Ungerer 		break;
1081144077eaSGreg Ungerer 	    case VEC_COPROC:
1082144077eaSGreg Ungerer 		info.si_code = ILL_COPROC;
1083144077eaSGreg Ungerer 		sig = SIGILL;
1084144077eaSGreg Ungerer 		break;
1085144077eaSGreg Ungerer 	    case VEC_TRAP1:
1086144077eaSGreg Ungerer 	    case VEC_TRAP2:
1087144077eaSGreg Ungerer 	    case VEC_TRAP3:
1088144077eaSGreg Ungerer 	    case VEC_TRAP4:
1089144077eaSGreg Ungerer 	    case VEC_TRAP5:
1090144077eaSGreg Ungerer 	    case VEC_TRAP6:
1091144077eaSGreg Ungerer 	    case VEC_TRAP7:
1092144077eaSGreg Ungerer 	    case VEC_TRAP8:
1093144077eaSGreg Ungerer 	    case VEC_TRAP9:
1094144077eaSGreg Ungerer 	    case VEC_TRAP10:
1095144077eaSGreg Ungerer 	    case VEC_TRAP11:
1096144077eaSGreg Ungerer 	    case VEC_TRAP12:
1097144077eaSGreg Ungerer 	    case VEC_TRAP13:
1098144077eaSGreg Ungerer 	    case VEC_TRAP14:
1099144077eaSGreg Ungerer 		info.si_code = ILL_ILLTRP;
1100144077eaSGreg Ungerer 		sig = SIGILL;
1101144077eaSGreg Ungerer 		break;
1102144077eaSGreg Ungerer 	    case VEC_FPBRUC:
1103144077eaSGreg Ungerer 	    case VEC_FPOE:
1104144077eaSGreg Ungerer 	    case VEC_FPNAN:
1105144077eaSGreg Ungerer 		info.si_code = FPE_FLTINV;
1106144077eaSGreg Ungerer 		sig = SIGFPE;
1107144077eaSGreg Ungerer 		break;
1108144077eaSGreg Ungerer 	    case VEC_FPIR:
1109144077eaSGreg Ungerer 		info.si_code = FPE_FLTRES;
1110144077eaSGreg Ungerer 		sig = SIGFPE;
1111144077eaSGreg Ungerer 		break;
1112144077eaSGreg Ungerer 	    case VEC_FPDIVZ:
1113144077eaSGreg Ungerer 		info.si_code = FPE_FLTDIV;
1114144077eaSGreg Ungerer 		sig = SIGFPE;
1115144077eaSGreg Ungerer 		break;
1116144077eaSGreg Ungerer 	    case VEC_FPUNDER:
1117144077eaSGreg Ungerer 		info.si_code = FPE_FLTUND;
1118144077eaSGreg Ungerer 		sig = SIGFPE;
1119144077eaSGreg Ungerer 		break;
1120144077eaSGreg Ungerer 	    case VEC_FPOVER:
1121144077eaSGreg Ungerer 		info.si_code = FPE_FLTOVF;
1122144077eaSGreg Ungerer 		sig = SIGFPE;
1123144077eaSGreg Ungerer 		break;
1124144077eaSGreg Ungerer 	    case VEC_ZERODIV:
1125144077eaSGreg Ungerer 		info.si_code = FPE_INTDIV;
1126144077eaSGreg Ungerer 		sig = SIGFPE;
1127144077eaSGreg Ungerer 		break;
1128144077eaSGreg Ungerer 	    case VEC_CHK:
1129144077eaSGreg Ungerer 	    case VEC_TRAP:
1130144077eaSGreg Ungerer 		info.si_code = FPE_INTOVF;
1131144077eaSGreg Ungerer 		sig = SIGFPE;
1132144077eaSGreg Ungerer 		break;
1133144077eaSGreg Ungerer 	    case VEC_TRACE:		/* ptrace single step */
1134144077eaSGreg Ungerer 		info.si_code = TRAP_TRACE;
1135144077eaSGreg Ungerer 		sig = SIGTRAP;
1136144077eaSGreg Ungerer 		break;
1137144077eaSGreg Ungerer 	    case VEC_TRAP15:		/* breakpoint */
1138144077eaSGreg Ungerer 		info.si_code = TRAP_BRKPT;
1139144077eaSGreg Ungerer 		sig = SIGTRAP;
1140144077eaSGreg Ungerer 		break;
1141144077eaSGreg Ungerer 	    default:
1142144077eaSGreg Ungerer 		info.si_code = ILL_ILLOPC;
1143144077eaSGreg Ungerer 		sig = SIGILL;
1144144077eaSGreg Ungerer 		break;
1145144077eaSGreg Ungerer 	}
1146144077eaSGreg Ungerer 	info.si_signo = sig;
1147144077eaSGreg Ungerer 	info.si_errno = 0;
1148144077eaSGreg Ungerer 	switch (fp->ptregs.format) {
1149144077eaSGreg Ungerer 	    default:
1150144077eaSGreg Ungerer 		info.si_addr = (void *) fp->ptregs.pc;
1151144077eaSGreg Ungerer 		break;
1152144077eaSGreg Ungerer 	    case 2:
1153144077eaSGreg Ungerer 		info.si_addr = (void *) fp->un.fmt2.iaddr;
1154144077eaSGreg Ungerer 		break;
1155144077eaSGreg Ungerer 	    case 7:
1156144077eaSGreg Ungerer 		info.si_addr = (void *) fp->un.fmt7.effaddr;
1157144077eaSGreg Ungerer 		break;
1158144077eaSGreg Ungerer 	    case 9:
1159144077eaSGreg Ungerer 		info.si_addr = (void *) fp->un.fmt9.iaddr;
1160144077eaSGreg Ungerer 		break;
1161144077eaSGreg Ungerer 	    case 10:
1162144077eaSGreg Ungerer 		info.si_addr = (void *) fp->un.fmta.daddr;
1163144077eaSGreg Ungerer 		break;
1164144077eaSGreg Ungerer 	    case 11:
1165144077eaSGreg Ungerer 		info.si_addr = (void *) fp->un.fmtb.daddr;
1166144077eaSGreg Ungerer 		break;
1167144077eaSGreg Ungerer 	}
1168144077eaSGreg Ungerer 	force_sig_info (sig, &info, current);
1169144077eaSGreg Ungerer }
1170144077eaSGreg Ungerer 
1171144077eaSGreg Ungerer void die_if_kernel (char *str, struct pt_regs *fp, int nr)
1172144077eaSGreg Ungerer {
1173144077eaSGreg Ungerer 	if (!(fp->sr & PS_S))
1174144077eaSGreg Ungerer 		return;
1175144077eaSGreg Ungerer 
1176144077eaSGreg Ungerer 	console_verbose();
1177144077eaSGreg Ungerer 	printk("%s: %08x\n",str,nr);
1178144077eaSGreg Ungerer 	show_registers(fp);
1179144077eaSGreg Ungerer 	add_taint(TAINT_DIE);
1180144077eaSGreg Ungerer 	do_exit(SIGSEGV);
1181144077eaSGreg Ungerer }
1182144077eaSGreg Ungerer 
1183144077eaSGreg Ungerer asmlinkage void set_esp0(unsigned long ssp)
1184144077eaSGreg Ungerer {
1185144077eaSGreg Ungerer 	current->thread.esp0 = ssp;
1186144077eaSGreg Ungerer }
1187144077eaSGreg Ungerer 
1188144077eaSGreg Ungerer /*
1189144077eaSGreg Ungerer  * This function is called if an error occur while accessing
1190144077eaSGreg Ungerer  * user-space from the fpsp040 code.
1191144077eaSGreg Ungerer  */
1192144077eaSGreg Ungerer asmlinkage void fpsp040_die(void)
1193144077eaSGreg Ungerer {
1194144077eaSGreg Ungerer 	do_exit(SIGSEGV);
1195144077eaSGreg Ungerer }
1196144077eaSGreg Ungerer 
1197144077eaSGreg Ungerer #ifdef CONFIG_M68KFPU_EMU
1198144077eaSGreg Ungerer asmlinkage void fpemu_signal(int signal, int code, void *addr)
1199144077eaSGreg Ungerer {
1200144077eaSGreg Ungerer 	siginfo_t info;
1201144077eaSGreg Ungerer 
1202144077eaSGreg Ungerer 	info.si_signo = signal;
1203144077eaSGreg Ungerer 	info.si_errno = 0;
1204144077eaSGreg Ungerer 	info.si_code = code;
1205144077eaSGreg Ungerer 	info.si_addr = addr;
1206144077eaSGreg Ungerer 	force_sig_info(signal, &info, current);
1207144077eaSGreg Ungerer }
12081da177e4SLinus Torvalds #endif
1209