📄 trap.c
字号:
#ifndef lintstatic char *sccsid = "@(#)trap.c 4.4 ULTRIX 4/11/91";#endif lint/************************************************************************ * * * Copyright (c) 1985, 1986, 1988, 1989 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* ------------------------------------------------------------------------ * Modification History: /sys/vax/trap.c * * 11-Apr-91 dlh * syscall(): * - on return from a system call, p_affinity was being loaded with * ALLCPU. This is wrong if the process is a vector process. * * 4-Sep-90 dlh * - illegal instruction fault needs to look to see if cpu is vector * present and if not is the instruction a legal vector instruction * - add vector disabled fault * * 14-Nov-89 sekhar * Fixes to turn profiling off when scale set to 1. * * 09-Nov-89 jaw * remove asymmetric syscall support. * * 04-Oct-89 jaw * release all locks held when "longjmp" out of a syscall occurs. This * is a tempory fix until code in "soclose" is fixed to handle * interrupted system calls. * * 15-Aug-89 scott * check for indirect syscall use for audit and sys_trace codepaths * use callp->sy_narg instead of *(caddr)locr0[AP] * * 20-Jul-89 jaw * cleanup debug for smp and optimize code in syscall path. * * 09-Jun-89 -- scott * added audit support * * 23-Jan-89 -- jmartin * Introduce a new trap type NOACCESS for protection fault on read. * * 10-Oct-88 -- jaw * check for holding a lock after doing a switch but before restoring * the old lock list. * * 10-Oct-88 -- jaw * replace switch_to_master with general routine switch_affinity * * 19 Aug 88 -- miche * Stay out of the idle loop for kernel debugger and pageout * silencing of secondary processors from user mode. Also, * save the process context for easier debugging. * * 25 Jul 88 -- jmartin * Allow pagein and grow to happen on any CPU. * * 18-Jun-88 -- jaw change to new cpu data format. * * 14 May 87 -- fred (Fred Canter) * Turn off graphics console loopback of kernel printf's * when the system panics (via trap). * * 21 Jan 87 -- jaw * performance fixes to syscall. * * 02-Apr-86 -- jrs * Clean up for better perfomance in single cpu case. * Allow some syscalls to be mp. * * 18 Mar 86 -- jrs * Change calls to cpuindex/cpuident * * 24 Feb 86 -- depp * Added code to SIGBUS to pass virtual address to process * * 16 Jul 85 -- jrs * Add run queue locking and multicpu sched mods * * 20 Jan 86 -- pmk * Added binary error logging for traps * * 14 Oct 85 -- reilly * Modified user.h * * 29 Oct 84 -- jrs * Fix carry bit clear for compat mode problem * Derived from 4.2BSD, labeled: * trap.c 6.2 84/06/10 * * ----------------------------------------------------------------------- */#include "../machine/psl.h"#include "../machine/reg.h"#include "../machine/pte.h"#include "../h/param.h"#include "../h/smp_lock.h"#include "../h/systm.h"#include "../h/dir.h"#include "../h/user.h"#include "assym.s"#include "../h/proc.h"#include "../h/seg.h"#include "../vax/trap.h"#include "../h/acct.h"#include "../h/kernel.h"#include "../h/errlog.h"#include "../h/cpudata.h"#include "../machine/mtpr.h"#include "../h/systrace.h"#include "../h/conf.h"#include "../io/uba/qdioctl.h" /* for QD_KERN_UNLOOP below */#include "../h/vmmac.h"#include "../machine/vmparam.h"#include "../machine/vectors.h"#include "../../machine/common/cpuconf.h"int vm_debug = 1;#ifdef KDEBUG#include "../machine/kdb/kdb_trap.h"#else !KDEBUGint in_kdb = 0; #endif !KDEBUG#define USER 040 /* user-mode flag added to type */struct sysent sysent[];int nsysent;#ifdef SYS_TRACEint traceopens = 0;#endif SYS_TRACEchar *trap_type[] = { "Reserved addressing mode", "Privileged instruction", "Reserved operand", "Breakpoint", "Xfc trap", "Syscall trap", "Arithmetic fault", "Ast trap", "Segmentation fault", "Protection fault", "Trace trap", "Compatibility mode trap",#ifdef notdef "Page fault", "Page table fault",#endif};#define TRAP_TYPES (sizeof trap_type / sizeof trap_type[0])extern int ws_display_type;/* * Called from the trap handler when a processor trap occurs. *//*ARGSUSED*/trap(sp, type, code, pc, psl) int sp, type; unsigned code; int pc, psl;{#ifdef KDEBUG register int *kdb_local_regptr;#define REG_11 kdb_local_regptr extern int *kdb_regs_ptr;#endif KDEBUG register int *locr0 = ((int *)&psl)-PS; register int i; register struct proc *p; register int s; struct el_rec *elrp; struct timeval syst; struct cpudata *pcpu; int new_affinity; /* new affinity mask of a process becoming a * vector process or of a process which needs * to switch it's affinity for some other * reason. */#ifdef KDEBUG asm("movl fp,r11"); kdb_regs_ptr = kdb_local_regptr;#endif KDEBUG syst = u.u_ru.ru_stime; if (USERMODE(locr0[PS])) { type |= USER; u.u_ar0 = locr0; } switch (type) { default:#ifdef KDEBUGkdb_goto_label:#endif KDEBUG elrp = ealloc(EL_EXPTFLTSIZE,EL_PRISEVERE); if (elrp != 0) { LSUBID(elrp,ELCT_EXPTFLT,(type + 1),EL_UNDEF,EL_UNDEF,EL_UNDEF,EL_UNDEF); elrp->el_body.elexptflt.exptflt_va = code; elrp->el_body.elexptflt.exptflt_pc = pc; elrp->el_body.elexptflt.exptflt_psl = psl; EVALID(elrp); } /* * If console is a graphics device, * force cprintf messages directly to screen. */ if (ws_display_type) { i = ws_display_type << 8; (*cdevsw[ws_display_type].d_ioctl)(i, QD_KERN_UNLOOP, 0, 0); } cprintf("trap type %d, code = %x, pc = %x\n", type, code, pc); type &= ~USER; if ((unsigned)type < TRAP_TYPES) { panic(trap_type[type]); } panic("trap");#ifdef KDEBUG include_kdb();#endif KDEBUG case T_NOACCESS+USER: if ( vm_debug && isatsv(u.u_procp, btop(code))) panic("no access to shared text"); else /* fall through to protection fault */ ; case T_PROTFLT+USER: /* protection fault */ i = SIGBUS; u.u_code = code; break; case T_PRIVINFLT+USER: /* privileged instruction fault */ if (is_legal_vector_instruction(pc) == is_vect_inst) { if (vptotal > 0) { /* * if this process is not already a vector * process, then call vp_allocate to convert this * process to vector process. This is done by * allocating the space to store the vector * context. */ if (u.u_procp->p_vpcontext == NULL) { if (vp_allocate (u.u_procp) == VP_FAILURE) { goto out; } } /* * change the processes affinity */ new_affinity = u.u_procp->p_affinity & vpmask; if (new_affinity == 0) { panic ("trap(): vector affinity problem"); } else { (void) switch_affinity (new_affinity); } goto out; } else { /* there are no vector processors in the system */ u.u_code = ILL_VECINST_FAULT; uprintf ("No vector processor available\n"); i = SIGILL; } } else { /* this is not a vector instruction */ u.u_code = type &~ USER; i = SIGILL; } break; case T_RESADFLT+USER: /* reserved addressing fault */ case T_RESOPFLT+USER: /* resereved operand fault */ u.u_code = type &~ USER; i = SIGILL; break; case T_ASTFLT+USER: astoff(); if ((u.u_oweupc & SOWEUPC) && (u.u_prof.pr_scale > 1)) { addupc(pc, &u.u_prof, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -