trap.c revision 1.83
11.83Stsutsui/* $NetBSD: trap.c,v 1.83 2011/01/17 14:53:43 tsutsui 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.83Stsutsui__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.83 2011/01/17 14:53:43 tsutsui 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.80Smrg#include "opt_m68k_arch.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.74Swrstuden#include <sys/sa.h> 1031.74Swrstuden#include <sys/savar.h> 1041.1Sdbj#include <sys/syscall.h> 1051.1Sdbj#include <sys/syslog.h> 1061.47Scl#include <sys/userret.h> 1071.59Syamt#include <sys/kauth.h> 1081.16Sdbj 1091.16Sdbj#ifdef DEBUG 1101.16Sdbj#include <dev/cons.h> 1111.14Sdbj#endif 1121.1Sdbj 1131.16Sdbj#include <machine/db_machdep.h> 1141.83Stsutsui#include <machine/pcb.h> 1151.1Sdbj#include <machine/psl.h> 1161.1Sdbj#include <machine/trap.h> 1171.1Sdbj#include <machine/cpu.h> 1181.1Sdbj#include <machine/reg.h> 1191.1Sdbj 1201.16Sdbj#include <m68k/cacheops.h> 1211.16Sdbj 1221.7Sdbj#include <uvm/uvm_extern.h> 1231.1Sdbj 1241.1Sdbj#ifdef COMPAT_SUNOS 1251.1Sdbj#include <compat/sunos/sunos_syscall.h> 1261.1Sdbjextern struct emul emul_sunos; 1271.1Sdbj#endif 1281.1Sdbj 1291.37Sjdolecek#ifdef KGDB 1301.37Sjdolecek#include <sys/kgdb.h> 1311.37Sjdolecek#endif 1321.37Sjdolecek 1331.53Schsint writeback(struct frame *, int); 1341.67Smhitchvoid trap(struct frame *, int, u_int, u_int); 1351.16Sdbj 1361.16Sdbj#ifdef DEBUG 1371.53Schsvoid dumpssw(u_short); 1381.53Schsvoid dumpwb(int, u_short, u_int, u_int); 1391.16Sdbj#endif 1401.16Sdbj 1411.53Schsstatic inline void userret(struct lwp *, struct frame *, u_quad_t, u_int, int); 1421.1Sdbj 1431.7Sdbjint astpending; 1441.1Sdbj 1451.54Sheconst char *trap_type[] = { 1461.1Sdbj "Bus error", 1471.1Sdbj "Address error", 1481.1Sdbj "Illegal instruction", 1491.1Sdbj "Zero divide", 1501.1Sdbj "CHK instruction", 1511.1Sdbj "TRAPV instruction", 1521.1Sdbj "Privilege violation", 1531.1Sdbj "Trace trap", 1541.1Sdbj "MMU fault", 1551.1Sdbj "SSIR trap", 1561.1Sdbj "Format error", 1571.1Sdbj "68881 exception", 1581.1Sdbj "Coprocessor violation", 1591.1Sdbj "Async system trap" 1601.1Sdbj}; 1611.1Sdbjint trap_types = sizeof trap_type / sizeof trap_type[0]; 1621.1Sdbj 1631.1Sdbj/* 1641.1Sdbj * Size of various exception stack frames (minus the standard 8 bytes) 1651.1Sdbj */ 1661.1Sdbjshort exframesize[] = { 1671.16Sdbj FMT0SIZE, /* type 0 - normal (68020/030/040/060) */ 1681.1Sdbj FMT1SIZE, /* type 1 - throwaway (68020/030/040) */ 1691.16Sdbj FMT2SIZE, /* type 2 - normal 6-word (68020/030/040/060) */ 1701.16Sdbj FMT3SIZE, /* type 3 - FP post-instruction (68040/060) */ 1711.16Sdbj FMT4SIZE, /* type 4 - access error/fp disabled (68060) */ 1721.16Sdbj -1, -1, /* type 5-6 - undefined */ 1731.1Sdbj FMT7SIZE, /* type 7 - access error (68040) */ 1741.1Sdbj 58, /* type 8 - bus fault (68010) */ 1751.1Sdbj FMT9SIZE, /* type 9 - coprocessor mid-instruction (68020/030) */ 1761.1Sdbj FMTASIZE, /* type A - short bus fault (68020/030) */ 1771.1Sdbj FMTBSIZE, /* type B - long bus fault (68020/030) */ 1781.1Sdbj -1, -1, -1, -1 /* type C-F - undefined */ 1791.1Sdbj}; 1801.1Sdbj 1811.16Sdbj#ifdef M68060 1821.16Sdbj#define KDFAULT_060(c) (cputype == CPU_68060 && ((c) & FSLW_TM_SV)) 1831.16Sdbj#define WRFAULT_060(c) (cputype == CPU_68060 && ((c) & FSLW_RW_W)) 1841.16Sdbj#else 1851.16Sdbj#define KDFAULT_060(c) 0 1861.16Sdbj#define WRFAULT_060(c) 0 1871.16Sdbj#endif 1881.16Sdbj 1891.1Sdbj#ifdef M68040 1901.16Sdbj#define KDFAULT_040(c) (cputype == CPU_68040 && \ 1911.16Sdbj ((c) & SSW4_TMMASK) == SSW4_TMKD) 1921.16Sdbj#define WRFAULT_040(c) (cputype == CPU_68040 && \ 1931.68Smhitch ((c) & (SSW4_LK|SSW4_RW)) != SSW4_RW) 1941.16Sdbj#else 1951.16Sdbj#define KDFAULT_040(c) 0 1961.16Sdbj#define WRFAULT_040(c) 0 1971.16Sdbj#endif 1981.16Sdbj 1991.16Sdbj#if defined(M68030) || defined(M68020) 2001.16Sdbj#define KDFAULT_OTH(c) (cputype <= CPU_68030 && \ 2011.16Sdbj ((c) & (SSW_DF|SSW_FCMASK)) == (SSW_DF|FC_SUPERD)) 2021.16Sdbj#define WRFAULT_OTH(c) (cputype <= CPU_68030 && \ 2031.68Smhitch (((c) & SSW_DF) != 0 && \ 2041.68Smhitch ((((c) & SSW_RW) == 0) || (((c) & SSW_RM) != 0)))) 2051.1Sdbj#else 2061.16Sdbj#define KDFAULT_OTH(c) 0 2071.16Sdbj#define WRFAULT_OTH(c) 0 2081.1Sdbj#endif 2091.1Sdbj 2101.16Sdbj#define KDFAULT(c) (KDFAULT_060(c) || KDFAULT_040(c) || KDFAULT_OTH(c)) 2111.16Sdbj#define WRFAULT(c) (WRFAULT_060(c) || WRFAULT_040(c) || WRFAULT_OTH(c)) 2121.16Sdbj 2131.1Sdbj#ifdef DEBUG 2141.1Sdbjint mmudebug = 0; 2151.1Sdbjint mmupid = -1; 2161.1Sdbj#define MDB_FOLLOW 1 2171.1Sdbj#define MDB_WBFOLLOW 2 2181.1Sdbj#define MDB_WBFAILED 4 2191.16Sdbj#define MDB_ISPID(p) ((p) == mmupid) 2201.1Sdbj#endif 2211.1Sdbj 2221.1Sdbj/* 2231.1Sdbj * trap and syscall both need the following work done before returning 2241.1Sdbj * to user mode. 2251.1Sdbj */ 2261.1Sdbjstatic inline void 2271.53Schsuserret(struct lwp *l, struct frame *fp, u_quad_t oticks, u_int faultaddr, 2281.53Schs int fromtrap) 2291.1Sdbj{ 2301.39Sthorpej struct proc *p = l->l_proc; 2311.48Scl#ifdef M68040 2321.20Sthorpej int sig; 2331.1Sdbj int beenhere = 0; 2341.1Sdbj 2351.1Sdbjagain: 2361.1Sdbj#endif 2371.47Scl /* Invoke MI userret code */ 2381.47Scl mi_userret(l); 2391.1Sdbj 2401.1Sdbj /* 2411.1Sdbj * If profiling, charge system time to the trapped pc. 2421.1Sdbj */ 2431.62Sad if (p->p_stflag & PST_PROFIL) { 2441.1Sdbj extern int psratio; 2451.1Sdbj 2461.62Sad addupc_task(l, fp->f_pc, 2471.1Sdbj (int)(p->p_sticks - oticks) * psratio); 2481.1Sdbj } 2491.1Sdbj#ifdef M68040 2501.1Sdbj /* 2511.1Sdbj * Deal with user mode writebacks (from trap, or from sigreturn). 2521.1Sdbj * If any writeback fails, go back and attempt signal delivery. 2531.1Sdbj * unless we have already been here and attempted the writeback 2541.1Sdbj * (e.g. bad address with user ignoring SIGSEGV). In that case 2551.40Swiz * we just return to the user without successfully completing 2561.1Sdbj * the writebacks. Maybe we should just drop the sucker? 2571.1Sdbj */ 2581.16Sdbj if (cputype == CPU_68040 && fp->f_format == FMT7) { 2591.1Sdbj if (beenhere) { 2601.1Sdbj#ifdef DEBUG 2611.1Sdbj if (mmudebug & MDB_WBFAILED) 2621.1Sdbj printf(fromtrap ? 2631.1Sdbj "pid %d(%s): writeback aborted, pc=%x, fa=%x\n" : 2641.1Sdbj "pid %d(%s): writeback aborted in sigreturn, pc=%x\n", 2651.1Sdbj p->p_pid, p->p_comm, fp->f_pc, faultaddr); 2661.1Sdbj#endif 2671.16Sdbj } else if ((sig = writeback(fp, fromtrap))) { 2681.45Scl ksiginfo_t ksi; 2691.1Sdbj beenhere = 1; 2701.1Sdbj oticks = p->p_sticks; 2711.45Scl (void)memset(&ksi, 0, sizeof(ksi)); 2721.45Scl ksi.ksi_signo = sig; 2731.45Scl ksi.ksi_addr = (void *)faultaddr; 2741.45Scl ksi.ksi_code = BUS_OBJERR; 2751.45Scl trapsignal(l, &ksi); 2761.1Sdbj goto again; 2771.1Sdbj } 2781.1Sdbj } 2791.1Sdbj#endif 2801.1Sdbj} 2811.1Sdbj 2821.1Sdbj/* 2831.28Sscw * Used by the common m68k syscall() and child_return() functions. 2841.28Sscw * XXX: Temporary until all m68k ports share common trap()/userret() code. 2851.28Sscw */ 2861.39Sthorpejvoid machine_userret(struct lwp *, struct frame *, u_quad_t); 2871.28Sscw 2881.28Sscwvoid 2891.53Schsmachine_userret(struct lwp *l, struct frame *f, u_quad_t t) 2901.28Sscw{ 2911.28Sscw 2921.39Sthorpej userret(l, f, t, 0, 0); 2931.28Sscw} 2941.28Sscw 2951.28Sscw/* 2961.1Sdbj * Trap is called from locore to handle most types of processor traps, 2971.1Sdbj * including events such as simulated software interrupts/AST's. 2981.1Sdbj * System calls are broken out for efficiency. 2991.1Sdbj */ 3001.1Sdbj/*ARGSUSED*/ 3011.16Sdbjvoid 3021.67Smhitchtrap(struct frame *fp, int type, unsigned code, unsigned v) 3031.1Sdbj{ 3041.1Sdbj extern char fubail[], subail[]; 3051.39Sthorpej struct lwp *l; 3061.1Sdbj struct proc *p; 3071.78Srmind struct pcb *pcb; 3081.79Schs void *onfault; 3091.45Scl ksiginfo_t ksi; 3101.45Scl int s; 3111.79Schs int rv; 3121.16Sdbj u_quad_t sticks = 0 /* XXX initialiser works around compiler bug */; 3131.51Swiz static int panicking = 0; 3141.1Sdbj 3151.82Smatt curcpu()->ci_data.cpu_ntrap++; 3161.39Sthorpej l = curlwp; 3171.79Schs p = l->l_proc; 3181.79Schs pcb = lwp_getpcb(l); 3191.45Scl 3201.46Sthorpej KSI_INIT_TRAP(&ksi); 3211.45Scl ksi.ksi_trap = type & ~T_USER; 3221.16Sdbj 3231.67Smhitch if (USERMODE(fp->f_sr)) { 3241.1Sdbj type |= T_USER; 3251.1Sdbj sticks = p->p_sticks; 3261.67Smhitch l->l_md.md_regs = fp->f_regs; 3271.60Sad LWP_CACHE_CREDS(l, p); 3281.1Sdbj } 3291.1Sdbj switch (type) { 3301.1Sdbj 3311.1Sdbj default: 3321.14Sdbj dopanic: 3331.14Sdbj /* 3341.14Sdbj * Let the kernel debugger see the trap frame that 3351.14Sdbj * caused us to panic. This is a convenience so 3361.14Sdbj * one can see registers at the point of failure. 3371.14Sdbj */ 3381.16Sdbj s = splhigh(); 3391.51Swiz panicking = 1; 3401.38Smycroft printf("trap type %d, code = 0x%x, v = 0x%x\n", type, code, v); 3411.38Smycroft printf("%s program counter = 0x%x\n", 3421.67Smhitch (type & T_USER) ? "user" : "kernel", fp->f_pc); 3431.14Sdbj#ifdef KGDB 3441.14Sdbj /* If connected, step or cont returns 1 */ 3451.67Smhitch if (kgdb_trap(type, (db_regs_t *)fp)) 3461.14Sdbj goto kgdb_cont; 3471.14Sdbj#endif 3481.16Sdbj#ifdef DDB 3491.67Smhitch (void)kdb_trap(type, (db_regs_t *)fp); 3501.1Sdbj#endif 3511.14Sdbj#ifdef KGDB 3521.14Sdbj kgdb_cont: 3531.14Sdbj#endif 3541.16Sdbj splx(s); 3551.14Sdbj if (panicstr) { 3561.16Sdbj printf("trap during panic!\n"); 3571.16Sdbj#ifdef DEBUG 3581.16Sdbj /* XXX should be a machine-dependent hook */ 3591.16Sdbj printf("(press a key)\n"); (void)cngetc(); 3601.16Sdbj#endif 3611.14Sdbj } 3621.67Smhitch regdump((struct trapframe *)fp, 128); 3631.1Sdbj type &= ~T_USER; 3641.16Sdbj if ((u_int)type < trap_types) 3651.1Sdbj panic(trap_type[type]); 3661.1Sdbj panic("trap"); 3671.1Sdbj 3681.1Sdbj case T_BUSERR: /* kernel bus error */ 3691.79Schs onfault = pcb->pcb_onfault; 3701.79Schs if (onfault == NULL) 3711.1Sdbj goto dopanic; 3721.79Schs rv = EFAULT; 3731.16Sdbj /* FALLTHROUGH */ 3741.16Sdbj 3751.16Sdbj copyfault: 3761.1Sdbj /* 3771.1Sdbj * If we have arranged to catch this fault in any of the 3781.1Sdbj * copy to/from user space routines, set PC to return to 3791.1Sdbj * indicated location and set flag informing buserror code 3801.1Sdbj * that it may need to clean up stack frame. 3811.1Sdbj */ 3821.67Smhitch fp->f_stackadj = exframesize[fp->f_format]; 3831.67Smhitch fp->f_format = fp->f_vector = 0; 3841.79Schs fp->f_pc = (int)onfault; 3851.79Schs fp->f_regs[D0] = rv; 3861.1Sdbj return; 3871.1Sdbj 3881.1Sdbj case T_BUSERR|T_USER: /* bus error */ 3891.1Sdbj case T_ADDRERR|T_USER: /* address error */ 3901.45Scl ksi.ksi_addr = (void *)v; 3911.45Scl ksi.ksi_signo = SIGBUS; 3921.45Scl ksi.ksi_code = (type == (T_BUSERR|T_USER)) ? 3931.45Scl BUS_OBJERR : BUS_ADRERR; 3941.1Sdbj break; 3951.1Sdbj 3961.1Sdbj case T_COPERR: /* kernel coprocessor violation */ 3971.1Sdbj case T_FMTERR|T_USER: /* do all RTE errors come in as T_USER? */ 3981.1Sdbj case T_FMTERR: /* ...just in case... */ 3991.1Sdbj /* 4001.1Sdbj * The user has most likely trashed the RTE or FP state info 4011.1Sdbj * in the stack frame of a signal handler. 4021.1Sdbj */ 4031.1Sdbj printf("pid %d: kernel %s exception\n", p->p_pid, 4041.1Sdbj type==T_COPERR ? "coprocessor" : "format"); 4051.1Sdbj type |= T_USER; 4061.62Sad 4071.73Sad mutex_enter(p->p_lock); 4081.29Sjdolecek SIGACTION(p, SIGILL).sa_handler = SIG_DFL; 4091.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigignore, SIGILL); 4101.29Sjdolecek sigdelset(&p->p_sigctx.ps_sigcatch, SIGILL); 4111.62Sad sigdelset(&l->l_sigmask, SIGILL); 4121.73Sad mutex_exit(p->p_lock); 4131.62Sad 4141.45Scl ksi.ksi_signo = SIGILL; 4151.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4161.45Scl /* XXX was ILL_RESAD_FAULT */ 4171.45Scl ksi.ksi_code = (type == T_COPERR) ? 4181.45Scl ILL_COPROC : ILL_ILLOPC; 4191.1Sdbj break; 4201.1Sdbj 4211.1Sdbj case T_COPERR|T_USER: /* user coprocessor violation */ 4221.1Sdbj /* What is a proper response here? */ 4231.45Scl ksi.ksi_signo = SIGFPE; 4241.45Scl ksi.ksi_code = FPE_FLTINV; 4251.1Sdbj break; 4261.1Sdbj 4271.1Sdbj case T_FPERR|T_USER: /* 68881 exceptions */ 4281.1Sdbj /* 4291.7Sdbj * We pass along the 68881 status register which locore stashed 4301.75Smartin * in code for us. 4311.1Sdbj */ 4321.45Scl ksi.ksi_signo = SIGFPE; 4331.75Smartin ksi.ksi_code = fpsr2siginfocode(code); 4341.1Sdbj break; 4351.1Sdbj 4361.1Sdbj#ifdef M68040 4371.56Swiz case T_FPEMULI|T_USER: /* unimplemented FP instruction */ 4381.1Sdbj case T_FPEMULD|T_USER: /* unimplemented FP data type */ 4391.1Sdbj /* XXX need to FSAVE */ 4401.1Sdbj printf("pid %d(%s): unimplemented FP %s at %x (EA %x)\n", 4411.1Sdbj p->p_pid, p->p_comm, 4421.67Smhitch fp->f_format == 2 ? "instruction" : "data type", 4431.67Smhitch fp->f_pc, fp->f_fmt2.f_iaddr); 4441.1Sdbj /* XXX need to FRESTORE */ 4451.45Scl ksi.ksi_signo = SIGFPE; 4461.45Scl ksi.ksi_code = FPE_FLTINV; 4471.1Sdbj break; 4481.1Sdbj#endif 4491.1Sdbj 4501.1Sdbj case T_ILLINST|T_USER: /* illegal instruction fault */ 4511.1Sdbj case T_PRIVINST|T_USER: /* privileged instruction fault */ 4521.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4531.45Scl /* XXX was ILL_PRIVIN_FAULT */ 4541.45Scl ksi.ksi_signo = SIGILL; 4551.45Scl ksi.ksi_code = (type == (T_PRIVINST|T_USER)) ? 4561.45Scl ILL_PRVOPC : ILL_ILLOPC; 4571.1Sdbj break; 4581.1Sdbj 4591.1Sdbj case T_ZERODIV|T_USER: /* Divide by zero */ 4601.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4611.45Scl /* XXX was FPE_INTDIV_TRAP */ 4621.45Scl ksi.ksi_signo = SIGFPE; 4631.45Scl ksi.ksi_code = FPE_FLTDIV; 4641.1Sdbj break; 4651.1Sdbj 4661.1Sdbj case T_CHKINST|T_USER: /* CHK instruction trap */ 4671.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4681.45Scl /* XXX was FPE_SUBRNG_TRAP */ 4691.45Scl ksi.ksi_signo = SIGFPE; 4701.1Sdbj break; 4711.1Sdbj 4721.1Sdbj case T_TRAPVINST|T_USER: /* TRAPV instruction trap */ 4731.67Smhitch ksi.ksi_addr = (void *)(int)fp->f_format; 4741.45Scl /* XXX was FPE_INTOVF_TRAP */ 4751.45Scl ksi.ksi_signo = SIGFPE; 4761.1Sdbj break; 4771.1Sdbj 4781.1Sdbj /* 4791.1Sdbj * XXX: Trace traps are a nightmare. 4801.1Sdbj * 4811.1Sdbj * HP-UX uses trap #1 for breakpoints, 4821.16Sdbj * NetBSD/m68k uses trap #2, 4831.1Sdbj * SUN 3.x uses trap #15, 4841.16Sdbj * DDB and KGDB uses trap #15 (for kernel breakpoints; 4851.16Sdbj * handled elsewhere). 4861.1Sdbj * 4871.16Sdbj * NetBSD and HP-UX traps both get mapped by locore.s into T_TRACE. 4881.1Sdbj * SUN 3.x traps get passed through as T_TRAP15 and are not really 4891.1Sdbj * supported yet. 4901.16Sdbj * 4911.17Sitohy * XXX: We should never get kernel-mode T_TRAP15 4921.16Sdbj * XXX: because locore.s now gives them special treatment. 4931.1Sdbj */ 4941.16Sdbj case T_TRAP15: /* kernel breakpoint */ 4951.16Sdbj#ifdef DEBUG 4961.16Sdbj printf("unexpected kernel trace trap, type = %d\n", type); 4971.67Smhitch printf("program counter = 0x%x\n", fp->f_pc); 4981.1Sdbj#endif 4991.67Smhitch fp->f_sr &= ~PSL_T; 5001.16Sdbj return; 5011.1Sdbj 5021.1Sdbj case T_TRACE|T_USER: /* user trace trap */ 5031.1Sdbj#ifdef COMPAT_SUNOS 5041.1Sdbj /* 5051.1Sdbj * SunOS uses Trap #2 for a "CPU cache flush". 5061.1Sdbj * Just flush the on-chip caches and return. 5071.1Sdbj */ 5081.1Sdbj if (p->p_emul == &emul_sunos) { 5091.1Sdbj ICIA(); 5101.1Sdbj DCIU(); 5111.1Sdbj return; 5121.1Sdbj } 5131.16Sdbj#endif 5141.17Sitohy /* FALLTHROUGH */ 5151.17Sitohy case T_TRACE: /* tracing a trap instruction */ 5161.17Sitohy case T_TRAP15|T_USER: /* SUN user trace trap */ 5171.67Smhitch fp->f_sr &= ~PSL_T; 5181.45Scl ksi.ksi_signo = SIGTRAP; 5191.1Sdbj break; 5201.1Sdbj 5211.1Sdbj case T_ASTFLT: /* system async trap, cannot happen */ 5221.1Sdbj goto dopanic; 5231.1Sdbj 5241.1Sdbj case T_ASTFLT|T_USER: /* user async trap */ 5251.1Sdbj astpending = 0; 5261.1Sdbj /* 5271.1Sdbj * We check for software interrupts first. This is because 5281.1Sdbj * they are at a higher level than ASTs, and on a VAX would 5291.1Sdbj * interrupt the AST. We assume that if we are processing 5301.1Sdbj * an AST that we must be at IPL0 so we don't bother to 5311.1Sdbj * check. Note that we ensure that we are at least at SIR 5321.1Sdbj * IPL while processing the SIR. 5331.1Sdbj */ 5341.1Sdbj spl1(); 5351.1Sdbj /* fall into... */ 5361.1Sdbj 5371.1Sdbj case T_SSIR: /* software interrupt */ 5381.1Sdbj case T_SSIR|T_USER: 5391.1Sdbj /* 5401.1Sdbj * If this was not an AST trap, we are all done. 5411.1Sdbj */ 5421.1Sdbj if (type != (T_ASTFLT|T_USER)) { 5431.82Smatt curcpu()->ci_data.cpu_ntrap--; 5441.1Sdbj return; 5451.1Sdbj } 5461.1Sdbj spl0(); 5471.62Sad if (l->l_pflag & LP_OWEUPC) { 5481.62Sad l->l_pflag &= ~LP_OWEUPC; 5491.62Sad ADDUPROF(l); 5501.1Sdbj } 5511.66Stsutsui if (curcpu()->ci_want_resched) 5521.62Sad preempt(); 5531.1Sdbj goto out; 5541.1Sdbj 5551.1Sdbj case T_MMUFLT: /* kernel mode page fault */ 5561.1Sdbj /* 5571.1Sdbj * If we were doing profiling ticks or other user mode 5581.1Sdbj * stuff from interrupt code, Just Say No. 5591.1Sdbj */ 5601.79Schs onfault = pcb->pcb_onfault; 5611.79Schs if (onfault == fubail || onfault == subail) { 5621.79Schs rv = EFAULT; 5631.1Sdbj goto copyfault; 5641.79Schs } 5651.1Sdbj /* fall into ... */ 5661.1Sdbj 5671.1Sdbj case T_MMUFLT|T_USER: /* page fault */ 5681.1Sdbj { 5691.7Sdbj vaddr_t va; 5701.1Sdbj struct vmspace *vm = p->p_vmspace; 5711.34Schs struct vm_map *map; 5721.1Sdbj vm_prot_t ftype; 5731.34Schs extern struct vm_map *kernel_map; 5741.1Sdbj 5751.79Schs onfault = pcb->pcb_onfault; 5761.79Schs 5771.1Sdbj#ifdef DEBUG 5781.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 5791.1Sdbj printf("trap: T_MMUFLT pid=%d, code=%x, v=%x, pc=%x, sr=%x\n", 5801.67Smhitch p->p_pid, code, v, fp->f_pc, fp->f_sr); 5811.1Sdbj#endif 5821.1Sdbj /* 5831.1Sdbj * It is only a kernel address space fault iff: 5841.1Sdbj * 1. (type & T_USER) == 0 and 5851.1Sdbj * 2. pcb_onfault not set or 5861.1Sdbj * 3. pcb_onfault set but supervisor space data fault 5871.1Sdbj * The last can occur during an exec() copyin where the 5881.1Sdbj * argument space is lazy-allocated. 5891.1Sdbj */ 5901.79Schs if ((type & T_USER) == 0 && (onfault == NULL || KDFAULT(code))) 5911.1Sdbj map = kernel_map; 5921.74Swrstuden else { 5931.16Sdbj map = vm ? &vm->vm_map : kernel_map; 5941.74Swrstuden if ((l->l_flag & LW_SA) 5951.74Swrstuden && (~l->l_pflag & LP_SA_NOBLOCK)) { 5961.74Swrstuden l->l_savp->savp_faultaddr = (vaddr_t)v; 5971.74Swrstuden l->l_pflag |= LP_SA_PAGEFAULT; 5981.74Swrstuden } 5991.74Swrstuden } 6001.16Sdbj 6011.1Sdbj if (WRFAULT(code)) 6021.36Schs ftype = VM_PROT_WRITE; 6031.1Sdbj else 6041.1Sdbj ftype = VM_PROT_READ; 6051.16Sdbj 6061.7Sdbj va = trunc_page((vaddr_t)v); 6071.16Sdbj 6081.1Sdbj if (map == kernel_map && va == 0) { 6091.16Sdbj printf("trap: bad kernel %s access at 0x%x\n", 6101.16Sdbj (ftype & VM_PROT_WRITE) ? "read/write" : 6111.16Sdbj "read", v); 6121.1Sdbj goto dopanic; 6131.1Sdbj } 6141.16Sdbj 6151.38Smycroft#ifdef DIAGNOSTIC 6161.51Swiz if (interrupt_depth && !panicking) { 6171.38Smycroft printf("trap: calling uvm_fault() from interrupt!\n"); 6181.38Smycroft goto dopanic; 6191.38Smycroft } 6201.38Smycroft#endif 6211.38Smycroft 6221.79Schs pcb->pcb_onfault = NULL; 6231.57Sdrochner rv = uvm_fault(map, va, ftype); 6241.79Schs pcb->pcb_onfault = onfault; 6251.7Sdbj#ifdef DEBUG 6261.7Sdbj if (rv && MDB_ISPID(p->p_pid)) 6271.57Sdrochner printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n", 6281.16Sdbj map, va, ftype, rv); 6291.7Sdbj#endif 6301.1Sdbj /* 6311.1Sdbj * If this was a stack access we keep track of the maximum 6321.1Sdbj * accessed stack size. Also, if vm_fault gets a protection 6331.1Sdbj * failure it is due to accessing the stack region outside 6341.1Sdbj * the current limit and we need to reflect that as an access 6351.1Sdbj * error. 6361.1Sdbj */ 6371.31Schs if (rv == 0) { 6381.64Schristos if (map != kernel_map && (void *)va >= vm->vm_maxsaddr) 6391.52Sjdolecek uvm_grow(p, va); 6401.52Sjdolecek 6411.1Sdbj if (type == T_MMUFLT) { 6421.81Schs if (ucas_ras_check(&fp->F_t)) { 6431.81Schs return; 6441.81Schs } 6451.16Sdbj#ifdef M68040 6461.16Sdbj if (cputype == CPU_68040) 6471.67Smhitch (void) writeback(fp, 1); 6481.1Sdbj#endif 6491.1Sdbj return; 6501.1Sdbj } 6511.74Swrstuden l->l_pflag &= ~LP_SA_PAGEFAULT; 6521.1Sdbj goto out; 6531.1Sdbj } 6541.45Scl if (rv == EACCES) { 6551.45Scl ksi.ksi_code = SEGV_ACCERR; 6561.45Scl rv = EFAULT; 6571.45Scl } else 6581.45Scl ksi.ksi_code = SEGV_MAPERR; 6591.1Sdbj if (type == T_MMUFLT) { 6601.79Schs if (onfault) 6611.1Sdbj goto copyfault; 6621.57Sdrochner printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n", 6631.16Sdbj map, va, ftype, rv); 6641.1Sdbj printf(" type %x, code [mmu,,ssw]: %x\n", 6651.1Sdbj type, code); 6661.1Sdbj goto dopanic; 6671.1Sdbj } 6681.74Swrstuden l->l_pflag &= ~LP_SA_PAGEFAULT; 6691.45Scl ksi.ksi_addr = (void *)v; 6701.31Schs if (rv == ENOMEM) { 6711.11Schs printf("UVM: pid %d (%s), uid %d killed: out of swap\n", 6721.11Schs p->p_pid, p->p_comm, 6731.61Sad l->l_cred ? 6741.61Sad kauth_cred_geteuid(l->l_cred) : -1); 6751.45Scl ksi.ksi_signo = SIGKILL; 6761.11Schs } else { 6771.45Scl ksi.ksi_signo = SIGSEGV; 6781.11Schs } 6791.1Sdbj break; 6801.1Sdbj } 6811.1Sdbj } 6821.45Scl trapsignal(l, &ksi); 6831.1Sdbj if ((type & T_USER) == 0) 6841.1Sdbj return; 6851.1Sdbjout: 6861.67Smhitch userret(l, fp, sticks, v, 1); 6871.1Sdbj} 6881.1Sdbj 6891.1Sdbj#ifdef M68040 6901.1Sdbj#ifdef DEBUG 6911.1Sdbjstruct writebackstats { 6921.1Sdbj int calls; 6931.1Sdbj int cpushes; 6941.1Sdbj int move16s; 6951.1Sdbj int wb1s, wb2s, wb3s; 6961.1Sdbj int wbsize[4]; 6971.1Sdbj} wbstats; 6981.1Sdbj 6991.54Sheconst char *f7sz[] = { "longword", "byte", "word", "line" }; 7001.54Sheconst char *f7tt[] = { "normal", "MOVE16", "AFC", "ACK" }; 7011.54Sheconst char *f7tm[] = { "d-push", "u-data", "u-code", "M-data", 7021.1Sdbj "M-code", "k-data", "k-code", "RES" }; 7031.54Sheconst char wberrstr[] = 7041.16Sdbj "WARNING: pid %d(%s) writeback [%s] failed, pc=%x fa=%x wba=%x wbd=%x\n"; 7051.1Sdbj#endif 7061.1Sdbj 7071.16Sdbjint 7081.53Schswriteback(struct frame *fp, int docachepush) 7091.1Sdbj{ 7101.1Sdbj struct fmt7 *f = &fp->f_fmt7; 7111.39Sthorpej struct lwp *l = curlwp; 7121.39Sthorpej struct proc *p = l->l_proc; 7131.78Srmind struct pcb *pcb = lwp_getpcb(l); 7141.1Sdbj int err = 0; 7151.1Sdbj u_int fa; 7161.78Srmind void *oonfault = pcb->pcb_onfault; 7171.15Sthorpej paddr_t pa; 7181.1Sdbj 7191.1Sdbj#ifdef DEBUG 7201.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) { 7211.1Sdbj printf(" pid=%d, fa=%x,", p->p_pid, f->f_fa); 7221.1Sdbj dumpssw(f->f_ssw); 7231.1Sdbj } 7241.1Sdbj wbstats.calls++; 7251.1Sdbj#endif 7261.1Sdbj /* 7271.1Sdbj * Deal with special cases first. 7281.1Sdbj */ 7291.1Sdbj if ((f->f_ssw & SSW4_TMMASK) == SSW4_TMDCP) { 7301.1Sdbj /* 7311.1Sdbj * Dcache push fault. 7321.1Sdbj * Line-align the address and write out the push data to 7331.1Sdbj * the indicated physical address. 7341.1Sdbj */ 7351.1Sdbj#ifdef DEBUG 7361.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) { 7371.1Sdbj printf(" pushing %s to PA %x, data %x", 7381.1Sdbj f7sz[(f->f_ssw & SSW4_SZMASK) >> 5], 7391.1Sdbj f->f_fa, f->f_pd0); 7401.1Sdbj if ((f->f_ssw & SSW4_SZMASK) == SSW4_SZLN) 7411.1Sdbj printf("/%x/%x/%x", 7421.1Sdbj f->f_pd1, f->f_pd2, f->f_pd3); 7431.1Sdbj printf("\n"); 7441.1Sdbj } 7451.1Sdbj if (f->f_wb1s & SSW4_WBSV) 7461.1Sdbj panic("writeback: cache push with WB1S valid"); 7471.1Sdbj wbstats.cpushes++; 7481.1Sdbj#endif 7491.1Sdbj /* 7501.1Sdbj * XXX there are security problems if we attempt to do a 7511.1Sdbj * cache push after a signal handler has been called. 7521.1Sdbj */ 7531.1Sdbj if (docachepush) { 7541.7Sdbj pmap_enter(pmap_kernel(), (vaddr_t)vmmap, 7551.18Sthorpej trunc_page(f->f_fa), VM_PROT_WRITE, 7561.18Sthorpej VM_PROT_WRITE|PMAP_WIRED); 7571.35Schris pmap_update(pmap_kernel()); 7581.1Sdbj fa = (u_int)&vmmap[(f->f_fa & PGOFSET) & ~0xF]; 7591.77Scegger memcpy((void *)fa, (void *)&f->f_pd0, 16); 7601.15Sthorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)fa, &pa); 7611.15Sthorpej DCFL(pa); 7621.7Sdbj pmap_remove(pmap_kernel(), (vaddr_t)vmmap, 7631.41Sthorpej (vaddr_t)&vmmap[PAGE_SIZE]); 7641.35Schris pmap_update(pmap_kernel()); 7651.1Sdbj } else 7661.1Sdbj printf("WARNING: pid %d(%s) uid %d: CPUSH not done\n", 7671.61Sad p->p_pid, p->p_comm, kauth_cred_geteuid(l->l_cred)); 7681.1Sdbj } else if ((f->f_ssw & (SSW4_RW|SSW4_TTMASK)) == SSW4_TTM16) { 7691.1Sdbj /* 7701.1Sdbj * MOVE16 fault. 7711.1Sdbj * Line-align the address and write out the push data to 7721.1Sdbj * the indicated virtual address. 7731.1Sdbj */ 7741.1Sdbj#ifdef DEBUG 7751.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 7761.1Sdbj printf(" MOVE16 to VA %x(%x), data %x/%x/%x/%x\n", 7771.1Sdbj f->f_fa, f->f_fa & ~0xF, f->f_pd0, f->f_pd1, 7781.1Sdbj f->f_pd2, f->f_pd3); 7791.1Sdbj if (f->f_wb1s & SSW4_WBSV) 7801.1Sdbj panic("writeback: MOVE16 with WB1S valid"); 7811.1Sdbj wbstats.move16s++; 7821.1Sdbj#endif 7831.1Sdbj if (KDFAULT(f->f_wb1s)) 7841.77Scegger memcpy((void *)(f->f_fa & ~0xF), (void *)&f->f_pd0, 16); 7851.1Sdbj else 7861.64Schristos err = suline((void *)(f->f_fa & ~0xF), (void *)&f->f_pd0); 7871.1Sdbj if (err) { 7881.1Sdbj fa = f->f_fa & ~0xF; 7891.1Sdbj#ifdef DEBUG 7901.1Sdbj if (mmudebug & MDB_WBFAILED) 7911.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 7921.1Sdbj "MOVE16", fp->f_pc, f->f_fa, 7931.1Sdbj f->f_fa & ~0xF, f->f_pd0); 7941.1Sdbj#endif 7951.1Sdbj } 7961.1Sdbj } else if (f->f_wb1s & SSW4_WBSV) { 7971.1Sdbj /* 7981.1Sdbj * Writeback #1. 7991.1Sdbj * Position the "memory-aligned" data and write it out. 8001.1Sdbj */ 8011.1Sdbj u_int wb1d = f->f_wb1d; 8021.1Sdbj int off; 8031.1Sdbj 8041.1Sdbj#ifdef DEBUG 8051.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8061.1Sdbj dumpwb(1, f->f_wb1s, f->f_wb1a, f->f_wb1d); 8071.1Sdbj wbstats.wb1s++; 8081.1Sdbj wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++; 8091.1Sdbj#endif 8101.1Sdbj off = (f->f_wb1a & 3) * 8; 8111.1Sdbj switch (f->f_wb1s & SSW4_SZMASK) { 8121.1Sdbj case SSW4_SZLW: 8131.1Sdbj if (off) 8141.1Sdbj wb1d = (wb1d >> (32 - off)) | (wb1d << off); 8151.1Sdbj if (KDFAULT(f->f_wb1s)) 8161.1Sdbj *(long *)f->f_wb1a = wb1d; 8171.1Sdbj else 8181.64Schristos err = suword((void *)f->f_wb1a, wb1d); 8191.1Sdbj break; 8201.1Sdbj case SSW4_SZB: 8211.1Sdbj off = 24 - off; 8221.1Sdbj if (off) 8231.1Sdbj wb1d >>= off; 8241.1Sdbj if (KDFAULT(f->f_wb1s)) 8251.1Sdbj *(char *)f->f_wb1a = wb1d; 8261.1Sdbj else 8271.64Schristos err = subyte((void *)f->f_wb1a, wb1d); 8281.1Sdbj break; 8291.1Sdbj case SSW4_SZW: 8301.1Sdbj off = (off + 16) % 32; 8311.1Sdbj if (off) 8321.1Sdbj wb1d = (wb1d >> (32 - off)) | (wb1d << off); 8331.1Sdbj if (KDFAULT(f->f_wb1s)) 8341.1Sdbj *(short *)f->f_wb1a = wb1d; 8351.1Sdbj else 8361.64Schristos err = susword((void *)f->f_wb1a, wb1d); 8371.1Sdbj break; 8381.1Sdbj } 8391.1Sdbj if (err) { 8401.1Sdbj fa = f->f_wb1a; 8411.1Sdbj#ifdef DEBUG 8421.1Sdbj if (mmudebug & MDB_WBFAILED) 8431.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 8441.1Sdbj "#1", fp->f_pc, f->f_fa, 8451.1Sdbj f->f_wb1a, f->f_wb1d); 8461.1Sdbj#endif 8471.1Sdbj } 8481.1Sdbj } 8491.1Sdbj /* 8501.1Sdbj * Deal with the "normal" writebacks. 8511.1Sdbj * 8521.1Sdbj * XXX writeback2 is known to reflect a LINE size writeback after 8531.1Sdbj * a MOVE16 was already dealt with above. Ignore it. 8541.1Sdbj */ 8551.1Sdbj if (err == 0 && (f->f_wb2s & SSW4_WBSV) && 8561.1Sdbj (f->f_wb2s & SSW4_SZMASK) != SSW4_SZLN) { 8571.1Sdbj#ifdef DEBUG 8581.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8591.1Sdbj dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d); 8601.1Sdbj wbstats.wb2s++; 8611.1Sdbj wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++; 8621.1Sdbj#endif 8631.1Sdbj switch (f->f_wb2s & SSW4_SZMASK) { 8641.1Sdbj case SSW4_SZLW: 8651.1Sdbj if (KDFAULT(f->f_wb2s)) 8661.1Sdbj *(long *)f->f_wb2a = f->f_wb2d; 8671.1Sdbj else 8681.64Schristos err = suword((void *)f->f_wb2a, f->f_wb2d); 8691.1Sdbj break; 8701.1Sdbj case SSW4_SZB: 8711.1Sdbj if (KDFAULT(f->f_wb2s)) 8721.1Sdbj *(char *)f->f_wb2a = f->f_wb2d; 8731.1Sdbj else 8741.64Schristos err = subyte((void *)f->f_wb2a, f->f_wb2d); 8751.1Sdbj break; 8761.1Sdbj case SSW4_SZW: 8771.1Sdbj if (KDFAULT(f->f_wb2s)) 8781.1Sdbj *(short *)f->f_wb2a = f->f_wb2d; 8791.1Sdbj else 8801.64Schristos err = susword((void *)f->f_wb2a, f->f_wb2d); 8811.1Sdbj break; 8821.1Sdbj } 8831.1Sdbj if (err) { 8841.1Sdbj fa = f->f_wb2a; 8851.1Sdbj#ifdef DEBUG 8861.1Sdbj if (mmudebug & MDB_WBFAILED) { 8871.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 8881.1Sdbj "#2", fp->f_pc, f->f_fa, 8891.1Sdbj f->f_wb2a, f->f_wb2d); 8901.1Sdbj dumpssw(f->f_ssw); 8911.1Sdbj dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d); 8921.1Sdbj } 8931.1Sdbj#endif 8941.1Sdbj } 8951.1Sdbj } 8961.1Sdbj if (err == 0 && (f->f_wb3s & SSW4_WBSV)) { 8971.1Sdbj#ifdef DEBUG 8981.1Sdbj if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) 8991.1Sdbj dumpwb(3, f->f_wb3s, f->f_wb3a, f->f_wb3d); 9001.1Sdbj wbstats.wb3s++; 9011.1Sdbj wbstats.wbsize[(f->f_wb3s&SSW4_SZMASK)>>5]++; 9021.1Sdbj#endif 9031.1Sdbj switch (f->f_wb3s & SSW4_SZMASK) { 9041.1Sdbj case SSW4_SZLW: 9051.1Sdbj if (KDFAULT(f->f_wb3s)) 9061.1Sdbj *(long *)f->f_wb3a = f->f_wb3d; 9071.1Sdbj else 9081.64Schristos err = suword((void *)f->f_wb3a, f->f_wb3d); 9091.1Sdbj break; 9101.1Sdbj case SSW4_SZB: 9111.1Sdbj if (KDFAULT(f->f_wb3s)) 9121.1Sdbj *(char *)f->f_wb3a = f->f_wb3d; 9131.1Sdbj else 9141.64Schristos err = subyte((void *)f->f_wb3a, f->f_wb3d); 9151.1Sdbj break; 9161.1Sdbj case SSW4_SZW: 9171.1Sdbj if (KDFAULT(f->f_wb3s)) 9181.1Sdbj *(short *)f->f_wb3a = f->f_wb3d; 9191.1Sdbj else 9201.64Schristos err = susword((void *)f->f_wb3a, f->f_wb3d); 9211.1Sdbj break; 9221.1Sdbj#ifdef DEBUG 9231.1Sdbj case SSW4_SZLN: 9241.1Sdbj panic("writeback: wb3s indicates LINE write"); 9251.1Sdbj#endif 9261.1Sdbj } 9271.1Sdbj if (err) { 9281.1Sdbj fa = f->f_wb3a; 9291.1Sdbj#ifdef DEBUG 9301.1Sdbj if (mmudebug & MDB_WBFAILED) 9311.1Sdbj printf(wberrstr, p->p_pid, p->p_comm, 9321.1Sdbj "#3", fp->f_pc, f->f_fa, 9331.1Sdbj f->f_wb3a, f->f_wb3d); 9341.1Sdbj#endif 9351.1Sdbj } 9361.1Sdbj } 9371.78Srmind pcb->pcb_onfault = oonfault; 9381.1Sdbj if (err) 9391.1Sdbj err = SIGSEGV; 9401.16Sdbj return (err); 9411.1Sdbj} 9421.1Sdbj 9431.1Sdbj#ifdef DEBUG 9441.16Sdbjvoid 9451.53Schsdumpssw(u_short ssw) 9461.1Sdbj{ 9471.1Sdbj printf(" SSW: %x: ", ssw); 9481.1Sdbj if (ssw & SSW4_CP) 9491.1Sdbj printf("CP,"); 9501.1Sdbj if (ssw & SSW4_CU) 9511.1Sdbj printf("CU,"); 9521.1Sdbj if (ssw & SSW4_CT) 9531.1Sdbj printf("CT,"); 9541.1Sdbj if (ssw & SSW4_CM) 9551.1Sdbj printf("CM,"); 9561.1Sdbj if (ssw & SSW4_MA) 9571.1Sdbj printf("MA,"); 9581.1Sdbj if (ssw & SSW4_ATC) 9591.1Sdbj printf("ATC,"); 9601.1Sdbj if (ssw & SSW4_LK) 9611.1Sdbj printf("LK,"); 9621.1Sdbj if (ssw & SSW4_RW) 9631.1Sdbj printf("RW,"); 9641.1Sdbj printf(" SZ=%s, TT=%s, TM=%s\n", 9651.1Sdbj f7sz[(ssw & SSW4_SZMASK) >> 5], 9661.1Sdbj f7tt[(ssw & SSW4_TTMASK) >> 3], 9671.1Sdbj f7tm[ssw & SSW4_TMMASK]); 9681.1Sdbj} 9691.1Sdbj 9701.16Sdbjvoid 9711.53Schsdumpwb(int num, u_short s, u_int a, u_int d) 9721.1Sdbj{ 9731.1Sdbj struct proc *p = curproc; 9741.7Sdbj paddr_t pa; 9751.1Sdbj 9761.1Sdbj printf(" writeback #%d: VA %x, data %x, SZ=%s, TT=%s, TM=%s\n", 9771.1Sdbj num, a, d, f7sz[(s & SSW4_SZMASK) >> 5], 9781.1Sdbj f7tt[(s & SSW4_TTMASK) >> 3], f7tm[s & SSW4_TMMASK]); 9791.16Sdbj printf(" PA "); 9801.63Sthorpej if (pmap_extract(p->p_vmspace->vm_map.pmap, (vaddr_t)a, &pa) == false) 9811.1Sdbj printf("<invalid address>"); 9821.1Sdbj else 9831.64Schristos printf("%lx, current value %lx", pa, fuword((void *)a)); 9841.1Sdbj printf("\n"); 9851.1Sdbj} 9861.1Sdbj#endif 9871.1Sdbj#endif 988