1/* $NetBSD: trap_subr.s,v 1.14 2011/02/08 20:20:17 rmind 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. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: Utah $Hdr: locore.s 1.66 92/12/22$ 37 * 38 * @(#)locore.s 8.6 (Berkeley) 5/27/94 39 */ 40 41#include "opt_compat_sunos.h" 42 43/* 44 * NOTICE: This is not a standalone file. To use it, #include it in 45 * your port's locore.s, like so: 46 * 47 * #include <m68k/m68k/trap_subr.s> 48 */ 49 50/* 51 * Common fault handling code. Called by exception vector handlers. 52 * Registers have been saved, and type for trap() placed in d0. 53 */ 54ASENTRY_NOPROFILE(fault) 55 movl %usp,%a0 | get and save 56 movl %a0,%sp@(FR_SP) | the user stack pointer 57 clrl %sp@- | no VA arg 58 clrl %sp@- | or code arg 59 movl %d0,%sp@- | push trap type 60 pea %sp@(12) | address of trap frame 61 jbsr _C_LABEL(trap) | handle trap 62 lea %sp@(16),%sp | pop value args 63 movl %sp@(FR_SP),%a0 | restore 64 movl %a0,%usp | user SP 65 moveml %sp@+,#0x7FFF | restore most user regs 66 addql #8,%sp | pop SP and stack adjust 67 jra _ASM_LABEL(rei) | all done 68 69/* 70 * Similar to above, but will tidy up the stack, if necessary. 71 */ 72ASENTRY(faultstkadj) 73 pea %sp@(12) | address of trap frame 74 jbsr _C_LABEL(trap) | handle the error 75 lea %sp@(16),%sp | pop value args 76/* for new 68060 Branch Prediction Error handler */ 77_ASM_LABEL(faultstkadjnotrap2): 78 movl %sp@(FR_SP),%a0 | restore user SP 79 movl %a0,%usp | from save area 80 movw %sp@(FR_ADJ),%d0 | need to adjust stack? 81 jne 1f | yes, go to it 82 moveml %sp@+,#0x7FFF | no, restore most user regs 83 addql #8,%sp | toss SSP and stkadj 84 jra _ASM_LABEL(rei) | all done 851: 86 lea %sp@(FR_HW),%a1 | pointer to HW frame 87 addql #8,%a1 | source pointer 88 movl %a1,%a0 | source 89 addw %d0,%a0 | + hole size = dest pointer 90 movl %a1@-,%a0@- | copy 91 movl %a1@-,%a0@- | 8 bytes 92 movl %a0,%sp@(FR_SP) | new SSP 93 moveml %sp@+,#0x7FFF | restore user registers 94 movl %sp@,%sp | and our SP 95 jra _ASM_LABEL(rei) | all done 96 97#if defined(COMPAT_13) || defined(COMPAT_SUNOS) 98/* 99 * Trap 1 - compat_13_sigreturn13 100 */ 101ENTRY_NOPROFILE(trap1) 102 jra _C_LABEL(m68k_compat_13_sigreturn13_stub) 103#endif 104 105/* 106 * Trap 2 - trace trap 107 * 108 * XXX SunOS uses this for a cache flush! What do we do here? 109 * XXX 110 * XXX movl #IC_CLEAR,%d0 111 * XXX movc %d0,%cacr 112 * XXX rte 113 */ 114ENTRY_NOPROFILE(trap2) 115 jra _C_LABEL(trace) 116 117#if defined(COMPAT_16) 118/* 119 * Trap 3 - sigreturn system call 120 */ 121ENTRY_NOPROFILE(trap3) 122 jra _C_LABEL(m68k_compat_16_sigreturn14_stub) 123#endif 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