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