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>
|
2002-05-19 08:16:25 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/ktr.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2002-05-19 08:16:25 +00:00
|
|
|
#include <sys/pioctl.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/syscall.h>
|
2002-05-09 14:22:55 +00:00
|
|
|
#include <sys/sysent.h>
|
2002-05-19 08:16:25 +00:00
|
|
|
#include <sys/systm.h>
|
2002-05-19 04:04:12 +00:00
|
|
|
#include <sys/uio.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <sys/user.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#ifdef KTRACE
|
2001-06-10 02:39:37 +00:00
|
|
|
#include <sys/ktrace.h>
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
2002-05-19 08:16:25 +00:00
|
|
|
#include <sys/vmmeter.h>
|
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-10-04 01:19:18 +00:00
|
|
|
#include <ddb/ddb.h>
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
#ifndef MULTIPROCESSOR
|
|
|
|
extern int intr_depth;
|
2001-11-05 00:49:03 +00:00
|
|
|
#endif
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
void trap(struct trapframe *);
|
|
|
|
|
|
|
|
static void trap_fatal(struct trapframe *frame);
|
|
|
|
static void printtrap(u_int vector, struct trapframe *frame, int isfatal,
|
|
|
|
int user);
|
|
|
|
static int trap_pfault(struct trapframe *frame, int user);
|
|
|
|
static int fix_unaligned(struct thread *td, struct trapframe *frame);
|
|
|
|
static int handle_onfault(struct trapframe *frame);
|
|
|
|
static void syscall(struct trapframe *frame);
|
2002-05-09 14:22:55 +00:00
|
|
|
|
2002-05-19 04:04:12 +00:00
|
|
|
static __inline void setusr(u_int);
|
|
|
|
|
|
|
|
int setfault(faultbuf); /* defined in locore.S */
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
/* Why are these not defined in a header? */
|
2002-05-19 04:04:12 +00:00
|
|
|
int badaddr(void *, size_t);
|
|
|
|
int badaddr_read(void *, size_t, int *);
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 04:04:12 +00:00
|
|
|
#ifdef WITNESS
|
2002-05-13 07:44:48 +00:00
|
|
|
extern char *syscallnames[];
|
2002-05-19 04:04:12 +00:00
|
|
|
#endif
|
2002-05-13 07:44:48 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
struct powerpc_exception {
|
|
|
|
u_int vector;
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct powerpc_exception powerpc_exceptions[] = {
|
|
|
|
{ 0x0100, "system reset" },
|
|
|
|
{ 0x0200, "machine check" },
|
|
|
|
{ 0x0300, "data storage interrupt" },
|
|
|
|
{ 0x0400, "instruction storage interrupt" },
|
|
|
|
{ 0x0500, "external interrupt" },
|
|
|
|
{ 0x0600, "alignment" },
|
|
|
|
{ 0x0700, "program" },
|
|
|
|
{ 0x0800, "floating-point unavailable" },
|
|
|
|
{ 0x0900, "decrementer" },
|
|
|
|
{ 0x0c00, "system call" },
|
|
|
|
{ 0x0d00, "trace" },
|
|
|
|
{ 0x0e00, "floating-point assist" },
|
|
|
|
{ 0x0f00, "performance monitoring" },
|
|
|
|
{ 0x0f20, "altivec unavailable" },
|
|
|
|
{ 0x1000, "instruction tlb miss" },
|
|
|
|
{ 0x1100, "data load tlb miss" },
|
|
|
|
{ 0x1200, "data store tlb miss" },
|
|
|
|
{ 0x1300, "instruction breakpoint" },
|
|
|
|
{ 0x1400, "system management" },
|
|
|
|
{ 0x1600, "altivec assist" },
|
|
|
|
{ 0x1700, "thermal management" },
|
|
|
|
{ 0x2000, "run mode/trace" },
|
|
|
|
{ 0x3000, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
trapname(u_int vector)
|
|
|
|
{
|
|
|
|
struct powerpc_exception *pe;
|
|
|
|
|
|
|
|
for (pe = powerpc_exceptions; pe->vector != 0x3000; pe++) {
|
|
|
|
if (pe->vector == vector)
|
|
|
|
return (pe->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ("unknown");
|
|
|
|
}
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
void
|
2002-05-19 04:04:12 +00:00
|
|
|
trap(struct trapframe *frame)
|
2001-11-05 00:49:03 +00:00
|
|
|
{
|
2002-05-19 04:04:12 +00:00
|
|
|
struct thread *td, *fputhread;
|
|
|
|
struct proc *p;
|
2002-05-19 08:16:25 +00:00
|
|
|
int sig, type, user;
|
|
|
|
u_int sticks, ucode;
|
|
|
|
|
|
|
|
atomic_add_int(&cnt.v_trap, 1);
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 04:04:12 +00:00
|
|
|
td = PCPU_GET(curthread);
|
|
|
|
p = td->td_proc;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
type = ucode = frame->exc;
|
|
|
|
sig = 0;
|
|
|
|
user = frame->srr1 & PSL_PR;
|
|
|
|
sticks = 0;
|
|
|
|
|
|
|
|
CTR3(KTR_TRAP, "trap: %s type=%s (%s)", p->p_comm,
|
|
|
|
trapname(type), user ? "user" : "kernel");
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
sticks = td->td_kse->ke_sticks;
|
|
|
|
td->td_frame = frame;
|
|
|
|
if (td->td_ucred != p->p_ucred)
|
|
|
|
cred_update_thread(td);
|
|
|
|
|
|
|
|
/* User Mode Traps */
|
|
|
|
switch (type) {
|
|
|
|
case EXC_RUNMODETRC:
|
|
|
|
case EXC_TRC:
|
|
|
|
frame->srr1 &= ~PSL_SE;
|
|
|
|
sig = SIGTRAP;
|
|
|
|
break;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
case EXC_DSI:
|
|
|
|
case EXC_ISI:
|
|
|
|
sig = trap_pfault(frame, 1);
|
|
|
|
break;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
case EXC_SC:
|
|
|
|
syscall(frame);
|
|
|
|
break;
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
case EXC_FPU:
|
|
|
|
if ((fputhread = PCPU_GET(fputhread)) != NULL) {
|
|
|
|
save_fpu(fputhread);
|
|
|
|
}
|
|
|
|
PCPU_SET(fputhread, td);
|
|
|
|
td->td_pcb->pcb_fpcpu = PCPU_GET(cpuid);
|
|
|
|
enable_fpu(td);
|
|
|
|
frame->srr1 |= PSL_FP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef ALTIVEC
|
|
|
|
case EXC_VEC:
|
|
|
|
if ((vecthread = PCPU_GET(vecthread)) != NULL) {
|
|
|
|
KASSERT(vecthread != td,
|
|
|
|
("altivec already enabled"));
|
|
|
|
save_vec(vecthread);
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
PCPU_SET(vecthread, td);
|
|
|
|
td->td_pcb->pcb_veccpu = PCPU_GET(cpuid);
|
|
|
|
enable_vec(td);
|
|
|
|
frame->srr1 |= PSL_VEC;
|
|
|
|
break;
|
|
|
|
#endif /* ALTIVEC */
|
|
|
|
|
|
|
|
case EXC_ALI:
|
|
|
|
if (fix_unaligned(td, frame) != 0)
|
|
|
|
sig = SIGBUS;
|
2001-06-10 02:39:37 +00:00
|
|
|
else
|
2002-05-19 08:16:25 +00:00
|
|
|
frame->srr0 += 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXC_PGM:
|
|
|
|
/* XXX temporarily */
|
|
|
|
/* XXX: Magic Number? */
|
|
|
|
if (frame->srr1 & 0x0002000)
|
|
|
|
sig = SIGTRAP;
|
|
|
|
else
|
|
|
|
sig = SIGILL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
trap_fatal(frame);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
} else {
|
|
|
|
/* Kernel Mode Traps */
|
|
|
|
|
|
|
|
KASSERT(cold || td->td_ucred != NULL,
|
|
|
|
("kernel trap doesn't have ucred"));
|
|
|
|
switch (type) {
|
|
|
|
case EXC_DSI:
|
|
|
|
if (trap_pfault(frame, 0) == 0)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case EXC_MCHK:
|
|
|
|
if (handle_onfault(frame))
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
trap_fatal(frame);
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
|
|
|
|
if (td != PCPU_GET(fputhread) ||
|
|
|
|
td->td_pcb->pcb_fpcpu != PCPU_GET(cpuid))
|
|
|
|
frame->srr1 &= ~PSL_FP;
|
|
|
|
|
|
|
|
#ifdef ALTIVEC
|
|
|
|
if (td != PCPU_GET(vecthread) ||
|
|
|
|
td->td_pcb->pcb_veccpu != PCPU_GET(cpuid))
|
|
|
|
frame->srr1 &= ~PSL_VEC;
|
|
|
|
#endif /* ALTIVEC */
|
|
|
|
|
|
|
|
if (sig != 0) {
|
|
|
|
if (p->p_sysent->sv_transtrap != NULL)
|
|
|
|
sig = (p->p_sysent->sv_transtrap)(sig, type);
|
|
|
|
trapsignal(p, sig, ucode);
|
|
|
|
}
|
|
|
|
|
|
|
|
userret(td, frame, sticks);
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
2002-07-13 04:36:50 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
cred_free_thread(td);
|
|
|
|
#endif /* DIAGNOSTIC */
|
2002-05-19 08:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
trap_fatal(struct trapframe *frame)
|
|
|
|
{
|
|
|
|
|
|
|
|
printtrap(frame->exc, frame, 1, (frame->srr1 & PSL_PR));
|
|
|
|
#ifdef DDB
|
2002-10-04 01:19:18 +00:00
|
|
|
if ((debugger_on_panic || db_active) && kdb_trap(frame->exc, frame))
|
2002-05-19 08:16:25 +00:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
panic("%s trap", trapname(frame->exc));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printtrap(u_int vector, struct trapframe *frame, int isfatal, int user)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
printf("%s %s trap:\n", isfatal ? "fatal" : "handled",
|
|
|
|
user ? "user" : "kernel");
|
|
|
|
printf("\n");
|
|
|
|
printf(" exception = 0x%x (%s)\n", vector >> 8,
|
|
|
|
trapname(vector));
|
|
|
|
switch (vector) {
|
|
|
|
case EXC_DSI:
|
|
|
|
printf(" virtual address = 0x%x\n", frame->dar);
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
|
|
|
case EXC_ISI:
|
2002-05-19 08:16:25 +00:00
|
|
|
printf(" virtual address = 0x%x\n", frame->srr0);
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2002-05-19 08:16:25 +00:00
|
|
|
}
|
2002-05-27 11:20:19 +00:00
|
|
|
printf(" srr0 = 0x%x\n", frame->srr0);
|
|
|
|
printf(" srr1 = 0x%x\n", frame->srr1);
|
2002-05-19 08:16:25 +00:00
|
|
|
printf(" curthread = %p\n", curthread);
|
|
|
|
if (curthread != NULL)
|
|
|
|
printf(" pid = %d, comm = %s\n",
|
|
|
|
curthread->td_proc->p_pid, curthread->td_proc->p_comm);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
/*
|
|
|
|
* Handles a fatal fault when we have onfault state to recover. Returns
|
|
|
|
* non-zero if there was onfault recovery state available.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
handle_onfault(struct trapframe *frame)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
faultbuf *fb;
|
|
|
|
|
|
|
|
td = curthread;
|
|
|
|
fb = td->td_pcb->pcb_onfault;
|
|
|
|
if (fb != NULL) {
|
|
|
|
frame->srr0 = (*fb)[0];
|
|
|
|
frame->fixreg[1] = (*fb)[1];
|
|
|
|
frame->fixreg[2] = (*fb)[2];
|
|
|
|
frame->cr = (*fb)[3];
|
|
|
|
bcopy(&(*fb)[4], &frame->fixreg[13],
|
|
|
|
19 * sizeof(register_t));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
void
|
|
|
|
syscall(struct trapframe *frame)
|
|
|
|
{
|
|
|
|
caddr_t params;
|
|
|
|
struct sysent *callp;
|
|
|
|
struct thread *td;
|
|
|
|
struct proc *p;
|
|
|
|
int error, n;
|
|
|
|
size_t narg;
|
|
|
|
register_t args[10];
|
|
|
|
u_int code;
|
2002-05-12 13:43:21 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
td = PCPU_GET(curthread);
|
|
|
|
p = td->td_proc;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
atomic_add_int(&cnt.v_syscall, 1);
|
|
|
|
|
|
|
|
code = frame->fixreg[0];
|
|
|
|
params = (caddr_t)(frame->fixreg + FIRSTARG);
|
|
|
|
n = NARGREG;
|
|
|
|
|
|
|
|
if (p->p_sysent->sv_prepsyscall) {
|
|
|
|
/*
|
|
|
|
* The prep code is MP aware.
|
|
|
|
*/
|
|
|
|
(*p->p_sysent->sv_prepsyscall)(frame, args, &code, ¶ms);
|
|
|
|
} else if (code == SYS_syscall) {
|
|
|
|
/*
|
|
|
|
* code is first argument,
|
|
|
|
* followed by actual args.
|
|
|
|
*/
|
2002-09-19 04:38:35 +00:00
|
|
|
code = *(u_int *) params;
|
|
|
|
params += sizeof(register_t);
|
2002-05-19 08:16:25 +00:00
|
|
|
n -= 1;
|
|
|
|
} else if (code == SYS___syscall) {
|
|
|
|
/*
|
|
|
|
* Like syscall, but code is a quad,
|
|
|
|
* so as to maintain quad alignment
|
|
|
|
* for the rest of the args.
|
|
|
|
*/
|
2002-09-19 04:38:35 +00:00
|
|
|
params += sizeof(register_t);
|
|
|
|
code = *(u_int *) params;
|
|
|
|
params += sizeof(register_t);
|
2002-05-19 08:16:25 +00:00
|
|
|
n -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->p_sysent->sv_mask)
|
|
|
|
code &= p->p_sysent->sv_mask;
|
|
|
|
|
|
|
|
if (code >= p->p_sysent->sv_size)
|
|
|
|
callp = &p->p_sysent->sv_table[0];
|
|
|
|
else
|
|
|
|
callp = &p->p_sysent->sv_table[code];
|
|
|
|
|
|
|
|
narg = callp->sy_narg & SYF_ARGMASK;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-09-19 04:38:35 +00:00
|
|
|
if (narg > n) {
|
2002-05-19 08:16:25 +00:00
|
|
|
bcopy(params, args, n * sizeof(register_t));
|
|
|
|
error = copyin(MOREARGS(frame->fixreg[1]), args + n,
|
2002-09-19 04:38:35 +00:00
|
|
|
(narg - n) * sizeof(register_t));
|
2002-05-19 08:16:25 +00:00
|
|
|
params = (caddr_t)args;
|
2002-06-07 05:47:35 +00:00
|
|
|
} else
|
|
|
|
error = 0;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-06-07 05:47:35 +00:00
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(td, KTR_SYSCALL))
|
2002-09-19 04:38:35 +00:00
|
|
|
ktrsyscall(code, narg, (register_t *)params);
|
2002-06-07 05:47:35 +00:00
|
|
|
#endif
|
2002-05-19 08:16:25 +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
|
|
|
|
2002-06-07 05:47:35 +00:00
|
|
|
if (error == 0) {
|
|
|
|
td->td_retval[0] = 0;
|
|
|
|
td->td_retval[1] = frame->fixreg[FIRSTARG + 1];
|
2002-05-19 08:16:25 +00:00
|
|
|
|
2002-06-07 05:47:35 +00:00
|
|
|
STOPEVENT(p, S_SCE, narg);
|
2002-05-19 08:16:25 +00:00
|
|
|
|
2002-06-07 05:47:35 +00:00
|
|
|
error = (*callp->sy_call)(td, params);
|
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
switch (error) {
|
|
|
|
case 0:
|
2002-09-19 04:38:35 +00:00
|
|
|
if ((frame->fixreg[0] == SYS___syscall) &&
|
|
|
|
(code != SYS_lseek)) {
|
|
|
|
/*
|
|
|
|
* 64-bit return, 32-bit syscall. Fixup byte order
|
|
|
|
*/
|
|
|
|
frame->fixreg[FIRSTARG] = 0;
|
|
|
|
frame->fixreg[FIRSTARG + 1] = td->td_retval[0];
|
|
|
|
} else {
|
|
|
|
frame->fixreg[FIRSTARG] = td->td_retval[0];
|
|
|
|
frame->fixreg[FIRSTARG + 1] = td->td_retval[1];
|
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
/* XXX: Magic number */
|
|
|
|
frame->cr &= ~0x10000000;
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2002-05-19 08:16:25 +00:00
|
|
|
case ERESTART:
|
|
|
|
/*
|
|
|
|
* Set user's pc back to redo the system call.
|
|
|
|
*/
|
|
|
|
frame->srr0 -= 4;
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2002-05-19 08:16:25 +00:00
|
|
|
case EJUSTRETURN:
|
|
|
|
/* nothing to do */
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2002-05-19 08:16:25 +00:00
|
|
|
default:
|
|
|
|
if (p->p_sysent->sv_errsize) {
|
|
|
|
if (error >= p->p_sysent->sv_errsize)
|
|
|
|
error = -1; /* XXX */
|
|
|
|
else
|
|
|
|
error = p->p_sysent->sv_errtbl[error];
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
frame->fixreg[FIRSTARG] = error;
|
|
|
|
/* XXX: Magic number: Carry Flag Equivalent? */
|
|
|
|
frame->cr |= 0x10000000;
|
|
|
|
break;
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
|
|
|
|
if ((callp->sy_narg & SYF_MPSAFE) == 0)
|
|
|
|
mtx_unlock(&Giant);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-06-07 05:47:35 +00:00
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(td, KTR_SYSRET))
|
|
|
|
ktrsysret(code, error, td->td_retval[0]);
|
|
|
|
#endif
|
|
|
|
|
2002-05-09 14:22:55 +00:00
|
|
|
/*
|
2002-05-19 08:16:25 +00:00
|
|
|
* Does the comment in the i386 code about errno apply here?
|
2002-05-09 14:22:55 +00:00
|
|
|
*/
|
2002-05-19 08:16:25 +00:00
|
|
|
STOPEVENT(p, S_SCX, code);
|
2001-11-05 00:49:03 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
#ifdef WITNESS
|
|
|
|
if (witness_list(td)) {
|
|
|
|
panic("system call %s returning with mutex(s) held\n",
|
|
|
|
syscallnames[code]);
|
|
|
|
}
|
2002-05-09 14:22:55 +00:00
|
|
|
#endif
|
2002-05-19 08:16:25 +00:00
|
|
|
mtx_assert(&sched_lock, MA_NOTOWNED);
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
static int
|
|
|
|
trap_pfault(struct trapframe *frame, int user)
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
2002-05-19 08:16:25 +00:00
|
|
|
vm_offset_t eva, va;
|
|
|
|
struct thread *td;
|
|
|
|
struct proc *p;
|
|
|
|
vm_map_t map;
|
|
|
|
vm_prot_t ftype;
|
|
|
|
int rv;
|
|
|
|
u_int user_sr;
|
2002-05-19 04:04:12 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
td = curthread;
|
2002-05-19 04:04:12 +00:00
|
|
|
p = td->td_proc;
|
2002-05-19 08:16:25 +00:00
|
|
|
if (frame->exc == EXC_ISI) {
|
|
|
|
eva = frame->srr0;
|
|
|
|
ftype = VM_PROT_READ | VM_PROT_EXECUTE;
|
|
|
|
} else {
|
|
|
|
eva = frame->dar;
|
|
|
|
if (frame->dsisr & DSISR_STORE)
|
2002-09-19 04:38:35 +00:00
|
|
|
ftype = VM_PROT_WRITE;
|
2002-05-19 08:16:25 +00:00
|
|
|
else
|
|
|
|
ftype = VM_PROT_READ;
|
|
|
|
}
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
if (user) {
|
|
|
|
map = &p->p_vmspace->vm_map;
|
|
|
|
} else {
|
|
|
|
if ((eva >> ADDR_SR_SHFT) == USER_SR) {
|
|
|
|
if (p->p_vmspace == NULL)
|
|
|
|
return (SIGSEGV);
|
|
|
|
|
|
|
|
__asm ("mfsr %0, %1"
|
|
|
|
: "=r"(user_sr)
|
|
|
|
: "K"(USER_SR));
|
|
|
|
eva &= ADDR_PIDX | ADDR_POFF;
|
|
|
|
eva |= user_sr << ADDR_SR_SHFT;
|
|
|
|
map = &p->p_vmspace->vm_map;
|
|
|
|
} else {
|
|
|
|
map = kernel_map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va = trunc_page(eva);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
mtx_lock(&Giant);
|
|
|
|
if (map != kernel_map) {
|
|
|
|
/*
|
|
|
|
* Keep swapout from messing with us during this
|
|
|
|
* critical time.
|
|
|
|
*/
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_LOCK(p);
|
2002-05-19 08:16:25 +00:00
|
|
|
++p->p_lock;
|
2002-05-09 14:22:55 +00:00
|
|
|
PROC_UNLOCK(p);
|
2002-05-19 08:16:25 +00:00
|
|
|
|
|
|
|
/* Fault in the user page: */
|
|
|
|
rv = vm_fault(map, va, ftype,
|
|
|
|
(ftype & VM_PROT_WRITE) ? VM_FAULT_DIRTY
|
|
|
|
: VM_FAULT_NORMAL);
|
|
|
|
|
|
|
|
PROC_LOCK(p);
|
|
|
|
--p->p_lock;
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't have to worry about process locking or stacks in the
|
|
|
|
* kernel.
|
|
|
|
*/
|
|
|
|
rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
mtx_unlock(&Giant);
|
|
|
|
|
|
|
|
if (rv == KERN_SUCCESS)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (!user && handle_onfault(frame))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (SIGSEGV);
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
2002-05-19 04:04:12 +00:00
|
|
|
setusr(u_int content)
|
2002-05-09 14:22:55 +00:00
|
|
|
{
|
|
|
|
__asm __volatile ("isync; mtsr %0,%1; isync"
|
|
|
|
:: "n"(USER_SR), "r"(content));
|
|
|
|
}
|
|
|
|
|
2001-06-10 02:39:37 +00:00
|
|
|
int
|
2002-05-19 04:04:12 +00:00
|
|
|
badaddr(void *addr, size_t size)
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
2002-05-19 04:04:12 +00:00
|
|
|
return (badaddr_read(addr, size, NULL));
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-05-19 04:04:12 +00:00
|
|
|
badaddr_read(void *addr, size_t size, int *rptr)
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
2002-05-19 04:04:12 +00:00
|
|
|
struct thread *td;
|
|
|
|
faultbuf env;
|
|
|
|
int x;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2002-05-19 04:04:12 +00:00
|
|
|
return (0);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2002-05-19 04:04:12 +00:00
|
|
|
fix_unaligned(struct thread *td, struct trapframe *frame)
|
2001-06-10 02:39:37 +00:00
|
|
|
{
|
2002-05-19 04:04:12 +00:00
|
|
|
struct thread *fputhread;
|
|
|
|
int indicator, reg;
|
|
|
|
double *fpr;
|
|
|
|
|
|
|
|
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-19 04:04:12 +00:00
|
|
|
reg = EXC_ALI_RST(frame->dsisr);
|
|
|
|
fpr = &td->td_pcb->pcb_fpu.fpr[reg];
|
|
|
|
fputhread = PCPU_GET(fputhread);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 04:04:12 +00:00
|
|
|
/* Juggle the FPU to ensure that we've initialized
|
|
|
|
* the FPRs, and that their current state is in
|
|
|
|
* the PCB.
|
|
|
|
*/
|
|
|
|
if (fputhread != td) {
|
|
|
|
if (fputhread)
|
|
|
|
save_fpu(fputhread);
|
|
|
|
enable_fpu(td);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
2002-05-19 04:04:12 +00:00
|
|
|
save_fpu(td);
|
|
|
|
|
|
|
|
if (indicator == EXC_ALI_LFD) {
|
|
|
|
if (copyin((void *)frame->dar, fpr,
|
|
|
|
sizeof(double)) != 0)
|
|
|
|
return -1;
|
|
|
|
enable_fpu(td);
|
|
|
|
} else {
|
|
|
|
if (copyout(fpr, (void *)frame->dar,
|
|
|
|
sizeof(double)) != 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2001-06-10 02:39:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|