Home | History | Annotate | Line # | Download | only in alpha
compat_13_machdep.c revision 1.6.2.1
      1  1.6.2.1   bouyer /* $NetBSD: compat_13_machdep.c,v 1.6.2.1 2000/11/20 19:56:20 bouyer 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.6.2.1   bouyer __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.6.2.1 2000/11/20 19:56:20 bouyer 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.1  thorpej #include <sys/syscallargs.h>
     42      1.1  thorpej 
     43      1.1  thorpej #include <machine/cpu.h>
     44      1.1  thorpej #include <machine/reg.h>
     45      1.3     ross #include <machine/alpha.h>
     46      1.4  thorpej 
     47      1.1  thorpej /*
     48      1.1  thorpej  * System call to cleanup state after a signal
     49      1.1  thorpej  * has been taken.  Reset signal mask and
     50      1.1  thorpej  * stack state from context left by sendsig (above).
     51      1.1  thorpej  * Return to previous pc and psl as specified by
     52      1.1  thorpej  * context left by sendsig. Check carefully to
     53      1.1  thorpej  * make sure that the user has not modified the
     54      1.6   simonb  * psl to gain improper privileges or to cause
     55      1.1  thorpej  * a machine fault.
     56      1.1  thorpej  */
     57      1.1  thorpej /* ARGSUSED */
     58      1.1  thorpej int
     59      1.1  thorpej compat_13_sys_sigreturn(p, v, retval)
     60      1.1  thorpej 	struct proc *p;
     61      1.1  thorpej 	void *v;
     62      1.1  thorpej 	register_t *retval;
     63      1.1  thorpej {
     64      1.1  thorpej 	struct compat_13_sys_sigreturn_args /* {
     65      1.1  thorpej 		syscallarg(struct sigcontext13 *) sigcntxp;
     66      1.1  thorpej 	} */ *uap = v;
     67      1.1  thorpej 	struct sigcontext13 *scp, ksc;
     68      1.1  thorpej 	sigset13_t mask13;
     69      1.1  thorpej 	sigset_t mask;
     70      1.1  thorpej 
     71      1.1  thorpej 	/*
     72      1.1  thorpej 	 * The trampoline code hands us the context.
     73      1.1  thorpej 	 * It is unsafe to keep track of it ourselves, in the event that a
     74      1.1  thorpej 	 * program jumps out of a signal handler.
     75      1.1  thorpej 	 */
     76      1.1  thorpej 	scp = SCARG(uap, sigcntxp);
     77      1.1  thorpej 	if (ALIGN(scp) != (u_int64_t)scp)
     78      1.1  thorpej 		return (EINVAL);
     79      1.1  thorpej 
     80      1.1  thorpej 	if (copyin((caddr_t)scp, &ksc, sizeof(ksc)) != 0)
     81      1.1  thorpej 		return (EFAULT);
     82      1.1  thorpej 
     83      1.1  thorpej 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
     84      1.1  thorpej 		return (EINVAL);
     85      1.1  thorpej 
     86      1.1  thorpej 	/* Restore register context. */
     87      1.1  thorpej 	p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
     88      1.1  thorpej 	p->p_md.md_tf->tf_regs[FRAME_PS] =
     89      1.1  thorpej 	    (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
     90      1.1  thorpej 
     91      1.1  thorpej 	regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
     92      1.1  thorpej 	alpha_pal_wrusp(ksc.sc_regs[R_SP]);
     93      1.1  thorpej 
     94      1.1  thorpej 	/* XXX ksc.sc_ownedfp ? */
     95  1.6.2.1   bouyer 	if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
     96  1.6.2.1   bouyer 		synchronize_fpstate(p, 0);
     97      1.1  thorpej 	bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
     98      1.1  thorpej 	    sizeof(struct fpreg));
     99      1.1  thorpej 	/* XXX ksc.sc_fp_control ? */
    100      1.1  thorpej 
    101      1.1  thorpej 	/* Restore signal stack. */
    102      1.1  thorpej 	if (ksc.sc_onstack & SS_ONSTACK)
    103      1.1  thorpej 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
    104      1.1  thorpej 	else
    105      1.1  thorpej 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
    106      1.1  thorpej 
    107      1.1  thorpej 	/*
    108      1.1  thorpej 	 * Restore signal mask.  Note the mask is a "long" in the stack
    109      1.1  thorpej 	 * frame.
    110      1.1  thorpej 	 */
    111      1.1  thorpej 	mask13 = ksc.sc_mask;
    112      1.1  thorpej 	native_sigset13_to_sigset(&mask13, &mask);
    113      1.1  thorpej 	(void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
    114      1.1  thorpej 
    115      1.1  thorpej 	return (EJUSTRETURN);
    116      1.1  thorpej }
    117