trap.c revision 1.87
11.87Schristos/* $NetBSD: trap.c,v 1.87 2014/03/24 20:01:03 christos 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.84Srmind * Copyright (c) 1988 University of Utah. 121.1Sdbj * Copyright (c) 1982, 1986, 1990, 1993 131.1Sdbj * The Regents of the University of California. All rights reserved. 141.1Sdbj * 151.1Sdbj * This code is derived from software contributed to Berkeley by 161.1Sdbj * the Systems Programming Group of the University of Utah Computer 171.1Sdbj * Science Department. 181.1Sdbj * 191.1Sdbj * Redistribution and use in source and binary forms, with or without 201.1Sdbj * modification, are permitted provided that the following conditions 211.1Sdbj * are met: 221.1Sdbj * 1. Redistributions of source code must retain the above copyright 231.1Sdbj * notice, this list of conditions and the following disclaimer. 241.1Sdbj * 2. Redistributions in binary form must reproduce the above copyright 251.1Sdbj * notice, this list of conditions and the following disclaimer in the 261.1Sdbj * documentation and/or other materials provided with the distribution. 271.43Sagc * 3. Neither the name of the University nor the names of its contributors 281.43Sagc * may be used to endorse or promote products derived from this software 291.43Sagc * without specific prior written permission. 301.43Sagc * 311.43Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 321.43Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 331.43Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 341.43Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 351.43Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 361.43Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 371.43Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 381.43Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 391.43Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 401.43Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 411.43Sagc * SUCH DAMAGE. 421.43Sagc * 431.43Sagc * from: Utah $Hdr: trap.c 1.37 92/12/20$ 441.43Sagc * 451.43Sagc * @(#)trap.c 8.5 (Berkeley) 1/4/94 461.43Sagc */ 471.42Slukem 481.42Slukem#include <sys/cdefs.h> 491.87Schristos__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.87 2014/03/24 20:01:03 christos Exp $"); 501.2Sthorpej 511.5Sjonathan#include "opt_ddb.h" 521.9Sitohy#include "opt_execfmt.h" 531.33Slukem#include "opt_kgdb.h" 541.3Sthorpej#include "opt_compat_sunos.h" 551.80Smrg#include "opt_m68k_arch.h" 561.1Sdbj 571.1Sdbj#include <sys/param.h> 581.1Sdbj#include <sys/systm.h> 591.1Sdbj#include <sys/proc.h> 601.1Sdbj#include <sys/acct.h> 611.1Sdbj#include <sys/kernel.h> 621.1Sdbj#include <sys/signalvar.h> 631.1Sdbj#include <sys/resourcevar.h> 641.1Sdbj#include <sys/syscall.h> 651.1Sdbj#include <sys/syslog.h> 661.47Scl#include <sys/userret.h> 671.59Syamt#include <sys/kauth.h> 681.16Sdbj 691.16Sdbj#ifdef DEBUG 701.16Sdbj#include <dev/cons.h> 711.14Sdbj#endif 721.1Sdbj 731.16Sdbj#include <machine/db_machdep.h> 741.83Stsutsui#include <machine/pcb.h> 751.1Sdbj#include <machine/psl.h> 761.1Sdbj#include <machine/trap.h> 771.1Sdbj#include <machine/cpu.h> 781.1Sdbj#include <machine/reg.h> 791.1Sdbj 801.16Sdbj#include <m68k/cacheops.h> 811.16Sdbj 821.7Sdbj#include <uvm/uvm_extern.h> 831.1Sdbj 841.1Sdbj#ifdef COMPAT_SUNOS 851.1Sdbj#include <compat/sunos/sunos_syscall.h> 861.1Sdbjextern struct emul emul_sunos; 871.1Sdbj#endif 881.1Sdbj 891.37Sjdolecek#ifdef KGDB 901.37Sjdolecek#include <sys/kgdb.h> 911.37Sjdolecek#endif 921.37Sjdolecek 931.53Schsint writeback(struct frame *, int); 941.67Smhitchvoid trap(struct frame *, int, u_int, u_int); 951.16Sdbj 961.16Sdbj#ifdef DEBUG 971.53Schsvoid dumpssw(u_short); 981.53Schsvoid dumpwb(int, u_short, u_int, u_int); 991.16Sdbj#endif 1001.16Sdbj 1011.53Schsstatic inline void userret(struct lwp *, struct frame *, u_quad_t, u_int, int); 1021.1Sdbj 1031.7Sdbjint astpending; 1041.1Sdbj 1051.54Sheconst char *trap_type[] = { 1061.1Sdbj "Bus error", 1071.1Sdbj "Address error", 1081.1Sdbj "Illegal instruction", 1091.1Sdbj "Zero divide", 1101.1Sdbj "CHK instruction", 1111.1Sdbj "TRAPV instruction", 1121.1Sdbj "Privilege violation", 1131.1Sdbj "Trace trap", 1141.1Sdbj "MMU fault", 1151.1Sdbj "SSIR trap", 1161.1Sdbj "Format error", 1171.1Sdbj "68881 exception", 1181.1Sdbj "Coprocessor violation", 1191.1Sdbj "Async system trap" 1201.1Sdbj}; 1211.1Sdbjint trap_types = sizeof trap_type / sizeof trap_type[0]; 1221.1Sdbj 1231.1Sdbj/* 1241.1Sdbj * Size of various exception stack frames (minus the standard 8 bytes) 1251.1Sdbj */ 1261.1Sdbjshort exframesize[] = { 1271.16Sdbj FMT0SIZE, /* type 0 - normal (68020/030/040/060) */ 1281.1Sdbj FMT1SIZE, /* type 1 - throwaway (68020/030/040) */ 1291.16Sdbj FMT2SIZE, /* type 2 - normal 6-word (68020/030/040/060) */ 1301.16Sdbj FMT3SIZE, /* type 3 - FP post-instruction (68040/060) */ 1311.16Sdbj FMT4SIZE, /* type 4 - access error/fp disabled (68060) */ 1321.16Sdbj -1, -1, /* type 5-6 - undefined */ 1331.1Sdbj FMT7SIZE, /* type 7 - access error (68040) */ 1341.1Sdbj 58, /* type 8 - bus fault (68010) */ 1351.1Sdbj FMT9SIZE, /* type 9 - coprocessor mid-instruction (68020/030) */ 1361.1Sdbj FMTASIZE, /* type A - short bus fault (68020/030) */ 1371.1Sdbj FMTBSIZE, /* type B - long bus fault (68020/030) */ 1381.1Sdbj -1, -1, -1, -1 /* type C-F - undefined */ 1391.1Sdbj}; 1401.1Sdbj 1411.16Sdbj#ifdef M68060 1421.16Sdbj#define KDFAULT_060(c) (cputype == CPU_68060 && ((c) & FSLW_TM_SV)) 1431.16Sdbj#define WRFAULT_060(c) (cputype == CPU_68060 && ((c) & FSLW_RW_W)) 1441.16Sdbj#else 1451.16Sdbj#define KDFAULT_060(c) 0 1461.16Sdbj#define WRFAULT_060(c) 0 1471.16Sdbj#endif 1481.16Sdbj 1491.1Sdbj#ifdef M68040 1501.16Sdbj#define KDFAULT_040(c) (cputype == CPU_68040 && \ 1511.16Sdbj ((c) & SSW4_TMMASK) == SSW4_TMKD) 1521.16Sdbj#define WRFAULT_040(c) (cputype == CPU_68040 && \ 1531.68Smhitch ((c) & (SSW4_LK|SSW4_RW)) != SSW4_RW) 1541.16Sdbj#else 1551.16Sdbj#define KDFAULT_040(c) 0 1561.16Sdbj#define WRFAULT_040(c) 0 1571.16Sdbj#endif 1581.16Sdbj 1591.16Sdbj#if defined(M68030) || defined(M68020) 1601.16Sdbj#define KDFAULT_OTH(c) (cputype <= CPU_68030 && \ 1611.16Sdbj ((c) & (SSW_DF|SSW_FCMASK)) == (SSW_DF|FC_SUPERD)) 1621.16Sdbj#define WRFAULT_OTH(c) (cputype <= CPU_68030 && \ 1631.68Smhitch (((c) & SSW_DF) != 0 && \ 1641.68Smhitch ((((c) & SSW_RW) == 0) || (((c) & SSW_RM) != 0)))) 1651.1Sdbj#else 1661.16Sdbj#define KDFAULT_OTH(c) 0 1671.16Sdbj#define WRFAULT_OTH(c) 0 1681.1Sdbj#endif 1691.1Sdbj 1701.16Sdbj#define KDFAULT(c) (KDFAULT_060(c) || KDFAULT_040(c) || KDFAULT_OTH(c)) 1711.16Sdbj#define WRFAULT(c) (WRFAULT_060(c) || WRFAULT_040(c) || WRFAULT_OTH(c)) 1721.16Sdbj 1731.1Sdbj#ifdef DEBUG 1741.1Sdbjint mmudebug = 0; 1751.1Sdbjint mmupid = -1; 1761.1Sdbj#define MDB_FOLLOW 1 1771.1Sdbj#define MDB_WBFOLLOW 2 1781.1Sdbj#define MDB_WBFAILED 4 1791.16Sdbj#define MDB_ISPID(p) ((p) == mmupid) 1801.1Sdbj#endif 1811.1Sdbj 1821.1Sdbj/* 1831.1Sdbj * trap and syscall both need the following work done before returning 1841.1Sdbj * to user mode. 1851.1Sdbj */ 1861.1Sdbjstatic inline void 1871.53Schsuserret(struct lwp *l, struct frame *fp, u_quad_t oticks, u_int faultaddr, 1881.53Schs int fromtrap) 1891.1Sdbj{ 1901.39Sthorpej struct proc *p = l->l_proc; 1911.48Scl#ifdef M68040 1921.20Sthorpej int sig; 1931.1Sdbj int beenhere = 0; 1941.1Sdbj 1951.1Sdbjagain: 1961.1Sdbj#endif 1971.47Scl /* Invoke MI userret code */ 1981.47Scl mi_userret(l); 1991.1Sdbj 2001.1Sdbj /* 2011.1Sdbj * If profiling, charge system time to the trapped pc. 2021.1Sdbj */ 2031.62Sad if (p->p_stflag & PST_PROFIL) { 2041.1Sdbj extern int psratio; 2051.1Sdbj 2061.62Sad addupc_task(l, fp->f_pc, 2071.1Sdbj (int)(p->p_sticks - oticks) * psratio); 2081.1Sdbj } 2091.1Sdbj#ifdef M68040 2101.1Sdbj /* 2111.1Sdbj * Deal with user mode writebacks (from trap, or from sigreturn). 2121.1Sdbj * If any writeback fails, go back and attempt signal delivery. 2131.1Sdbj * unless we have already been here and attempted the writeback 2141.1Sdbj * (e.g. bad address with user ignoring SIGSEGV). In that case 2151.40Swiz * we just return to the user without successfully completing 2161.1Sdbj * the writebacks. Maybe we should just drop the sucker? 2171.1Sdbj */ 2181.16Sdbj if (cputype == CPU_68040 && fp->f_format == FMT7) { 2191.1Sdbj if (beenhere) { 2201.1Sdbj#ifdef DEBUG 2211.1Sdbj if (mmudebug & MDB_WBFAILED) 2221.1Sdbj printf(fromtrap ? 2231.1Sdbj "pid %d(%s): writeback aborted, pc=%x, fa=%x\n" : 2241.1Sdbj "pid %d(%s): writeback aborted in sigreturn, pc=%x\n", 2251.1Sdbj p->p_pid, p->p_comm, fp->f_pc, faultaddr); 2261.1Sdbj#endif 2271.16Sdbj } else if ((sig = writeback(fp, fromtrap))) { 2281.45Scl ksiginfo_t ksi; 2291.1Sdbj beenhere = 1; 2301.1Sdbj oticks = p->p_sticks; 2311.45Scl (void)memset(&ksi, 0, sizeof(ksi)); 2321.45Scl ksi.ksi_signo = sig; 2331.45Scl ksi.ksi_addr = (void *)faultaddr; 2341.45Scl ksi.ksi_code = BUS_OBJERR; 2351.45Scl trapsignal(l, &ksi); 2361.1Sdbj goto again; 2371.1Sdbj } 2381.1Sdbj } 2391.1Sdbj#endif 2401.1Sdbj} 2411.1Sdbj 2421.1Sdbj/* 2431.28Sscw * Used by the common m68k syscall() and child_return() functions. 2441.28Sscw * XXX: Temporary until all m68k ports share common trap()/userret() code. 2451.28Sscw */ 2461.39Sthorpejvoid machine_userret(struct lwp *, struct frame *, u_quad_t); 2471.28Sscw 2481.28Sscwvoid 2491.53Schsmachine_userret(struct lwp *l, struct frame *f, u_quad_t t) 2501.28Sscw{ 2511.28Sscw 2521.39Sthorpej userret(l, f, t, 0, 0); 2531.28Sscw} 2541.28Sscw 2551.28Sscw/* 2561.1Sdbj * Trap is called from locore to handle most types of processor traps, 2571.1Sdbj * including events such as simulated software interrupts/AST's. 2581.1Sdbj * System calls are broken out for efficiency. 2591.1Sdbj */ 2601.1Sdbj/*ARGSUSED*/ 2611.16Sdbjvoid 2621.67Smhitchtrap(struct frame *fp, int type, unsigned code, unsigned v) 2631.1Sdbj{ 2641.1Sdbj extern char fubail[], subail[]; 2651.39Sthorpej struct lwp *l; 2661.1Sdbj struct proc *p; 2671.78Srmind struct pcb *pcb; 2681.79Schs void *onfault; 2691.45Scl ksiginfo_t ksi; 2701.45Scl int s; 2711.79Schs int rv; 2721.16Sdbj u_quad_t sticks = 0 /* XXX initialiser works around compiler bug */; 2731.87Schristos static int panicking __diagused; 2741.1Sdbj 2751.82Smatt curcpu()->ci_data.cpu_ntrap++; 2761.39Sthorpej l = curlwp; 2771.79Schs p = l->l_proc; 2781.79Schs pcb = lwp_getpcb(l); 2791.45Scl 2801.46Sthorpej KSI_INIT_TRAP(&ksi); 2811.45Scl ksi.ksi_trap = type & ~T_USER; 2821.16Sdbj 2831.67Smhitch if (USERMODE(fp->f_sr)) { 2841.1Sdbj type |= T_USER; 2851.1Sdbj sticks = p->p_sticks; 2861.67Smhitch l->l_md.md_regs = fp->f_regs; 2871.60Sad LWP_CACHE_CREDS(l, p); 2881.1Sdbj } 2891.1Sdbj switch (type) { 2901.1Sdbj 2911.1Sdbj default: 2921.14Sdbj dopanic: 2931.14Sdbj /* 2941.14Sdbj * Let the kernel debugger see the trap frame that 2951.14Sdbj * caused us to panic. This is a convenience so 2961.14Sdbj * one can see registers at the point of failure. 2971.14Sdbj */ 2981.16Sdbj s = splhigh(); 2991.51Swiz panicking = 1; 3001.38Smycroft printf("trap type %d, code = 0x%x, v = 0x%x\n", type, code, v); 3011.38Smycroft printf("%s program counter = 0x%x\n", 3021.67Smhitch (type & T_USER) ? "user" : "kernel", fp->f_pc); 3031.14Sdbj#ifdef KGDB 3041.14Sdbj /* If connected, step or cont returns 1 */ 3051.67Smhitch if (kgdb_trap(type, (db_regs_t *)fp)) 3061.14Sdbj goto kgdb_cont; 3071.14Sdbj#endif 3081.16Sdbj#ifdef DDB 3091.67Smhitch (void)kdb_trap(type, (db_regs_t *)fp); 3101.1Sdbj#endif 3111.14Sdbj#ifdef KGDB 3121.14Sdbj kgdb_cont: 3131.14Sdbj#endif 3141.16Sdbj splx(s); 3151.14Sdbj if (panicstr) { 3161.16Sdbj printf("trap during panic!\n"); 3171.16Sdbj#ifdef DEBUG 3181.16Sdbj /* XXX should be a machine-dependent hook */ 3191.16Sdbj printf("(press a key)\n"); (void)cngetc(); 3201.16Sdbj#endif 3211.14Sdbj } 3221.67Smhitch regdump((struct trapframe *)fp, 128); 3231.1Sdbj type &= ~T_USER; 3241.16Sdbj if ((u_int)type < trap_types) 3251.1Sdbj panic(trap_type[type]); 3261.1Sdbj panic("trap"); 3271.1Sdbj 3281.1Sdbj case T_BUSERR: /* kernel bus error */ 3291.79Schs onfault = pcb->pcb_onfault; 3301.79Schs if (onfault == NULL) 3311.1Sdbj goto dopanic; 3321.79Schs rv = EFAULT; 3331.16Sdbj /* FALLTHROUGH */ 3341.16Sdbj 3351.16Sdbj copyfault: 3361.1Sdbj /* 3371.1Sdbj * If we have arranged to catch this fault in any of the 3381.1Sdbj * copy to/from user space routines, set PC to return to 3391.1Sdbj * indicated location and set flag informing buserror code 3401.1Sdbj * that it may need to clean up stack frame. 3411.1Sdbj */ 3421.67Smhitch fp->f_stackadj = exframesize[fp->f_format]; 3431.67Smhitch fp->f_format = fp->f_vector = 0; 3441.79Schs fp->f_pc = (int)onfault; 3451.79Schs fp->f_regs[D0] = rv; 3461.1Sdbj return; 3471.1Sdbj 3481.1Sdbj case T_BUSERR|T_USER: /* bus error */ 3491.1Sdbj case T_ADDRERR|T_USER: /* address error */ 3501.45Scl ksi.ksi_addr = (void *)v; 3511.45Scl ksi.ksi_signo = SIGBUS; 3521.45Scl ksi.ksi_code = (type == (T_BUSERR|T_USER)) ? 3531.45Scl BUS_OBJERR : BUS_ADRERR; 3541.1Sdbj break; 3551.1Sdbj 3561.1Sdbj case T_COPERR: /* kernel coprocessor violation */ 3571.1Sdbj case T_FMTERR|T_USER: /* do all RTE errors come in as T_USER? */ 3581.1Sdbj case T_FMTERR: /* ...just in case... */ 3591.1Sdbj /* 3601.1Sdbj * The user has most likely trashed the RTE or FP state info 3611.1Sdbj * in the stack frame of a signal handler. 3621.1Sdbj */ 3631.1Sdbj printf("pid %d: kernel %s exception\n", p->p_pid, 3641.1Sdbj type==T_COPERR ? "coprocessor" : "format"); 3651.1Sdbj type |= T_USER; 3661.62Sad 3671.73Sad mutex_enter(p->p_lock); 3681.29Sjdolecek SIGACTION(p, SIGILL).sa_handler = SIG_DFL; 3691.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigignore, SIGILL); 3701.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigcatch, SIGILL); 3711.62Sad sigdelset(&l->l_sigmask, SIGILL); 3721.73Sad mutex_exit(p->p_lock); 3731.62Sad 3741.45Scl ksi.ksi_signo = SIGILL; 3751.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 3761.45Scl /* XXX was ILL_RESAD_FAULT */ 3771.45Scl ksi.ksi_code = (type == T_COPERR) ? 3781.45Scl ILL_COPROC : ILL_ILLOPC; 3791.1Sdbj break; 3801.1Sdbj 3811.1Sdbj case T_COPERR|T_USER: /* user coprocessor violation */ 3821.1Sdbj /* What is a proper response here? */ 3831.45Scl ksi.ksi_signo = SIGFPE; 3841.45Scl ksi.ksi_code = FPE_FLTINV; 3851.1Sdbj break; 3861.1Sdbj 3871.1Sdbj case T_FPERR|T_USER: /* 68881 exceptions */ 3881.1Sdbj /* 3891.7Sdbj * We pass along the 68881 status register which locore stashed 3901.75Smartin * in code for us. 3911.1Sdbj */ 3921.45Scl ksi.ksi_signo = SIGFPE; 3931.75Smartin ksi.ksi_code = fpsr2siginfocode(code); 3941.1Sdbj break; 3951.1Sdbj 3961.1Sdbj#ifdef M68040 3971.56Swiz case T_FPEMULI|T_USER: /* unimplemented FP instruction */ 3981.1Sdbj case T_FPEMULD|T_USER: /* unimplemented FP data type */ 3991.1Sdbj /* XXX need to FSAVE */ 4001.1Sdbj printf("pid %d(%s): unimplemented FP %s at %x (EA %x)\n", 4011.1Sdbj p->p_pid, p->p_comm, 4021.67Smhitch fp->f_format == 2 ? "instruction" : "data type", 4031.67Smhitch fp->f_pc, fp->f_fmt2.f_iaddr); 4041.1Sdbj /* XXX need to FRESTORE */ 4051.45Scl ksi.ksi_signo = SIGFPE; 4061.45Scl ksi.ksi_code = FPE_FLTINV; 4071.1Sdbj break; 4081.1Sdbj#endif 4091.1Sdbj 4101.1Sdbj case T_ILLINST|T_USER: /* illegal instruction fault */ 4111.1Sdbj case T_PRIVINST|T_USER: /* privileged instruction fault */ 4121.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4131.45Scl /* XXX was ILL_PRIVIN_FAULT */ 4141.45Scl ksi.ksi_signo = SIGILL; 4151.45Scl ksi.ksi_code = (type == (T_PRIVINST|T_USER)) ? 4161.45Scl ILL_PRVOPC : ILL_ILLOPC; 4171.1Sdbj break; 4181.1Sdbj 4191.1Sdbj case T_ZERODIV|T_USER: /* Divide by zero */ 4201.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4211.45Scl /* XXX was FPE_INTDIV_TRAP */ 4221.45Scl ksi.ksi_signo = SIGFPE; 4231.45Scl ksi.ksi_code = FPE_FLTDIV; 4241.1Sdbj break; 4251.1Sdbj 4261.1Sdbj case T_CHKINST|T_USER: /* CHK instruction trap */ 4271.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4281.45Scl /* XXX was FPE_SUBRNG_TRAP */ 4291.45Scl ksi.ksi_signo = SIGFPE; 4301.1Sdbj break; 4311.1Sdbj 4321.1Sdbj case T_TRAPVINST|T_USER: /* TRAPV instruction trap */ 4331.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4341.45Scl /* XXX was FPE_INTOVF_TRAP */ 4351.45Scl ksi.ksi_signo = SIGFPE; 4361.1Sdbj break; 4371.1Sdbj 4381.1Sdbj /* 4391.1Sdbj * XXX: Trace traps are a nightmare. 4401.1Sdbj * 4411.1Sdbj * HP-UX uses trap #1 for breakpoints, 4421.16Sdbj * NetBSD/m68k uses trap #2, 4431.1Sdbj * SUN 3.x uses trap #15, 4441.16Sdbj * DDB and KGDB uses trap #15 (for kernel breakpoints; 4451.16Sdbj * handled elsewhere). 4461.1Sdbj * 4471.16Sdbj * NetBSD and HP-UX traps both get mapped by locore.s into T_TRACE. 4481.1Sdbj * SUN 3.x traps get passed through as T_TRAP15 and are not really 4491.1Sdbj * supported yet. 4501.16Sdbj * 4511.17Sitohy * XXX: We should never get kernel-mode T_TRAP15 4521.16Sdbj * XXX: because locore.s now gives them special treatment. 4531.1Sdbj */ 4541.16Sdbj case T_TRAP15: /* kernel breakpoint */ 4551.16Sdbj#ifdef DEBUG 4561.16Sdbj printf("unexpected kernel trace trap, type = %d\n", type); 4571.67Smhitch printf("program counter = 0x%x\n", fp->f_pc); 4581.1Sdbj#endif 4591.67Smhitch fp->f_sr &= ~PSL_T; 4601.16Sdbj return; 4611.1Sdbj 4621.1Sdbj case T_TRACE|T_USER: /* user trace trap */ 4631.1Sdbj#ifdef COMPAT_SUNOS 4641.1Sdbj /* 4651.1Sdbj * SunOS uses Trap #2 for a "CPU cache flush". 4661.1Sdbj * Just flush the on-chip caches and return. 4671.1Sdbj */ 4681.1Sdbj if (p->p_emul == &emul_sunos) { 4691.1Sdbj ICIA(); 4701.1Sdbj DCIU(); 4711.1Sdbj return; 4721.1Sdbj } 4731.16Sdbj#endif 4741.17Sitohy /* FALLTHROUGH */ 4751.17Sitohy case T_TRACE: /* tracing a trap instruction */ 4761.17Sitohy case T_TRAP15|T_USER: /* SUN user trace trap */ 4771.67Smhitch fp->f_sr &= ~PSL_T; 4781.45Scl ksi.ksi_signo = SIGTRAP; 4791.1Sdbj break; 4801.1Sdbj 4811.1Sdbj case T_ASTFLT: /* system async trap, cannot happen */ 4821.1Sdbj goto dopanic; 4831.1Sdbj 4841.1Sdbj case T_ASTFLT|T_USER: /* user async trap */ 4851.1Sdbj astpending = 0; 4861.1Sdbj /* 4871.1Sdbj * We check for software interrupts first. This is because 4881.1Sdbj * they are at a higher level than ASTs, and on a VAX would 4891.1Sdbj * interrupt the AST. We assume that if we are processing 4901.1Sdbj * an AST that we must be at IPL0 so we don't bother to 4911.1Sdbj * check. Note that we ensure that we are at least at SIR 4921.1Sdbj * IPL while processing the SIR. 4931.1Sdbj */ 4941.1Sdbj spl1(); 4951.1Sdbj /* fall into... */ 4961.1Sdbj 4971.1Sdbj case T_SSIR: /* software interrupt */ 4981.1Sdbj case T_SSIR|T_USER: 4991.1Sdbj /* 5001.1Sdbj * If this was not an AST trap, we are all done. 5011.1Sdbj */ 5021.1Sdbj if (type != (T_ASTFLT|T_USER)) { 5031.82Smatt curcpu()->ci_data.cpu_ntrap--; 5041.1Sdbj return; 5051.1Sdbj } 5061.1Sdbj spl0(); 5071.62Sad if (l->l_pflag & LP_OWEUPC) { 5081.62Sad l->l_pflag &= ~LP_OWEUPC; 5091.62Sad ADDUPROF(l); 5101.1Sdbj } 5111.66Stsutsui if (curcpu()->ci_want_resched) 5121.62Sad preempt(); 5131.1Sdbj goto out; 5141.1Sdbj 5151.1Sdbj case T_MMUFLT: /* kernel mode page fault */ 5161.1Sdbj /* 5171.1Sdbj * If we were doing profiling ticks or other user mode 5181.1Sdbj * stuff from interrupt code, Just Say No. 5191.1Sdbj */ 5201.79Schs onfault = pcb->pcb_onfault; 5211.79Schs if (onfault == fubail || onfault == subail) { 5221.79Schs rv = EFAULT; 5231.1Sdbj goto copyfault; 5241.79Schs } 5251.1Sdbj /* fall into ... */ 5261.1Sdbj 5271.1Sdbj case T_MMUFLT|T_USER: /* page fault */ 5281.1Sdbj { 5291.7Sdbj vaddr_t va; 5301.1Sdbj struct vmspace *vm = p->p_vmspace; 5311.34Schs struct vm_map *map; 5321.1Sdbj vm_prot_t ftype; 5331.34Schs extern struct vm_map *kernel_map; 5341.1Sdbj 5351.79Schs onfault = pcb->pcb_onfault; 5361.79Schs 5371.1Sdbj#ifdef DEBUG 5381.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 5391.1Sdbj printf("trap: T_MMUFLT pid=%d, code=%x, v=%x, pc=%x, sr=%x\n", 5401.67Smhitch p->p_pid, code, v, fp->f_pc, fp->f_sr); 5411.1Sdbj#endif 5421.1Sdbj /* 5431.1Sdbj * It is only a kernel address space fault iff: 5441.1Sdbj * 1. (type & T_USER) == 0 and 5451.1Sdbj * 2. pcb_onfault not set or 5461.1Sdbj * 3. pcb_onfault set but supervisor space data fault 5471.1Sdbj * The last can occur during an exec() copyin where the 5481.1Sdbj * argument space is lazy-allocated. 5491.1Sdbj */ 5501.79Schs if ((type & T_USER) == 0 && (onfault == NULL || KDFAULT(code))) 5511.1Sdbj map = kernel_map; 5521.74Swrstuden else { 5531.16Sdbj map = vm ? &vm->vm_map : kernel_map; 5541.74Swrstuden } 5551.16Sdbj 5561.1Sdbj if (WRFAULT(code)) 5571.36Schs ftype = VM_PROT_WRITE; 5581.1Sdbj else 5591.1Sdbj ftype = VM_PROT_READ; 5601.16Sdbj 5611.7Sdbj va = trunc_page((vaddr_t)v); 5621.16Sdbj 5631.1Sdbj if (map == kernel_map && va == 0) { 5641.16Sdbj printf("trap: bad kernel %s access at 0x%x\n", 5651.16Sdbj (ftype & VM_PROT_WRITE) ? "read/write" : 5661.16Sdbj "read", v); 5671.1Sdbj goto dopanic; 5681.1Sdbj } 5691.16Sdbj 5701.38Smycroft#ifdef DIAGNOSTIC 5711.51Swiz if (interrupt_depth && !panicking) { 5721.38Smycroft printf("trap: calling uvm_fault() from interrupt!\n"); 5731.38Smycroft goto dopanic; 5741.38Smycroft } 5751.38Smycroft#endif 5761.38Smycroft 5771.79Schs pcb->pcb_onfault = NULL; 5781.57Sdrochner rv = uvm_fault(map, va, ftype); 5791.79Schs pcb->pcb_onfault = onfault; 5801.7Sdbj#ifdef DEBUG 5811.7Sdbj if (rv && MDB_ISPID(p->p_pid)) 5821.57Sdrochner printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n", 5831.16Sdbj map, va, ftype, rv); 5841.7Sdbj#endif 5851.1Sdbj /* 5861.1Sdbj * If this was a stack access we keep track of the maximum 5871.1Sdbj * accessed stack size. Also, if vm_fault gets a protection 5881.1Sdbj * failure it is due to accessing the stack region outside 5891.1Sdbj * the current limit and we need to reflect that as an access 5901.1Sdbj * error. 5911.1Sdbj */ 5921.31Schs if (rv == 0) { 5931.64Schristos if (map != kernel_map && (void *)va >= vm->vm_maxsaddr) 5941.52Sjdolecek uvm_grow(p, va); 5951.52Sjdolecek 5961.1Sdbj if (type == T_MMUFLT) { 5971.81Schs if (ucas_ras_check(&fp->F_t)) { 5981.81Schs return; 5991.81Schs } 6001.16Sdbj#ifdef M68040 6011.16Sdbj if (cputype == CPU_68040) 6021.67Smhitch (void) writeback(fp, 1); 6031.1Sdbj#endif 6041.1Sdbj return; 6051.1Sdbj } 6061.1Sdbj goto out; 6071.1Sdbj } 6081.45Scl if (rv == EACCES) { 6091.45Scl ksi.ksi_code = SEGV_ACCERR; 6101.45Scl rv = EFAULT; 6111.45Scl } else 6121.45Scl ksi.ksi_code = SEGV_MAPERR; 6131.1Sdbj if (type == T_MMUFLT) { 6141.79Schs if (onfault) 6151.1Sdbj goto copyfault; 6161.57Sdrochner printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n", 6171.16Sdbj map, va, ftype, rv); 6181.1Sdbj printf(" type %x, code [mmu,,ssw]: %x\n", 6191.1Sdbj type, code); 6201.1Sdbj goto dopanic; 6211.1Sdbj } 6221.45Scl ksi.ksi_addr = (void *)v; 6231.31Schs if (rv == ENOMEM) { 6241.11Schs printf("UVM: pid %d (%s), uid %d killed: out of swap\n", 6251.11Schs p->p_pid, p->p_comm, 6261.61Sad l->l_cred ? 6271.61Sad kauth_cred_geteuid(l->l_cred) : -1); 6281.45Scl ksi.ksi_signo = SIGKILL; 6291.11Schs } else { 6301.45Scl ksi.ksi_signo = SIGSEGV; 6311.11Schs } 6321.1Sdbj break; 6331.1Sdbj } 6341.1Sdbj } 6351.45Scl trapsignal(l, &ksi); 6361.1Sdbj if ((type & T_USER) == 0) 6371.1Sdbj return; 6381.1Sdbjout: 6391.67Smhitch userret(l, fp, sticks, v, 1); 6401.1Sdbj} 6411.1Sdbj 6421.1Sdbj#ifdef M68040 6431.1Sdbj#ifdef DEBUG 6441.1Sdbjstruct writebackstats { 6451.1Sdbj int calls; 6461.1Sdbj int cpushes; 6471.1Sdbj int move16s; 6481.1Sdbj int wb1s, wb2s, wb3s; 6491.1Sdbj int wbsize[4]; 6501.1Sdbj} wbstats; 6511.1Sdbj 6521.54Sheconst char *f7sz[] = { "longword", "byte", "word", "line" }; 6531.54Sheconst char *f7tt[] = { "normal", "MOVE16", "AFC", "ACK" }; 6541.54Sheconst char *f7tm[] = { "d-push", "u-data", "u-code", "M-data", 6551.1Sdbj "M-code", "k-data", "k-code", "RES" }; 6561.54Sheconst char wberrstr[] = 6571.16Sdbj "WARNING: pid %d(%s) writeback [%s] failed, pc=%x fa=%x wba=%x wbd=%x\n"; 6581.1Sdbj#endif 6591.1Sdbj 6601.16Sdbjint 6611.53Schswriteback(struct frame *fp, int docachepush) 6621.1Sdbj{ 6631.1Sdbj struct fmt7 *f = &fp->f_fmt7; 6641.39Sthorpej struct lwp *l = curlwp; 6651.39Sthorpej struct proc *p = l->l_proc; 6661.78Srmind struct pcb *pcb = lwp_getpcb(l); 6671.1Sdbj int err = 0; 6681.1Sdbj u_int fa; 6691.78Srmind void *oonfault = pcb->pcb_onfault; 6701.15Sthorpej paddr_t pa; 6711.1Sdbj 6721.1Sdbj#ifdef DEBUG 6731.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) { 6741.1Sdbj printf(" pid=%d, fa=%x,", p->p_pid, f->f_fa); 6751.1Sdbj dumpssw(f->f_ssw); 6761.1Sdbj } 6771.1Sdbj wbstats.calls++; 6781.1Sdbj#endif 6791.1Sdbj /* 6801.1Sdbj * Deal with special cases first. 6811.1Sdbj */ 6821.1Sdbj if ((f->f_ssw & SSW4_TMMASK) == SSW4_TMDCP) { 6831.1Sdbj /* 6841.1Sdbj * Dcache push fault. 6851.1Sdbj * Line-align the address and write out the push data to 6861.1Sdbj * the indicated physical address. 6871.1Sdbj */ 6881.1Sdbj#ifdef DEBUG 6891.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) { 6901.1Sdbj printf(" pushing %s to PA %x, data %x", 6911.1Sdbj f7sz[(f->f_ssw & SSW4_SZMASK) >> 5], 6921.1Sdbj f->f_fa, f->f_pd0); 6931.1Sdbj if ((f->f_ssw & SSW4_SZMASK) == SSW4_SZLN) 6941.1Sdbj printf("/%x/%x/%x", 6951.1Sdbj f->f_pd1, f->f_pd2, f->f_pd3); 6961.1Sdbj printf("\n"); 6971.1Sdbj } 6981.1Sdbj if (f->f_wb1s & SSW4_WBSV) 6991.1Sdbj panic("writeback: cache push with WB1S valid"); 7001.1Sdbj wbstats.cpushes++; 7011.1Sdbj#endif 7021.1Sdbj /* 7031.1Sdbj * XXX there are security problems if we attempt to do a 7041.1Sdbj * cache push after a signal handler has been called. 7051.1Sdbj */ 7061.1Sdbj if (docachepush) { 7071.7Sdbj pmap_enter(pmap_kernel(), (vaddr_t)vmmap, 7081.18Sthorpej trunc_page(f->f_fa), VM_PROT_WRITE, 7091.18Sthorpej VM_PROT_WRITE|PMAP_WIRED); 7101.35Schris pmap_update(pmap_kernel()); 7111.1Sdbj fa = (u_int)&vmmap[(f->f_fa & PGOFSET) & ~0xF]; 7121.77Scegger memcpy((void *)fa, (void *)&f->f_pd0, 16); 7131.15Sthorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)fa, &pa); 7141.15Sthorpej DCFL(pa); 7151.7Sdbj pmap_remove(pmap_kernel(), (vaddr_t)vmmap, 7161.41Sthorpej (vaddr_t)&vmmap[PAGE_SIZE]); 7171.35Schris pmap_update(pmap_kernel()); 7181.1Sdbj } else 7191.1Sdbj printf("WARNING: pid %d(%s) uid %d: CPUSH not done\n", 7201.61Sad p->p_pid, p->p_comm, kauth_cred_geteuid(l->l_cred)); 7211.1Sdbj } else if ((f->f_ssw & (SSW4_RW|SSW4_TTMASK)) == SSW4_TTM16) { 7221.1Sdbj /* 7231.1Sdbj * MOVE16 fault. 7241.1Sdbj * Line-align the address and write out the push data to 7251.1Sdbj * the indicated virtual address. 7261.1Sdbj */ 7271.1Sdbj#ifdef DEBUG 7281.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 7291.1Sdbj printf(" MOVE16 to VA %x(%x), data %x/%x/%x/%x\n", 7301.1Sdbj f->f_fa, f->f_fa & ~0xF, f->f_pd0, f->f_pd1, 7311.1Sdbj f->f_pd2, f->f_pd3); 7321.1Sdbj if (f->f_wb1s & SSW4_WBSV) 7331.1Sdbj panic("writeback: MOVE16 with WB1S valid"); 7341.1Sdbj wbstats.move16s++; 7351.1Sdbj#endif 7361.1Sdbj if (KDFAULT(f->f_wb1s)) 7371.77Scegger memcpy((void *)(f->f_fa & ~0xF), (void *)&f->f_pd0, 16); 7381.1Sdbj else 7391.64Schristos err = suline((void *)(f->f_fa & ~0xF), (void *)&f->f_pd0); 7401.1Sdbj if (err) { 7411.1Sdbj fa = f->f_fa & ~0xF; 7421.1Sdbj#ifdef DEBUG 7431.1Sdbj if (mmudebug & MDB_WBFAILED) 7441.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 7451.1Sdbj "MOVE16", fp->f_pc, f->f_fa, 7461.1Sdbj f->f_fa & ~0xF, f->f_pd0); 7471.1Sdbj#endif 7481.1Sdbj } 7491.1Sdbj } else if (f->f_wb1s & SSW4_WBSV) { 7501.1Sdbj /* 7511.1Sdbj * Writeback #1. 7521.1Sdbj * Position the "memory-aligned" data and write it out. 7531.1Sdbj */ 7541.1Sdbj u_int wb1d = f->f_wb1d; 7551.1Sdbj int off; 7561.1Sdbj 7571.1Sdbj#ifdef DEBUG 7581.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 7591.1Sdbj dumpwb(1, f->f_wb1s, f->f_wb1a, f->f_wb1d); 7601.1Sdbj wbstats.wb1s++; 7611.1Sdbj wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++; 7621.1Sdbj#endif 7631.1Sdbj off = (f->f_wb1a & 3) * 8; 7641.1Sdbj switch (f->f_wb1s & SSW4_SZMASK) { 7651.1Sdbj case SSW4_SZLW: 7661.1Sdbj if (off) 7671.1Sdbj wb1d = (wb1d >> (32 - off)) | (wb1d << off); 7681.1Sdbj if (KDFAULT(f->f_wb1s)) 7691.1Sdbj *(long *)f->f_wb1a = wb1d; 7701.1Sdbj else 7711.64Schristos err = suword((void *)f->f_wb1a, wb1d); 7721.1Sdbj break; 7731.1Sdbj case SSW4_SZB: 7741.1Sdbj off = 24 - off; 7751.1Sdbj if (off) 7761.1Sdbj wb1d >>= off; 7771.1Sdbj if (KDFAULT(f->f_wb1s)) 7781.1Sdbj *(char *)f->f_wb1a = wb1d; 7791.1Sdbj else 7801.64Schristos err = subyte((void *)f->f_wb1a, wb1d); 7811.1Sdbj break; 7821.1Sdbj case SSW4_SZW: 7831.1Sdbj off = (off + 16) % 32; 7841.1Sdbj if (off) 7851.1Sdbj wb1d = (wb1d >> (32 - off)) | (wb1d << off); 7861.1Sdbj if (KDFAULT(f->f_wb1s)) 7871.1Sdbj *(short *)f->f_wb1a = wb1d; 7881.1Sdbj else 7891.64Schristos err = susword((void *)f->f_wb1a, wb1d); 7901.1Sdbj break; 7911.1Sdbj } 7921.1Sdbj if (err) { 7931.1Sdbj fa = f->f_wb1a; 7941.1Sdbj#ifdef DEBUG 7951.1Sdbj if (mmudebug & MDB_WBFAILED) 7961.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 7971.1Sdbj "#1", fp->f_pc, f->f_fa, 7981.1Sdbj f->f_wb1a, f->f_wb1d); 7991.1Sdbj#endif 8001.1Sdbj } 8011.1Sdbj } 8021.1Sdbj /* 8031.1Sdbj * Deal with the "normal" writebacks. 8041.1Sdbj * 8051.1Sdbj * XXX writeback2 is known to reflect a LINE size writeback after 8061.1Sdbj * a MOVE16 was already dealt with above. Ignore it. 8071.1Sdbj */ 8081.1Sdbj if (err == 0 && (f->f_wb2s & SSW4_WBSV) && 8091.1Sdbj (f->f_wb2s & SSW4_SZMASK) != SSW4_SZLN) { 8101.1Sdbj#ifdef DEBUG 8111.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8121.1Sdbj dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d); 8131.1Sdbj wbstats.wb2s++; 8141.1Sdbj wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++; 8151.1Sdbj#endif 8161.1Sdbj switch (f->f_wb2s & SSW4_SZMASK) { 8171.1Sdbj case SSW4_SZLW: 8181.1Sdbj if (KDFAULT(f->f_wb2s)) 8191.1Sdbj *(long *)f->f_wb2a = f->f_wb2d; 8201.1Sdbj else 8211.64Schristos err = suword((void *)f->f_wb2a, f->f_wb2d); 8221.1Sdbj break; 8231.1Sdbj case SSW4_SZB: 8241.1Sdbj if (KDFAULT(f->f_wb2s)) 8251.1Sdbj *(char *)f->f_wb2a = f->f_wb2d; 8261.1Sdbj else 8271.64Schristos err = subyte((void *)f->f_wb2a, f->f_wb2d); 8281.1Sdbj break; 8291.1Sdbj case SSW4_SZW: 8301.1Sdbj if (KDFAULT(f->f_wb2s)) 8311.1Sdbj *(short *)f->f_wb2a = f->f_wb2d; 8321.1Sdbj else 8331.64Schristos err = susword((void *)f->f_wb2a, f->f_wb2d); 8341.1Sdbj break; 8351.1Sdbj } 8361.1Sdbj if (err) { 8371.1Sdbj fa = f->f_wb2a; 8381.1Sdbj#ifdef DEBUG 8391.1Sdbj if (mmudebug & MDB_WBFAILED) { 8401.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 8411.1Sdbj "#2", fp->f_pc, f->f_fa, 8421.1Sdbj f->f_wb2a, f->f_wb2d); 8431.1Sdbj dumpssw(f->f_ssw); 8441.1Sdbj dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d); 8451.1Sdbj } 8461.1Sdbj#endif 8471.1Sdbj } 8481.1Sdbj } 8491.1Sdbj if (err == 0 && (f->f_wb3s & SSW4_WBSV)) { 8501.1Sdbj#ifdef DEBUG 8511.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8521.1Sdbj dumpwb(3, f->f_wb3s, f->f_wb3a, f->f_wb3d); 8531.1Sdbj wbstats.wb3s++; 8541.1Sdbj wbstats.wbsize[(f->f_wb3s&SSW4_SZMASK)>>5]++; 8551.1Sdbj#endif 8561.1Sdbj switch (f->f_wb3s & SSW4_SZMASK) { 8571.1Sdbj case SSW4_SZLW: 8581.1Sdbj if (KDFAULT(f->f_wb3s)) 8591.1Sdbj *(long *)f->f_wb3a = f->f_wb3d; 8601.1Sdbj else 8611.64Schristos err = suword((void *)f->f_wb3a, f->f_wb3d); 8621.1Sdbj break; 8631.1Sdbj case SSW4_SZB: 8641.1Sdbj if (KDFAULT(f->f_wb3s)) 8651.1Sdbj *(char *)f->f_wb3a = f->f_wb3d; 8661.1Sdbj else 8671.64Schristos err = subyte((void *)f->f_wb3a, f->f_wb3d); 8681.1Sdbj break; 8691.1Sdbj case SSW4_SZW: 8701.1Sdbj if (KDFAULT(f->f_wb3s)) 8711.1Sdbj *(short *)f->f_wb3a = f->f_wb3d; 8721.1Sdbj else 8731.64Schristos err = susword((void *)f->f_wb3a, f->f_wb3d); 8741.1Sdbj break; 8751.1Sdbj#ifdef DEBUG 8761.1Sdbj case SSW4_SZLN: 8771.1Sdbj panic("writeback: wb3s indicates LINE write"); 8781.1Sdbj#endif 8791.1Sdbj } 8801.1Sdbj if (err) { 8811.1Sdbj fa = f->f_wb3a; 8821.1Sdbj#ifdef DEBUG 8831.1Sdbj if (mmudebug & MDB_WBFAILED) 8841.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 8851.1Sdbj "#3", fp->f_pc, f->f_fa, 8861.1Sdbj f->f_wb3a, f->f_wb3d); 8871.1Sdbj#endif 8881.1Sdbj } 8891.1Sdbj } 8901.78Srmind pcb->pcb_onfault = oonfault; 8911.1Sdbj if (err) 8921.1Sdbj err = SIGSEGV; 8931.16Sdbj return (err); 8941.1Sdbj} 8951.1Sdbj 8961.1Sdbj#ifdef DEBUG 8971.16Sdbjvoid 8981.53Schsdumpssw(u_short ssw) 8991.1Sdbj{ 9001.1Sdbj printf(" SSW: %x: ", ssw); 9011.1Sdbj if (ssw & SSW4_CP) 9021.1Sdbj printf("CP,"); 9031.1Sdbj if (ssw & SSW4_CU) 9041.1Sdbj printf("CU,"); 9051.1Sdbj if (ssw & SSW4_CT) 9061.1Sdbj printf("CT,"); 9071.1Sdbj if (ssw & SSW4_CM) 9081.1Sdbj printf("CM,"); 9091.1Sdbj if (ssw & SSW4_MA) 9101.1Sdbj printf("MA,"); 9111.1Sdbj if (ssw & SSW4_ATC) 9121.1Sdbj printf("ATC,"); 9131.1Sdbj if (ssw & SSW4_LK) 9141.1Sdbj printf("LK,"); 9151.1Sdbj if (ssw & SSW4_RW) 9161.1Sdbj printf("RW,"); 9171.1Sdbj printf(" SZ=%s, TT=%s, TM=%s\n", 9181.1Sdbj f7sz[(ssw & SSW4_SZMASK) >> 5], 9191.1Sdbj f7tt[(ssw & SSW4_TTMASK) >> 3], 9201.1Sdbj f7tm[ssw & SSW4_TMMASK]); 9211.1Sdbj} 9221.1Sdbj 9231.16Sdbjvoid 9241.53Schsdumpwb(int num, u_short s, u_int a, u_int d) 9251.1Sdbj{ 9261.1Sdbj struct proc *p = curproc; 9271.7Sdbj paddr_t pa; 9281.1Sdbj 9291.1Sdbj printf(" writeback #%d: VA %x, data %x, SZ=%s, TT=%s, TM=%s\n", 9301.1Sdbj num, a, d, f7sz[(s & SSW4_SZMASK) >> 5], 9311.1Sdbj f7tt[(s & SSW4_TTMASK) >> 3], f7tm[s & SSW4_TMMASK]); 9321.16Sdbj printf(" PA "); 9331.63Sthorpej if (pmap_extract(p->p_vmspace->vm_map.pmap, (vaddr_t)a, &pa) == false) 9341.1Sdbj printf("<invalid address>"); 9351.1Sdbj else 9361.64Schristos printf("%lx, current value %lx", pa, fuword((void *)a)); 9371.1Sdbj printf("\n"); 9381.1Sdbj} 9391.1Sdbj#endif 9401.1Sdbj#endif 941