2001-06-10 02:39:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1995, 1996 TooLs GmbH.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by TooLs GmbH.
|
|
|
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2002-05-09 14:22:55 +00:00
|
|
|
* $NetBSD: trap.c,v 1.58 2002/03/04 04:07:35 dbj Exp $
|
2001-06-10 02:39:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
#include "opt_ktrace.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <sys/proc.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/systm.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <sys/sysent.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <sys/user.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#ifdef KTRACE
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <sys/uio.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <sys/ktrace.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#include <vm/vm_extern.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <vm/vm_param.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_map.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <vm/vm_page.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <machine/db_machdep.h>
|
|
|
|
#include <machine/fpu.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <machine/frame.h>
|
|
|
|
#include <machine/pcb.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <machine/pmap.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <machine/psl.h>
|
|
|
|
#include <machine/trap.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <machine/spr.h>
|
|
|
|
#include <machine/sr.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
/* These definitions should probably be somewhere else XXX */
|
2001-06-10 02:39:37 +00:00
|
|
|
#define FIRSTARG 3 /* first argument is in reg 3 */
|
|
|
|
#define NARGREG 8 /* 8 args are in registers */
|
|
|
|
#define MOREARGS(sp) ((caddr_t)((int)(sp) + 8)) /* more args go here */
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#ifndef MULTIPROCESSOR
|
|
|
|
volatile int astpending;
|
|
|
|
volatile int want_resched;
|
|
|
|
extern int intr_depth;
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
void *syscall = NULL; /* XXX dummy symbol for emul_netbsd */
|
|
|
|
|
2002-03-20 23:17:50 +00:00
|
|
|
static int fix_unaligned(struct proc *p, struct trapframe *frame);
|
2002-05-09 14:22:55 +00:00
|
|
|
static __inline void setusr(int);
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
void trap(struct trapframe *); /* Called from locore / trap_subr */
|
|
|
|
int setfault(faultbuf); /* defined in locore.S */
|
|
|
|
/* Why are these not defined in a header? */
|
|
|
|
int badaddr(void *, size_t);
|
|
|
|
int badaddr_read(void *, size_t, int *);
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-13 07:44:48 +00:00
|
|
|
extern char *syscallnames[];
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
void
|
|
|
|
trap(frame)
|
|
|
|
struct trapframe *frame;
|
2001-11-05 00:49:03 +00:00
|
|
|
{
|
2002-05-09 14:22:55 +00:00
|
|
|
struct thread *td = PCPU_GET(curthread);
|
2002-05-13 07:44:48 +00:00
|
|
|
struct thread *fputhread;
|
2002-05-09 14:22:55 +00:00
|
|
|
struct proc *p = td->td_proc;
|
|
|
|
int type = frame->exc;
|
|
|
|
int ftype, rv;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_traps.ev_count++;
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
if (frame->srr1 & PSL_PR)
|
|
|
|
type |= EXC_USER;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (curpcb->pcb_pmreal != curpm)
|
|
|
|
panic("trap: curpm (%p) != curpcb->pcb_pmreal (%p)",
|
|
|
|
curpm, curpcb->pcb_pmreal);
|
|
|
|
#endif
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
uvmexp.traps++;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case EXC_RUNMODETRC|EXC_USER:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case EXC_TRC|EXC_USER:
|
|
|
|
PROC_LOCK(p);
|
|
|
|
frame->srr1 &= ~PSL_SE;
|
|
|
|
trapsignal(p, SIGTRAP, EXC_TRC);
|
|
|
|
PROC_UNLOCK(p);
|
2001-06-10 02:39:37 +00:00
|
|
|
break;
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_DSI: {
|
|
|
|
faultbuf *fb;
|
|
|
|
/*
|
|
|
|
* Only query UVM if no interrupts are active (this applies
|
|
|
|
* "on-fault" as well.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_kdsi.ev_count++;
|
|
|
|
#endif
|
|
|
|
if (intr_depth < 0) {
|
|
|
|
struct vm_map *map;
|
|
|
|
vm_offset_t va;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
KERNEL_LOCK(LK_CANRECURSE|LK_EXCLUSIVE);
|
|
|
|
#endif
|
|
|
|
map = kernel_map;
|
|
|
|
va = frame->dar;
|
|
|
|
if ((va >> ADDR_SR_SHFT) == USER_SR) {
|
|
|
|
register_t user_sr;
|
|
|
|
|
|
|
|
__asm ("mfsr %0, %1"
|
|
|
|
: "=r"(user_sr) : "K"(USER_SR));
|
|
|
|
va &= ADDR_PIDX | ADDR_POFF;
|
|
|
|
va |= user_sr << ADDR_SR_SHFT;
|
|
|
|
/* KERNEL_PROC_LOCK(p); XXX */
|
|
|
|
map = &p->p_vmspace->vm_map;
|
|
|
|
}
|
|
|
|
if (frame->dsisr & DSISR_STORE)
|
|
|
|
ftype = VM_PROT_WRITE;
|
2001-06-10 02:39:37 +00:00
|
|
|
else
|
2002-05-09 14:22:55 +00:00
|
|
|
ftype = VM_PROT_READ;
|
|
|
|
rv = vm_fault(map, trunc_page(va), ftype,
|
|
|
|
VM_FAULT_NORMAL);
|
|
|
|
#if 0
|
|
|
|
KERNEL_UNLOCK();
|
|
|
|
#endif
|
|
|
|
if (rv == 0)
|
2001-06-10 02:39:37 +00:00
|
|
|
return;
|
2002-05-09 14:22:55 +00:00
|
|
|
if (rv == EACCES)
|
|
|
|
rv = EFAULT;
|
|
|
|
} else {
|
|
|
|
rv = EFAULT;
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
2002-05-09 14:22:55 +00:00
|
|
|
if ((fb = td->td_pcb->pcb_onfault) != NULL) {
|
|
|
|
frame->srr0 = (*fb)[0];
|
|
|
|
frame->fixreg[1] = (*fb)[1];
|
|
|
|
frame->fixreg[2] = (*fb)[2];
|
|
|
|
frame->fixreg[3] = rv;
|
|
|
|
frame->cr = (*fb)[3];
|
|
|
|
memcpy(&frame->fixreg[13], &(*fb)[4],
|
|
|
|
19 * sizeof(register_t));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("trap: kernel %s DSI @ %#x by %#x (DSISR %#x, err=%d)\n",
|
|
|
|
(frame->dsisr & DSISR_STORE) ? "write" : "read",
|
|
|
|
frame->dar, frame->srr0, frame->dsisr, rv);
|
|
|
|
goto brain_damage2;
|
2001-11-05 00:49:03 +00:00
|
|
|
}
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_DSI|EXC_USER:
|
|
|
|
PROC_LOCK(p);
|
2002-05-12 06:06:24 +00:00
|
|
|
++p->p_lock;
|
|
|
|
PROC_UNLOCK(p);
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_udsi.ev_count++;
|
2002-03-20 21:09:09 +00:00
|
|
|
#endif
|
2002-05-09 14:22:55 +00:00
|
|
|
if (frame->dsisr & DSISR_STORE)
|
|
|
|
ftype = VM_PROT_WRITE;
|
|
|
|
else
|
|
|
|
ftype = VM_PROT_READ;
|
|
|
|
rv = vm_fault(&p->p_vmspace->vm_map, trunc_page(frame->dar),
|
|
|
|
ftype, VM_FAULT_NORMAL);
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_udsi_fatal.ev_count++;
|
|
|
|
#endif
|
|
|
|
printf("trap: pid %d (%s): user %s DSI @ %#x "
|
|
|
|
"by %#x (DSISR %#x, err=%d)\n",
|
|
|
|
p->p_pid, p->p_comm,
|
|
|
|
(frame->dsisr & DSISR_STORE) ? "write" : "read",
|
|
|
|
frame->dar, frame->srr0, frame->dsisr, rv);
|
|
|
|
if (rv == ENOMEM) {
|
|
|
|
printf("UVM: pid %d (%s), uid %d killed: "
|
|
|
|
"out of swap\n",
|
|
|
|
p->p_pid, p->p_comm,
|
|
|
|
td->td_ucred ? td->td_ucred->cr_uid : -1);
|
|
|
|
trapsignal(p, SIGKILL, EXC_DSI);
|
|
|
|
} else {
|
|
|
|
trapsignal(p, SIGSEGV, EXC_DSI);
|
|
|
|
}
|
2002-05-12 06:06:24 +00:00
|
|
|
PROC_LOCK(p);
|
|
|
|
--p->p_lock;
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
break;
|
|
|
|
case EXC_ISI:
|
|
|
|
printf("trap: kernel ISI by %#x (SRR1 %#x)\n",
|
|
|
|
frame->srr0, frame->srr1);
|
|
|
|
goto brain_damage2;
|
|
|
|
case EXC_ISI|EXC_USER:
|
|
|
|
PROC_LOCK(p);
|
2002-05-12 06:06:24 +00:00
|
|
|
++p->p_lock;
|
|
|
|
PROC_UNLOCK(p);
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_isi.ev_count++;
|
|
|
|
#endif
|
|
|
|
ftype = VM_PROT_READ | VM_PROT_EXECUTE;
|
|
|
|
rv = vm_fault(&p->p_vmspace->vm_map, trunc_page(frame->srr0),
|
|
|
|
ftype, VM_FAULT_NORMAL);
|
|
|
|
if (rv == 0) {
|
2002-05-12 06:06:24 +00:00
|
|
|
PROC_LOCK(p);
|
|
|
|
--p->p_lock;
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_isi_fatal.ev_count++;
|
|
|
|
#endif
|
|
|
|
printf("trap: pid %d (%s): user ISI trap @ %#x "
|
|
|
|
"(SSR1=%#x)\n",
|
|
|
|
p->p_pid, p->p_comm, frame->srr0, frame->srr1);
|
|
|
|
trapsignal(p, SIGSEGV, EXC_ISI);
|
2002-05-12 06:06:24 +00:00
|
|
|
PROC_LOCK(p);
|
|
|
|
--p->p_lock;
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
break;
|
|
|
|
case EXC_SC|EXC_USER:
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_scalls.ev_count++;
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
const struct sysent *callp;
|
|
|
|
size_t argsize;
|
|
|
|
register_t code, error;
|
|
|
|
register_t *params, rval[2];
|
|
|
|
int n;
|
|
|
|
register_t args[10];
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
uvmexp.syscalls++;
|
|
|
|
#endif
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
code = frame->fixreg[0];
|
|
|
|
callp = &p->p_sysent->sv_table[0];
|
|
|
|
params = frame->fixreg + FIRSTARG;
|
|
|
|
n = NARGREG;
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case SYS_syscall:
|
|
|
|
/*
|
|
|
|
* code is first argument,
|
|
|
|
* followed by actual args.
|
|
|
|
*/
|
|
|
|
code = *params++;
|
|
|
|
n -= 1;
|
|
|
|
break;
|
|
|
|
case SYS___syscall:
|
|
|
|
params++;
|
|
|
|
code = *params++;
|
|
|
|
n -= 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
if (p->p_sysent->sv_mask)
|
|
|
|
code &= p->p_sysent->sv_mask;
|
|
|
|
callp += code;
|
|
|
|
argsize = callp->sy_narg & SYF_ARGMASK;
|
|
|
|
|
|
|
|
if (argsize > n * sizeof(register_t)) {
|
|
|
|
memcpy(args, params, n * sizeof(register_t));
|
|
|
|
error = copyin(MOREARGS(frame->fixreg[1]),
|
|
|
|
args + n,
|
|
|
|
argsize - n * sizeof(register_t));
|
|
|
|
if (error)
|
|
|
|
goto syscall_bad;
|
|
|
|
params = args;
|
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-12 13:43:21 +00:00
|
|
|
/*
|
|
|
|
* Try to run the syscall without Giant if the syscall
|
|
|
|
* is MP safe.
|
|
|
|
*/
|
|
|
|
if ((callp->sy_narg & SYF_MPSAFE) == 0)
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
|
2001-06-10 02:39:37 +00:00
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(p, KTR_SYSCALL))
|
2002-05-09 14:22:55 +00:00
|
|
|
ktrsyscall(p, code, argsize, params);
|
2001-06-10 02:39:37 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
rval[0] = 0;
|
|
|
|
rval[1] = 0;
|
|
|
|
|
|
|
|
error = (*callp->sy_call)(td, params);
|
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
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 0
|
|
|
|
if (p->p_emul->e_errno)
|
|
|
|
error = p->p_emul->e_errno[error];
|
|
|
|
#endif
|
|
|
|
frame->fixreg[FIRSTARG] = error;
|
|
|
|
frame->cr |= 0x10000000;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-12 13:43:21 +00:00
|
|
|
/*
|
|
|
|
* Release Giant if we had to get it. Don't use
|
|
|
|
* mtx_owned(), we want to catch broken syscalls.
|
|
|
|
*/
|
|
|
|
if ((callp->sy_narg & SYF_MPSAFE) == 0)
|
|
|
|
mtx_unlock(&Giant);
|
2001-11-05 00:49:03 +00:00
|
|
|
#ifdef KTRACE
|
2002-05-09 14:22:55 +00:00
|
|
|
if (KTRPOINT(p, KTR_SYSRET))
|
|
|
|
ktrsysret(p, code, error, rval[0]);
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
break;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_FPU|EXC_USER:
|
2002-05-13 07:44:48 +00:00
|
|
|
if ((fputhread = PCPU_GET(fputhread)) != NULL) {
|
|
|
|
KASSERT(fputhread != td,
|
|
|
|
("floating-point already enabled"));
|
|
|
|
save_fpu(fputhread);
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
2002-05-13 07:44:48 +00:00
|
|
|
PCPU_SET(fputhread, td);
|
|
|
|
td->td_pcb->pcb_fpcpu = PCPU_GET(cpuid);
|
|
|
|
enable_fpu(td);
|
|
|
|
frame->srr1 |= PSL_FP;
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#ifdef ALTIVEC
|
|
|
|
case EXC_VEC|EXC_USER:
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_vec.ev_count++;
|
|
|
|
#endif
|
|
|
|
if (vecproc) {
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_vecsw.ev_count++;
|
|
|
|
#endif
|
|
|
|
save_vec(vecproc);
|
|
|
|
}
|
|
|
|
vecproc = p;
|
|
|
|
enable_vec(p);
|
|
|
|
break;
|
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_AST|EXC_USER:
|
|
|
|
astpending = 0; /* we are about to do it */
|
|
|
|
PROC_LOCK(p);
|
|
|
|
#if 0
|
|
|
|
uvmexp.softs++;
|
|
|
|
if (p->p_flag & P_OWEUPC) {
|
|
|
|
p->p_flag &= ~P_OWEUPC;
|
|
|
|
ADDUPROF(p);
|
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
2002-05-09 14:22:55 +00:00
|
|
|
/* Check whether we are being preempted. */
|
|
|
|
if (want_resched)
|
|
|
|
mi_switch();
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
break;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_ALI|EXC_USER:
|
|
|
|
PROC_LOCK(p);
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_ali.ev_count++;
|
|
|
|
#endif
|
|
|
|
if (fix_unaligned(p, frame) != 0) {
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_ali_fatal.ev_count++;
|
|
|
|
#endif
|
|
|
|
printf("trap: pid %d (%s): user ALI trap @ %#x "
|
|
|
|
"(SSR1=%#x)\n",
|
|
|
|
p->p_pid, p->p_comm, frame->srr0,
|
|
|
|
frame->srr1);
|
|
|
|
trapsignal(p, SIGBUS, EXC_ALI);
|
|
|
|
} else
|
|
|
|
frame->srr0 += 4;
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
break;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_PGM|EXC_USER:
|
|
|
|
/* XXX temporarily */
|
|
|
|
PROC_LOCK(p);
|
|
|
|
#if 0
|
|
|
|
curcpu()->ci_ev_pgm.ev_count++;
|
|
|
|
#endif
|
|
|
|
printf("trap: pid %d (%s): user PGM trap @ %#x "
|
|
|
|
"(SSR1=%#x)\n",
|
|
|
|
p->p_pid, p->p_comm, frame->srr0, frame->srr1);
|
|
|
|
if (frame->srr1 & 0x00020000) /* Bit 14 is set if trap */
|
|
|
|
trapsignal(p, SIGTRAP, EXC_PGM);
|
2001-11-05 00:49:03 +00:00
|
|
|
else
|
2002-05-09 14:22:55 +00:00
|
|
|
trapsignal(p, SIGILL, EXC_PGM);
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
break;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_MCHK: {
|
|
|
|
faultbuf *fb;
|
|
|
|
|
|
|
|
if ((fb = td->td_pcb->pcb_onfault) != NULL) {
|
|
|
|
frame->srr0 = (*fb)[0];
|
|
|
|
frame->fixreg[1] = (*fb)[1];
|
|
|
|
frame->fixreg[2] = (*fb)[2];
|
|
|
|
frame->fixreg[3] = EFAULT;
|
|
|
|
frame->cr = (*fb)[3];
|
|
|
|
memcpy(&frame->fixreg[13], &(*fb)[4],
|
|
|
|
19 * sizeof(register_t));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto brain_damage;
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
default:
|
|
|
|
brain_damage:
|
|
|
|
printf("trap type %x at %x\n", type, frame->srr0);
|
|
|
|
brain_damage2:
|
|
|
|
#ifdef DDBX
|
|
|
|
if (kdb_trap(type, frame))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
#ifdef TRAP_PANICWAIT
|
|
|
|
printf("Press a key to panic.\n");
|
|
|
|
cnpollc(1);
|
|
|
|
cngetc();
|
|
|
|
cnpollc(0);
|
|
|
|
#endif
|
|
|
|
panic("trap");
|
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-13 07:44:48 +00:00
|
|
|
#if 0
|
2002-05-09 14:22:55 +00:00
|
|
|
/* Take pending signals. */
|
|
|
|
{
|
|
|
|
int sig;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
while ((sig = CURSIG(p)) != 0)
|
|
|
|
postsig(sig);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
2002-05-13 07:44:48 +00:00
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
/*
|
|
|
|
* If someone stole the fp or vector unit while we were away,
|
|
|
|
* disable it
|
|
|
|
*/
|
2002-05-13 07:44:48 +00:00
|
|
|
if (td != PCPU_GET(fputhread) ||
|
|
|
|
td->td_pcb->pcb_fpcpu != PCPU_GET(cpuid))
|
2002-05-09 14:22:55 +00:00
|
|
|
frame->srr1 &= ~PSL_FP;
|
|
|
|
#ifdef ALTIVEC
|
|
|
|
if (p != vecproc)
|
|
|
|
frame->srr1 &= ~PSL_VEC;
|
|
|
|
#endif
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
curcpu()->ci_schedstate.spc_curpriority = p->p_priority = p->p_usrpri;
|
|
|
|
p->p_priority = p->p_usrpri;
|
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
void child_return(void *);
|
|
|
|
|
2001-06-10 02:39:37 +00:00
|
|
|
void
|
|
|
|
child_return(void *arg)
|
|
|
|
{
|
2002-05-09 14:22:55 +00:00
|
|
|
struct thread *td = arg;
|
|
|
|
struct proc *p = td->td_proc;
|
|
|
|
struct trapframe *tf = trapframe(td);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
tf->fixreg[FIRSTARG] = 0;
|
|
|
|
tf->fixreg[FIRSTARG + 1] = 1;
|
|
|
|
tf->cr &= ~0x10000000;
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
|
|
|
tf->srr1 &= ~(PSL_FP|PSL_VEC); /* Disable FP & AltiVec, as we can't
|
|
|
|
be them. */
|
|
|
|
td->td_pcb->pcb_fpcpu = NULL;
|
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
#ifdef KTRACE
|
2002-05-09 14:22:55 +00:00
|
|
|
if (KTRPOINT(p, KTR_SYSRET)) {
|
|
|
|
PROC_LOCK(p);
|
2001-06-10 02:39:37 +00:00
|
|
|
ktrsysret(p, SYS_fork, 0, 0);
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
2001-06-10 02:39:37 +00:00
|
|
|
#endif
|
|
|
|
/* Profiling? XXX */
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
2001-06-10 02:39:37 +00:00
|
|
|
curcpu()->ci_schedstate.spc_curpriority = p->p_priority;
|
|
|
|
#endif
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
setusr(content)
|
|
|
|
int content;
|
|
|
|
{
|
|
|
|
__asm __volatile ("isync; mtsr %0,%1; isync"
|
|
|
|
:: "n"(USER_SR), "r"(content));
|
|
|
|
}
|
|
|
|
|
|
|
|
int kcopy(const void *, void *, size_t);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* kcopy(const void *src, void *dst, size_t len);
|
|
|
|
*
|
|
|
|
* Copy len bytes from src to dst, aborting if we encounter a fatal
|
|
|
|
* page fault.
|
|
|
|
*
|
|
|
|
* kcopy() _must_ save and restore the old fault handler since it is
|
|
|
|
* called by uiomove(), which may be in the path of servicing a non-fatal
|
|
|
|
* page fault.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kcopy(const void *src, void *dst, size_t len)
|
|
|
|
{
|
2002-05-09 14:22:55 +00:00
|
|
|
struct thread *td;
|
2001-06-10 02:39:37 +00:00
|
|
|
faultbuf env, *oldfault;
|
2002-05-09 14:22:55 +00:00
|
|
|
int rv;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
td = PCPU_GET(curthread);
|
|
|
|
oldfault = td->td_pcb->pcb_onfault;
|
|
|
|
if ((rv = setfault(env)) != 0) {
|
|
|
|
td->td_pcb->pcb_onfault = oldfault;
|
|
|
|
return rv;
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
memcpy(dst, src, len);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
td->td_pcb->pcb_onfault = oldfault;
|
2001-06-10 02:39:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-05-09 14:22:55 +00:00
|
|
|
badaddr(addr, size)
|
|
|
|
void *addr;
|
|
|
|
size_t size;
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
|
|
|
return badaddr_read(addr, size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-05-09 14:22:55 +00:00
|
|
|
badaddr_read(addr, size, rptr)
|
|
|
|
void *addr;
|
|
|
|
size_t size;
|
|
|
|
int *rptr;
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
2002-05-09 14:22:55 +00:00
|
|
|
struct thread *td;
|
2001-06-10 02:39:37 +00:00
|
|
|
faultbuf env;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
/* Get rid of any stale machine checks that have been waiting. */
|
|
|
|
__asm __volatile ("sync; isync");
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
td = PCPU_GET(curthread);
|
|
|
|
|
2001-06-10 02:39:37 +00:00
|
|
|
if (setfault(env)) {
|
2002-05-09 14:22:55 +00:00
|
|
|
td->td_pcb->pcb_onfault = 0;
|
2001-06-10 02:39:37 +00:00
|
|
|
__asm __volatile ("sync");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__asm __volatile ("sync");
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
x = *(volatile int8_t *)addr;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
x = *(volatile int16_t *)addr;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
x = *(volatile int32_t *)addr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("badaddr: invalid size (%d)", size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we took the machine check, if we caused one. */
|
|
|
|
__asm __volatile ("sync; isync");
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
td->td_pcb->pcb_onfault = 0;
|
2001-06-10 02:39:37 +00:00
|
|
|
__asm __volatile ("sync"); /* To be sure. */
|
|
|
|
|
|
|
|
/* Use the value to avoid reorder. */
|
|
|
|
if (rptr)
|
|
|
|
*rptr = x;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For now, this only deals with the particular unaligned access case
|
|
|
|
* that gcc tends to generate. Eventually it should handle all of the
|
|
|
|
* possibilities that can happen on a 32-bit PowerPC in big-endian mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
fix_unaligned(p, frame)
|
|
|
|
struct proc *p;
|
|
|
|
struct trapframe *frame;
|
|
|
|
{
|
2002-05-09 14:22:55 +00:00
|
|
|
int indicator = EXC_ALI_OPCODE_INDICATOR(frame->dsisr);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
switch (indicator) {
|
|
|
|
case EXC_ALI_LFD:
|
|
|
|
case EXC_ALI_STFD:
|
2002-05-09 14:22:55 +00:00
|
|
|
#if 0
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
|
|
|
int reg = EXC_ALI_RST(frame->dsisr);
|
|
|
|
double *fpr = &p->p_addr->u_pcb.pcb_fpu.fpr[reg];
|
|
|
|
|
|
|
|
/* Juggle the FPU to ensure that we've initialized
|
|
|
|
* the FPRs, and that their current state is in
|
|
|
|
* the PCB.
|
|
|
|
*/
|
2002-05-09 14:22:55 +00:00
|
|
|
if (fpuproc != p) {
|
|
|
|
if (fpuproc)
|
|
|
|
save_fpu(fpuproc);
|
|
|
|
enable_fpu(p);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
2002-05-09 14:22:55 +00:00
|
|
|
save_fpu(p);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
if (indicator == EXC_ALI_LFD) {
|
|
|
|
if (copyin((void *)frame->dar, fpr,
|
|
|
|
sizeof(double)) != 0)
|
|
|
|
return -1;
|
2002-05-09 14:22:55 +00:00
|
|
|
enable_fpu(p);
|
2001-06-10 02:39:37 +00:00
|
|
|
} else {
|
|
|
|
if (copyout(fpr, (void *)frame->dar,
|
|
|
|
sizeof(double)) != 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-05-09 14:22:55 +00:00
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|