Home | History | Annotate | Line # | Download | only in alpha
compat_13_machdep.c revision 1.12
      1  1.12   martin /* $NetBSD: compat_13_machdep.c,v 1.12 2005/09/14 17:52:24 martin Exp $ */
      2   1.1  thorpej 
      3   1.1  thorpej /*
      4   1.1  thorpej  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
      5   1.1  thorpej  * All rights reserved.
      6   1.1  thorpej  *
      7   1.1  thorpej  * Author: Chris G. Demetriou
      8   1.1  thorpej  *
      9   1.1  thorpej  * Permission to use, copy, modify and distribute this software and
     10   1.1  thorpej  * its documentation is hereby granted, provided that both the copyright
     11   1.1  thorpej  * notice and this permission notice appear in all copies of the
     12   1.1  thorpej  * software, derivative works or modified versions, and any portions
     13   1.1  thorpej  * thereof, and that both notices appear in supporting documentation.
     14   1.1  thorpej  *
     15   1.1  thorpej  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16   1.1  thorpej  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17   1.1  thorpej  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18   1.1  thorpej  *
     19   1.1  thorpej  * Carnegie Mellon requests users of this software to return to
     20   1.1  thorpej  *
     21   1.1  thorpej  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22   1.1  thorpej  *  School of Computer Science
     23   1.1  thorpej  *  Carnegie Mellon University
     24   1.1  thorpej  *  Pittsburgh PA 15213-3890
     25   1.1  thorpej  *
     26   1.1  thorpej  * any improvements or extensions that they make and grant Carnegie the
     27   1.1  thorpej  * rights to redistribute these changes.
     28   1.1  thorpej  */
     29   1.1  thorpej 
     30   1.1  thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31   1.1  thorpej 
     32  1.12   martin __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.12 2005/09/14 17:52:24 martin Exp $");
     33   1.1  thorpej 
     34   1.1  thorpej #include <sys/param.h>
     35   1.1  thorpej #include <sys/systm.h>
     36   1.1  thorpej #include <sys/signalvar.h>
     37   1.1  thorpej #include <sys/kernel.h>
     38   1.1  thorpej #include <sys/proc.h>
     39   1.1  thorpej #include <sys/user.h>
     40   1.1  thorpej #include <sys/mount.h>
     41  1.11  thorpej #include <sys/sa.h>
     42   1.1  thorpej #include <sys/syscallargs.h>
     43   1.1  thorpej 
     44  1.12   martin #include <compat/sys/signal.h>
     45  1.12   martin #include <compat/sys/signalvar.h>
     46  1.12   martin 
     47   1.1  thorpej #include <machine/cpu.h>
     48   1.1  thorpej #include <machine/reg.h>
     49   1.3     ross #include <machine/alpha.h>
     50   1.4  thorpej 
     51   1.1  thorpej /*
     52   1.1  thorpej  * System call to cleanup state after a signal
     53   1.1  thorpej  * has been taken.  Reset signal mask and
     54   1.1  thorpej  * stack state from context left by sendsig (above).
     55   1.1  thorpej  * Return to previous pc and psl as specified by
     56   1.1  thorpej  * context left by sendsig. Check carefully to
     57   1.1  thorpej  * make sure that the user has not modified the
     58   1.6   simonb  * psl to gain improper privileges or to cause
     59   1.1  thorpej  * a machine fault.
     60   1.1  thorpej  */
     61   1.1  thorpej /* ARGSUSED */
     62   1.1  thorpej int
     63  1.11  thorpej compat_13_sys_sigreturn(l, v, retval)
     64  1.11  thorpej 	struct lwp *l;
     65   1.1  thorpej 	void *v;
     66   1.1  thorpej 	register_t *retval;
     67   1.1  thorpej {
     68   1.1  thorpej 	struct compat_13_sys_sigreturn_args /* {
     69   1.1  thorpej 		syscallarg(struct sigcontext13 *) sigcntxp;
     70   1.1  thorpej 	} */ *uap = v;
     71   1.1  thorpej 	struct sigcontext13 *scp, ksc;
     72   1.1  thorpej 	sigset13_t mask13;
     73   1.1  thorpej 	sigset_t mask;
     74   1.1  thorpej 
     75   1.1  thorpej 	/*
     76   1.1  thorpej 	 * The trampoline code hands us the context.
     77   1.1  thorpej 	 * It is unsafe to keep track of it ourselves, in the event that a
     78   1.1  thorpej 	 * program jumps out of a signal handler.
     79   1.1  thorpej 	 */
     80   1.1  thorpej 	scp = SCARG(uap, sigcntxp);
     81   1.1  thorpej 	if (ALIGN(scp) != (u_int64_t)scp)
     82   1.1  thorpej 		return (EINVAL);
     83   1.1  thorpej 
     84   1.1  thorpej 	if (copyin((caddr_t)scp, &ksc, sizeof(ksc)) != 0)
     85   1.1  thorpej 		return (EFAULT);
     86   1.1  thorpej 
     87   1.1  thorpej 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
     88   1.1  thorpej 		return (EINVAL);
     89   1.1  thorpej 
     90   1.1  thorpej 	/* Restore register context. */
     91  1.11  thorpej 	l->l_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
     92  1.11  thorpej 	l->l_md.md_tf->tf_regs[FRAME_PS] =
     93   1.1  thorpej 	    (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
     94   1.1  thorpej 
     95  1.11  thorpej 	regtoframe((struct reg *)ksc.sc_regs, l->l_md.md_tf);
     96   1.1  thorpej 	alpha_pal_wrusp(ksc.sc_regs[R_SP]);
     97   1.1  thorpej 
     98   1.1  thorpej 	/* XXX ksc.sc_ownedfp ? */
     99  1.11  thorpej 	if (l->l_addr->u_pcb.pcb_fpcpu != NULL)
    100  1.11  thorpej 		fpusave_proc(l, 0);
    101  1.11  thorpej 	memcpy(&l->l_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
    102   1.1  thorpej 	    sizeof(struct fpreg));
    103   1.1  thorpej 	/* XXX ksc.sc_fp_control ? */
    104   1.1  thorpej 
    105   1.1  thorpej 	/* Restore signal stack. */
    106   1.1  thorpej 	if (ksc.sc_onstack & SS_ONSTACK)
    107  1.11  thorpej 		l->l_proc->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
    108   1.1  thorpej 	else
    109  1.11  thorpej 		l->l_proc->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
    110   1.1  thorpej 
    111   1.1  thorpej 	/*
    112   1.1  thorpej 	 * Restore signal mask.  Note the mask is a "long" in the stack
    113   1.1  thorpej 	 * frame.
    114   1.1  thorpej 	 */
    115   1.1  thorpej 	mask13 = ksc.sc_mask;
    116   1.1  thorpej 	native_sigset13_to_sigset(&mask13, &mask);
    117  1.11  thorpej 	(void) sigprocmask1(l->l_proc, SIG_SETMASK, &mask, 0);
    118   1.1  thorpej 
    119   1.1  thorpej 	return (EJUSTRETURN);
    120   1.1  thorpej }
    121