xref: /netbsd/sys/arch/m68k/m68k/compat_13_machdep.c (revision bf9ec67e)
1 /*	$NetBSD: compat_13_machdep.c,v 1.3 2000/12/22 22:58:54 jdolecek Exp $	*/
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1982, 1986, 1990, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	from: Utah Hdr: machdep.c 1.74 92/12/20
41  *	from: @(#)machdep.c	8.10 (Berkeley) 4/20/94
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/proc.h>
48 #include <sys/user.h>
49 #include <sys/signal.h>
50 #include <sys/signalvar.h>
51 
52 #include <sys/mount.h>
53 #include <sys/syscallargs.h>
54 
55 #include <machine/cpu.h>
56 #include <machine/reg.h>
57 
58 extern int fputype;
59 extern short exframesize[];
60 void	m68881_restore __P((struct fpframe *));
61 
62 /*
63  * System call to cleanup state after a signal
64  * has been taken.  Reset signal mask and
65  * stack state from context left by sendsig (above).
66  * Return to previous pc and psl as specified by
67  * context left by sendsig. Check carefully to
68  * make sure that the user has not modified the
69  * psl to gain improper privileges or to cause
70  * a machine fault.
71  */
72 int
73 compat_13_sys_sigreturn(p, v, retval)
74 	struct proc *p;
75 	void *v;
76 	register_t *retval;
77 {
78 	struct compat_13_sys_sigreturn_args /* {
79 		syscallarg(struct sigcontext13 *) sigcntxp;
80 	} */ *uap = v;
81 	struct sigcontext13 *scp;
82 	struct frame *frame;
83 	struct sigcontext13 tsigc;
84 	sigset_t mask;
85 
86 	/*
87 	 * The trampoline code hands us the context.
88 	 * It is unsafe to keep track of it ourselves, in the event that a
89 	 * program jumps out of a signal handler.
90 	 */
91 	scp = SCARG(uap, sigcntxp);
92 	if ((int)scp & 1)
93 		return (EINVAL);
94 
95 	if (copyin(scp, &tsigc, sizeof(tsigc)) != 0)
96 		return (EFAULT);
97 	scp = &tsigc;
98 
99 	/* Make sure the user isn't pulling a fast one on us! */
100 	if ((scp->sc_ps & (PSL_MBZ|PSL_IPL|PSL_S)) != 0)
101 		return (EINVAL);
102 
103 	/* Restore register context. */
104 	frame = (struct frame *) p->p_md.md_regs;
105 
106 	/*
107 	 * We only support restoring the sigcontext13 in this call.
108 	 * We are not called from the sigcode (per sendsig()), so
109 	 * we will not have a sigstate to restore.
110 	 */
111 	if (scp->sc_ap != 0)
112 		return (EINVAL);
113 
114 	/*
115 	 * Restore the user supplied information.
116 	 * This should be at the last so that the error (EINVAL)
117 	 * is reported to the sigreturn caller, not to the
118 	 * jump destination.
119 	 */
120 
121 	frame->f_regs[SP] = scp->sc_sp;
122 	frame->f_regs[A6] = scp->sc_fp;
123 	frame->f_pc = scp->sc_pc;
124 	frame->f_sr = scp->sc_ps;
125 
126 	/* Restore signal stack. */
127 	if (scp->sc_onstack & SS_ONSTACK)
128 		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
129 	else
130 		p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
131 
132 	/* Restore signal mask. */
133 	native_sigset13_to_sigset(&scp->sc_mask, &mask);
134 	(void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
135 
136 	return (EJUSTRETURN);
137 }
138