xref: /netbsd-src/sys/arch/m68k/m68k/trap_subr.s (revision 7cc2f76925f078d01ddc9e640a98f4ccfc9f8c3b)
1/*	$NetBSD: trap_subr.s,v 1.6 1999/11/10 00:01:32 thorpej Exp $	*/
2
3/*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1980, 1990, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 *    must display the following acknowledgement:
22 *	This product includes software developed by the University of
23 *	California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 *    may be used to endorse or promote products derived from this software
26 *    without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: Utah $Hdr: locore.s 1.66 92/12/22$
41 *
42 *	@(#)locore.s	8.6 (Berkeley) 5/27/94
43 */
44
45/*
46 * NOTICE: This is not a standalone file.  To use it, #include it in
47 * your port's locore.s, like so:
48 *
49 *	#include <m68k/m68k/trap_subr.s>
50 */
51
52/*
53 * Common fault handling code.  Called by exception vector handlers.
54 * Registers have been saved, and type for trap() placed in d0.
55 */
56ASENTRY_NOPROFILE(fault)
57	movl	%usp,%a0		| get and save
58	movl	%a0,%sp@(FR_SP)		|   the user stack pointer
59	clrl	%sp@-			| no VA arg
60	clrl	%sp@-			| or code arg
61	movl	%d0,%sp@-		| push trap type
62	jbsr	_C_LABEL(trap)		| handle trap
63	lea	%sp@(12),%sp		| pop value args
64	movl	%sp@(FR_SP),%a0		| restore
65	movl	%a0,%usp		|   user SP
66	moveml	%sp@+,#0x7FFF		| restore most user regs
67	addql	#8,%sp			| pop SP and stack adjust
68	jra	_ASM_LABEL(rei)		| all done
69
70/*
71 * Similar to above, but will tidy up the stack, if necessary.
72 */
73ASENTRY(faultstkadj)
74	jbsr	_C_LABEL(trap)		| handle the error
75/* for 68060 Branch Prediction Error handler */
76_ASM_LABEL(faultstkadjnotrap):
77	lea	%sp@(12),%sp		| pop value args
78/* for new 68060 Branch Prediction Error handler */
79_ASM_LABEL(faultstkadjnotrap2):
80	movl	%sp@(FR_SP),%a0		| restore user SP
81	movl	%a0,%usp		|   from save area
82	movw	%sp@(FR_ADJ),%d0	| need to adjust stack?
83	jne	1f			| yes, go to it
84	moveml	%sp@+,#0x7FFF		| no, restore most user regs
85	addql	#8,%sp			| toss SSP and stkadj
86	jra	_ASM_LABEL(rei)		| all done
871:
88	lea	%sp@(FR_HW),%a1		| pointer to HW frame
89	addql	#8,%a1			| source pointer
90	movl	%a1,%a0			| source
91	addw	%d0,%a0			|  + hole size = dest pointer
92	movl	%a1@-,%a0@-		| copy
93	movl	%a1@-,%a0@-		|  8 bytes
94	movl	%a0,%sp@(FR_SP)		| new SSP
95	moveml	%sp@+,#0x7FFF		| restore user registers
96	movl	%sp@,%sp		| and our SP
97	jra	_ASM_LABEL(rei)		| all done
98
99#ifdef COMPAT_13
100/*
101 * Trap 1 - compat_13_sigreturn13
102 */
103ENTRY_NOPROFILE(trap1)
104	jra	_C_LABEL(m68k_compat_13_sigreturn13_stub)
105#endif
106
107/*
108 * Trap 2 - trace trap
109 *
110 * XXX SunOS uses this for a cache flush!  What do we do here?
111 * XXX
112 * XXX	movl	#IC_CLEAR,%d0
113 * XXX	movc	%d0,%cacr
114 * XXX	rte
115 */
116ENTRY_NOPROFILE(trap2)
117	jra	_C_LABEL(trace)
118
119/*
120 * Trap 3 - sigreturn system call
121 */
122ENTRY_NOPROFILE(trap3)
123	jra	_C_LABEL(m68k_sigreturn_stub)
124
125/*
126 * The following exceptions only cause four and six word stack frames
127 * and require no post-trap stack adjustment.
128 */
129ENTRY_NOPROFILE(illinst)
130	clrl	%sp@-
131	moveml	#0xFFFF,%sp@-
132	moveq	#T_ILLINST,%d0
133	jra	_ASM_LABEL(fault)
134
135ENTRY_NOPROFILE(zerodiv)
136	clrl	%sp@-
137	moveml	#0xFFFF,%sp@-
138	moveq	#T_ZERODIV,%d0
139	jra	_ASM_LABEL(fault)
140
141ENTRY_NOPROFILE(chkinst)
142	clrl	%sp@-
143	moveml	#0xFFFF,%sp@-
144	moveq	#T_CHKINST,%d0
145	jra	_ASM_LABEL(fault)
146
147ENTRY_NOPROFILE(trapvinst)
148	clrl	%sp@-
149	moveml	#0xFFFF,%sp@-
150	moveq	#T_TRAPVINST,%d0
151	jra	_ASM_LABEL(fault)
152
153ENTRY_NOPROFILE(privinst)
154	clrl	%sp@-
155	moveml	#0xFFFF,%sp@-
156	moveq	#T_PRIVINST,%d0
157	jra	_ASM_LABEL(fault)
158
159/*
160 * Coprocessor and format errors can generate mid-instruction stack
161 * frames and cause signal delivery, hence we need to check for potential
162 * stack adjustment.
163 */
164ENTRY_NOPROFILE(coperr)
165	clrl	%sp@-			| stack adjust count
166	moveml	#0xFFFF,%sp@-
167	movl	%usp,%a0		| get and save
168	movl	%a0,%sp@(FR_SP)		|   the user stack pointer
169	clrl	%sp@-			| no VA arg
170	clrl	%sp@-			| or code arg
171	movl	#T_COPERR,%sp@-		| push trap type
172	jra	_ASM_LABEL(faultstkadj)	| call trap and deal with stack
173					|   adjustments
174
175ENTRY_NOPROFILE(fmterr)
176	clrl	%sp@-			| stack adjust count
177	moveml	#0xFFFF,%sp@-
178	movl	%usp,%a0		| get and save
179	movl	%a0,%sp@(FR_SP)		|   the user stack pointer
180	clrl	%sp@-			| no VA arg
181	clrl	%sp@-			| or code arg
182	movl	#T_FMTERR,%sp@-		| push trap type
183	jra	_ASM_LABEL(faultstkadj)	| call trap and deal with stack
184					|   adjustments
185