2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
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
|
|
|
*/
|
|
|
|
|
2003-04-03 21:36:33 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2004-07-12 22:26:20 +00:00
|
|
|
#include <sys/kdb.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>
|
2006-07-27 19:50:16 +00:00
|
|
|
#include <sys/ptrace.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>
|
2005-03-15 11:41:55 +00:00
|
|
|
#include <sys/signalvar.h>
|
2002-05-19 08:16:25 +00:00
|
|
|
#include <sys/vmmeter.h>
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2006-09-16 17:03:02 +00:00
|
|
|
#include <security/audit/audit.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
|
|
|
|
2010-07-13 05:32:19 +00:00
|
|
|
#include <machine/_inttypes.h>
|
2009-02-20 17:48:40 +00:00
|
|
|
#include <machine/altivec.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-19 08:16:25 +00:00
|
|
|
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);
|
2010-02-22 14:17:23 +00:00
|
|
|
static int ppc_instr_emulate(struct trapframe *frame);
|
2002-05-19 08:16:25 +00:00
|
|
|
static int handle_onfault(struct trapframe *frame);
|
|
|
|
static void syscall(struct trapframe *frame);
|
2002-05-09 14:22:55 +00:00
|
|
|
|
2010-07-13 05:32:19 +00:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
static int handle_slb_spill(pmap_t pm, vm_offset_t addr);
|
|
|
|
#endif
|
|
|
|
|
2002-05-19 04:04:12 +00:00
|
|
|
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 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" },
|
2010-07-13 05:32:19 +00:00
|
|
|
{ 0x0380, "data segment exception" },
|
2002-05-19 08:16:25 +00:00
|
|
|
{ 0x0400, "instruction storage interrupt" },
|
2010-07-13 05:32:19 +00:00
|
|
|
{ 0x0480, "instruction segment exception" },
|
2002-05-19 08:16:25 +00:00
|
|
|
{ 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" },
|
2004-07-06 11:46:56 +00:00
|
|
|
{ 0x1400, "system management" },
|
2002-05-19 08:16:25 +00:00
|
|
|
{ 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
|
|
|
{
|
2003-03-20 10:28:20 +00:00
|
|
|
struct thread *td;
|
2002-05-19 04:04:12 +00:00
|
|
|
struct proc *p;
|
2002-05-19 08:16:25 +00:00
|
|
|
int sig, type, user;
|
2006-02-08 08:09:17 +00:00
|
|
|
u_int ucode;
|
1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, most
changes in MD code are trivial, before this change, trapsignal and
sendsig use discrete parameters, now they uses member fields of
ksiginfo_t structure. For sendsig, this change allows us to pass
POSIX realtime signal value to user code.
2. Remove cpu_thread_siginfo, it is no longer needed because we now always
generate ksiginfo_t data and feed it to libpthread.
3. Add p_sigqueue to proc structure to hold shared signals which were
blocked by all threads in the proc.
4. Add td_sigqueue to thread structure to hold all signals delivered to
thread.
5. i386 and amd64 now return POSIX standard si_code, other arches will
be fixed.
6. In this sigqueue implementation, pending signal set is kept as before,
an extra siginfo list holds additional siginfo_t data for signals.
kernel code uses psignal() still behavior as before, it won't be failed
even under memory pressure, only exception is when deleting a signal,
we should call sigqueue_delete to remove signal from sigqueue but
not SIGDELSET. Current there is no kernel code will deliver a signal
with additional data, so kernel should be as stable as before,
a ksiginfo can carry more information, for example, allow signal to
be delivered but throw away siginfo data if memory is not enough.
SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can
not be caught or masked.
The sigqueue() syscall allows user code to queue a signal to target
process, if resource is unavailable, EAGAIN will be returned as
specification said.
Just before thread exits, signal queue memory will be freed by
sigqueue_flush.
Current, all signals are allowed to be queued, not only realtime signals.
Earlier patch reviewed by: jhb, deischen
Tested on: i386, amd64
2005-10-14 12:43:47 +00:00
|
|
|
ksiginfo_t ksi;
|
2002-05-19 08:16:25 +00:00
|
|
|
|
2007-06-04 21:38:48 +00:00
|
|
|
PCPU_INC(cnt.v_trap);
|
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;
|
|
|
|
|
2007-11-14 06:51:33 +00:00
|
|
|
CTR3(KTR_TRAP, "trap: %s type=%s (%s)", td->td_name,
|
2002-05-19 08:16:25 +00:00
|
|
|
trapname(type), user ? "user" : "kernel");
|
|
|
|
|
|
|
|
if (user) {
|
2006-02-08 08:09:17 +00:00
|
|
|
td->td_pticks = 0;
|
2002-05-19 08:16:25 +00:00
|
|
|
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
|
|
|
|
2010-07-13 05:32:19 +00:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
case EXC_ISE:
|
|
|
|
case EXC_DSE:
|
|
|
|
if (handle_slb_spill(&p->p_vmspace->vm_pmap,
|
|
|
|
(type == EXC_ISE) ? frame->srr0 :
|
|
|
|
frame->cpu.aim.dar) != 0)
|
|
|
|
sig = SIGSEGV;
|
|
|
|
break;
|
|
|
|
#endif
|
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:
|
2003-03-20 10:28:20 +00:00
|
|
|
KASSERT((td->td_pcb->pcb_flags & PCB_FPU) != PCB_FPU,
|
|
|
|
("FPU already enabled for thread"));
|
2002-05-19 08:16:25 +00:00
|
|
|
enable_fpu(td);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXC_VEC:
|
2009-02-20 17:48:40 +00:00
|
|
|
KASSERT((td->td_pcb->pcb_flags & PCB_VEC) != PCB_VEC,
|
|
|
|
("Altivec already enabled for thread"));
|
2002-05-19 08:16:25 +00:00
|
|
|
enable_vec(td);
|
|
|
|
break;
|
2009-02-20 17:48:40 +00:00
|
|
|
|
2010-10-05 18:08:07 +00:00
|
|
|
case EXC_VECAST_G4:
|
|
|
|
case EXC_VECAST_G5:
|
|
|
|
/*
|
|
|
|
* We get a VPU assist exception for IEEE mode
|
|
|
|
* vector operations on denormalized floats.
|
|
|
|
* Emulating this is a giant pain, so for now,
|
|
|
|
* just switch off IEEE mode and treat them as
|
|
|
|
* zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
save_vec(td);
|
|
|
|
td->td_pcb->pcb_vec.vscr |= ALTIVEC_VSCR_NJ;
|
|
|
|
enable_vec(td);
|
2005-07-30 11:14:31 +00:00
|
|
|
break;
|
2002-05-19 08:16:25 +00:00
|
|
|
|
|
|
|
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:
|
2009-04-19 06:30:00 +00:00
|
|
|
/* Identify the trap reason */
|
|
|
|
if (frame->srr1 & EXC_PGM_TRAP)
|
2002-05-19 08:16:25 +00:00
|
|
|
sig = SIGTRAP;
|
2010-02-22 14:17:23 +00:00
|
|
|
else if (ppc_instr_emulate(frame) == 0)
|
|
|
|
frame->srr0 += 4;
|
|
|
|
else
|
2002-05-19 08:16:25 +00:00
|
|
|
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;
|
2010-07-13 05:32:19 +00:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
case EXC_DSE:
|
2010-10-30 23:07:30 +00:00
|
|
|
if ((frame->cpu.aim.dar & SEGMENT_MASK) == USER_ADDR) {
|
|
|
|
__asm __volatile ("slbmte %0, %1" ::
|
|
|
|
"r"(td->td_pcb->pcb_cpu.aim.usr_vsid),
|
|
|
|
"r"(USER_SLB_SLBE));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case EXC_ISE:
|
2010-07-13 05:32:19 +00:00
|
|
|
if (handle_slb_spill(kernel_pmap,
|
|
|
|
(type == EXC_ISE) ? frame->srr0 :
|
|
|
|
frame->cpu.aim.dar) != 0)
|
|
|
|
panic("Fault handling kernel SLB miss");
|
|
|
|
return;
|
|
|
|
#endif
|
2002-05-19 08:16:25 +00:00
|
|
|
case EXC_MCHK:
|
|
|
|
if (handle_onfault(frame))
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default:
|
2004-08-02 02:37:29 +00:00
|
|
|
break;
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
2004-08-02 02:37:29 +00:00
|
|
|
trap_fatal(frame);
|
2001-11-05 00:49:03 +00:00
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
|
|
|
|
if (sig != 0) {
|
|
|
|
if (p->p_sysent->sv_transtrap != NULL)
|
|
|
|
sig = (p->p_sysent->sv_transtrap)(sig, type);
|
1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, most
changes in MD code are trivial, before this change, trapsignal and
sendsig use discrete parameters, now they uses member fields of
ksiginfo_t structure. For sendsig, this change allows us to pass
POSIX realtime signal value to user code.
2. Remove cpu_thread_siginfo, it is no longer needed because we now always
generate ksiginfo_t data and feed it to libpthread.
3. Add p_sigqueue to proc structure to hold shared signals which were
blocked by all threads in the proc.
4. Add td_sigqueue to thread structure to hold all signals delivered to
thread.
5. i386 and amd64 now return POSIX standard si_code, other arches will
be fixed.
6. In this sigqueue implementation, pending signal set is kept as before,
an extra siginfo list holds additional siginfo_t data for signals.
kernel code uses psignal() still behavior as before, it won't be failed
even under memory pressure, only exception is when deleting a signal,
we should call sigqueue_delete to remove signal from sigqueue but
not SIGDELSET. Current there is no kernel code will deliver a signal
with additional data, so kernel should be as stable as before,
a ksiginfo can carry more information, for example, allow signal to
be delivered but throw away siginfo data if memory is not enough.
SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can
not be caught or masked.
The sigqueue() syscall allows user code to queue a signal to target
process, if resource is unavailable, EAGAIN will be returned as
specification said.
Just before thread exits, signal queue memory will be freed by
sigqueue_flush.
Current, all signals are allowed to be queued, not only realtime signals.
Earlier patch reviewed by: jhb, deischen
Tested on: i386, amd64
2005-10-14 12:43:47 +00:00
|
|
|
ksiginfo_init_trap(&ksi);
|
|
|
|
ksi.ksi_signo = sig;
|
|
|
|
ksi.ksi_code = (int) ucode; /* XXX, not POSIX */
|
|
|
|
/* ksi.ksi_addr = ? */
|
|
|
|
ksi.ksi_trapno = type;
|
|
|
|
trapsignal(td, &ksi);
|
2002-05-19 08:16:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-08 08:09:17 +00:00
|
|
|
userret(td, frame);
|
2002-05-19 08:16:25 +00:00
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
trap_fatal(struct trapframe *frame)
|
|
|
|
{
|
|
|
|
|
|
|
|
printtrap(frame->exc, frame, 1, (frame->srr1 & PSL_PR));
|
2004-07-12 22:26:20 +00:00
|
|
|
#ifdef KDB
|
|
|
|
if ((debugger_on_panic || kdb_active) &&
|
|
|
|
kdb_trap(frame->exc, 0, 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) {
|
2010-07-13 05:32:19 +00:00
|
|
|
case EXC_DSE:
|
2002-05-19 08:16:25 +00:00
|
|
|
case EXC_DSI:
|
2010-07-13 05:32:19 +00:00
|
|
|
printf(" virtual address = 0x%" PRIxPTR "\n",
|
|
|
|
frame->cpu.aim.dar);
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2010-07-13 05:32:19 +00:00
|
|
|
case EXC_ISE:
|
2002-05-09 14:22:55 +00:00
|
|
|
case EXC_ISI:
|
2010-07-13 05:32:19 +00:00
|
|
|
printf(" virtual address = 0x%" PRIxPTR "\n", frame->srr0);
|
2002-05-09 14:22:55 +00:00
|
|
|
break;
|
2002-05-19 08:16:25 +00:00
|
|
|
}
|
2010-07-13 05:32:19 +00:00
|
|
|
printf(" srr0 = 0x%" PRIxPTR "\n", frame->srr0);
|
|
|
|
printf(" srr1 = 0x%" PRIxPTR "\n", frame->srr1);
|
|
|
|
printf(" lr = 0x%" PRIxPTR "\n", frame->lr);
|
2002-05-19 08:16:25 +00:00
|
|
|
printf(" curthread = %p\n", curthread);
|
|
|
|
if (curthread != NULL)
|
|
|
|
printf(" pid = %d, comm = %s\n",
|
2007-11-14 06:21:24 +00:00
|
|
|
curthread->td_proc->p_pid, curthread->td_name);
|
2002-05-19 08:16:25 +00:00
|
|
|
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];
|
2004-07-09 11:00:41 +00:00
|
|
|
frame->fixreg[3] = 1;
|
2002-05-19 08:16:25 +00:00
|
|
|
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
|
|
|
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
int
|
|
|
|
cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
|
2002-05-19 08:16:25 +00:00
|
|
|
{
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
struct proc *p;
|
|
|
|
struct trapframe *frame;
|
|
|
|
caddr_t params;
|
2010-07-13 05:32:19 +00:00
|
|
|
size_t argsz;
|
|
|
|
int error, n, i;
|
2002-05-12 13:43:21 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
p = td->td_proc;
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
frame = td->td_frame;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
sa->code = frame->fixreg[0];
|
2002-05-19 08:16:25 +00:00
|
|
|
params = (caddr_t)(frame->fixreg + FIRSTARG);
|
|
|
|
n = NARGREG;
|
2004-07-06 11:46:56 +00:00
|
|
|
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
if (sa->code == SYS_syscall) {
|
2002-05-19 08:16:25 +00:00
|
|
|
/*
|
|
|
|
* code is first argument,
|
|
|
|
* followed by actual args.
|
|
|
|
*/
|
2010-07-13 05:32:19 +00:00
|
|
|
sa->code = *(register_t *) params;
|
2002-09-19 04:38:35 +00:00
|
|
|
params += sizeof(register_t);
|
2002-05-19 08:16:25 +00:00
|
|
|
n -= 1;
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
} else if (sa->code == SYS___syscall) {
|
2002-05-19 08:16:25 +00:00
|
|
|
/*
|
|
|
|
* Like syscall, but code is a quad,
|
|
|
|
* so as to maintain quad alignment
|
|
|
|
* for the rest of the args.
|
|
|
|
*/
|
2011-01-26 20:03:58 +00:00
|
|
|
if (SV_PROC_FLAG(p, SV_ILP32)) {
|
2010-07-13 05:32:19 +00:00
|
|
|
params += sizeof(register_t);
|
|
|
|
sa->code = *(register_t *) params;
|
|
|
|
params += sizeof(register_t);
|
|
|
|
n -= 2;
|
|
|
|
} else {
|
|
|
|
sa->code = *(register_t *) params;
|
|
|
|
params += sizeof(register_t);
|
|
|
|
n -= 1;
|
|
|
|
}
|
2002-05-19 08:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p->p_sysent->sv_mask)
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
sa->code &= p->p_sysent->sv_mask;
|
|
|
|
if (sa->code >= p->p_sysent->sv_size)
|
|
|
|
sa->callp = &p->p_sysent->sv_table[0];
|
|
|
|
else
|
|
|
|
sa->callp = &p->p_sysent->sv_table[sa->code];
|
|
|
|
|
|
|
|
sa->narg = sa->callp->sy_narg;
|
|
|
|
|
2011-01-26 20:03:58 +00:00
|
|
|
if (SV_PROC_FLAG(p, SV_ILP32)) {
|
2010-07-13 05:32:19 +00:00
|
|
|
argsz = sizeof(uint32_t);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
sa->args[i] = ((u_register_t *)(params))[i] &
|
|
|
|
0xffffffff;
|
|
|
|
} else {
|
|
|
|
argsz = sizeof(uint64_t);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
sa->args[i] = ((u_register_t *)(params))[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sa->narg > n)
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
error = copyin(MOREARGS(frame->fixreg[1]), sa->args + n,
|
2010-07-13 05:32:19 +00:00
|
|
|
(sa->narg - n) * argsz);
|
|
|
|
else
|
2002-06-07 05:47:35 +00:00
|
|
|
error = 0;
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2010-07-13 05:32:19 +00:00
|
|
|
#ifdef __powerpc64__
|
2011-01-26 20:03:58 +00:00
|
|
|
if (SV_PROC_FLAG(p, SV_ILP32) && sa->narg > n) {
|
2010-07-13 05:32:19 +00:00
|
|
|
/* Expand the size of arguments copied from the stack */
|
|
|
|
|
|
|
|
for (i = sa->narg; i >= n; i--)
|
|
|
|
sa->args[i] = ((uint32_t *)(&sa->args[n]))[i-n];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-06-07 05:47:35 +00:00
|
|
|
if (error == 0) {
|
|
|
|
td->td_retval[0] = 0;
|
|
|
|
td->td_retval[1] = frame->fixreg[FIRSTARG + 1];
|
|
|
|
}
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2009-11-10 11:43:07 +00:00
|
|
|
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
void
|
|
|
|
syscall(struct trapframe *frame)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
struct syscall_args sa;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
td = PCPU_GET(curthread);
|
|
|
|
td->td_frame = frame;
|
2002-06-07 05:47:35 +00:00
|
|
|
|
2010-11-03 16:21:47 +00:00
|
|
|
#ifdef __powerpc64__
|
2010-11-03 15:15:48 +00:00
|
|
|
/*
|
|
|
|
* Speculatively restore last user SLB segment, which we know is
|
|
|
|
* invalid already, since we are likely to do copyin()/copyout().
|
|
|
|
*/
|
|
|
|
__asm __volatile ("slbmte %0, %1; isync" ::
|
|
|
|
"r"(td->td_pcb->pcb_cpu.aim.usr_vsid), "r"(USER_SLB_SLBE));
|
2010-11-03 16:21:47 +00:00
|
|
|
#endif
|
2010-11-03 15:15:48 +00:00
|
|
|
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 18:32:02 +00:00
|
|
|
error = syscallenter(td, &sa);
|
|
|
|
syscallret(td, error, &sa);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
2010-07-13 05:32:19 +00:00
|
|
|
#ifdef __powerpc64__
|
|
|
|
static int
|
|
|
|
handle_slb_spill(pmap_t pm, vm_offset_t addr)
|
|
|
|
{
|
2010-09-16 03:46:17 +00:00
|
|
|
struct slb *user_entry;
|
2010-09-16 00:22:25 +00:00
|
|
|
uint64_t esid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
esid = (uintptr_t)addr >> ADDR_SR_SHFT;
|
2010-07-13 05:32:19 +00:00
|
|
|
|
|
|
|
if (pm == kernel_pmap) {
|
2010-09-16 03:46:17 +00:00
|
|
|
slb_insert_kernel((esid << SLBE_ESID_SHIFT) | SLBE_VALID,
|
|
|
|
kernel_va_to_slbv(addr));
|
2010-07-13 05:32:19 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PMAP_LOCK(pm);
|
2010-09-16 00:22:25 +00:00
|
|
|
user_entry = user_va_to_slb_entry(pm, addr);
|
|
|
|
|
|
|
|
if (user_entry == NULL) {
|
|
|
|
/* allocate_vsid auto-spills it */
|
2010-09-16 03:46:17 +00:00
|
|
|
(void)allocate_user_vsid(pm, esid, 0);
|
2010-09-16 00:22:25 +00:00
|
|
|
} else {
|
2010-07-13 05:32:19 +00:00
|
|
|
/*
|
|
|
|
* Check that another CPU has not already mapped this.
|
|
|
|
* XXX: Per-thread SLB caches would be better.
|
|
|
|
*/
|
2010-09-16 03:46:17 +00:00
|
|
|
for (i = 0; i < pm->pm_slb_len; i++)
|
|
|
|
if (pm->pm_slb[i] == user_entry)
|
2010-07-13 05:32:19 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-16 03:46:17 +00:00
|
|
|
if (i == pm->pm_slb_len)
|
|
|
|
slb_insert_user(pm, user_entry);
|
2010-07-13 05:32:19 +00:00
|
|
|
}
|
|
|
|
PMAP_UNLOCK(pm);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
2010-07-13 05:32:19 +00:00
|
|
|
register_t 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;
|
2011-01-13 04:37:48 +00:00
|
|
|
ftype = VM_PROT_EXECUTE;
|
|
|
|
if (frame->srr1 & SRR1_ISI_PFAULT)
|
|
|
|
ftype |= VM_PROT_READ;
|
2002-05-19 08:16:25 +00:00
|
|
|
} else {
|
2008-03-02 17:05:57 +00:00
|
|
|
eva = frame->cpu.aim.dar;
|
|
|
|
if (frame->cpu.aim.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 {
|
2010-07-13 05:32:19 +00:00
|
|
|
if ((eva >> ADDR_SR_SHFT) == (USER_ADDR >> ADDR_SR_SHFT)) {
|
2002-05-19 08:16:25 +00:00
|
|
|
if (p->p_vmspace == NULL)
|
|
|
|
return (SIGSEGV);
|
2004-07-06 11:46:56 +00:00
|
|
|
|
2010-07-13 05:32:19 +00:00
|
|
|
map = &p->p_vmspace->vm_map;
|
|
|
|
|
2010-09-16 00:22:25 +00:00
|
|
|
user_sr = td->td_pcb->pcb_cpu.aim.usr_segm;
|
2002-05-19 08:16:25 +00:00
|
|
|
eva &= ADDR_PIDX | ADDR_POFF;
|
|
|
|
eva |= user_sr << ADDR_SR_SHFT;
|
|
|
|
} else {
|
|
|
|
map = kernel_map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va = trunc_page(eva);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
2002-05-19 08:16:25 +00:00
|
|
|
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: */
|
2009-11-27 20:24:11 +00:00
|
|
|
rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
|
2002-05-19 08:16:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (rv == KERN_SUCCESS)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (!user && handle_onfault(frame))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (SIGSEGV);
|
2002-05-09 14:22:55 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2010-07-13 05:32:19 +00:00
|
|
|
panic("badaddr: invalid size (%zd)", size);
|
2001-06-10 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2008-03-02 17:05:57 +00:00
|
|
|
indicator = EXC_ALI_OPCODE_INDICATOR(frame->cpu.aim.dsisr);
|
2001-06-10 02:39:37 +00:00
|
|
|
|
|
|
|
switch (indicator) {
|
|
|
|
case EXC_ALI_LFD:
|
|
|
|
case EXC_ALI_STFD:
|
2008-03-02 17:05:57 +00:00
|
|
|
reg = EXC_ALI_RST(frame->cpu.aim.dsisr);
|
2002-05-19 04:04:12 +00:00
|
|
|
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) {
|
2008-03-02 17:05:57 +00:00
|
|
|
if (copyin((void *)frame->cpu.aim.dar, fpr,
|
2002-05-19 04:04:12 +00:00
|
|
|
sizeof(double)) != 0)
|
|
|
|
return -1;
|
|
|
|
enable_fpu(td);
|
|
|
|
} else {
|
2008-03-02 17:05:57 +00:00
|
|
|
if (copyout(fpr, (void *)frame->cpu.aim.dar,
|
2002-05-19 04:04:12 +00:00
|
|
|
sizeof(double)) != 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2001-06-10 02:39:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-22 14:17:23 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ppc_instr_emulate(struct trapframe *frame)
|
|
|
|
{
|
|
|
|
uint32_t instr;
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
instr = fuword32((void *)frame->srr0);
|
|
|
|
|
|
|
|
if ((instr & 0xfc1fffff) == 0x7c1f42a6) { /* mfpvr */
|
|
|
|
reg = (instr & ~0xfc1fffff) >> 21;
|
|
|
|
frame->fixreg[reg] = mfpvr();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|