trunc_page(frame->srr0), 0, ftype)) {
trunc_page(frame->srr0), 0, ftype) == 0) {
trap(frame)	struct trapframe *frame;{	struct proc *p = curproc;	int type = frame->exc;	u_quad_t sticks;	union sigval sv;	char *name;	db_expr_t offset;	if (frame->srr1 & PSL_PR) {		type |= EXC_USER;		sticks = p->p_sticks;	}	switch (type) {	case EXC_TRC|EXC_USER:				{			sv.sival_int = frame->srr0;			trapsignal(p, SIGTRAP, type, TRAP_TRACE, sv);		}		break;	case EXC_MCHK:		{			faultbuf *fb;			if ((fb = p->p_addr->u_pcb.pcb_onfault)) {				p->p_addr->u_pcb.pcb_onfault = 0;				frame->srr0 = fb->pc;		/* PC */				frame->srr1 = fb->sr;		/* SR */				frame->fixreg[1] = fb->sp;	/* SP */				frame->fixreg[3] = 1;		/* != 0 */				frame->cr = fb->cr;				bcopy(&fb->regs[0], &frame->fixreg[13], 19*4);				return;			}		}		goto brain_damage;	case EXC_DSI:		{			struct vm_map *map;			vm_offset_t va;			int ftype;			faultbuf *fb;						map = kernel_map;			va = frame->dar;			if ((va >> ADDR_SR_SHFT) == USER_SR) {				sr_t user_sr;								asm ("mfsr %0, %1"				     : "=r"(user_sr) : "K"(USER_SR));				va &= ADDR_PIDX | ADDR_POFF;				va |= user_sr << ADDR_SR_SHFT;				map = &p->p_vmspace->vm_map;			}			if (frame->dsisr & DSISR_STORE)				ftype = VM_PROT_READ | VM_PROT_WRITE;			else				ftype = VM_PROT_READ;			if (uvm_fault(map, trunc_page(va), 0, ftype) == 0) {				return;			}			if ((fb = p->p_addr->u_pcb.pcb_onfault)) {				p->p_addr->u_pcb.pcb_onfault = 0;				frame->srr0 = fb->pc;		/* PC */				frame->fixreg[1] = fb->sp;	/* SP */				frame->fixreg[3] = 1;		/* != 0 */				frame->cr = fb->cr;				bcopy(&fb->regs[0], &frame->fixreg[13], 19*4);				return;			}			map = kernel_map;		}printf("kern dsi on addr %x iar %x\n", frame->dar, frame->srr0);		goto brain_damage;	case EXC_DSI|EXC_USER:		{			int ftype, vftype;						if (frame->dsisr & DSISR_STORE) {				ftype = VM_PROT_READ | VM_PROT_WRITE;				vftype = VM_PROT_WRITE;			} else				vftype = ftype = VM_PROT_READ;			if (uvm_fault(&p->p_vmspace->vm_map,				     trunc_page(frame->dar), 0, ftype) == 0) {				break;			}#if 0printf("dsi on addr %x iar %x lr %x\n", frame->dar, frame->srr0,frame->lr);#endif/* * keep this for later in case we want it later.*/			sv.sival_int = frame->dar;			trapsignal(p, SIGSEGV, vftype, SEGV_MAPERR, sv);		}		break;	case EXC_ISI|EXC_USER:		{			int ftype;						ftype = VM_PROT_READ | VM_PROT_EXECUTE;			if (uvm_fault(&p->p_vmspace->vm_map,				     trunc_page(frame->srr0), 0, ftype)) {				break;			}		}#if 0printf("isi iar %x\n", frame->srr0);#endif	case EXC_MCHK|EXC_USER:/* XXX Likely that returning from this trap is bogus... *//* XXX Have to make sure that sigreturn does the right thing. */		sv.sival_int = frame->srr0;		trapsignal(p, SIGSEGV, VM_PROT_EXECUTE, SEGV_MAPERR, sv);		break;	case EXC_SC|EXC_USER:		{			struct sysent *callp;			size_t argsize;			register_t code, error;			register_t *params, rval[2];			int nsys, n;			register_t args[10];						uvmexp.syscalls++;						nsys = p->p_emul->e_nsysent;			callp = p->p_emul->e_sysent;						code = frame->fixreg[0];			params = frame->fixreg + FIRSTARG;						switch (code) {			case SYS_syscall:				/*				 * code is first argument,				 * followed by actual args.				 */				code = *params++;				break;			case SYS___syscall:				/*				 * Like syscall, but code is a quad,				 * so as to maintain quad alignment				 * for the rest of the args.				 */				if (callp != sysent)					break;				params++;				code = *params++;				break;			default:				break;			}			if (code < 0 || code >= nsys)				callp += p->p_emul->e_nosys;			else				callp += code;			argsize = callp->sy_argsize;			n = NARGREG - (params - (frame->fixreg + FIRSTARG));			if (argsize > n * sizeof(register_t)) {				bcopy(params, args, n * sizeof(register_t));				if ((error = copyin(MOREARGS(frame->fixreg[1]),				   args + n, argsize - n * sizeof(register_t)))) {#ifdef	KTRACE					/* Can't get all the arguments! */					if (KTRPOINT(p, KTR_SYSCALL))						ktrsyscall(p, code,							   argsize, args);#endif					goto syscall_bad;				}				params = args;			}#ifdef	KTRACE			if (KTRPOINT(p, KTR_SYSCALL))				ktrsyscall(p, code, argsize, params);#endif			rval[0] = 0;			rval[1] = frame->fixreg[FIRSTARG + 1];#ifdef SYSCALL_DEBUG	scdebug_call(p, code, params);#endif						switch (error = (*callp->sy_call)(p, params, rval)) {			case 0:				frame->fixreg[0] = error;				frame->fixreg[FIRSTARG] = rval[0];				frame->fixreg[FIRSTARG + 1] = rval[1];				frame->cr &= ~0x10000000;				break;			case ERESTART:				/*				 * Set user's pc back to redo the system call.				 */				frame->srr0 -= 4;				break;			case EJUSTRETURN:				/* nothing to do */				break;			default:syscall_bad:				if (p->p_emul->e_errno)					error = p->p_emul->e_errno[error];				frame->fixreg[0] = error;				frame->fixreg[FIRSTARG] = error;				frame->fixreg[FIRSTARG + 1] = rval[1];				frame->cr |= 0x10000000;				break;			}#ifdef SYSCALL_DEBUG        scdebug_ret(p, code, error, rval); #endif  #ifdef	KTRACE			if (KTRPOINT(p, KTR_SYSRET))				ktrsysret(p, code, error, rval[0]);#endif		}		break;	case EXC_FPU|EXC_USER:		if (fpuproc)			save_fpu(fpuproc);		fpuproc = p;		enable_fpu(p);		break;	case EXC_ALI|EXC_USER:		/* alignment exception 		 * we check to see if this can be fixed up		 * by the code that fixes the typical gcc misaligned code		 * then kill the process if not.		 */		if (fix_unaligned(p, frame) == 0) {			frame->srr0 += 4;		} else {			sv.sival_int = frame->srr0;			trapsignal(p, SIGSEGV, VM_PROT_EXECUTE, SEGV_MAPERR,				sv);		}		break;	default:	brain_damage:/*mpc_print_pci_stat();*/#ifdef DDB		/* set up registers */		db_save_regs(frame);#endif		db_find_sym_and_offset(frame->srr0, &name, &offset);		if (!name) {			name = "0";			offset = frame->srr0;		}		panic ("trap type %x at %x (%s+0x%x) lr %x\n",			type, frame->srr0, name, offset, frame->lr);	case EXC_PGM|EXC_USER:	{		char *errstr[8];		int errnum = 0;		if (frame->srr1 & (1<<(31-11))) { 			/* floating point enabled program exception */			errstr[errnum] = "floating point";			errnum++;		} 		if (frame->srr1 & (1<<(31-12))) {			/* illegal instruction program exception */			errstr[errnum] = "illegal instruction";			errnum++;		}		if (frame->srr1 & (1<<(31-13))) {			/* privileged instruction exception */			errstr[errnum] = "priviledged instr";			errnum++;		}		if (frame->srr1 & (1<<(31-14))) {			errstr[errnum] = "trap instr";			errnum++;			/* trap instruction exception */			/*				instr = copyin (srr0)				if (instr == BKPT_INST && uid == 0) {					db_trap(T_BREAKPOINT?)					break;				}			*/		}		if (frame->srr1 & (1<<(31-15))) {			errstr[errnum] = "previous address";			errnum++;		}#if 0printf("pgm iar %x srr1 %x\n", frame->srr0, frame->srr1);for (i = 0; i < errnum; i++) {	printf("\t[%s]\n", errstr[i]);}#endif		sv.sival_int = frame->srr0;		trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv);		break;	}	case EXC_PGM:		/* should check for correct byte here or panic */#ifdef DDB		db_save_regs(frame);		db_trap(T_BREAKPOINT, 0);#else		panic("trap EXC_PGM");#endif		break;	/* This is not really a perf exception, but is an ALTIVEC unavail	 * if we do not handle it, kill the process with illegal instruction.	 */	case EXC_PERF|EXC_USER:#ifdef PPC_VECTOR_SUPPORTED	case EXC_VEC|EXC_USER:		if (ppc_vecproc) {			save_vec(ppc_vecproc);		}		ppc_vecproc = p;		enable_vec(p);		break;#else /* PPC_VECTOR_SUPPORTED */		sv.sival_int = frame->srr0;		trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv);		break;#endif /* PPC_VECTOR_SUPPORTED */	case EXC_AST|EXC_USER:		/* This is just here that we trap */		break;	}	astpending = 0;		/* we are about to do it */	uvmexp.softs++;	if (p->p_flag & P_OWEUPC) {		p->p_flag &= ~P_OWEUPC;		ADDUPROF(p);	}	/* take pending signals */	{		int sig;		while ((sig = CURSIG(p)))			postsig(sig);	}	p->p_priority = p->p_usrpri;	if (want_resched) {		int sig;		/*		 * We're being preempted.		 */		preempt(NULL);		while ((sig = CURSIG(p)))			postsig(sig);	}	/*	 * If profiling, charge recent system time to the trapped pc.	 */	if (p->p_flag & P_PROFIL) {		extern int psratio;		addupc_task(p, frame->srr0,			    (int)(p->p_sticks - sticks) * psratio);	}	/*	 * If someone stole the fpu while we were away, disable it	 */	if (p != fpuproc) {		frame->srr1 &= ~PSL_FP;	} else {		frame->srr1 |= PSL_FP;	}#ifdef PPC_VECTOR_SUPPORTED	/*	 * If someone stole the vector unit while we were away, disable it	 */	if (p != ppc_vecproc) {		frame->srr1 &= ~PSL_VEC;	} else {		frame->srr1 |= PSL_VEC;	}#endif /* PPC_VECTOR_SUPPORTED */	curpriority = p->p_priority;}