trap.c revision 1.45
11.45Scl/* $NetBSD: trap.c,v 1.45 2003/09/22 14:27:11 cl Exp $ */ 21.7Sdbj 31.7Sdbj/* 41.10Sabs * This file was taken from mvme68k/mvme68k/trap.c 51.7Sdbj * should probably be re-synced when needed. 61.16Sdbj * Darrin B. Jewell <jewell@mit.edu> Tue Aug 3 10:53:12 UTC 1999 71.16Sdbj * original cvs id: NetBSD: trap.c,v 1.32 1999/08/03 10:52:06 dbj Exp 81.7Sdbj */ 91.1Sdbj 101.1Sdbj/* 111.1Sdbj * Copyright (c) 1982, 1986, 1990, 1993 121.1Sdbj * The Regents of the University of California. All rights reserved. 131.1Sdbj * 141.1Sdbj * This code is derived from software contributed to Berkeley by 151.1Sdbj * the Systems Programming Group of the University of Utah Computer 161.1Sdbj * Science Department. 171.1Sdbj * 181.1Sdbj * Redistribution and use in source and binary forms, with or without 191.1Sdbj * modification, are permitted provided that the following conditions 201.1Sdbj * are met: 211.1Sdbj * 1. Redistributions of source code must retain the above copyright 221.1Sdbj * notice, this list of conditions and the following disclaimer. 231.1Sdbj * 2. Redistributions in binary form must reproduce the above copyright 241.1Sdbj * notice, this list of conditions and the following disclaimer in the 251.1Sdbj * documentation and/or other materials provided with the distribution. 261.43Sagc * 3. Neither the name of the University nor the names of its contributors 271.43Sagc * may be used to endorse or promote products derived from this software 281.43Sagc * without specific prior written permission. 291.43Sagc * 301.43Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 311.43Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 321.43Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 331.43Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 341.43Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 351.43Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 361.43Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 371.43Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 381.43Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 391.43Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 401.43Sagc * SUCH DAMAGE. 411.43Sagc * 421.43Sagc * from: Utah $Hdr: trap.c 1.37 92/12/20$ 431.43Sagc * 441.43Sagc * @(#)trap.c 8.5 (Berkeley) 1/4/94 451.43Sagc */ 461.43Sagc/* 471.43Sagc * Copyright (c) 1988 University of Utah. 481.43Sagc * 491.43Sagc * This code is derived from software contributed to Berkeley by 501.43Sagc * the Systems Programming Group of the University of Utah Computer 511.43Sagc * Science Department. 521.43Sagc * 531.43Sagc * Redistribution and use in source and binary forms, with or without 541.43Sagc * modification, are permitted provided that the following conditions 551.43Sagc * are met: 561.43Sagc * 1. Redistributions of source code must retain the above copyright 571.43Sagc * notice, this list of conditions and the following disclaimer. 581.43Sagc * 2. Redistributions in binary form must reproduce the above copyright 591.43Sagc * notice, this list of conditions and the following disclaimer in the 601.43Sagc * documentation and/or other materials provided with the distribution. 611.1Sdbj * 3. All advertising materials mentioning features or use of this software 621.1Sdbj * must display the following acknowledgement: 631.1Sdbj * This product includes software developed by the University of 641.1Sdbj * California, Berkeley and its contributors. 651.1Sdbj * 4. Neither the name of the University nor the names of its contributors 661.1Sdbj * may be used to endorse or promote products derived from this software 671.1Sdbj * without specific prior written permission. 681.1Sdbj * 691.1Sdbj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 701.1Sdbj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 711.1Sdbj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 721.1Sdbj * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 731.1Sdbj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 741.1Sdbj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 751.1Sdbj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 761.1Sdbj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 771.1Sdbj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 781.1Sdbj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 791.1Sdbj * SUCH DAMAGE. 801.1Sdbj * 811.1Sdbj * from: Utah $Hdr: trap.c 1.37 92/12/20$ 821.1Sdbj * 831.1Sdbj * @(#)trap.c 8.5 (Berkeley) 1/4/94 841.1Sdbj */ 851.42Slukem 861.42Slukem#include <sys/cdefs.h> 871.45Scl__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.45 2003/09/22 14:27:11 cl Exp $"); 881.2Sthorpej 891.5Sjonathan#include "opt_ddb.h" 901.9Sitohy#include "opt_execfmt.h" 911.33Slukem#include "opt_kgdb.h" 921.3Sthorpej#include "opt_compat_sunos.h" 931.4Sthorpej#include "opt_compat_hpux.h" 941.1Sdbj 951.1Sdbj#include <sys/param.h> 961.1Sdbj#include <sys/systm.h> 971.1Sdbj#include <sys/proc.h> 981.1Sdbj#include <sys/acct.h> 991.1Sdbj#include <sys/kernel.h> 1001.1Sdbj#include <sys/signalvar.h> 1011.1Sdbj#include <sys/resourcevar.h> 1021.39Sthorpej#include <sys/sa.h> 1031.39Sthorpej#include <sys/savar.h> 1041.1Sdbj#include <sys/syscall.h> 1051.1Sdbj#include <sys/syslog.h> 1061.1Sdbj#include <sys/user.h> 1071.16Sdbj 1081.16Sdbj#ifdef DEBUG 1091.16Sdbj#include <dev/cons.h> 1101.14Sdbj#endif 1111.1Sdbj 1121.16Sdbj#include <machine/db_machdep.h> 1131.1Sdbj#include <machine/psl.h> 1141.1Sdbj#include <machine/trap.h> 1151.1Sdbj#include <machine/cpu.h> 1161.1Sdbj#include <machine/reg.h> 1171.1Sdbj 1181.16Sdbj#include <m68k/cacheops.h> 1191.16Sdbj 1201.7Sdbj#include <uvm/uvm_extern.h> 1211.1Sdbj 1221.1Sdbj#ifdef COMPAT_HPUX 1231.1Sdbj#include <compat/hpux/hpux.h> 1241.1Sdbj#endif 1251.1Sdbj 1261.1Sdbj#ifdef COMPAT_SUNOS 1271.1Sdbj#include <compat/sunos/sunos_syscall.h> 1281.1Sdbjextern struct emul emul_sunos; 1291.1Sdbj#endif 1301.1Sdbj 1311.37Sjdolecek#ifdef KGDB 1321.37Sjdolecek#include <sys/kgdb.h> 1331.37Sjdolecek#endif 1341.37Sjdolecek 1351.16Sdbjint writeback __P((struct frame *fp, int docachepush)); 1361.16Sdbjvoid trap __P((int type, u_int code, u_int v, struct frame frame)); 1371.16Sdbj 1381.16Sdbj#ifdef DEBUG 1391.16Sdbjvoid dumpssw __P((u_short)); 1401.16Sdbjvoid dumpwb __P((int, u_short, u_int, u_int)); 1411.16Sdbj#endif 1421.16Sdbj 1431.39Sthorpejstatic inline void userret __P((struct lwp *l, struct frame *fp, 1441.16Sdbj u_quad_t oticks, u_int faultaddr, int fromtrap)); 1451.1Sdbj 1461.7Sdbjint astpending; 1471.1Sdbj 1481.1Sdbjchar *trap_type[] = { 1491.1Sdbj "Bus error", 1501.1Sdbj "Address error", 1511.1Sdbj "Illegal instruction", 1521.1Sdbj "Zero divide", 1531.1Sdbj "CHK instruction", 1541.1Sdbj "TRAPV instruction", 1551.1Sdbj "Privilege violation", 1561.1Sdbj "Trace trap", 1571.1Sdbj "MMU fault", 1581.1Sdbj "SSIR trap", 1591.1Sdbj "Format error", 1601.1Sdbj "68881 exception", 1611.1Sdbj "Coprocessor violation", 1621.1Sdbj "Async system trap" 1631.1Sdbj}; 1641.1Sdbjint trap_types = sizeof trap_type / sizeof trap_type[0]; 1651.1Sdbj 1661.1Sdbj/* 1671.1Sdbj * Size of various exception stack frames (minus the standard 8 bytes) 1681.1Sdbj */ 1691.1Sdbjshort exframesize[] = { 1701.16Sdbj FMT0SIZE, /* type 0 - normal (68020/030/040/060) */ 1711.1Sdbj FMT1SIZE, /* type 1 - throwaway (68020/030/040) */ 1721.16Sdbj FMT2SIZE, /* type 2 - normal 6-word (68020/030/040/060) */ 1731.16Sdbj FMT3SIZE, /* type 3 - FP post-instruction (68040/060) */ 1741.16Sdbj FMT4SIZE, /* type 4 - access error/fp disabled (68060) */ 1751.16Sdbj -1, -1, /* type 5-6 - undefined */ 1761.1Sdbj FMT7SIZE, /* type 7 - access error (68040) */ 1771.1Sdbj 58, /* type 8 - bus fault (68010) */ 1781.1Sdbj FMT9SIZE, /* type 9 - coprocessor mid-instruction (68020/030) */ 1791.1Sdbj FMTASIZE, /* type A - short bus fault (68020/030) */ 1801.1Sdbj FMTBSIZE, /* type B - long bus fault (68020/030) */ 1811.1Sdbj -1, -1, -1, -1 /* type C-F - undefined */ 1821.1Sdbj}; 1831.1Sdbj 1841.16Sdbj#ifdef M68060 1851.16Sdbj#define KDFAULT_060(c) (cputype == CPU_68060 && ((c) & FSLW_TM_SV)) 1861.16Sdbj#define WRFAULT_060(c) (cputype == CPU_68060 && ((c) & FSLW_RW_W)) 1871.16Sdbj#else 1881.16Sdbj#define KDFAULT_060(c) 0 1891.16Sdbj#define WRFAULT_060(c) 0 1901.16Sdbj#endif 1911.16Sdbj 1921.1Sdbj#ifdef M68040 1931.16Sdbj#define KDFAULT_040(c) (cputype == CPU_68040 && \ 1941.16Sdbj ((c) & SSW4_TMMASK) == SSW4_TMKD) 1951.16Sdbj#define WRFAULT_040(c) (cputype == CPU_68040 && \ 1961.16Sdbj ((c) & SSW4_RW) == 0) 1971.16Sdbj#else 1981.16Sdbj#define KDFAULT_040(c) 0 1991.16Sdbj#define WRFAULT_040(c) 0 2001.16Sdbj#endif 2011.16Sdbj 2021.16Sdbj#if defined(M68030) || defined(M68020) 2031.16Sdbj#define KDFAULT_OTH(c) (cputype <= CPU_68030 && \ 2041.16Sdbj ((c) & (SSW_DF|SSW_FCMASK)) == (SSW_DF|FC_SUPERD)) 2051.16Sdbj#define WRFAULT_OTH(c) (cputype <= CPU_68030 && \ 2061.16Sdbj ((c) & (SSW_DF|SSW_RW)) == SSW_DF) 2071.1Sdbj#else 2081.16Sdbj#define KDFAULT_OTH(c) 0 2091.16Sdbj#define WRFAULT_OTH(c) 0 2101.1Sdbj#endif 2111.1Sdbj 2121.16Sdbj#define KDFAULT(c) (KDFAULT_060(c) || KDFAULT_040(c) || KDFAULT_OTH(c)) 2131.16Sdbj#define WRFAULT(c) (WRFAULT_060(c) || WRFAULT_040(c) || WRFAULT_OTH(c)) 2141.16Sdbj 2151.1Sdbj#ifdef DEBUG 2161.1Sdbjint mmudebug = 0; 2171.1Sdbjint mmupid = -1; 2181.1Sdbj#define MDB_FOLLOW 1 2191.1Sdbj#define MDB_WBFOLLOW 2 2201.1Sdbj#define MDB_WBFAILED 4 2211.16Sdbj#define MDB_ISPID(p) ((p) == mmupid) 2221.1Sdbj#endif 2231.1Sdbj 2241.16Sdbj 2251.1Sdbj#define NSIR 32 2261.16Sdbjvoid (*sir_routines[NSIR])(void *); 2271.1Sdbjvoid *sir_args[NSIR]; 2281.1Sdbjint next_sir; 2291.1Sdbj 2301.1Sdbj/* 2311.1Sdbj * trap and syscall both need the following work done before returning 2321.1Sdbj * to user mode. 2331.1Sdbj */ 2341.1Sdbjstatic inline void 2351.39Sthorpejuserret(l, fp, oticks, faultaddr, fromtrap) 2361.39Sthorpej struct lwp *l; 2371.1Sdbj struct frame *fp; 2381.1Sdbj u_quad_t oticks; 2391.1Sdbj u_int faultaddr; 2401.1Sdbj int fromtrap; 2411.1Sdbj{ 2421.39Sthorpej struct proc *p = l->l_proc; 2431.20Sthorpej int sig; 2441.1Sdbj#ifdef M68040 2451.1Sdbj int beenhere = 0; 2461.1Sdbj 2471.1Sdbjagain: 2481.1Sdbj#endif 2491.1Sdbj /* take pending signals */ 2501.39Sthorpej while ((sig = CURSIG(l)) != 0) 2511.1Sdbj postsig(sig); 2521.39Sthorpej 2531.39Sthorpej /* Invoke per-process kernel-exit handling, if any */ 2541.39Sthorpej if (p->p_userret) 2551.39Sthorpej (p->p_userret)(l, p->p_userret_arg); 2561.39Sthorpej 2571.39Sthorpej /* Invoke any pending upcalls. */ 2581.39Sthorpej while (l->l_flag & L_SA_UPCALL) 2591.39Sthorpej sa_upcall_userret(l); 2601.1Sdbj 2611.1Sdbj /* 2621.1Sdbj * If profiling, charge system time to the trapped pc. 2631.1Sdbj */ 2641.1Sdbj if (p->p_flag & P_PROFIL) { 2651.1Sdbj extern int psratio; 2661.1Sdbj 2671.1Sdbj addupc_task(p, fp->f_pc, 2681.1Sdbj (int)(p->p_sticks - oticks) * psratio); 2691.1Sdbj } 2701.1Sdbj#ifdef M68040 2711.1Sdbj /* 2721.1Sdbj * Deal with user mode writebacks (from trap, or from sigreturn). 2731.1Sdbj * If any writeback fails, go back and attempt signal delivery. 2741.1Sdbj * unless we have already been here and attempted the writeback 2751.1Sdbj * (e.g. bad address with user ignoring SIGSEGV). In that case 2761.40Swiz * we just return to the user without successfully completing 2771.1Sdbj * the writebacks. Maybe we should just drop the sucker? 2781.1Sdbj */ 2791.16Sdbj if (cputype == CPU_68040 && fp->f_format == FMT7) { 2801.1Sdbj if (beenhere) { 2811.1Sdbj#ifdef DEBUG 2821.1Sdbj if (mmudebug & MDB_WBFAILED) 2831.1Sdbj printf(fromtrap ? 2841.1Sdbj "pid %d(%s): writeback aborted, pc=%x, fa=%x\n" : 2851.1Sdbj "pid %d(%s): writeback aborted in sigreturn, pc=%x\n", 2861.1Sdbj p->p_pid, p->p_comm, fp->f_pc, faultaddr); 2871.1Sdbj#endif 2881.16Sdbj } else if ((sig = writeback(fp, fromtrap))) { 2891.45Scl ksiginfo_t ksi; 2901.1Sdbj beenhere = 1; 2911.1Sdbj oticks = p->p_sticks; 2921.45Scl (void)memset(&ksi, 0, sizeof(ksi)); 2931.45Scl ksi.ksi_signo = sig; 2941.45Scl ksi.ksi_addr = (void *)faultaddr; 2951.45Scl ksi.ksi_code = BUS_OBJERR; 2961.45Scl trapsignal(l, &ksi); 2971.1Sdbj goto again; 2981.1Sdbj } 2991.1Sdbj } 3001.1Sdbj#endif 3011.39Sthorpej curcpu()->ci_schedstate.spc_curpriority = l->l_priority = l->l_usrpri; 3021.1Sdbj} 3031.1Sdbj 3041.1Sdbj/* 3051.28Sscw * Used by the common m68k syscall() and child_return() functions. 3061.28Sscw * XXX: Temporary until all m68k ports share common trap()/userret() code. 3071.28Sscw */ 3081.39Sthorpejvoid machine_userret(struct lwp *, struct frame *, u_quad_t); 3091.28Sscw 3101.28Sscwvoid 3111.39Sthorpejmachine_userret(l, f, t) 3121.39Sthorpej struct lwp *l; 3131.28Sscw struct frame *f; 3141.28Sscw u_quad_t t; 3151.28Sscw{ 3161.28Sscw 3171.39Sthorpej userret(l, f, t, 0, 0); 3181.28Sscw} 3191.28Sscw 3201.28Sscw/* 3211.1Sdbj * Trap is called from locore to handle most types of processor traps, 3221.1Sdbj * including events such as simulated software interrupts/AST's. 3231.1Sdbj * System calls are broken out for efficiency. 3241.1Sdbj */ 3251.1Sdbj/*ARGSUSED*/ 3261.16Sdbjvoid 3271.1Sdbjtrap(type, code, v, frame) 3281.1Sdbj int type; 3291.1Sdbj unsigned code; 3301.1Sdbj unsigned v; 3311.1Sdbj struct frame frame; 3321.1Sdbj{ 3331.1Sdbj extern char fubail[], subail[]; 3341.39Sthorpej struct lwp *l; 3351.1Sdbj struct proc *p; 3361.45Scl ksiginfo_t ksi; 3371.45Scl int s; 3381.16Sdbj u_quad_t sticks = 0 /* XXX initialiser works around compiler bug */; 3391.7Sdbj int bit; 3401.38Smycroft static int panicing = 0; 3411.1Sdbj 3421.7Sdbj uvmexp.traps++; 3431.39Sthorpej l = curlwp; 3441.45Scl 3451.45Scl (void)memset(&ksi, 0, sizeof(ksi)); 3461.45Scl ksi.ksi_trap = type & ~T_USER; 3471.16Sdbj 3481.16Sdbj /* I have verified that this DOES happen! -gwr */ 3491.39Sthorpej if (l == NULL) 3501.39Sthorpej l = &lwp0; 3511.39Sthorpej p = l->l_proc; 3521.39Sthorpej 3531.16Sdbj#ifdef DIAGNOSTIC 3541.39Sthorpej if (l->l_addr == NULL) 3551.16Sdbj panic("trap: no pcb"); 3561.16Sdbj#endif 3571.16Sdbj 3581.1Sdbj if (USERMODE(frame.f_sr)) { 3591.1Sdbj type |= T_USER; 3601.1Sdbj sticks = p->p_sticks; 3611.39Sthorpej l->l_md.md_regs = frame.f_regs; 3621.1Sdbj } 3631.1Sdbj switch (type) { 3641.1Sdbj 3651.1Sdbj default: 3661.14Sdbj dopanic: 3671.14Sdbj /* 3681.14Sdbj * Let the kernel debugger see the trap frame that 3691.14Sdbj * caused us to panic. This is a convenience so 3701.14Sdbj * one can see registers at the point of failure. 3711.14Sdbj */ 3721.16Sdbj s = splhigh(); 3731.38Smycroft panicing = 1; 3741.38Smycroft printf("trap type %d, code = 0x%x, v = 0x%x\n", type, code, v); 3751.38Smycroft printf("%s program counter = 0x%x\n", 3761.38Smycroft (type & T_USER) ? "user" : "kernel", frame.f_pc); 3771.14Sdbj#ifdef KGDB 3781.14Sdbj /* If connected, step or cont returns 1 */ 3791.37Sjdolecek if (kgdb_trap(type, (db_regs_t *)&frame)) 3801.14Sdbj goto kgdb_cont; 3811.14Sdbj#endif 3821.16Sdbj#ifdef DDB 3831.16Sdbj (void)kdb_trap(type, (db_regs_t *)&frame); 3841.1Sdbj#endif 3851.14Sdbj#ifdef KGDB 3861.14Sdbj kgdb_cont: 3871.14Sdbj#endif 3881.16Sdbj splx(s); 3891.14Sdbj if (panicstr) { 3901.16Sdbj printf("trap during panic!\n"); 3911.16Sdbj#ifdef DEBUG 3921.16Sdbj /* XXX should be a machine-dependent hook */ 3931.16Sdbj printf("(press a key)\n"); (void)cngetc(); 3941.16Sdbj#endif 3951.14Sdbj } 3961.1Sdbj regdump((struct trapframe *)&frame, 128); 3971.1Sdbj type &= ~T_USER; 3981.16Sdbj if ((u_int)type < trap_types) 3991.1Sdbj panic(trap_type[type]); 4001.1Sdbj panic("trap"); 4011.1Sdbj 4021.1Sdbj case T_BUSERR: /* kernel bus error */ 4031.39Sthorpej if (l->l_addr->u_pcb.pcb_onfault == 0) 4041.1Sdbj goto dopanic; 4051.16Sdbj /* FALLTHROUGH */ 4061.16Sdbj 4071.16Sdbj copyfault: 4081.1Sdbj /* 4091.1Sdbj * If we have arranged to catch this fault in any of the 4101.1Sdbj * copy to/from user space routines, set PC to return to 4111.1Sdbj * indicated location and set flag informing buserror code 4121.1Sdbj * that it may need to clean up stack frame. 4131.1Sdbj */ 4141.1Sdbj frame.f_stackadj = exframesize[frame.f_format]; 4151.1Sdbj frame.f_format = frame.f_vector = 0; 4161.39Sthorpej frame.f_pc = (int) l->l_addr->u_pcb.pcb_onfault; 4171.1Sdbj return; 4181.1Sdbj 4191.1Sdbj case T_BUSERR|T_USER: /* bus error */ 4201.1Sdbj case T_ADDRERR|T_USER: /* address error */ 4211.45Scl ksi.ksi_addr = (void *)v; 4221.45Scl ksi.ksi_signo = SIGBUS; 4231.45Scl ksi.ksi_code = (type == (T_BUSERR|T_USER)) ? 4241.45Scl BUS_OBJERR : BUS_ADRERR; 4251.1Sdbj break; 4261.1Sdbj 4271.1Sdbj case T_COPERR: /* kernel coprocessor violation */ 4281.1Sdbj case T_FMTERR|T_USER: /* do all RTE errors come in as T_USER? */ 4291.1Sdbj case T_FMTERR: /* ...just in case... */ 4301.1Sdbj /* 4311.1Sdbj * The user has most likely trashed the RTE or FP state info 4321.1Sdbj * in the stack frame of a signal handler. 4331.1Sdbj */ 4341.1Sdbj printf("pid %d: kernel %s exception\n", p->p_pid, 4351.1Sdbj type==T_COPERR ? "coprocessor" : "format"); 4361.1Sdbj type |= T_USER; 4371.29Sjdolecek SIGACTION(p, SIGILL).sa_handler = SIG_DFL; 4381.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigignore, SIGILL); 4391.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigcatch, SIGILL); 4401.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigmask, SIGILL); 4411.45Scl ksi.ksi_signo = SIGILL; 4421.45Scl ksi.ksi_addr = (void *)(int)frame.f_format; 4431.45Scl /* XXX was ILL_RESAD_FAULT */ 4441.45Scl ksi.ksi_code = (type == T_COPERR) ? 4451.45Scl ILL_COPROC : ILL_ILLOPC; 4461.1Sdbj break; 4471.1Sdbj 4481.1Sdbj case T_COPERR|T_USER: /* user coprocessor violation */ 4491.1Sdbj /* What is a proper response here? */ 4501.45Scl ksi.ksi_signo = SIGFPE; 4511.45Scl ksi.ksi_code = FPE_FLTINV; 4521.1Sdbj break; 4531.1Sdbj 4541.1Sdbj case T_FPERR|T_USER: /* 68881 exceptions */ 4551.1Sdbj /* 4561.7Sdbj * We pass along the 68881 status register which locore stashed 4571.1Sdbj * in code for us. Note that there is a possibility that the 4581.7Sdbj * bit pattern of this register will conflict with one of the 4591.1Sdbj * FPE_* codes defined in signal.h. Fortunately for us, the 4601.1Sdbj * only such codes we use are all in the range 1-7 and the low 4611.7Sdbj * 3 bits of the status register are defined as 0 so there is 4621.1Sdbj * no clash. 4631.1Sdbj */ 4641.45Scl ksi.ksi_signo = SIGFPE; 4651.45Scl ksi.ksi_addr = (void *)code; 4661.1Sdbj break; 4671.1Sdbj 4681.1Sdbj#ifdef M68040 4691.1Sdbj case T_FPEMULI|T_USER: /* unimplemented FP instuction */ 4701.1Sdbj case T_FPEMULD|T_USER: /* unimplemented FP data type */ 4711.1Sdbj /* XXX need to FSAVE */ 4721.1Sdbj printf("pid %d(%s): unimplemented FP %s at %x (EA %x)\n", 4731.1Sdbj p->p_pid, p->p_comm, 4741.1Sdbj frame.f_format == 2 ? "instruction" : "data type", 4751.1Sdbj frame.f_pc, frame.f_fmt2.f_iaddr); 4761.1Sdbj /* XXX need to FRESTORE */ 4771.45Scl ksi.ksi_signo = SIGFPE; 4781.45Scl ksi.ksi_code = FPE_FLTINV; 4791.1Sdbj break; 4801.1Sdbj#endif 4811.1Sdbj 4821.1Sdbj case T_ILLINST|T_USER: /* illegal instruction fault */ 4831.1Sdbj#ifdef COMPAT_HPUX 4841.1Sdbj if (p->p_emul == &emul_hpux) { 4851.45Scl ksi.ksi_addr = (void *)HPUX_ILL_ILLINST_TRAP; 4861.45Scl ksi.ksi_signo = SIGILL; 4871.1Sdbj break; 4881.1Sdbj } 4891.1Sdbj /* fall through */ 4901.1Sdbj#endif 4911.1Sdbj case T_PRIVINST|T_USER: /* privileged instruction fault */ 4921.1Sdbj#ifdef COMPAT_HPUX 4931.1Sdbj if (p->p_emul == &emul_hpux) 4941.45Scl ksi.ksi_addr = (void *)HPUX_ILL_PRIV_TRAP; 4951.1Sdbj else 4961.1Sdbj#endif 4971.45Scl ksi.ksi_addr = (void *)(int)frame.f_format; 4981.45Scl /* XXX was ILL_PRIVIN_FAULT */ 4991.45Scl ksi.ksi_signo = SIGILL; 5001.45Scl ksi.ksi_code = (type == (T_PRIVINST|T_USER)) ? 5011.45Scl ILL_PRVOPC : ILL_ILLOPC; 5021.1Sdbj break; 5031.1Sdbj 5041.1Sdbj case T_ZERODIV|T_USER: /* Divide by zero */ 5051.1Sdbj#ifdef COMPAT_HPUX 5061.1Sdbj if (p->p_emul == &emul_hpux) 5071.45Scl ksi.ksi_addr = (void *)HPUX_FPE_INTDIV_TRAP; 5081.1Sdbj else 5091.1Sdbj#endif 5101.45Scl ksi.ksi_addr = (void *)(int)frame.f_format; 5111.45Scl /* XXX was FPE_INTDIV_TRAP */ 5121.45Scl ksi.ksi_signo = SIGFPE; 5131.45Scl ksi.ksi_code = FPE_FLTDIV; 5141.1Sdbj break; 5151.1Sdbj 5161.1Sdbj case T_CHKINST|T_USER: /* CHK instruction trap */ 5171.1Sdbj#ifdef COMPAT_HPUX 5181.1Sdbj if (p->p_emul == &emul_hpux) { 5191.1Sdbj /* handled differently under hp-ux */ 5201.45Scl ksi.ksi_signo = SIGILL; 5211.45Scl ksi.ksi_addr = (void *)HPUX_ILL_CHK_TRAP; 5221.1Sdbj break; 5231.1Sdbj } 5241.1Sdbj#endif 5251.45Scl ksi.ksi_addr = (void *)(int)frame.f_format; 5261.45Scl /* XXX was FPE_SUBRNG_TRAP */ 5271.45Scl ksi.ksi_signo = SIGFPE; 5281.1Sdbj break; 5291.1Sdbj 5301.1Sdbj case T_TRAPVINST|T_USER: /* TRAPV instruction trap */ 5311.1Sdbj#ifdef COMPAT_HPUX 5321.1Sdbj if (p->p_emul == &emul_hpux) { 5331.1Sdbj /* handled differently under hp-ux */ 5341.45Scl ksi.ksi_signo = SIGILL; 5351.45Scl ksi.ksi_addr = (void *)HPUX_ILL_TRAPV_TRAP; 5361.1Sdbj break; 5371.1Sdbj } 5381.1Sdbj#endif 5391.45Scl ksi.ksi_addr = (void *)(int)frame.f_format; 5401.45Scl /* XXX was FPE_INTOVF_TRAP */ 5411.45Scl ksi.ksi_signo = SIGFPE; 5421.1Sdbj break; 5431.1Sdbj 5441.1Sdbj /* 5451.1Sdbj * XXX: Trace traps are a nightmare. 5461.1Sdbj * 5471.1Sdbj * HP-UX uses trap #1 for breakpoints, 5481.16Sdbj * NetBSD/m68k uses trap #2, 5491.1Sdbj * SUN 3.x uses trap #15, 5501.16Sdbj * DDB and KGDB uses trap #15 (for kernel breakpoints; 5511.16Sdbj * handled elsewhere). 5521.1Sdbj * 5531.16Sdbj * NetBSD and HP-UX traps both get mapped by locore.s into T_TRACE. 5541.1Sdbj * SUN 3.x traps get passed through as T_TRAP15 and are not really 5551.1Sdbj * supported yet. 5561.16Sdbj * 5571.17Sitohy * XXX: We should never get kernel-mode T_TRAP15 5581.16Sdbj * XXX: because locore.s now gives them special treatment. 5591.1Sdbj */ 5601.16Sdbj case T_TRAP15: /* kernel breakpoint */ 5611.16Sdbj#ifdef DEBUG 5621.16Sdbj printf("unexpected kernel trace trap, type = %d\n", type); 5631.16Sdbj printf("program counter = 0x%x\n", frame.f_pc); 5641.1Sdbj#endif 5651.1Sdbj frame.f_sr &= ~PSL_T; 5661.16Sdbj return; 5671.1Sdbj 5681.1Sdbj case T_TRACE|T_USER: /* user trace trap */ 5691.1Sdbj#ifdef COMPAT_SUNOS 5701.1Sdbj /* 5711.1Sdbj * SunOS uses Trap #2 for a "CPU cache flush". 5721.1Sdbj * Just flush the on-chip caches and return. 5731.1Sdbj */ 5741.1Sdbj if (p->p_emul == &emul_sunos) { 5751.1Sdbj ICIA(); 5761.1Sdbj DCIU(); 5771.1Sdbj return; 5781.1Sdbj } 5791.16Sdbj#endif 5801.17Sitohy /* FALLTHROUGH */ 5811.17Sitohy case T_TRACE: /* tracing a trap instruction */ 5821.17Sitohy case T_TRAP15|T_USER: /* SUN user trace trap */ 5831.1Sdbj frame.f_sr &= ~PSL_T; 5841.45Scl ksi.ksi_signo = SIGTRAP; 5851.1Sdbj break; 5861.1Sdbj 5871.1Sdbj case T_ASTFLT: /* system async trap, cannot happen */ 5881.1Sdbj goto dopanic; 5891.1Sdbj 5901.1Sdbj case T_ASTFLT|T_USER: /* user async trap */ 5911.1Sdbj astpending = 0; 5921.1Sdbj /* 5931.1Sdbj * We check for software interrupts first. This is because 5941.1Sdbj * they are at a higher level than ASTs, and on a VAX would 5951.1Sdbj * interrupt the AST. We assume that if we are processing 5961.1Sdbj * an AST that we must be at IPL0 so we don't bother to 5971.1Sdbj * check. Note that we ensure that we are at least at SIR 5981.1Sdbj * IPL while processing the SIR. 5991.1Sdbj */ 6001.1Sdbj spl1(); 6011.1Sdbj /* fall into... */ 6021.1Sdbj 6031.1Sdbj case T_SSIR: /* software interrupt */ 6041.1Sdbj case T_SSIR|T_USER: 6051.16Sdbj while ((bit = ffs(ssir))) { 6061.1Sdbj --bit; 6071.1Sdbj ssir &= ~(1 << bit); 6081.7Sdbj uvmexp.softs++; 6091.1Sdbj if (sir_routines[bit]) 6101.1Sdbj sir_routines[bit](sir_args[bit]); 6111.1Sdbj } 6121.1Sdbj /* 6131.1Sdbj * If this was not an AST trap, we are all done. 6141.1Sdbj */ 6151.1Sdbj if (type != (T_ASTFLT|T_USER)) { 6161.16Sdbj uvmexp.traps--; 6171.1Sdbj return; 6181.1Sdbj } 6191.1Sdbj spl0(); 6201.1Sdbj if (p->p_flag & P_OWEUPC) { 6211.1Sdbj p->p_flag &= ~P_OWEUPC; 6221.1Sdbj ADDUPROF(p); 6231.1Sdbj } 6241.39Sthorpej if (want_resched) 6251.39Sthorpej preempt(0); 6261.1Sdbj goto out; 6271.1Sdbj 6281.1Sdbj case T_MMUFLT: /* kernel mode page fault */ 6291.1Sdbj /* 6301.1Sdbj * If we were doing profiling ticks or other user mode 6311.1Sdbj * stuff from interrupt code, Just Say No. 6321.1Sdbj */ 6331.39Sthorpej if (l->l_addr->u_pcb.pcb_onfault == fubail || 6341.39Sthorpej l->l_addr->u_pcb.pcb_onfault == subail) 6351.1Sdbj goto copyfault; 6361.1Sdbj /* fall into ... */ 6371.1Sdbj 6381.1Sdbj case T_MMUFLT|T_USER: /* page fault */ 6391.1Sdbj { 6401.7Sdbj vaddr_t va; 6411.1Sdbj struct vmspace *vm = p->p_vmspace; 6421.34Schs struct vm_map *map; 6431.1Sdbj int rv; 6441.1Sdbj vm_prot_t ftype; 6451.34Schs extern struct vm_map *kernel_map; 6461.1Sdbj 6471.1Sdbj#ifdef DEBUG 6481.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 6491.1Sdbj printf("trap: T_MMUFLT pid=%d, code=%x, v=%x, pc=%x, sr=%x\n", 6501.1Sdbj p->p_pid, code, v, frame.f_pc, frame.f_sr); 6511.1Sdbj#endif 6521.1Sdbj /* 6531.1Sdbj * It is only a kernel address space fault iff: 6541.1Sdbj * 1. (type & T_USER) == 0 and 6551.1Sdbj * 2. pcb_onfault not set or 6561.1Sdbj * 3. pcb_onfault set but supervisor space data fault 6571.1Sdbj * The last can occur during an exec() copyin where the 6581.1Sdbj * argument space is lazy-allocated. 6591.1Sdbj */ 6601.16Sdbj if ((type & T_USER) == 0 && 6611.39Sthorpej ((l->l_addr->u_pcb.pcb_onfault == 0) || KDFAULT(code))) 6621.1Sdbj map = kernel_map; 6631.44Scl else { 6641.16Sdbj map = vm ? &vm->vm_map : kernel_map; 6651.44Scl if (l->l_flag & L_SA) { 6661.44Scl KDASSERT(p != NULL && p->p_sa != NULL); 6671.44Scl p->p_sa->sa_vp_faultaddr = (vaddr_t)v; 6681.44Scl l->l_flag |= L_SA_PAGEFAULT; 6691.44Scl } 6701.44Scl } 6711.16Sdbj 6721.1Sdbj if (WRFAULT(code)) 6731.36Schs ftype = VM_PROT_WRITE; 6741.1Sdbj else 6751.1Sdbj ftype = VM_PROT_READ; 6761.16Sdbj 6771.7Sdbj va = trunc_page((vaddr_t)v); 6781.16Sdbj 6791.1Sdbj if (map == kernel_map && va == 0) { 6801.16Sdbj printf("trap: bad kernel %s access at 0x%x\n", 6811.16Sdbj (ftype & VM_PROT_WRITE) ? "read/write" : 6821.16Sdbj "read", v); 6831.1Sdbj goto dopanic; 6841.1Sdbj } 6851.16Sdbj 6861.38Smycroft#ifdef DIAGNOSTIC 6871.38Smycroft if (interrupt_depth && !panicing) { 6881.38Smycroft printf("trap: calling uvm_fault() from interrupt!\n"); 6891.38Smycroft goto dopanic; 6901.38Smycroft } 6911.38Smycroft#endif 6921.38Smycroft 6931.1Sdbj#ifdef COMPAT_HPUX 6941.1Sdbj if (ISHPMMADDR(va)) { 6951.16Sdbj int pmap_mapmulti __P((pmap_t, vaddr_t)); 6961.7Sdbj vaddr_t bva; 6971.1Sdbj 6981.1Sdbj rv = pmap_mapmulti(map->pmap, va); 6991.31Schs if (rv != 0) { 7001.1Sdbj bva = HPMMBASEADDR(va); 7011.7Sdbj rv = uvm_fault(map, bva, 0, ftype); 7021.31Schs if (rv == 0) 7031.1Sdbj (void) pmap_mapmulti(map->pmap, va); 7041.1Sdbj } 7051.1Sdbj } else 7061.1Sdbj#endif 7071.7Sdbj rv = uvm_fault(map, va, 0, ftype); 7081.7Sdbj#ifdef DEBUG 7091.7Sdbj if (rv && MDB_ISPID(p->p_pid)) 7101.7Sdbj printf("uvm_fault(%p, 0x%lx, 0, 0x%x) -> 0x%x\n", 7111.16Sdbj map, va, ftype, rv); 7121.7Sdbj#endif 7131.1Sdbj /* 7141.1Sdbj * If this was a stack access we keep track of the maximum 7151.1Sdbj * accessed stack size. Also, if vm_fault gets a protection 7161.1Sdbj * failure it is due to accessing the stack region outside 7171.1Sdbj * the current limit and we need to reflect that as an access 7181.1Sdbj * error. 7191.1Sdbj */ 7201.16Sdbj if ((vm != NULL && (caddr_t)va >= vm->vm_maxsaddr) 7211.16Sdbj && map != kernel_map) { 7221.31Schs if (rv == 0) { 7231.1Sdbj unsigned nss; 7241.1Sdbj 7251.19Sragge nss = btoc(USRSTACK-(unsigned)va); 7261.1Sdbj if (nss > vm->vm_ssize) 7271.1Sdbj vm->vm_ssize = nss; 7281.45Scl } 7291.1Sdbj } 7301.31Schs if (rv == 0) { 7311.1Sdbj if (type == T_MMUFLT) { 7321.16Sdbj#ifdef M68040 7331.16Sdbj if (cputype == CPU_68040) 7341.1Sdbj (void) writeback(&frame, 1); 7351.1Sdbj#endif 7361.1Sdbj return; 7371.1Sdbj } 7381.44Scl l->l_flag &= ~L_SA_PAGEFAULT; 7391.1Sdbj goto out; 7401.1Sdbj } 7411.45Scl if (rv == EACCES) { 7421.45Scl ksi.ksi_code = SEGV_ACCERR; 7431.45Scl rv = EFAULT; 7441.45Scl } else 7451.45Scl ksi.ksi_code = SEGV_MAPERR; 7461.1Sdbj if (type == T_MMUFLT) { 7471.39Sthorpej if (l->l_addr->u_pcb.pcb_onfault) 7481.1Sdbj goto copyfault; 7491.7Sdbj printf("uvm_fault(%p, 0x%lx, 0, 0x%x) -> 0x%x\n", 7501.16Sdbj map, va, ftype, rv); 7511.1Sdbj printf(" type %x, code [mmu,,ssw]: %x\n", 7521.1Sdbj type, code); 7531.1Sdbj goto dopanic; 7541.1Sdbj } 7551.44Scl l->l_flag &= ~L_SA_PAGEFAULT; 7561.45Scl ksi.ksi_addr = (void *)v; 7571.31Schs if (rv == ENOMEM) { 7581.11Schs printf("UVM: pid %d (%s), uid %d killed: out of swap\n", 7591.11Schs p->p_pid, p->p_comm, 7601.11Schs p->p_cred && p->p_ucred ? 7611.11Schs p->p_ucred->cr_uid : -1); 7621.45Scl ksi.ksi_signo = SIGKILL; 7631.11Schs } else { 7641.45Scl ksi.ksi_signo = SIGSEGV; 7651.11Schs } 7661.1Sdbj break; 7671.1Sdbj } 7681.1Sdbj } 7691.45Scl trapsignal(l, &ksi); 7701.1Sdbj if ((type & T_USER) == 0) 7711.1Sdbj return; 7721.1Sdbjout: 7731.39Sthorpej userret(l, &frame, sticks, v, 1); 7741.1Sdbj} 7751.1Sdbj 7761.1Sdbj#ifdef M68040 7771.1Sdbj#ifdef DEBUG 7781.1Sdbjstruct writebackstats { 7791.1Sdbj int calls; 7801.1Sdbj int cpushes; 7811.1Sdbj int move16s; 7821.1Sdbj int wb1s, wb2s, wb3s; 7831.1Sdbj int wbsize[4]; 7841.1Sdbj} wbstats; 7851.1Sdbj 7861.1Sdbjchar *f7sz[] = { "longword", "byte", "word", "line" }; 7871.1Sdbjchar *f7tt[] = { "normal", "MOVE16", "AFC", "ACK" }; 7881.1Sdbjchar *f7tm[] = { "d-push", "u-data", "u-code", "M-data", 7891.1Sdbj "M-code", "k-data", "k-code", "RES" }; 7901.1Sdbjchar wberrstr[] = 7911.16Sdbj "WARNING: pid %d(%s) writeback [%s] failed, pc=%x fa=%x wba=%x wbd=%x\n"; 7921.1Sdbj#endif 7931.1Sdbj 7941.16Sdbjint 7951.1Sdbjwriteback(fp, docachepush) 7961.1Sdbj struct frame *fp; 7971.1Sdbj int docachepush; 7981.1Sdbj{ 7991.1Sdbj struct fmt7 *f = &fp->f_fmt7; 8001.39Sthorpej struct lwp *l = curlwp; 8011.39Sthorpej struct proc *p = l->l_proc; 8021.1Sdbj int err = 0; 8031.1Sdbj u_int fa; 8041.39Sthorpej caddr_t oonfault = l->l_addr->u_pcb.pcb_onfault; 8051.15Sthorpej paddr_t pa; 8061.1Sdbj 8071.1Sdbj#ifdef DEBUG 8081.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) { 8091.1Sdbj printf(" pid=%d, fa=%x,", p->p_pid, f->f_fa); 8101.1Sdbj dumpssw(f->f_ssw); 8111.1Sdbj } 8121.1Sdbj wbstats.calls++; 8131.1Sdbj#endif 8141.1Sdbj /* 8151.1Sdbj * Deal with special cases first. 8161.1Sdbj */ 8171.1Sdbj if ((f->f_ssw & SSW4_TMMASK) == SSW4_TMDCP) { 8181.1Sdbj /* 8191.1Sdbj * Dcache push fault. 8201.1Sdbj * Line-align the address and write out the push data to 8211.1Sdbj * the indicated physical address. 8221.1Sdbj */ 8231.1Sdbj#ifdef DEBUG 8241.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) { 8251.1Sdbj printf(" pushing %s to PA %x, data %x", 8261.1Sdbj f7sz[(f->f_ssw & SSW4_SZMASK) >> 5], 8271.1Sdbj f->f_fa, f->f_pd0); 8281.1Sdbj if ((f->f_ssw & SSW4_SZMASK) == SSW4_SZLN) 8291.1Sdbj printf("/%x/%x/%x", 8301.1Sdbj f->f_pd1, f->f_pd2, f->f_pd3); 8311.1Sdbj printf("\n"); 8321.1Sdbj } 8331.1Sdbj if (f->f_wb1s & SSW4_WBSV) 8341.1Sdbj panic("writeback: cache push with WB1S valid"); 8351.1Sdbj wbstats.cpushes++; 8361.1Sdbj#endif 8371.1Sdbj /* 8381.1Sdbj * XXX there are security problems if we attempt to do a 8391.1Sdbj * cache push after a signal handler has been called. 8401.1Sdbj */ 8411.1Sdbj if (docachepush) { 8421.7Sdbj pmap_enter(pmap_kernel(), (vaddr_t)vmmap, 8431.18Sthorpej trunc_page(f->f_fa), VM_PROT_WRITE, 8441.18Sthorpej VM_PROT_WRITE|PMAP_WIRED); 8451.35Schris pmap_update(pmap_kernel()); 8461.1Sdbj fa = (u_int)&vmmap[(f->f_fa & PGOFSET) & ~0xF]; 8471.1Sdbj bcopy((caddr_t)&f->f_pd0, (caddr_t)fa, 16); 8481.15Sthorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)fa, &pa); 8491.15Sthorpej DCFL(pa); 8501.7Sdbj pmap_remove(pmap_kernel(), (vaddr_t)vmmap, 8511.41Sthorpej (vaddr_t)&vmmap[PAGE_SIZE]); 8521.35Schris pmap_update(pmap_kernel()); 8531.1Sdbj } else 8541.1Sdbj printf("WARNING: pid %d(%s) uid %d: CPUSH not done\n", 8551.1Sdbj p->p_pid, p->p_comm, p->p_ucred->cr_uid); 8561.1Sdbj } else if ((f->f_ssw & (SSW4_RW|SSW4_TTMASK)) == SSW4_TTM16) { 8571.1Sdbj /* 8581.1Sdbj * MOVE16 fault. 8591.1Sdbj * Line-align the address and write out the push data to 8601.1Sdbj * the indicated virtual address. 8611.1Sdbj */ 8621.1Sdbj#ifdef DEBUG 8631.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8641.1Sdbj printf(" MOVE16 to VA %x(%x), data %x/%x/%x/%x\n", 8651.1Sdbj f->f_fa, f->f_fa & ~0xF, f->f_pd0, f->f_pd1, 8661.1Sdbj f->f_pd2, f->f_pd3); 8671.1Sdbj if (f->f_wb1s & SSW4_WBSV) 8681.1Sdbj panic("writeback: MOVE16 with WB1S valid"); 8691.1Sdbj wbstats.move16s++; 8701.1Sdbj#endif 8711.1Sdbj if (KDFAULT(f->f_wb1s)) 8721.1Sdbj bcopy((caddr_t)&f->f_pd0, (caddr_t)(f->f_fa & ~0xF), 16); 8731.1Sdbj else 8741.1Sdbj err = suline((caddr_t)(f->f_fa & ~0xF), (caddr_t)&f->f_pd0); 8751.1Sdbj if (err) { 8761.1Sdbj fa = f->f_fa & ~0xF; 8771.1Sdbj#ifdef DEBUG 8781.1Sdbj if (mmudebug & MDB_WBFAILED) 8791.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 8801.1Sdbj "MOVE16", fp->f_pc, f->f_fa, 8811.1Sdbj f->f_fa & ~0xF, f->f_pd0); 8821.1Sdbj#endif 8831.1Sdbj } 8841.1Sdbj } else if (f->f_wb1s & SSW4_WBSV) { 8851.1Sdbj /* 8861.1Sdbj * Writeback #1. 8871.1Sdbj * Position the "memory-aligned" data and write it out. 8881.1Sdbj */ 8891.1Sdbj u_int wb1d = f->f_wb1d; 8901.1Sdbj int off; 8911.1Sdbj 8921.1Sdbj#ifdef DEBUG 8931.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8941.1Sdbj dumpwb(1, f->f_wb1s, f->f_wb1a, f->f_wb1d); 8951.1Sdbj wbstats.wb1s++; 8961.1Sdbj wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++; 8971.1Sdbj#endif 8981.1Sdbj off = (f->f_wb1a & 3) * 8; 8991.1Sdbj switch (f->f_wb1s & SSW4_SZMASK) { 9001.1Sdbj case SSW4_SZLW: 9011.1Sdbj if (off) 9021.1Sdbj wb1d = (wb1d >> (32 - off)) | (wb1d << off); 9031.1Sdbj if (KDFAULT(f->f_wb1s)) 9041.1Sdbj *(long *)f->f_wb1a = wb1d; 9051.1Sdbj else 9061.1Sdbj err = suword((caddr_t)f->f_wb1a, wb1d); 9071.1Sdbj break; 9081.1Sdbj case SSW4_SZB: 9091.1Sdbj off = 24 - off; 9101.1Sdbj if (off) 9111.1Sdbj wb1d >>= off; 9121.1Sdbj if (KDFAULT(f->f_wb1s)) 9131.1Sdbj *(char *)f->f_wb1a = wb1d; 9141.1Sdbj else 9151.1Sdbj err = subyte((caddr_t)f->f_wb1a, wb1d); 9161.1Sdbj break; 9171.1Sdbj case SSW4_SZW: 9181.1Sdbj off = (off + 16) % 32; 9191.1Sdbj if (off) 9201.1Sdbj wb1d = (wb1d >> (32 - off)) | (wb1d << off); 9211.1Sdbj if (KDFAULT(f->f_wb1s)) 9221.1Sdbj *(short *)f->f_wb1a = wb1d; 9231.1Sdbj else 9241.1Sdbj err = susword((caddr_t)f->f_wb1a, wb1d); 9251.1Sdbj break; 9261.1Sdbj } 9271.1Sdbj if (err) { 9281.1Sdbj fa = f->f_wb1a; 9291.1Sdbj#ifdef DEBUG 9301.1Sdbj if (mmudebug & MDB_WBFAILED) 9311.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 9321.1Sdbj "#1", fp->f_pc, f->f_fa, 9331.1Sdbj f->f_wb1a, f->f_wb1d); 9341.1Sdbj#endif 9351.1Sdbj } 9361.1Sdbj } 9371.1Sdbj /* 9381.1Sdbj * Deal with the "normal" writebacks. 9391.1Sdbj * 9401.1Sdbj * XXX writeback2 is known to reflect a LINE size writeback after 9411.1Sdbj * a MOVE16 was already dealt with above. Ignore it. 9421.1Sdbj */ 9431.1Sdbj if (err == 0 && (f->f_wb2s & SSW4_WBSV) && 9441.1Sdbj (f->f_wb2s & SSW4_SZMASK) != SSW4_SZLN) { 9451.1Sdbj#ifdef DEBUG 9461.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 9471.1Sdbj dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d); 9481.1Sdbj wbstats.wb2s++; 9491.1Sdbj wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++; 9501.1Sdbj#endif 9511.1Sdbj switch (f->f_wb2s & SSW4_SZMASK) { 9521.1Sdbj case SSW4_SZLW: 9531.1Sdbj if (KDFAULT(f->f_wb2s)) 9541.1Sdbj *(long *)f->f_wb2a = f->f_wb2d; 9551.1Sdbj else 9561.1Sdbj err = suword((caddr_t)f->f_wb2a, f->f_wb2d); 9571.1Sdbj break; 9581.1Sdbj case SSW4_SZB: 9591.1Sdbj if (KDFAULT(f->f_wb2s)) 9601.1Sdbj *(char *)f->f_wb2a = f->f_wb2d; 9611.1Sdbj else 9621.1Sdbj err = subyte((caddr_t)f->f_wb2a, f->f_wb2d); 9631.1Sdbj break; 9641.1Sdbj case SSW4_SZW: 9651.1Sdbj if (KDFAULT(f->f_wb2s)) 9661.1Sdbj *(short *)f->f_wb2a = f->f_wb2d; 9671.1Sdbj else 9681.1Sdbj err = susword((caddr_t)f->f_wb2a, f->f_wb2d); 9691.1Sdbj break; 9701.1Sdbj } 9711.1Sdbj if (err) { 9721.1Sdbj fa = f->f_wb2a; 9731.1Sdbj#ifdef DEBUG 9741.1Sdbj if (mmudebug & MDB_WBFAILED) { 9751.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 9761.1Sdbj "#2", fp->f_pc, f->f_fa, 9771.1Sdbj f->f_wb2a, f->f_wb2d); 9781.1Sdbj dumpssw(f->f_ssw); 9791.1Sdbj dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d); 9801.1Sdbj } 9811.1Sdbj#endif 9821.1Sdbj } 9831.1Sdbj } 9841.1Sdbj if (err == 0 && (f->f_wb3s & SSW4_WBSV)) { 9851.1Sdbj#ifdef DEBUG 9861.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 9871.1Sdbj dumpwb(3, f->f_wb3s, f->f_wb3a, f->f_wb3d); 9881.1Sdbj wbstats.wb3s++; 9891.1Sdbj wbstats.wbsize[(f->f_wb3s&SSW4_SZMASK)>>5]++; 9901.1Sdbj#endif 9911.1Sdbj switch (f->f_wb3s & SSW4_SZMASK) { 9921.1Sdbj case SSW4_SZLW: 9931.1Sdbj if (KDFAULT(f->f_wb3s)) 9941.1Sdbj *(long *)f->f_wb3a = f->f_wb3d; 9951.1Sdbj else 9961.1Sdbj err = suword((caddr_t)f->f_wb3a, f->f_wb3d); 9971.1Sdbj break; 9981.1Sdbj case SSW4_SZB: 9991.1Sdbj if (KDFAULT(f->f_wb3s)) 10001.1Sdbj *(char *)f->f_wb3a = f->f_wb3d; 10011.1Sdbj else 10021.1Sdbj err = subyte((caddr_t)f->f_wb3a, f->f_wb3d); 10031.1Sdbj break; 10041.1Sdbj case SSW4_SZW: 10051.1Sdbj if (KDFAULT(f->f_wb3s)) 10061.1Sdbj *(short *)f->f_wb3a = f->f_wb3d; 10071.1Sdbj else 10081.1Sdbj err = susword((caddr_t)f->f_wb3a, f->f_wb3d); 10091.1Sdbj break; 10101.1Sdbj#ifdef DEBUG 10111.1Sdbj case SSW4_SZLN: 10121.1Sdbj panic("writeback: wb3s indicates LINE write"); 10131.1Sdbj#endif 10141.1Sdbj } 10151.1Sdbj if (err) { 10161.1Sdbj fa = f->f_wb3a; 10171.1Sdbj#ifdef DEBUG 10181.1Sdbj if (mmudebug & MDB_WBFAILED) 10191.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 10201.1Sdbj "#3", fp->f_pc, f->f_fa, 10211.1Sdbj f->f_wb3a, f->f_wb3d); 10221.1Sdbj#endif 10231.1Sdbj } 10241.1Sdbj } 10251.39Sthorpej l->l_addr->u_pcb.pcb_onfault = oonfault; 10261.1Sdbj if (err) 10271.1Sdbj err = SIGSEGV; 10281.16Sdbj return (err); 10291.1Sdbj} 10301.1Sdbj 10311.1Sdbj#ifdef DEBUG 10321.16Sdbjvoid 10331.1Sdbjdumpssw(ssw) 10341.1Sdbj u_short ssw; 10351.1Sdbj{ 10361.1Sdbj printf(" SSW: %x: ", ssw); 10371.1Sdbj if (ssw & SSW4_CP) 10381.1Sdbj printf("CP,"); 10391.1Sdbj if (ssw & SSW4_CU) 10401.1Sdbj printf("CU,"); 10411.1Sdbj if (ssw & SSW4_CT) 10421.1Sdbj printf("CT,"); 10431.1Sdbj if (ssw & SSW4_CM) 10441.1Sdbj printf("CM,"); 10451.1Sdbj if (ssw & SSW4_MA) 10461.1Sdbj printf("MA,"); 10471.1Sdbj if (ssw & SSW4_ATC) 10481.1Sdbj printf("ATC,"); 10491.1Sdbj if (ssw & SSW4_LK) 10501.1Sdbj printf("LK,"); 10511.1Sdbj if (ssw & SSW4_RW) 10521.1Sdbj printf("RW,"); 10531.1Sdbj printf(" SZ=%s, TT=%s, TM=%s\n", 10541.1Sdbj f7sz[(ssw & SSW4_SZMASK) >> 5], 10551.1Sdbj f7tt[(ssw & SSW4_TTMASK) >> 3], 10561.1Sdbj f7tm[ssw & SSW4_TMMASK]); 10571.1Sdbj} 10581.1Sdbj 10591.16Sdbjvoid 10601.1Sdbjdumpwb(num, s, a, d) 10611.1Sdbj int num; 10621.1Sdbj u_short s; 10631.1Sdbj u_int a, d; 10641.1Sdbj{ 10651.1Sdbj struct proc *p = curproc; 10661.7Sdbj paddr_t pa; 10671.1Sdbj 10681.1Sdbj printf(" writeback #%d: VA %x, data %x, SZ=%s, TT=%s, TM=%s\n", 10691.1Sdbj num, a, d, f7sz[(s & SSW4_SZMASK) >> 5], 10701.1Sdbj f7tt[(s & SSW4_TTMASK) >> 3], f7tm[s & SSW4_TMMASK]); 10711.16Sdbj printf(" PA "); 10721.15Sthorpej if (pmap_extract(p->p_vmspace->vm_map.pmap, (vaddr_t)a, &pa) == FALSE) 10731.1Sdbj printf("<invalid address>"); 10741.1Sdbj else 10751.16Sdbj printf("%lx, current value %lx", pa, fuword((caddr_t)a)); 10761.1Sdbj printf("\n"); 10771.1Sdbj} 10781.1Sdbj#endif 10791.1Sdbj#endif 10801.1Sdbj 10811.1Sdbj/* 10821.1Sdbj * Allocation routines for software interrupts. 10831.1Sdbj */ 10841.1Sdbju_long 10851.1Sdbjallocate_sir(proc, arg) 10861.16Sdbj void (*proc)(void *); 10871.1Sdbj void *arg; 10881.1Sdbj{ 10891.1Sdbj int bit; 10901.1Sdbj 10911.1Sdbj if( next_sir >= NSIR ) 10921.1Sdbj panic("allocate_sir: none left"); 10931.1Sdbj bit = next_sir++; 10941.1Sdbj sir_routines[bit] = proc; 10951.1Sdbj sir_args[bit] = arg; 10961.1Sdbj return (1 << bit); 10971.1Sdbj} 10981.1Sdbj 10991.1Sdbjvoid 11001.1Sdbjinit_sir() 11011.1Sdbj{ 11021.16Sdbj extern void netintr(void); 11031.1Sdbj 11041.16Sdbj sir_routines[0] = (void (*)(void *))netintr; 11051.30Sthorpej sir_routines[1] = softclock; 11061.1Sdbj next_sir = 2; 11071.1Sdbj} 1108