diff options
-rw-r--r-- | sys/arch/sparc64/include/netbsd_machdep.h | 22 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/genassym.cf | 10 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/locore.s | 6 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/netbsd_machdep.c | 302 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/sigcode_netbsd.s | 150 |
5 files changed, 489 insertions, 1 deletions
diff --git a/sys/arch/sparc64/include/netbsd_machdep.h b/sys/arch/sparc64/include/netbsd_machdep.h new file mode 100644 index 00000000000..1081611f25b --- /dev/null +++ b/sys/arch/sparc64/include/netbsd_machdep.h @@ -0,0 +1,22 @@ +/* $OpenBSD: netbsd_machdep.h,v 1.1 2001/09/06 10:45:41 art Exp $ */ + +#ifndef _NETBSD_MACHDEP_H +#define _NETBSD_MACHDEP_H + +struct netbsd_sigcontext { + int sc_onstack; + int __sc_mask13; + long sc_sp; + long sc_pc; + long sc_npc; + long sc_tstate; + long sc_g1; + long sc_o0; + netbsd_sigset_t sc_mask; +}; + +#ifdef _KERNEL +void netbsd_sendsig __P((sig_t, int, int, u_long, int, union sigval)); +#endif + +#endif /* _NETBSD_MACHDEP_H */ diff --git a/sys/arch/sparc64/sparc64/genassym.cf b/sys/arch/sparc64/sparc64/genassym.cf index 1f7622f285c..8be71d9a3fc 100644 --- a/sys/arch/sparc64/sparc64/genassym.cf +++ b/sys/arch/sparc64/sparc64/genassym.cf @@ -104,6 +104,10 @@ include <machine/reg.h> #include <sparc64/sparc64/cpuvar.h> +ifdef COMPAT_NETBSD +include <compat/netbsd/netbsd_syscall.h> +endif + ifdef notyet include <sparc64/dev/zsreg.h> include <sparc64/dev/zsvar.h> @@ -274,3 +278,9 @@ define DBR_OUT offsetof(struct db_regs, dbr_out) define DBR_LOCAL offsetof(struct db_regs, dbr_local) define DBR_IN offsetof(struct db_regs, dbr_in) endif + +ifdef COMPAT_NETBSD +define NETBSD_SYS___sigreturn14 NETBSD_SYS___sigreturn14 +define NETBSD_SYS_exit NETBSD_SYS_exit +endif + diff --git a/sys/arch/sparc64/sparc64/locore.s b/sys/arch/sparc64/sparc64/locore.s index 8aa6d83baa3..dabcdfabd05 100644 --- a/sys/arch/sparc64/sparc64/locore.s +++ b/sys/arch/sparc64/sparc64/locore.s @@ -1,4 +1,4 @@ -/* $OpenBSD: locore.s,v 1.6 2001/09/04 16:51:18 jason Exp $ */ +/* $OpenBSD: locore.s,v 1.7 2001/09/06 10:45:41 art Exp $ */ /* $NetBSD: locore.s,v 1.137 2001/08/13 06:10:10 jdolecek Exp $ */ /* @@ -6378,6 +6378,10 @@ _C_LABEL(sigcode): _C_LABEL(esigcode): #endif +#ifdef COMPAT_NETBSD +#include "sigcode_netbsd.s" +#endif + #if !defined(_LP64) #define SIGCODE_NAME sigcode diff --git a/sys/arch/sparc64/sparc64/netbsd_machdep.c b/sys/arch/sparc64/sparc64/netbsd_machdep.c new file mode 100644 index 00000000000..5dcf8adfa42 --- /dev/null +++ b/sys/arch/sparc64/sparc64/netbsd_machdep.c @@ -0,0 +1,302 @@ +/* $OpenBSD: netbsd_machdep.c,v 1.1 2001/09/06 10:45:41 art Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * 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 the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 THE FOUNDATION 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. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS 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. + * + * @(#)machdep.c 8.6 (Berkeley) 1/14/94 + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/signalvar.h> +#include <sys/kernel.h> +#include <sys/exec.h> +#include <sys/proc.h> +#include <sys/buf.h> +#include <sys/mount.h> +#include <sys/syscallargs.h> +#include <sys/user.h> +#include <machine/cpu.h> + +#include <vm/vm.h> + +#include <compat/netbsd/netbsd_types.h> +#include <compat/netbsd/netbsd_signal.h> +#include <compat/netbsd/netbsd_syscallargs.h> + +#include <machine/netbsd_machdep.h> +#include <machine/signal.h> +#include <machine/frame.h> +#include <machine/cpu.h> +#include <machine/pmap.h> +#include <machine/openfirm.h> +#include <machine/sparc64.h> + +#include <sparc64/sparc64/cache.h> + + +#ifdef DEBUG +extern int sigdebug; +extern int sigpid; +#define SDB_FOLLOW 0x01 +#define SDB_KSTACK 0x02 +#endif + +struct netbsd_sigframe { + int sf_signo; /* signal number */ + int sf_code; /* code */ +#ifndef __arch64__ + struct sigcontext *sf_scp; /* SunOS user addr of sigcontext */ + int sf_addr; /* SunOS compat, always 0 for now */ +#endif + struct netbsd_sigcontext sf_sc; /* actual sigcontext */ +}; + +#ifdef __arch64__ +#define STACK_OFFSET BIAS +#define CPOUTREG(l,v) copyout(&(v), (l), sizeof(v)) +#undef CCFSZ +#define CCFSZ CC64FSZ +#else +#define STACK_OFFSET 0 +#define CPOUTREG(l,v) copyout(&(v), (l), sizeof(v)) +#endif + +/* + * Send an interrupt to process. + */ +void +netbsd_sendsig(catcher, sig, mask, code, type, val) + sig_t catcher; + int sig, mask; + u_long code; + int type; + union sigval val; +{ + struct proc *p = curproc; + struct sigacts *psp = p->p_sigacts; + struct trapframe64 *tf; + vaddr_t addr; + struct rwindow *oldsp, *newsp; + struct netbsd_sigframe sf, *fp; + int onstack; + extern char netbsd_sigcode[], netbsd_esigcode[]; +#define szsigcode (netbsd_esigcode - netbsd_sigcode) + + tf = p->p_md.md_tf; + oldsp = (struct rwindow *)(u_long)(tf->tf_out[6] + STACK_OFFSET); + + /* + * Compute new user stack addresses, subtract off + * one signal frame, and align. + */ + onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK; + + if ((psp->ps_flags & SAS_ALTSTACK) && !onstack && + (psp->ps_sigonstack & sigmask(sig))) { + fp = (struct netbsd_sigframe *)((caddr_t)psp->ps_sigstk.ss_sp + + psp->ps_sigstk.ss_size); + psp->ps_sigstk.ss_flags = SS_ONSTACK; + } else + fp = (struct netbsd_sigframe *)oldsp; + /* Allocate an aligned sigframe */ + fp = (struct netbsd_sigframe *)((long)(fp - 1) & ~0x0f); + + /* + * Now set up the signal frame. We build it in kernel space + * and then copy it out. We probably ought to just build it + * directly in user space.... + */ + sf.sf_signo = sig; + sf.sf_code = 0; /* XXX */ +#ifndef __arch64__ + sf.sf_scp = 0; + sf.sf_addr = 0; /* XXX */ +#endif + + /* + * Build the signal context to be used by sigreturn. + */ + sf.sf_sc.sc_onstack = onstack; + sf.sf_sc.sc_mask.__bits[0] = mask; + /* Save register context. */ + sf.sf_sc.sc_sp = (long)tf->tf_out[6]; + sf.sf_sc.sc_pc = tf->tf_pc; + sf.sf_sc.sc_npc = tf->tf_npc; +#ifdef __arch64__ + sf.sf_sc.sc_tstate = tf->tf_tstate; /* XXX */ +#else + sf.sf_sc.sc_psr = TSTATECCR_TO_PSR(tf->tf_tstate); /* XXX */ +#endif + sf.sf_sc.sc_g1 = tf->tf_global[1]; + sf.sf_sc.sc_o0 = tf->tf_out[0]; + + /* + * Put the stack in a consistent state before we whack away + * at it. Note that write_user_windows may just dump the + * registers into the pcb; we need them in the process's memory. + * We also need to make sure that when we start the signal handler, + * its %i6 (%fp), which is loaded from the newly allocated stack area, + * joins seamlessly with the frame it was in when the signal occurred, + * so that the debugger and _longjmp code can back up through it. + */ + newsp = (struct rwindow *)((vaddr_t)fp - sizeof(struct rwindow)); + write_user_windows(); + /* XXX do not copyout siginfo if not needed */ + if (rwindow_save(p) || copyout((caddr_t)&sf, (caddr_t)fp, sizeof sf) || + CPOUTREG(&(((struct rwindow *)newsp)->rw_in[6]), tf->tf_out[6])) { + /* + * Process has trashed its stack; give it an illegal + * instruction to halt it in its tracks. + */ + sigexit(p, SIGILL); + /* NOTREACHED */ + } + + /* + * Arrange to continue execution at the code copied out in exec(). + * It needs the function to call in %g1, and a new stack pointer. + */ + addr = (vaddr_t)PS_STRINGS - szsigcode; + tf->tf_global[1] = (vaddr_t)catcher; + tf->tf_pc = addr; + tf->tf_npc = addr + 4; + tf->tf_out[6] = (vaddr_t)newsp - STACK_OFFSET; +} + +/* ARGSUSED */ +int +netbsd_sys___sigreturn14(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct netbsd_sys___sigreturn14_args /* { + syscallarg(struct netbsd_sigcontext *) sigcntxp; + } */ *uap = v; + struct netbsd_sigcontext *scp, nbsc; + struct trapframe64 *tf; + + write_user_windows(); + + scp = SCARG(uap, sigcntxp); +#ifdef DEBUG + if (sigdebug & SDB_FOLLOW) + printf("netbsd__sys___sigreturn: pid %d, scp %p\n", + p->p_pid, scp); +#endif + if (ALIGN(scp) != (u_int64_t)scp) + return (EINVAL); + + if (copyin((caddr_t)scp, (caddr_t)&nbsc, sizeof (nbsc))) + return (EFAULT); + + tf = p->p_md.md_tf; + /* + * Only the icc bits in the psr are used, so it need not be + * verified. pc and npc must be multiples of 4. This is all + * that is required; if it holds, just do it. + */ + if (((nbsc.sc_pc | nbsc.sc_npc) & 3) != 0 || + (nbsc.sc_pc == 0) || (nbsc.sc_npc == 0)) + return (EINVAL); + /* take only psr ICC field */ +#ifdef __arch64__ + tf->tf_tstate = (u_int64_t)(tf->tf_tstate & ~TSTATE_CCR) | + (scp->sc_tstate & TSTATE_CCR); +#else + tf->tf_tstate = (u_int64_t)(tf->tf_tstate & ~TSTATE_CCR) | + PSRCC_TO_TSTATE(scp->sc_psr); +#endif + tf->tf_pc = (u_int64_t)scp->sc_pc; + tf->tf_npc = (u_int64_t)scp->sc_npc; + tf->tf_global[1] = (u_int64_t)scp->sc_g1; + tf->tf_out[0] = (u_int64_t)scp->sc_o0; + tf->tf_out[6] = (u_int64_t)scp->sc_sp; + + /* Restore signal stack. */ + if (nbsc.sc_onstack & SS_ONSTACK) + p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; + else + p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; + + /* Restore signal mask. */ + p->p_sigmask = scp->sc_mask.__bits[0] & ~sigcantmask; + + return (EJUSTRETURN); +} diff --git a/sys/arch/sparc64/sparc64/sigcode_netbsd.s b/sys/arch/sparc64/sparc64/sigcode_netbsd.s new file mode 100644 index 00000000000..617b3630a04 --- /dev/null +++ b/sys/arch/sparc64/sparc64/sigcode_netbsd.s @@ -0,0 +1,150 @@ +/* $OpenBSD: sigcode_netbsd.s,v 1.1 2001/09/06 10:45:41 art Exp $ */ +/* + * Copyright (c) 1996-2001 Eduardo Horvath + * Copyright (c) 1996 Paul Kranenburg + * Copyright (c) 1996 + * The President and Fellows of Harvard College. + * All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. + * All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * This product includes software developed by Harvard University. + * + * 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 the University of + * California, Berkeley and its contributors. + * This product includes software developed by Harvard University. + * This product includes software developed by Paul Kranenburg. + * 4. Neither the name of the University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS 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. + * + * @(#)locore.s 8.4 (Berkeley) 12/10/93 + */ + + .globl _C_LABEL(netbsd_sigcode) + .globl _C_LABEL(netbsd_esigcode) +_C_LABEL(netbsd_sigcode): + /* + * XXX the `save' and `restore' below are unnecessary: should + * replace with simple arithmetic on %sp + * + * Make room on the stack for 64 %f registers + %fsr. This comes + * out to 64*4+8 or 264 bytes, but this must be aligned to a multiple + * of 64, or 320 bytes. + */ + save %sp, -CC64FSZ - 320, %sp + mov %g2, %l2 ! save globals in %l registers + mov %g3, %l3 + mov %g4, %l4 + mov %g5, %l5 + mov %g6, %l6 + mov %g7, %l7 + /* + * Saving the fpu registers is expensive, so do it iff it is + * enabled and dirty. + */ + rd %fprs, %l0 + btst FPRS_DL|FPRS_DU, %l0 ! All clean? + bz,pt %icc, 2f + btst FPRS_DL, %l0 ! test dl + bz,pt %icc, 1f + btst FPRS_DU, %l0 ! test du + + ! fpu is enabled, oh well + stx %fsr, [%sp + CC64FSZ + BIAS + 0] + add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 ! Generate a pointer so we can + andn %l0, BLOCK_ALIGN, %l0 ! do a block store + stda %f0, [%l0] ASI_BLK_P + inc BLOCK_SIZE, %l0 + stda %f16, [%l0] ASI_BLK_P +1: + bz,pt %icc, 2f + add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 ! Generate a pointer so we can + andn %l0, BLOCK_ALIGN, %l0 ! do a block store + add %l0, 2*BLOCK_SIZE, %l0 ! and skip what we already stored + stda %f32, [%l0] ASI_BLK_P + inc BLOCK_SIZE, %l0 + stda %f48, [%l0] ASI_BLK_P +2: + membar #Sync + rd %y, %l1 ! in any case, save %y + lduw [%fp + BIAS + 128], %o0 ! sig + lduw [%fp + BIAS + 128 + 4], %o1 ! code + call %g1 ! (*sa->sa_handler)(sig,code,scp) + add %fp, BIAS + 128 + 8, %o2 ! scp + + /* + * Now that the handler has returned, re-establish all the state + * we just saved above, then do a sigreturn. + */ + btst 3, %l0 ! All clean? + bz,pt %icc, 2f + btst 1, %l0 ! test dl + bz,pt %icc, 1f + btst 2, %l0 ! test du + + ldx [%sp + CC64FSZ + BIAS + 0], %fsr + add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 ! Generate a pointer so we can + andn %l0, BLOCK_ALIGN, %l0 ! do a block load + ldda [%l0] ASI_BLK_P, %f0 + inc BLOCK_SIZE, %l0 + ldda [%l0] ASI_BLK_P, %f16 +1: + bz,pt %icc, 2f + wr %l1, %g0, %y ! in any case, restore %y + add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 ! Generate a pointer so we can + andn %l0, BLOCK_ALIGN, %l0 ! do a block load + inc 2*BLOCK_SIZE, %l0 ! and skip what we already loaded + ldda [%l0] ASI_BLK_P, %f32 + inc BLOCK_SIZE, %l0 + ldda [%l0] ASI_BLK_P, %f48 +2: + mov %l2, %g2 + mov %l3, %g3 + mov %l4, %g4 + mov %l5, %g5 + mov %l6, %g6 + mov %l7, %g7 + membar #Sync + + restore %g0, NETBSD_SYS___sigreturn14, %g1 ! get registers back & set syscall # + add %sp, BIAS + 128 + 8, %o0! compute scp +! andn %o0, 0x0f, %o0 + t ST_SYSCALL ! sigreturn(scp) + ! sigreturn does not return unless it fails + mov NETBSD_SYS_exit, %g1 ! exit(errno) + t ST_SYSCALL +_C_LABEL(netbsd_esigcode): |