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