1*41aa5859Sriastradh /* $NetBSD: linux_machdep.c,v 1.52 2021/09/07 11:43:03 riastradh Exp $ */
272041f8eSerh
372041f8eSerh /*-
472041f8eSerh * Copyright (c) 1998 The NetBSD Foundation, Inc.
572041f8eSerh * All rights reserved.
672041f8eSerh *
772041f8eSerh * This code is derived from software contributed to The NetBSD Foundation
872041f8eSerh * by Eric Haszlakiewicz.
972041f8eSerh *
1072041f8eSerh * Redistribution and use in source and binary forms, with or without
1172041f8eSerh * modification, are permitted provided that the following conditions
1272041f8eSerh * are met:
1372041f8eSerh * 1. Redistributions of source code must retain the above copyright
1472041f8eSerh * notice, this list of conditions and the following disclaimer.
1572041f8eSerh * 2. Redistributions in binary form must reproduce the above copyright
1672041f8eSerh * notice, this list of conditions and the following disclaimer in the
1772041f8eSerh * documentation and/or other materials provided with the distribution.
1872041f8eSerh *
1972041f8eSerh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2072041f8eSerh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2172041f8eSerh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2272041f8eSerh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2372041f8eSerh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2472041f8eSerh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2572041f8eSerh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2672041f8eSerh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2772041f8eSerh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2872041f8eSerh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2972041f8eSerh * POSSIBILITY OF SUCH DAMAGE.
3072041f8eSerh *
3172041f8eSerh * Based on sys/arch/i386/i386/linux_machdep.c:
3272041f8eSerh * linux_machdep.c,v 1.42 1998/09/11 12:50:06 mycroft Exp
3372041f8eSerh * written by Frank van der Linden
3472041f8eSerh *
3572041f8eSerh */
3672041f8eSerh
37dab6ef8bSlukem #include <sys/cdefs.h>
38*41aa5859Sriastradh __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.52 2021/09/07 11:43:03 riastradh Exp $");
39dab6ef8bSlukem
4072041f8eSerh #include <sys/param.h>
4172041f8eSerh #include <sys/systm.h>
4272041f8eSerh #include <sys/signalvar.h>
4372041f8eSerh #include <sys/kernel.h>
4472041f8eSerh #include <sys/proc.h>
4572041f8eSerh #include <sys/buf.h>
4672041f8eSerh #include <sys/reboot.h>
4772041f8eSerh #include <sys/conf.h>
4872041f8eSerh #include <sys/exec.h>
4972041f8eSerh #include <sys/file.h>
5072041f8eSerh #include <sys/callout.h>
5172041f8eSerh #include <sys/mbuf.h>
5272041f8eSerh #include <sys/msgbuf.h>
5372041f8eSerh #include <sys/mount.h>
5472041f8eSerh #include <sys/vnode.h>
5572041f8eSerh #include <sys/device.h>
5672041f8eSerh #include <sys/syscallargs.h>
5772041f8eSerh #include <sys/filedesc.h>
5872041f8eSerh #include <sys/exec_elf.h>
59de8918d9Smanu #include <sys/ioctl.h>
606c89e74bSyamt #include <sys/kauth.h>
61d2397ac5Smrg
6272041f8eSerh #include <uvm/uvm_extern.h>
6372041f8eSerh
64908291d2Schristos #include <compat/linux/common/linux_types.h>
65908291d2Schristos #include <compat/linux/common/linux_signal.h>
66908291d2Schristos #include <compat/linux/common/linux_siginfo.h>
67908291d2Schristos #include <compat/linux/common/linux_util.h>
68908291d2Schristos #include <compat/linux/common/linux_ioctl.h>
69908291d2Schristos #include <compat/linux/common/linux_exec.h>
70908291d2Schristos #include <compat/linux/common/linux_machdep.h>
71cdc6431cSerh #include <compat/linux/common/linux_emuldata.h>
72908291d2Schristos
73908291d2Schristos #include <compat/linux/linux_syscallargs.h>
74908291d2Schristos
75cdc6431cSerh #include <machine/alpha.h>
7672041f8eSerh #include <machine/reg.h>
7772041f8eSerh
786a89288aSmrg #if defined(_KERNEL_OPT)
7972041f8eSerh #include "wsdisplay.h"
8073f3cd8cSjdolecek #endif
8172041f8eSerh #if (NWSDISPLAY >0)
8272041f8eSerh #include <dev/wscons/wsdisplay_usl_io.h>
8372041f8eSerh #endif
845217f633Ssommerfeld #ifdef DEBUG
855217f633Ssommerfeld #include <machine/sigdebug.h>
865217f633Ssommerfeld #endif
8772041f8eSerh
8872041f8eSerh /*
8972041f8eSerh * Deal with some alpha-specific things in the Linux emulation code.
9072041f8eSerh */
9172041f8eSerh
9272041f8eSerh void
linux_setregs(struct lwp * l,struct exec_package * epp,vaddr_t stack)9333fa5ccbSchs linux_setregs(struct lwp *l, struct exec_package *epp, vaddr_t stack)
9472041f8eSerh {
958aec0ac7Ssimonb #ifdef DEBUG
9646141a31Sthorpej struct trapframe *tfp = l->l_md.md_tf;
978aec0ac7Ssimonb #endif
988aec0ac7Ssimonb
9946141a31Sthorpej setregs(l, epp, stack);
1008aec0ac7Ssimonb #ifdef DEBUG
1018aec0ac7Ssimonb /*
1028aec0ac7Ssimonb * Linux has registers set to zero on entry; for DEBUG kernels
1038aec0ac7Ssimonb * the alpha setregs() fills registers with 0xbabefacedeadbeef.
1048aec0ac7Ssimonb */
1058aec0ac7Ssimonb memset(tfp->tf_regs, 0, FRAME_SIZE * sizeof tfp->tf_regs[0]);
1068aec0ac7Ssimonb #endif
10772041f8eSerh }
10872041f8eSerh
10925fb6de8Smatt void
setup_linux_rt_sigframe(struct trapframe * tf,const ksiginfo_t * ksi,const sigset_t * mask)110f72d02ffSchristos setup_linux_rt_sigframe(struct trapframe *tf, const ksiginfo_t *ksi,
111f72d02ffSchristos const sigset_t *mask)
11272041f8eSerh {
11346141a31Sthorpej struct lwp *l = curlwp;
11446141a31Sthorpej struct proc *p = l->l_proc;
11572041f8eSerh struct linux_rt_sigframe *sfp, sigframe;
116b07ec3fcSad int onstack, error;
11772041f8eSerh int fsize, rndfsize;
118f72d02ffSchristos int sig = ksi->ksi_signo;
11972041f8eSerh extern char linux_rt_sigcode[], linux_rt_esigcode[];
12072041f8eSerh
12172041f8eSerh /* Do we need to jump onto the signal stack? */
122b07ec3fcSad onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
123e9e91a0fSjdolecek (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
12472041f8eSerh
12572041f8eSerh /* Allocate space for the signal handler context. */
12672041f8eSerh fsize = sizeof(struct linux_rt_sigframe);
12772041f8eSerh rndfsize = ((fsize + 15) / 16) * 16;
12872041f8eSerh
12972041f8eSerh if (onstack)
13072041f8eSerh sfp = (struct linux_rt_sigframe *)
131731acd91Syamt ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
13272041f8eSerh else
13372041f8eSerh sfp = (struct linux_rt_sigframe *)(alpha_pal_rdusp());
134731acd91Syamt sfp = (struct linux_rt_sigframe *)((char *)sfp - rndfsize);
13572041f8eSerh
13672041f8eSerh #ifdef DEBUG
1375217f633Ssommerfeld if ((sigdebug & SDB_KSTACK) && (p->p_pid == sigpid))
13872041f8eSerh printf("linux_sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
13972041f8eSerh sig, &onstack, sfp);
14072041f8eSerh #endif /* DEBUG */
14172041f8eSerh
142*41aa5859Sriastradh memset(&sigframe, 0, sizeof(sigframe));
143*41aa5859Sriastradh
14472041f8eSerh /*
14572041f8eSerh * Build the signal context to be used by sigreturn.
14672041f8eSerh */
14725fb6de8Smatt memset(&sigframe.uc, 0, sizeof(struct linux_ucontext));
14872041f8eSerh sigframe.uc.uc_mcontext.sc_onstack = onstack;
1490174e675Serh
1500174e675Serh /* Setup potentially partial signal mask in sc_mask. */
1510174e675Serh /* But get all of it in uc_sigmask */
15228debea3Schristos native_to_linux_old_sigset(&sigframe.uc.uc_mcontext.sc_mask, mask);
15328debea3Schristos native_to_linux_sigset(&sigframe.uc.uc_sigmask, mask);
1540174e675Serh
15572041f8eSerh sigframe.uc.uc_mcontext.sc_pc = tf->tf_regs[FRAME_PC];
15672041f8eSerh sigframe.uc.uc_mcontext.sc_ps = ALPHA_PSL_USERMODE;
15772041f8eSerh frametoreg(tf, (struct reg *)sigframe.uc.uc_mcontext.sc_regs);
15872041f8eSerh sigframe.uc.uc_mcontext.sc_regs[R_SP] = alpha_pal_rdusp();
15972041f8eSerh
160dcd3c686Smatt fpu_load();
161dcd3c686Smatt alpha_pal_wrfen(1);
1622df695b1Sross sigframe.uc.uc_mcontext.sc_fpcr = alpha_read_fpcr();
16346141a31Sthorpej sigframe.uc.uc_mcontext.sc_fp_control = alpha_read_fp_c(l);
16472041f8eSerh alpha_pal_wrfen(0);
16572041f8eSerh
16672041f8eSerh sigframe.uc.uc_mcontext.sc_traparg_a0 = tf->tf_regs[FRAME_A0];
16772041f8eSerh sigframe.uc.uc_mcontext.sc_traparg_a1 = tf->tf_regs[FRAME_A1];
16872041f8eSerh sigframe.uc.uc_mcontext.sc_traparg_a2 = tf->tf_regs[FRAME_A2];
169f72d02ffSchristos native_to_linux_siginfo(&sigframe.info, &ksi->ksi_info);
170b07ec3fcSad sendsig_reset(l, sig);
171284c2b9aSad mutex_exit(p->p_lock);
17253524e44Schristos error = copyout((void *)&sigframe, (void *)sfp, fsize);
173284c2b9aSad mutex_enter(p->p_lock);
174b07ec3fcSad
175b07ec3fcSad if (error != 0) {
17672041f8eSerh #ifdef DEBUG
17772041f8eSerh if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
17872041f8eSerh printf("sendsig(%d): copyout failed on sig %d\n",
17972041f8eSerh p->p_pid, sig);
18072041f8eSerh #endif
18172041f8eSerh /*
18272041f8eSerh * Process has trashed its stack; give it an illegal
18372041f8eSerh * instruction to halt it in its tracks.
18472041f8eSerh */
18546141a31Sthorpej sigexit(l, SIGILL);
18672041f8eSerh /* NOTREACHED */
18772041f8eSerh }
18872041f8eSerh
18972041f8eSerh /* Pass pointers to siginfo and ucontext in the regs */
19072041f8eSerh tf->tf_regs[FRAME_A1] = (unsigned long)&sfp->info;
19172041f8eSerh tf->tf_regs[FRAME_A2] = (unsigned long)&sfp->uc;
19272041f8eSerh
19372041f8eSerh /* Address of trampoline code. End up at this PC after mi_switch */
19472041f8eSerh tf->tf_regs[FRAME_PC] =
19548717cfcSjoerg (u_int64_t)(p->p_psstrp - (linux_rt_esigcode - linux_rt_sigcode));
19672041f8eSerh
19772041f8eSerh /* Adjust the stack */
19872041f8eSerh alpha_pal_wrusp((unsigned long)sfp);
19972041f8eSerh
20072041f8eSerh /* Remember that we're now on the signal stack. */
20172041f8eSerh if (onstack)
202b07ec3fcSad l->l_sigstk.ss_flags |= SS_ONSTACK;
20372041f8eSerh }
20472041f8eSerh
setup_linux_sigframe(struct trapframe * tf,const ksiginfo_t * ksi,const sigset_t * mask)205f72d02ffSchristos void setup_linux_sigframe(struct trapframe *tf, const ksiginfo_t *ksi,
206f72d02ffSchristos const sigset_t *mask)
20772041f8eSerh {
20846141a31Sthorpej struct lwp *l = curlwp;
20946141a31Sthorpej struct proc *p = l->l_proc;
21072041f8eSerh struct linux_sigframe *sfp, sigframe;
211b07ec3fcSad int onstack, error;
21272041f8eSerh int fsize, rndfsize;
213f72d02ffSchristos int sig = ksi->ksi_signo;
21472041f8eSerh extern char linux_sigcode[], linux_esigcode[];
21572041f8eSerh
21672041f8eSerh /* Do we need to jump onto the signal stack? */
217b07ec3fcSad onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
218e9e91a0fSjdolecek (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
21972041f8eSerh
22072041f8eSerh /* Allocate space for the signal handler context. */
22172041f8eSerh fsize = sizeof(struct linux_sigframe);
22272041f8eSerh rndfsize = ((fsize + 15) / 16) * 16;
22372041f8eSerh
22472041f8eSerh if (onstack)
22572041f8eSerh sfp = (struct linux_sigframe *)
226731acd91Syamt ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
22772041f8eSerh else
22872041f8eSerh sfp = (struct linux_sigframe *)(alpha_pal_rdusp());
229731acd91Syamt sfp = (struct linux_sigframe *)((char *)sfp - rndfsize);
23072041f8eSerh
23172041f8eSerh #ifdef DEBUG
2325217f633Ssommerfeld if ((sigdebug & SDB_KSTACK) && (p->p_pid == sigpid))
23372041f8eSerh printf("linux_sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
23472041f8eSerh sig, &onstack, sfp);
23572041f8eSerh #endif /* DEBUG */
23672041f8eSerh
237*41aa5859Sriastradh memset(&sigframe, 0, sizeof(sigframe));
238*41aa5859Sriastradh
23972041f8eSerh /*
24072041f8eSerh * Build the signal context to be used by sigreturn.
24172041f8eSerh */
242b6caa3beSpooka memset(&sigframe.sf_sc, 0, sizeof(struct linux_sigcontext));
24372041f8eSerh sigframe.sf_sc.sc_onstack = onstack;
24428debea3Schristos native_to_linux_old_sigset(&sigframe.sf_sc.sc_mask, mask);
24572041f8eSerh sigframe.sf_sc.sc_pc = tf->tf_regs[FRAME_PC];
24672041f8eSerh sigframe.sf_sc.sc_ps = ALPHA_PSL_USERMODE;
24772041f8eSerh frametoreg(tf, (struct reg *)sigframe.sf_sc.sc_regs);
24872041f8eSerh sigframe.sf_sc.sc_regs[R_SP] = alpha_pal_rdusp();
24972041f8eSerh
250c1a69249Sthorpej if (fpu_valid_p(l)) {
251eaddd780Srmind struct pcb *pcb = lwp_getpcb(l);
252eaddd780Srmind
253c1a69249Sthorpej fpu_save(l);
254eaddd780Srmind sigframe.sf_sc.sc_fpcr = pcb->pcb_fp.fpr_cr;
25572041f8eSerh }
25672041f8eSerh /* XXX ownedfp ? etc...? */
25772041f8eSerh
25872041f8eSerh sigframe.sf_sc.sc_traparg_a0 = tf->tf_regs[FRAME_A0];
25972041f8eSerh sigframe.sf_sc.sc_traparg_a1 = tf->tf_regs[FRAME_A1];
26072041f8eSerh sigframe.sf_sc.sc_traparg_a2 = tf->tf_regs[FRAME_A2];
26172041f8eSerh
262b07ec3fcSad sendsig_reset(l, sig);
263284c2b9aSad mutex_exit(p->p_lock);
26453524e44Schristos error = copyout((void *)&sigframe, (void *)sfp, fsize);
265284c2b9aSad mutex_enter(p->p_lock);
266b07ec3fcSad
267b07ec3fcSad if (error != 0) {
26872041f8eSerh #ifdef DEBUG
26972041f8eSerh if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
27072041f8eSerh printf("sendsig(%d): copyout failed on sig %d\n",
27172041f8eSerh p->p_pid, sig);
27272041f8eSerh #endif
27372041f8eSerh /*
27472041f8eSerh * Process has trashed its stack; give it an illegal
27572041f8eSerh * instruction to halt it in its tracks.
27672041f8eSerh */
27746141a31Sthorpej sigexit(l, SIGILL);
27872041f8eSerh /* NOTREACHED */
27972041f8eSerh }
28072041f8eSerh
28172041f8eSerh /* Pass pointers to sigcontext in the regs */
28272041f8eSerh tf->tf_regs[FRAME_A1] = 0;
28372041f8eSerh tf->tf_regs[FRAME_A2] = (unsigned long)&sfp->sf_sc;
28472041f8eSerh
28572041f8eSerh /* Address of trampoline code. End up at this PC after mi_switch */
28672041f8eSerh tf->tf_regs[FRAME_PC] =
28748717cfcSjoerg (u_int64_t)(p->p_psstrp - (linux_esigcode - linux_sigcode));
28872041f8eSerh
28972041f8eSerh /* Adjust the stack */
29072041f8eSerh alpha_pal_wrusp((unsigned long)sfp);
29172041f8eSerh
29272041f8eSerh /* Remember that we're now on the signal stack. */
29372041f8eSerh if (onstack)
294b07ec3fcSad l->l_sigstk.ss_flags |= SS_ONSTACK;
29572041f8eSerh }
29672041f8eSerh
29772041f8eSerh /*
29872041f8eSerh * Send an interrupt to process.
29972041f8eSerh *
30072041f8eSerh * Stack is set up to allow sigcode stored
30172041f8eSerh * in u. to call routine, followed by kcall
30272041f8eSerh * to sigreturn routine below. After sigreturn
30372041f8eSerh * resets the signal mask, the stack, and the
30472041f8eSerh * frame pointer, it returns to the user
30572041f8eSerh * specified pc, psl.
30672041f8eSerh */
30772041f8eSerh void
linux_sendsig(const ksiginfo_t * ksi,const sigset_t * mask)30825fb6de8Smatt linux_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
30972041f8eSerh {
31046141a31Sthorpej struct lwp *l = curlwp;
31146141a31Sthorpej struct proc *p = l->l_proc;
31246141a31Sthorpej struct trapframe *tf = l->l_md.md_tf;
31325fb6de8Smatt const int sig = ksi->ksi_signo;
314011d4d5fSthorpej sig_t catcher = SIGACTION(p, sig).sa_handler;
315872ef3b1Sjdolecek #ifdef notyet
316cdc6431cSerh struct linux_emuldata *edp;
31772041f8eSerh
31872041f8eSerh /* Setup the signal frame (and part of the trapframe) */
31972041f8eSerh /*OLD: if (p->p_sigacts->ps_siginfo & sigmask(sig))*/
320cdc6431cSerh /* XXX XAX this is broken now. need someplace to store what
321cdc6431cSerh XXX XAX kind of signal handler a signal has.*/
322cdc6431cSerh #if 0
323cdc6431cSerh edp = (struct linux_emuldata *)p->p_emuldata;
324cdc6431cSerh #else
325cdc6431cSerh edp = 0;
326cdc6431cSerh #endif
327cdc6431cSerh if (edp && sigismember(&edp->ps_siginfo, sig))
328f72d02ffSchristos setup_linux_rt_sigframe(tf, ksi, mask);
32972041f8eSerh else
330872ef3b1Sjdolecek #endif /* notyet */
331f72d02ffSchristos setup_linux_sigframe(tf, ksi, mask);
33272041f8eSerh
33372041f8eSerh /* Signal handler for trampoline code */
33472041f8eSerh tf->tf_regs[FRAME_T12] = (u_int64_t)catcher;
335ac29fb37Schristos tf->tf_regs[FRAME_A0] = native_to_linux_signo[sig];
33672041f8eSerh
33772041f8eSerh /*
33872041f8eSerh * Linux has a custom restorer option. To support it we would
33972041f8eSerh * need to store an array of restorers and a sigcode block
34072041f8eSerh * which knew to use it. Doesn't seem worth the trouble.
34172041f8eSerh * -erh
34272041f8eSerh */
34372041f8eSerh
34472041f8eSerh #ifdef DEBUG
34572041f8eSerh if (sigdebug & SDB_FOLLOW)
34646141a31Sthorpej printf("sendsig(%d): pc %lx, catcher %lx\n", l->l_proc->p_pid,
34772041f8eSerh tf->tf_regs[FRAME_PC], tf->tf_regs[FRAME_A3]);
34846141a31Sthorpej if ((sigdebug & SDB_KSTACK) && l->l_proc->p_pid == sigpid)
34946141a31Sthorpej printf("sendsig(%d): sig %d returns\n", l->l_proc->p_pid, sig);
35072041f8eSerh #endif
35172041f8eSerh }
35272041f8eSerh
35372041f8eSerh /*
35472041f8eSerh * System call to cleanup state after a signal
35572041f8eSerh * has been taken. Reset signal mask and
35672041f8eSerh * stack state from context left by sendsig (above).
35772041f8eSerh * Return to previous pc as specified by context
35872041f8eSerh * left by sendsig.
35972041f8eSerh * Linux real-time signals use a different sigframe,
36072041f8eSerh * but the sigcontext is the same.
36172041f8eSerh */
36272041f8eSerh
36372041f8eSerh int
linux_restore_sigcontext(struct lwp * l,struct linux_sigcontext context,sigset_t * mask)36446141a31Sthorpej linux_restore_sigcontext(struct lwp *l, struct linux_sigcontext context,
3650174e675Serh sigset_t *mask)
36672041f8eSerh {
36746141a31Sthorpej struct proc *p = l->l_proc;
368eaddd780Srmind struct pcb *pcb;
369b07ec3fcSad
37072041f8eSerh /*
37172041f8eSerh * Linux doesn't (yet) have alternate signal stacks.
37272041f8eSerh * However, the OSF/1 sigcontext which they use has
37372041f8eSerh * an onstack member. This could be needed in the future.
37472041f8eSerh */
375284c2b9aSad mutex_enter(p->p_lock);
37672041f8eSerh if (context.sc_onstack & LINUX_SA_ONSTACK)
377b07ec3fcSad l->l_sigstk.ss_flags |= SS_ONSTACK;
37872041f8eSerh else
379b07ec3fcSad l->l_sigstk.ss_flags &= ~SS_ONSTACK;
38072041f8eSerh
38172041f8eSerh /* Reset the signal mask */
382b07ec3fcSad (void) sigprocmask1(l, SIG_SETMASK, mask, 0);
383284c2b9aSad mutex_exit(p->p_lock);
38472041f8eSerh
38572041f8eSerh /*
38672041f8eSerh * Check for security violations.
38772041f8eSerh * Linux doesn't allow any changes to the PSL.
38872041f8eSerh */
38972041f8eSerh if (context.sc_ps != ALPHA_PSL_USERMODE)
39072041f8eSerh return(EINVAL);
39172041f8eSerh
39246141a31Sthorpej l->l_md.md_tf->tf_regs[FRAME_PC] = context.sc_pc;
39346141a31Sthorpej l->l_md.md_tf->tf_regs[FRAME_PS] = context.sc_ps;
39472041f8eSerh
39546141a31Sthorpej regtoframe((struct reg *)context.sc_regs, l->l_md.md_tf);
39672041f8eSerh alpha_pal_wrusp(context.sc_regs[R_SP]);
39772041f8eSerh
39872041f8eSerh /* Restore fp regs and fpr_cr */
399eaddd780Srmind pcb = lwp_getpcb(l);
400eaddd780Srmind memcpy(&pcb->pcb_fp, (struct fpreg *)context.sc_fpregs,
40172041f8eSerh sizeof(struct fpreg));
40272041f8eSerh /* XXX sc_ownedfp ? */
40372041f8eSerh /* XXX sc_fp_control ? */
40472041f8eSerh
40572041f8eSerh #ifdef DEBUG
40672041f8eSerh if (sigdebug & SDB_FOLLOW)
4075217f633Ssommerfeld printf("linux_rt_sigreturn(%d): returns\n", p->p_pid);
40872041f8eSerh #endif
40972041f8eSerh return (EJUSTRETURN);
41072041f8eSerh }
41172041f8eSerh
41272041f8eSerh int
linux_sys_rt_sigreturn(struct lwp * l,const struct linux_sys_rt_sigreturn_args * uap,register_t * retval)4137e2790cfSdsl linux_sys_rt_sigreturn(struct lwp *l, const struct linux_sys_rt_sigreturn_args *uap, register_t *retval)
41472041f8eSerh {
4157e2790cfSdsl /* {
41672041f8eSerh syscallarg(struct linux_rt_sigframe *) sfp;
4177e2790cfSdsl } */
41872041f8eSerh struct linux_rt_sigframe *sfp, sigframe;
4190174e675Serh sigset_t mask;
42072041f8eSerh
42172041f8eSerh /*
42272041f8eSerh * The trampoline code hands us the context.
42372041f8eSerh * It is unsafe to keep track of it ourselves, in the event that a
42472041f8eSerh * program jumps out of a signal handler.
42572041f8eSerh */
42672041f8eSerh
42772041f8eSerh sfp = SCARG(uap, sfp);
42872041f8eSerh
42972041f8eSerh if (ALIGN(sfp) != (u_int64_t)sfp)
43072041f8eSerh return(EINVAL);
43172041f8eSerh
43272041f8eSerh /*
43372041f8eSerh * Fetch the frame structure.
43472041f8eSerh */
43553524e44Schristos if (copyin((void *)sfp, &sigframe,
43672041f8eSerh sizeof(struct linux_rt_sigframe)) != 0)
43772041f8eSerh return (EFAULT);
43872041f8eSerh
4390174e675Serh /* Grab the signal mask */
440e52b5e4bSchristos linux_to_native_sigset(&mask, &sigframe.uc.uc_sigmask);
4410174e675Serh
44246141a31Sthorpej return(linux_restore_sigcontext(l, sigframe.uc.uc_mcontext, &mask));
44372041f8eSerh }
44472041f8eSerh
44572041f8eSerh
44672041f8eSerh int
linux_sys_sigreturn(struct lwp * l,const struct linux_sys_sigreturn_args * uap,register_t * retval)4477e2790cfSdsl linux_sys_sigreturn(struct lwp *l, const struct linux_sys_sigreturn_args *uap, register_t *retval)
44872041f8eSerh {
4497e2790cfSdsl /* {
45072041f8eSerh syscallarg(struct linux_sigframe *) sfp;
4517e2790cfSdsl } */
4520174e675Serh struct linux_sigframe *sfp, frame;
4530174e675Serh sigset_t mask;
45472041f8eSerh
45572041f8eSerh /*
45672041f8eSerh * The trampoline code hands us the context.
45772041f8eSerh * It is unsafe to keep track of it ourselves, in the event that a
45872041f8eSerh * program jumps out of a signal handler.
45972041f8eSerh */
46072041f8eSerh
4610174e675Serh sfp = SCARG(uap, sfp);
4620174e675Serh if (ALIGN(sfp) != (u_int64_t)sfp)
46372041f8eSerh return(EINVAL);
46472041f8eSerh
46572041f8eSerh /*
4660174e675Serh * Fetch the frame structure.
46772041f8eSerh */
46853524e44Schristos if (copyin((void *)sfp, &frame, sizeof(struct linux_sigframe)) != 0)
46972041f8eSerh return(EFAULT);
47072041f8eSerh
4710174e675Serh /* Grab the signal mask. */
4720174e675Serh /* XXX use frame.extramask */
473e52b5e4bSchristos linux_old_to_native_sigset(&mask, frame.sf_sc.sc_mask);
4740174e675Serh
47546141a31Sthorpej return(linux_restore_sigcontext(l, frame.sf_sc, &mask));
47672041f8eSerh }
47772041f8eSerh
47872041f8eSerh /*
47972041f8eSerh * We come here in a last attempt to satisfy a Linux ioctl() call
48072041f8eSerh */
48172041f8eSerh /* XXX XAX update this, add maps, etc... */
48272041f8eSerh int
linux_machdepioctl(struct lwp * l,const struct linux_sys_ioctl_args * uap,register_t * retval)4837e2790cfSdsl linux_machdepioctl(struct lwp *l, const struct linux_sys_ioctl_args *uap, register_t *retval)
48472041f8eSerh {
4857e2790cfSdsl /* {
48672041f8eSerh syscallarg(int) fd;
48772041f8eSerh syscallarg(u_long) com;
48853524e44Schristos syscallarg(void *) data;
4897e2790cfSdsl } */
49072041f8eSerh struct sys_ioctl_args bia;
49172041f8eSerh u_long com;
49272041f8eSerh
49372041f8eSerh SCARG(&bia, fd) = SCARG(uap, fd);
49472041f8eSerh SCARG(&bia, data) = SCARG(uap, data);
49572041f8eSerh com = SCARG(uap, com);
49672041f8eSerh
49772041f8eSerh switch (com) {
49872041f8eSerh default:
49972041f8eSerh printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
50072041f8eSerh return EINVAL;
50172041f8eSerh }
50272041f8eSerh SCARG(&bia, com) = com;
50395e1ffb1Schristos return sys_ioctl(l, &bia, retval);
50472041f8eSerh }
50572041f8eSerh
50672041f8eSerh /* XXX XAX fix this */
50772041f8eSerh dev_t
linux_fakedev(dev_t dev,int raw)50828bae79bSdsl linux_fakedev(dev_t dev, int raw)
50972041f8eSerh {
51072041f8eSerh return dev;
51172041f8eSerh }
51272041f8eSerh
51333e2d79fSfvdl int
linux_usertrap(struct lwp * l,vaddr_t trapaddr,void * arg)51433e2d79fSfvdl linux_usertrap(struct lwp *l, vaddr_t trapaddr, void *arg)
51533e2d79fSfvdl {
51633e2d79fSfvdl return 0;
51733e2d79fSfvdl }
518