Split you the syscall handling to a separate file.
This commit is contained in:
parent
0b060244ab
commit
293b5c2221
196
sys/arm/arm/syscall.c
Normal file
196
sys/arm/arm/syscall.c
Normal file
@ -0,0 +1,196 @@
|
||||
/* $NetBSD: fault.c,v 1.45 2003/11/20 14:44:36 scw Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright 2004 Olivier Houchard
|
||||
* Copyright 2003 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Steve C. Woodford for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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 for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
||||
* 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.
|
||||
*/
|
||||
/*-
|
||||
* Copyright (c) 1994-1997 Mark Brinicombe.
|
||||
* Copyright (c) 1994 Brini.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software written for Brini by Mark Brinicombe
|
||||
*
|
||||
* 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 Brini.
|
||||
* 4. The name of the company nor the name of the author may be used to
|
||||
* endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI OR CONTRIBUTORS 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.
|
||||
*
|
||||
* RiscBSD kernel project
|
||||
*
|
||||
* fault.c
|
||||
*
|
||||
* Fault handlers
|
||||
*
|
||||
* Created : 28/11/94
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/sysent.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/pioctl.h>
|
||||
|
||||
#include <machine/frame.h>
|
||||
|
||||
void swi_handler(struct trapframe *);
|
||||
|
||||
static __inline void
|
||||
call_trapsignal(struct thread *td, int sig, u_long code)
|
||||
{
|
||||
ksiginfo_t ksi;
|
||||
|
||||
ksiginfo_init_trap(&ksi);
|
||||
ksi.ksi_signo = sig;
|
||||
ksi.ksi_code = (int)code;
|
||||
trapsignal(td, &ksi);
|
||||
}
|
||||
|
||||
int
|
||||
cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
|
||||
{
|
||||
struct proc *p;
|
||||
register_t *ap;
|
||||
int error;
|
||||
|
||||
sa->code = td->td_frame->tf_r7;
|
||||
ap = &td->td_frame->tf_r0;
|
||||
if (sa->code == SYS_syscall) {
|
||||
sa->code = *ap++;
|
||||
sa->nap--;
|
||||
} else if (sa->code == SYS___syscall) {
|
||||
sa->code = ap[_QUAD_LOWWORD];
|
||||
sa->nap -= 2;
|
||||
ap += 2;
|
||||
}
|
||||
p = td->td_proc;
|
||||
if (p->p_sysent->sv_mask)
|
||||
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;
|
||||
error = 0;
|
||||
memcpy(sa->args, ap, sa->nap * sizeof(register_t));
|
||||
if (sa->narg > sa->nap) {
|
||||
error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
|
||||
sa->nap, (sa->narg - sa->nap) * sizeof(register_t));
|
||||
}
|
||||
if (error == 0) {
|
||||
td->td_retval[0] = 0;
|
||||
td->td_retval[1] = 0;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
#include "../../kern/subr_syscall.c"
|
||||
|
||||
static void
|
||||
syscall(struct thread *td, struct trapframe *frame)
|
||||
{
|
||||
struct syscall_args sa;
|
||||
int error;
|
||||
|
||||
sa.nap = 4;
|
||||
|
||||
error = syscallenter(td, &sa);
|
||||
KASSERT(error != 0 || td->td_ar == NULL,
|
||||
("returning from syscall with td_ar set!"));
|
||||
syscallret(td, error, &sa);
|
||||
}
|
||||
|
||||
void
|
||||
swi_handler(struct trapframe *frame)
|
||||
{
|
||||
struct thread *td = curthread;
|
||||
|
||||
td->td_frame = frame;
|
||||
|
||||
td->td_pticks = 0;
|
||||
/*
|
||||
* Make sure the program counter is correctly aligned so we
|
||||
* don't take an alignment fault trying to read the opcode.
|
||||
* XXX: Fix for Thumb mode
|
||||
*/
|
||||
if (__predict_false(((frame->tf_pc - INSN_SIZE) & 3) != 0)) {
|
||||
call_trapsignal(td, SIGILL, 0);
|
||||
userret(td, frame);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Enable interrupts if they were enabled before the exception.
|
||||
* Since all syscalls *should* come from user mode it will always
|
||||
* be safe to enable them, but check anyway.
|
||||
*/
|
||||
if (td->td_md.md_spinlock_count == 0) {
|
||||
if (__predict_true(frame->tf_spsr & PSR_I) == 0)
|
||||
enable_interrupts(PSR_I);
|
||||
if (__predict_true(frame->tf_spsr & PSR_F) == 0)
|
||||
enable_interrupts(PSR_F);
|
||||
}
|
||||
|
||||
syscall(td, frame);
|
||||
}
|
@ -79,28 +79,15 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/sysent.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/ktr.h>
|
||||
#ifdef KTRACE
|
||||
#include <sys/uio.h>
|
||||
#include <sys/ktrace.h>
|
||||
#endif
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/pioctl.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
@ -108,28 +95,16 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/vm_map.h>
|
||||
#include <vm/vm_extern.h>
|
||||
|
||||
#include <machine/armreg.h>
|
||||
#include <machine/cpuconf.h>
|
||||
#include <machine/vmparam.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/intr.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/machdep.h>
|
||||
#include <machine/pcb.h>
|
||||
#include <machine/proc.h>
|
||||
#include <machine/swi.h>
|
||||
|
||||
#include <security/audit/audit.h>
|
||||
#include <machine/vmparam.h>
|
||||
|
||||
#ifdef KDB
|
||||
#include <sys/kdb.h>
|
||||
#endif
|
||||
|
||||
|
||||
void swi_handler(struct trapframe *);
|
||||
|
||||
#include <machine/disassem.h>
|
||||
#include <machine/machdep.h>
|
||||
|
||||
extern char fusubailout[];
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -775,106 +750,4 @@ badaddr_read(void *addr, size_t size, void *rptr)
|
||||
|
||||
/* Return EFAULT if the address was invalid, else zero */
|
||||
return (rv);
|
||||
}
|
||||
|
||||
int
|
||||
cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
|
||||
{
|
||||
struct proc *p;
|
||||
register_t *ap;
|
||||
int error;
|
||||
|
||||
#ifdef __ARM_EABI__
|
||||
sa->code = td->td_frame->tf_r7;
|
||||
#else
|
||||
sa->code = sa->insn & 0x000fffff;
|
||||
#endif
|
||||
ap = &td->td_frame->tf_r0;
|
||||
if (sa->code == SYS_syscall) {
|
||||
sa->code = *ap++;
|
||||
sa->nap--;
|
||||
} else if (sa->code == SYS___syscall) {
|
||||
sa->code = ap[_QUAD_LOWWORD];
|
||||
sa->nap -= 2;
|
||||
ap += 2;
|
||||
}
|
||||
p = td->td_proc;
|
||||
if (p->p_sysent->sv_mask)
|
||||
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;
|
||||
error = 0;
|
||||
memcpy(sa->args, ap, sa->nap * sizeof(register_t));
|
||||
if (sa->narg > sa->nap) {
|
||||
error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
|
||||
sa->nap, (sa->narg - sa->nap) * sizeof(register_t));
|
||||
}
|
||||
if (error == 0) {
|
||||
td->td_retval[0] = 0;
|
||||
td->td_retval[1] = 0;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
#include "../../kern/subr_syscall.c"
|
||||
|
||||
static void
|
||||
syscall(struct thread *td, struct trapframe *frame)
|
||||
{
|
||||
struct syscall_args sa;
|
||||
int error;
|
||||
|
||||
#ifndef __ARM_EABI__
|
||||
sa.insn = *(uint32_t *)(frame->tf_pc - INSN_SIZE);
|
||||
switch (sa.insn & SWI_OS_MASK) {
|
||||
case 0: /* XXX: we need our own one. */
|
||||
break;
|
||||
default:
|
||||
call_trapsignal(td, SIGILL, 0);
|
||||
userret(td, frame);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
sa.nap = 4;
|
||||
|
||||
error = syscallenter(td, &sa);
|
||||
KASSERT(error != 0 || td->td_ar == NULL,
|
||||
("returning from syscall with td_ar set!"));
|
||||
syscallret(td, error, &sa);
|
||||
}
|
||||
|
||||
void
|
||||
swi_handler(struct trapframe *frame)
|
||||
{
|
||||
struct thread *td = curthread;
|
||||
|
||||
td->td_frame = frame;
|
||||
|
||||
td->td_pticks = 0;
|
||||
/*
|
||||
* Make sure the program counter is correctly aligned so we
|
||||
* don't take an alignment fault trying to read the opcode.
|
||||
*/
|
||||
if (__predict_false(((frame->tf_pc - INSN_SIZE) & 3) != 0)) {
|
||||
call_trapsignal(td, SIGILL, 0);
|
||||
userret(td, frame);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Enable interrupts if they were enabled before the exception.
|
||||
* Since all syscalls *should* come from user mode it will always
|
||||
* be safe to enable them, but check anyway.
|
||||
*/
|
||||
if (td->td_md.md_spinlock_count == 0) {
|
||||
if (__predict_true(frame->tf_spsr & PSR_I) == 0)
|
||||
enable_interrupts(PSR_I);
|
||||
if (__predict_true(frame->tf_spsr & PSR_F) == 0)
|
||||
enable_interrupts(PSR_F);
|
||||
}
|
||||
|
||||
syscall(td, frame);
|
||||
}
|
||||
|
||||
}
|
@ -49,6 +49,7 @@ arm/arm/stdatomic.c standard \
|
||||
arm/arm/support.S standard
|
||||
arm/arm/swtch.S standard
|
||||
arm/arm/sys_machdep.c standard
|
||||
arm/arm/syscall.c standard
|
||||
arm/arm/trap.c standard
|
||||
arm/arm/uio_machdep.c standard
|
||||
arm/arm/undefined.c standard
|
||||
|
Loading…
x
Reference in New Issue
Block a user