int ret; union sigval sv; int s, si;
int ret, s, si, trapnum;
trap(type, frame)	int type;	struct trapframe *frame;{	struct proc *p = curproc;	struct pcb *pcbp;	vaddr_t va;	struct vm_map *map;	struct vmspace *vm;	register vm_prot_t vftype;	register pa_space_t space;	u_int opcode;	int ret;	union sigval sv;	int s, si;	const char *tts;	opcode = frame->tf_iir;	if (type == T_ITLBMISS || type == T_ITLBMISSNA) {		va = frame->tf_iioq_head;		space = frame->tf_iisq_head;		vftype = VM_PROT_READ;	/* XXX VM_PROT_EXECUTE ??? */	} else {		va = frame->tf_ior;		space = frame->tf_isr;		vftype = inst_store(opcode) ? VM_PROT_WRITE : VM_PROT_READ;	}	if (frame->tf_flags & TFF_LAST)		p->p_md.md_regs = frame;#ifdef TRAPDEBUG	if ((type & ~T_USER) > trap_types)		tts = "reserved";	else		tts = trap_type[type & ~T_USER];	if (type != T_INTERRUPT && (type & ~T_USER) != T_IBREAK)		db_printf("trap: %d, %s for %x:%x at %x:%x, fl=%x, fp=%p\n",		    type, tts, space, va, frame->tf_iisq_head,		    frame->tf_iioq_head, frame->tf_flags, frame);	else if ((type & ~T_USER) == T_IBREAK)		db_printf("trap: break instruction %x:%x at %x:%x, fp=%p\n",		    break5(opcode), break13(opcode),		    frame->tf_iisq_head, frame->tf_iioq_head, frame);	{		extern int etext;		if (frame < (struct trapframe *)&etext) {			printf("trap: bogus frame ptr %p\n", frame);			goto dead_end;		}	}#endif	switch (type) {	case T_NONEXIST:	case T_NONEXIST|T_USER:#ifndef DDB		/* we've got screwed up by the central scrutinizer */		panic ("trap: elvis has just left the building!");		break;#else		goto dead_end;#endif	case T_RECOVERY:	case T_RECOVERY|T_USER:#ifndef DDB		/* XXX will implement later */		printf ("trap: handicapped");		break;#else		goto dead_end;#endif#ifdef DIAGNOSTIC	case T_EXCEPTION:		panic("FPU/SFU emulation botch");		/* these just can't happen ever */	case T_PRIV_OP:	case T_PRIV_REG:		/* these just can't make it to the trap() ever */	case T_HPMC:      case T_HPMC | T_USER:	case T_EMULATION: case T_EMULATION | T_USER:#endif	case T_IBREAK:	case T_DATALIGN:	case T_DBREAK:	dead_end:#ifdef DDB		if (kdb_trap (type, va, frame)) {			if (type == T_IBREAK) {				/* skip break instruction */				frame->tf_iioq_head = frame->tf_iioq_tail;				frame->tf_iioq_tail += 4;			}			return;		}#else		if (type == T_DATALIGN)			panic ("trap: %s at 0x%x", tts, va);		else			panic ("trap: no debugger for \"%s\" (%d)", tts, type);#endif		break;	case T_IBREAK | T_USER:	case T_DBREAK | T_USER:		/* pass to user debugger */		break;	case T_EXCEPTION | T_USER:	/* co-proc assist trap */		sv.sival_int = va;		trapsignal(p, SIGFPE, type &~ T_USER, FPE_FLTINV, sv);		break;	case T_OVERFLOW | T_USER:		sv.sival_int = va;		trapsignal(p, SIGFPE, type &~ T_USER, FPE_INTOVF, sv);		break;			case T_CONDITION | T_USER:		break;	case T_ILLEGAL | T_USER:		sv.sival_int = va;		trapsignal(p, SIGILL, type &~ T_USER, ILL_ILLOPC, sv);		break;	case T_PRIV_OP | T_USER:		sv.sival_int = va;		trapsignal(p, SIGILL, type &~ T_USER, ILL_PRVOPC, sv);		break;	case T_PRIV_REG | T_USER:		sv.sival_int = va;		trapsignal(p, SIGILL, type &~ T_USER, ILL_PRVREG, sv);		break;		/* these should never got here */	case T_HIGHERPL | T_USER:	case T_LOWERPL | T_USER:		sv.sival_int = va;		trapsignal(p, SIGSEGV, type &~ T_USER, SEGV_ACCERR, sv);		break;	case T_IPROT | T_USER:	case T_DPROT | T_USER:		sv.sival_int = va;		trapsignal(p, SIGSEGV, vftype, SEGV_ACCERR, sv);		break;	case T_DATACC:   	case T_USER | T_DATACC:	case T_ITLBMISS:	case T_USER | T_ITLBMISS:	case T_DTLBMISS:	case T_USER | T_DTLBMISS:	case T_ITLBMISSNA:	case T_USER | T_ITLBMISSNA:	case T_DTLBMISSNA:	case T_USER | T_DTLBMISSNA:	case T_TLB_DIRTY:	case T_USER | T_TLB_DIRTY:		va = hppa_trunc_page(va);		vm = p->p_vmspace;		if (!vm) {#ifdef TRAPDEBUG			printf("trap: no vm, p=%p\n", p);#endif			goto dead_end;		}		/*		 * it could be a kernel map for exec_map faults		 */		if (!(type & T_USER) && space == HPPA_SID_KERNEL)			map = kernel_map;		else			map = &vm->vm_map;		if (map->pmap->pmap_space != space) {#ifdef TRAPDEBUG			printf("trap: space missmatch %d != %d\n",			    space, map->pmap->pmap_space);#endif			/* actually dump the user, crap the kernel */			goto dead_end;		}		ret = uvm_fault(map, va, 0, vftype);#ifdef TRAPDEBUG		printf("uvm_fault(%p, %x, %d, %d)=%d\n",		    map, va, 0, vftype, ret);#endif		/*		 * If this was a stack access we keep track of the maximum		 * accessed stack size.  Also, if uvm_fault gets a protection		 * failure it is due to accessing the stack region outside		 * the current limit and we need to reflect that as an access		 * error.		 */		if (va >= (vaddr_t)vm->vm_maxsaddr + vm->vm_ssize) {			if (ret == 0) {				vsize_t nss = btoc(va - USRSTACK + NBPG);				if (nss > vm->vm_ssize)					vm->vm_ssize = nss;			} else if (ret == EACCES)				ret = EFAULT;		}		if (ret != 0) {			if (type & T_USER) {printf("trapsignal: uvm_fault\n");				sv.sival_int = frame->tf_ior;				trapsignal(p, SIGSEGV, vftype, SEGV_MAPERR, sv);			} else {				if (p && p->p_addr->u_pcb.pcb_onfault) {#ifdef PMAPDEBUG					printf("trap: copyin/out %d\n",ret);#endif					pcbp = &p->p_addr->u_pcb;					frame->tf_iioq_tail = 4 +					    (frame->tf_iioq_head =						pcbp->pcb_onfault);					pcbp->pcb_onfault = 0;					break;				}#if 1if (kdb_trap (type, va, frame))	return;#else				panic("trap: uvm_fault(%p, %x, %d, %d): %d",				    map, va, 0, vftype, ret);#endif			}		}		break;	case T_DATALIGN | T_USER:		sv.sival_int = va;		trapsignal(p, SIGBUS, vftype, BUS_ADRALN, sv);		break;	case T_INTERRUPT:	case T_INTERRUPT|T_USER:		frame->tf_flags |= TFF_INTR;		cpu_intr(frame);#if 0if (kdb_trap (type, va, frame))return;#endif		/* FALLTHROUGH */	case T_LOWERPL:		__asm __volatile ("ldcws 0(%1), %0"				  : "=r" (si) : "r" (&sir));		s = spl0();		if (si & SIR_CLOCK) {			splclock();			softclock();			spl0();		}		if (si & SIR_NET) {			register int ni;			/* use atomic "load & clear" */			__asm __volatile ("ldcws 0(%1), %0"					  : "=r" (ni) : "r" (&netisr));			splnet();#define	DONETISR(m,c) if (ni & (1 << (m))) c()#include <net/netisr_dispatch.h>		}		splx(s);		break;	case T_DPROT:	case T_IPROT:	case T_OVERFLOW:	case T_CONDITION:	case T_ILLEGAL:	case T_HIGHERPL:	case T_TAKENBR:	case T_POWERFAIL:	case T_LPMC:	case T_PAGEREF:	case T_DATAPID:  	case T_DATAPID  | T_USER:		if (0 /* T-chip */) {			break;		}		/* FALLTHROUGH to unimplemented */	default:#if 1if (kdb_trap (type, va, frame))	return;#endif		panic ("trap: unimplemented \'%s\' (%d)", tts, type);	}	if (type & T_USER)		userret(p, p->p_md.md_regs->tf_iioq_head, 0);}