Home | History | Annotate | Line # | Download | only in powerpc
linux_machdep.c revision 1.41.4.2
      1  1.41.4.1     rmind /*	$NetBSD: linux_machdep.c,v 1.41.4.2 2011/05/31 03:04:29 rmind Exp $ */
      2       1.1      manu 
      3       1.1      manu /*-
      4       1.1      manu  * Copyright (c) 1995, 2000, 2001 The NetBSD Foundation, Inc.
      5       1.1      manu  * All rights reserved.
      6       1.1      manu  *
      7       1.1      manu  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      manu  * by Frank van der Linden and Emmanuel Dreyfus.
      9       1.1      manu  *
     10       1.1      manu  * Redistribution and use in source and binary forms, with or without
     11       1.1      manu  * modification, are permitted provided that the following conditions
     12       1.1      manu  * are met:
     13       1.1      manu  * 1. Redistributions of source code must retain the above copyright
     14       1.1      manu  *    notice, this list of conditions and the following disclaimer.
     15       1.1      manu  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      manu  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      manu  *    documentation and/or other materials provided with the distribution.
     18       1.1      manu  *
     19       1.1      manu  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1      manu  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      manu  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      manu  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1      manu  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      manu  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      manu  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      manu  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      manu  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      manu  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      manu  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      manu  */
     31      1.12     lukem 
     32      1.12     lukem #include <sys/cdefs.h>
     33  1.41.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.41.4.2 2011/05/31 03:04:29 rmind Exp $");
     34       1.1      manu 
     35       1.1      manu #include <sys/param.h>
     36       1.1      manu #include <sys/systm.h>
     37       1.1      manu #include <sys/signalvar.h>
     38       1.1      manu #include <sys/kernel.h>
     39       1.1      manu #include <sys/proc.h>
     40       1.1      manu #include <sys/buf.h>
     41       1.1      manu #include <sys/reboot.h>
     42       1.1      manu #include <sys/conf.h>
     43       1.1      manu #include <sys/exec.h>
     44       1.1      manu #include <sys/file.h>
     45       1.1      manu #include <sys/callout.h>
     46       1.1      manu #include <sys/malloc.h>
     47       1.1      manu #include <sys/mbuf.h>
     48       1.1      manu #include <sys/msgbuf.h>
     49       1.1      manu #include <sys/mount.h>
     50       1.1      manu #include <sys/vnode.h>
     51       1.1      manu #include <sys/device.h>
     52       1.1      manu #include <sys/syscallargs.h>
     53       1.1      manu #include <sys/filedesc.h>
     54       1.1      manu #include <sys/exec_elf.h>
     55       1.1      manu #include <sys/disklabel.h>
     56       1.3      manu #include <sys/ioctl.h>
     57       1.1      manu #include <miscfs/specfs/specdev.h>
     58       1.1      manu 
     59       1.1      manu #include <compat/linux/common/linux_types.h>
     60       1.1      manu #include <compat/linux/common/linux_signal.h>
     61       1.1      manu #include <compat/linux/common/linux_util.h>
     62       1.1      manu #include <compat/linux/common/linux_ioctl.h>
     63       1.1      manu #include <compat/linux/common/linux_hdio.h>
     64       1.1      manu #include <compat/linux/common/linux_exec.h>
     65       1.1      manu #include <compat/linux/common/linux_machdep.h>
     66       1.1      manu 
     67       1.1      manu #include <compat/linux/linux_syscallargs.h>
     68       1.1      manu 
     69      1.35        ad #include <sys/cpu.h>
     70      1.11       wiz #include <machine/fpu.h>
     71       1.1      manu #include <machine/psl.h>
     72  1.41.4.1     rmind #include <machine/pcb.h>
     73       1.1      manu #include <machine/vmparam.h>
     74       1.1      manu 
     75       1.1      manu /*
     76       1.1      manu  * To see whether wscons is configured (for virtual console ioctl calls).
     77       1.1      manu  */
     78      1.10       mrg #if defined(_KERNEL_OPT)
     79       1.1      manu #include "wsdisplay.h"
     80       1.1      manu #endif
     81       1.1      manu #if (NWSDISPLAY > 0)
     82       1.1      manu #include <dev/wscons/wsconsio.h>
     83       1.1      manu #include <dev/wscons/wsdisplay_usl_io.h>
     84       1.1      manu #endif
     85       1.1      manu 
     86      1.29     perry /*
     87       1.1      manu  * Set set up registers on exec.
     88       1.1      manu  */
     89       1.1      manu void
     90  1.41.4.1     rmind linux_setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
     91      1.29     perry {
     92      1.20   thorpej 	setregs(l, pack, stack);
     93       1.1      manu }
     94       1.1      manu 
     95       1.1      manu /*
     96       1.1      manu  * Send an interrupt to process.
     97       1.1      manu  *
     98       1.1      manu  * Adapted from arch/powerpc/powerpc/sig_machdep.c:sendsig and
     99       1.1      manu  * compat/linux/arch/i386/linux_machdep.c:linux_sendsig
    100       1.1      manu  *
    101       1.6      manu  * XXX Does not work well yet with RT signals
    102       1.1      manu  *
    103       1.1      manu  */
    104       1.1      manu 
    105      1.23      matt void
    106      1.24  christos linux_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
    107       1.1      manu {
    108      1.26   thorpej 	const int sig = ksi->ksi_signo;
    109      1.20   thorpej 	struct lwp *l = curlwp;
    110      1.20   thorpej 	struct proc *p = l->l_proc;
    111       1.1      manu 	struct trapframe *tf;
    112      1.16   thorpej 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    113       1.8      manu 	struct linux_sigregs frame;
    114       1.4  christos 	struct linux_pt_regs linux_regs;
    115       1.1      manu 	struct linux_sigcontext sc;
    116       1.8      manu 	register_t fp;
    117      1.32        ad 	int onstack, error;
    118       1.1      manu 	int i;
    119       1.1      manu 
    120      1.20   thorpej 	tf = trapframe(l);
    121      1.29     perry 
    122      1.29     perry 	/*
    123      1.29     perry 	 * Do we need to jump onto the signal stack?
    124       1.1      manu 	 */
    125       1.1      manu 	onstack =
    126      1.32        ad 	    (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    127       1.1      manu 	    (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    128       1.1      manu 
    129       1.1      manu 	/*
    130       1.1      manu 	 * Signal stack is broken (see at the end of linux_sigreturn), so we do
    131       1.1      manu 	 * not use it yet. XXX fix this.
    132       1.1      manu 	 */
    133       1.1      manu 	onstack=0;
    134       1.1      manu 
    135      1.29     perry 	/*
    136      1.29     perry 	 * Allocate space for the signal handler context.
    137       1.1      manu 	 */
    138       1.4  christos 	if (onstack) {
    139       1.8      manu 		fp = (register_t)
    140      1.34   tsutsui 		    ((char *)l->l_sigstk.ss_sp +
    141      1.32        ad 		    l->l_sigstk.ss_size);
    142       1.4  christos 	} else {
    143  1.41.4.1     rmind 		fp = tf->tf_fixreg[1];
    144       1.4  christos 	}
    145       1.8      manu #ifdef DEBUG_LINUX
    146       1.8      manu 	printf("fp at start of linux_sendsig = %x\n", fp);
    147       1.8      manu #endif
    148       1.8      manu 	fp -= sizeof(struct linux_sigregs);
    149       1.8      manu 	fp &= ~0xf;
    150       1.1      manu 
    151      1.29     perry 	/*
    152       1.1      manu 	 * Prepare a sigcontext for later.
    153       1.1      manu 	 */
    154       1.8      manu 	memset(&sc, 0, sizeof sc);
    155      1.14  christos 	sc.lsignal = (int)native_to_linux_signo[sig];
    156       1.1      manu 	sc.lhandler = (unsigned long)catcher;
    157      1.13  christos 	native_to_linux_old_extra_sigset(&sc.lmask, &sc._unused[3], mask);
    158       1.1      manu 	sc.lregs = (struct linux_pt_regs*)fp;
    159       1.1      manu 
    160       1.1      manu 	/*
    161      1.29     perry 	 * Setup the signal stack frame as Linux does it in
    162       1.1      manu 	 * arch/ppc/kernel/signal.c:setup_frame()
    163       1.1      manu 	 *
    164      1.29     perry 	 * Save register context.
    165       1.1      manu 	 */
    166      1.29     perry 	for (i = 0; i < 32; i++)
    167  1.41.4.1     rmind 		linux_regs.lgpr[i] = tf->tf_fixreg[i];
    168  1.41.4.1     rmind 	linux_regs.lnip = tf->tf_srr0;
    169  1.41.4.1     rmind 	linux_regs.lmsr = tf->tf_srr1 & PSL_USERSRR1;
    170  1.41.4.1     rmind 	linux_regs.lorig_gpr3 = tf->tf_fixreg[3]; /* XXX Is that right? */
    171  1.41.4.1     rmind 	linux_regs.lctr = tf->tf_ctr;
    172  1.41.4.1     rmind 	linux_regs.llink = tf->tf_lr;
    173  1.41.4.1     rmind 	linux_regs.lxer = tf->tf_xer;
    174  1.41.4.1     rmind 	linux_regs.lccr = tf->tf_cr;
    175       1.1      manu 	linux_regs.lmq = 0;  			/* Unused, 601 only */
    176  1.41.4.1     rmind 	linux_regs.ltrap = tf->tf_exc;
    177  1.41.4.1     rmind 	linux_regs.ldar = tf->tf_dar;
    178  1.41.4.1     rmind 	linux_regs.ldsisr = tf->tf_dsisr;
    179       1.8      manu 	linux_regs.lresult = 0;
    180       1.8      manu 
    181       1.8      manu 	memset(&frame, 0, sizeof(frame));
    182       1.8      manu 	memcpy(&frame.lgp_regs, &linux_regs, sizeof(linux_regs));
    183       1.1      manu 
    184  1.41.4.2     rmind #ifdef PPC_HAVE_FPU
    185  1.41.4.2     rmind 	fpu_save();
    186  1.41.4.2     rmind #endif
    187      1.28      matt 	memcpy(&frame.lfp_regs, curpcb->pcb_fpu.fpreg, sizeof(frame.lfp_regs));
    188       1.1      manu 
    189       1.1      manu 	/*
    190       1.4  christos 	 * Copy Linux's signal trampoline on the user stack It should not
    191       1.6      manu 	 * be used, but Linux binaries might expect it to be there.
    192       1.1      manu 	 */
    193       1.4  christos 	frame.ltramp[0] = 0x38997777; /* li r0, 0x7777 */
    194       1.4  christos 	frame.ltramp[1] = 0x44000002; /* sc */
    195      1.29     perry 
    196       1.1      manu 	/*
    197       1.1      manu 	 * Move it to the user stack
    198      1.29     perry 	 * There is a little trick here, about the LINUX_ABIGAP: the
    199       1.1      manu 	 * linux_sigreg structure has a 56 int gap to support rs6000/xcoff
    200       1.1      manu 	 * binaries. But the Linux kernel seems to do without it, and it
    201       1.1      manu 	 * just skip it when building the stack frame. Hence the LINUX_ABIGAP.
    202       1.1      manu 	 */
    203      1.32        ad 	sendsig_reset(l, sig);
    204      1.38        ad 	mutex_exit(p->p_lock);
    205      1.33  christos 	error = copyout(&frame, (void *)fp, sizeof (frame) - LINUX_ABIGAP);
    206      1.32        ad 
    207      1.32        ad 	if (error != 0) {
    208       1.1      manu 		/*
    209       1.1      manu 		 * Process has trashed its stack; give it an illegal
    210       1.9      manu 		 * instruction to halt it in its tracks.
    211       1.1      manu 		 */
    212      1.38        ad 		mutex_enter(p->p_lock);
    213      1.20   thorpej 		sigexit(l, SIGILL);
    214       1.1      manu 		/* NOTREACHED */
    215       1.1      manu 	}
    216       1.1      manu 
    217       1.1      manu 	/*
    218       1.1      manu 	 * Add a sigcontext on the stack
    219       1.1      manu 	 */
    220       1.8      manu 	fp -= sizeof(struct linux_sigcontext);
    221      1.33  christos 	error = copyout(&sc, (void *)fp, sizeof (struct linux_sigcontext));
    222      1.38        ad 	mutex_enter(p->p_lock);
    223      1.32        ad 
    224      1.32        ad 	if (error != 0) {
    225       1.1      manu 		/*
    226       1.1      manu 		 * Process has trashed its stack; give it an illegal
    227       1.9      manu 		 * instruction to halt it in its tracks.
    228       1.1      manu 		 */
    229      1.20   thorpej 		sigexit(l, SIGILL);
    230       1.1      manu 		/* NOTREACHED */
    231       1.1      manu 	}
    232       1.1      manu 
    233       1.1      manu 	/*
    234       1.8      manu 	 * Set the registers according to how the Linux process expects them.
    235       1.8      manu 	 * "Mind the gap" Linux expects a gap here.
    236       1.1      manu 	 */
    237  1.41.4.1     rmind 	tf->tf_fixreg[1] = fp - LINUX__SIGNAL_FRAMESIZE;
    238  1.41.4.1     rmind 	tf->tf_lr = (int)catcher;
    239  1.41.4.1     rmind 	tf->tf_fixreg[3] = (int)native_to_linux_signo[sig];
    240  1.41.4.1     rmind 	tf->tf_fixreg[4] = fp;
    241  1.41.4.1     rmind 	tf->tf_srr0 = (int)p->p_sigctx.ps_sigcode;
    242       1.1      manu 
    243       1.8      manu #ifdef DEBUG_LINUX
    244       1.8      manu 	printf("fp at end of linux_sendsig = %x\n", fp);
    245       1.8      manu #endif
    246      1.29     perry 	/*
    247      1.29     perry 	 * Remember that we're now on the signal stack.
    248       1.1      manu 	 */
    249       1.1      manu 	if (onstack)
    250      1.32        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    251       1.1      manu #ifdef DEBUG_LINUX
    252       1.1      manu 	printf("linux_sendsig: exitting. fp=0x%lx\n",(long)fp);
    253       1.1      manu #endif
    254       1.1      manu }
    255       1.1      manu 
    256       1.1      manu /*
    257       1.1      manu  * System call to cleanup state after a signal
    258       1.1      manu  * has been taken.  Reset signal mask and
    259       1.1      manu  * stack state from context left by sendsig (above).
    260       1.1      manu  * Return to previous pc and psl as specified by
    261       1.1      manu  * context left by sendsig. Check carefully to
    262       1.1      manu  * make sure that the user has not modified the
    263       1.1      manu  * psl to gain improper privileges or to cause
    264       1.1      manu  * a machine fault.
    265       1.1      manu  *
    266       1.1      manu  * XXX not tested
    267       1.1      manu  */
    268       1.1      manu int
    269      1.37       dsl linux_sys_rt_sigreturn(struct lwp *l, const struct linux_sys_rt_sigreturn_args *uap, register_t *retval)
    270       1.1      manu {
    271      1.37       dsl 	/* {
    272       1.1      manu 		syscallarg(struct linux_rt_sigframe *) sfp;
    273      1.37       dsl 	} */
    274      1.20   thorpej 	struct proc *p = l->l_proc;
    275       1.1      manu 	struct linux_rt_sigframe *scp, sigframe;
    276       1.8      manu 	struct linux_sigregs sregs;
    277       1.8      manu 	struct linux_pt_regs *lregs;
    278       1.1      manu 	struct trapframe *tf;
    279       1.1      manu 	sigset_t mask;
    280       1.1      manu 	int i;
    281       1.1      manu 
    282       1.1      manu 	/*
    283       1.1      manu 	 * The trampoline code hands us the context.
    284       1.1      manu 	 * It is unsafe to keep track of it ourselves, in the event that a
    285       1.1      manu 	 * program jumps out of a signal handler.
    286       1.1      manu 	 */
    287       1.1      manu 	scp = SCARG(uap, sfp);
    288       1.1      manu 
    289       1.1      manu 	/*
    290       1.1      manu 	 * Get the context from user stack
    291       1.1      manu 	 */
    292      1.33  christos 	if (copyin((void *)scp, &sigframe, sizeof(*scp)))
    293       1.1      manu 		return (EFAULT);
    294       1.1      manu 
    295       1.1      manu 	/*
    296       1.8      manu 	 *  Restore register context.
    297       1.1      manu 	 */
    298      1.33  christos 	if (copyin((void *)sigframe.luc.luc_context.lregs,
    299       1.8      manu 		   &sregs, sizeof(sregs)))
    300       1.8      manu 		return (EFAULT);
    301       1.8      manu 	lregs = (struct linux_pt_regs *)&sregs.lgp_regs;
    302       1.8      manu 
    303      1.20   thorpej 	tf = trapframe(l);
    304       1.1      manu #ifdef DEBUG_LINUX
    305      1.41       wiz 	printf("linux_sys_rt_sigreturn: trapframe=0x%lx scp=0x%lx\n",
    306       1.1      manu 	    (unsigned long)tf, (unsigned long)scp);
    307       1.1      manu #endif
    308       1.1      manu 
    309      1.28      matt 	if (!PSL_USEROK_P(lregs->lmsr))
    310      1.29     perry 		return (EINVAL);
    311       1.1      manu 
    312      1.29     perry 	for (i = 0; i < 32; i++)
    313  1.41.4.1     rmind 		tf->tf_fixreg[i] = lregs->lgpr[i];
    314  1.41.4.1     rmind 	tf->tf_lr = lregs->llink;
    315  1.41.4.1     rmind 	tf->tf_cr = lregs->lccr;
    316  1.41.4.1     rmind 	tf->tf_xer = lregs->lxer;
    317  1.41.4.1     rmind 	tf->tf_ctr = lregs->lctr;
    318  1.41.4.1     rmind 	tf->tf_srr0 = lregs->lnip;
    319  1.41.4.1     rmind 	tf->tf_srr1 = lregs->lmsr;
    320       1.8      manu 
    321      1.28      matt 	/*
    322      1.28      matt 	 * Make sure the fpu state is discarded
    323      1.28      matt 	 */
    324  1.41.4.2     rmind #ifdef PPC_HAVE_FPU
    325  1.41.4.2     rmind 	fpu_discard();
    326  1.41.4.2     rmind #endif
    327      1.28      matt 
    328      1.33  christos 	memcpy(curpcb->pcb_fpu.fpreg, (void *)&sregs.lfp_regs,
    329      1.28      matt 	       sizeof(curpcb->pcb_fpu.fpreg));
    330       1.1      manu 
    331  1.41.4.2     rmind 	fpu_mark_used(curlwp);
    332  1.41.4.2     rmind 
    333      1.38        ad 	mutex_enter(p->p_lock);
    334      1.32        ad 
    335      1.29     perry 	/*
    336      1.29     perry 	 * Restore signal stack.
    337      1.29     perry 	 *
    338      1.29     perry 	 * XXX cannot find the onstack information in Linux sig context.
    339       1.1      manu 	 * Is signal stack really supported on Linux?
    340      1.29     perry 	 *
    341       1.1      manu 	 * It seems to be supported in libc6...
    342       1.1      manu 	 */
    343      1.29     perry 	/* if (sc.sc_onstack & SS_ONSTACK)
    344      1.32        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    345       1.1      manu 	else */
    346      1.32        ad 		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    347       1.1      manu 
    348       1.8      manu 	/*
    349       1.8      manu 	 * Grab the signal mask
    350       1.8      manu 	 */
    351      1.13  christos 	linux_to_native_sigset(&mask, &sigframe.luc.luc_sigmask);
    352      1.32        ad 	(void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
    353      1.32        ad 
    354      1.38        ad 	mutex_exit(p->p_lock);
    355       1.8      manu 
    356       1.1      manu 	return (EJUSTRETURN);
    357       1.1      manu }
    358       1.1      manu 
    359       1.1      manu 
    360       1.1      manu /*
    361       1.1      manu  * The following needs code review for potential security issues
    362       1.1      manu  */
    363       1.1      manu int
    364      1.37       dsl linux_sys_sigreturn(struct lwp *l, const struct linux_sys_sigreturn_args *uap, register_t *retval)
    365       1.1      manu {
    366      1.37       dsl 	/* {
    367       1.1      manu 		syscallarg(struct linux_sigcontext *) scp;
    368      1.37       dsl 	} */
    369      1.20   thorpej 	struct proc *p = l->l_proc;
    370       1.1      manu 	struct linux_sigcontext *scp, context;
    371       1.8      manu 	struct linux_sigregs sregs;
    372       1.8      manu 	struct linux_pt_regs *lregs;
    373       1.1      manu 	struct trapframe *tf;
    374       1.1      manu 	sigset_t mask;
    375       1.1      manu 	int i;
    376       1.1      manu 
    377       1.1      manu 	/*
    378       1.1      manu 	 * The trampoline code hands us the context.
    379       1.1      manu 	 * It is unsafe to keep track of it ourselves, in the event that a
    380       1.1      manu 	 * program jumps out of a signal handler.
    381       1.1      manu 	 */
    382       1.1      manu 	scp = SCARG(uap, scp);
    383       1.1      manu 
    384       1.1      manu 	/*
    385       1.8      manu 	 * Get the context from user stack
    386       1.1      manu 	 */
    387       1.8      manu 	if (copyin(scp, &context, sizeof(*scp)))
    388       1.8      manu 		return (EFAULT);
    389       1.1      manu 
    390       1.1      manu 	/*
    391       1.8      manu 	 *  Restore register context.
    392       1.1      manu 	 */
    393      1.33  christos 	if (copyin((void *)context.lregs, &sregs, sizeof(sregs)))
    394       1.8      manu 		return (EFAULT);
    395       1.8      manu 	lregs = (struct linux_pt_regs *)&sregs.lgp_regs;
    396       1.8      manu 
    397      1.20   thorpej 	tf = trapframe(l);
    398       1.1      manu #ifdef DEBUG_LINUX
    399       1.1      manu 	printf("linux_sys_sigreturn: trapframe=0x%lx scp=0x%lx\n",
    400       1.1      manu 	    (unsigned long)tf, (unsigned long)scp);
    401       1.1      manu #endif
    402       1.1      manu 
    403      1.28      matt 	if (!PSL_USEROK_P(lregs->lmsr))
    404      1.29     perry 		return (EINVAL);
    405       1.1      manu 
    406      1.29     perry 	for (i = 0; i < 32; i++)
    407  1.41.4.1     rmind 		tf->tf_fixreg[i] = lregs->lgpr[i];
    408  1.41.4.1     rmind 	tf->tf_lr = lregs->llink;
    409  1.41.4.1     rmind 	tf->tf_cr = lregs->lccr;
    410  1.41.4.1     rmind 	tf->tf_xer = lregs->lxer;
    411  1.41.4.1     rmind 	tf->tf_ctr = lregs->lctr;
    412  1.41.4.1     rmind 	tf->tf_srr0 = lregs->lnip;
    413  1.41.4.1     rmind 	tf->tf_srr1 = lregs->lmsr;
    414       1.8      manu 
    415      1.28      matt 	/*
    416      1.28      matt 	 * Make sure the fpu state is discarded
    417      1.28      matt 	 */
    418  1.41.4.2     rmind #ifdef PPC_HAVE_FPU
    419  1.41.4.2     rmind 	fpu_discard();
    420  1.41.4.2     rmind #endif
    421      1.28      matt 
    422      1.33  christos 	memcpy(curpcb->pcb_fpu.fpreg, (void *)&sregs.lfp_regs,
    423      1.28      matt 	       sizeof(curpcb->pcb_fpu.fpreg));
    424       1.1      manu 
    425  1.41.4.2     rmind 	fpu_mark_used(curlwp);
    426  1.41.4.2     rmind 
    427      1.38        ad 	mutex_enter(p->p_lock);
    428      1.32        ad 
    429      1.29     perry 	/*
    430      1.29     perry 	 * Restore signal stack.
    431      1.29     perry 	 *
    432      1.29     perry 	 * XXX cannot find the onstack information in Linux sig context.
    433       1.1      manu 	 * Is signal stack really supported on Linux?
    434       1.1      manu 	 */
    435       1.4  christos #if 0
    436      1.29     perry 	if (sc.sc_onstack & SS_ONSTACK)
    437      1.32        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    438       1.4  christos 	else
    439       1.4  christos #endif
    440      1.32        ad 		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    441       1.1      manu 
    442       1.1      manu 	/* Restore signal mask. */
    443      1.13  christos 	linux_old_extra_to_native_sigset(&mask, &context.lmask,
    444      1.13  christos 	    &context._unused[3]);
    445      1.32        ad 	(void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
    446      1.32        ad 
    447      1.38        ad 	mutex_exit(p->p_lock);
    448       1.1      manu 
    449       1.1      manu 	return (EJUSTRETURN);
    450       1.1      manu }
    451       1.1      manu 
    452      1.29     perry /*
    453       1.6      manu  * major device numbers remapping
    454       1.6      manu  */
    455       1.1      manu dev_t
    456      1.36       dsl linux_fakedev(dev_t dev, int raw)
    457       1.1      manu {
    458      1.15  jdolecek 	/* XXX write me */
    459      1.15  jdolecek 	return dev;
    460       1.1      manu }
    461       1.1      manu 
    462       1.1      manu /*
    463       1.1      manu  * We come here in a last attempt to satisfy a Linux ioctl() call
    464       1.1      manu  */
    465       1.1      manu int
    466      1.37       dsl linux_machdepioctl(struct lwp *l, const struct linux_sys_ioctl_args *uap, register_t *retval)
    467      1.29     perry {
    468      1.37       dsl 	/* {
    469       1.1      manu 		syscallarg(int) fd;
    470       1.1      manu 		syscallarg(u_long) com;
    471      1.33  christos 		syscallarg(void *) data;
    472      1.37       dsl 	} */
    473       1.1      manu 	struct sys_ioctl_args bia;
    474       1.1      manu 	u_long com;
    475      1.29     perry 
    476       1.1      manu 	SCARG(&bia, fd) = SCARG(uap, fd);
    477       1.1      manu 	SCARG(&bia, data) = SCARG(uap, data);
    478       1.1      manu 	com = SCARG(uap, com);
    479      1.29     perry 
    480       1.1      manu 	switch (com) {
    481       1.1      manu 	default:
    482       1.1      manu 		printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
    483       1.1      manu 		return EINVAL;
    484       1.1      manu 	}
    485       1.1      manu 	SCARG(&bia, com) = com;
    486      1.20   thorpej 	/* XXX NJWLWP */
    487      1.22      fvdl 	return sys_ioctl(curlwp, &bia, retval);
    488       1.1      manu }
    489       1.1      manu 
    490       1.1      manu /*
    491      1.29     perry  * wrapper linux_sys_new_uname() -> linux_sys_uname()
    492       1.1      manu  */
    493      1.29     perry int
    494      1.37       dsl linux_sys_new_uname(struct lwp *l, const struct linux_sys_new_uname_args *uap, register_t *retval)
    495       1.1      manu {
    496      1.37       dsl 	return linux_sys_uname(l, (const void *)uap, retval);
    497       1.1      manu }
    498       1.1      manu 
    499       1.1      manu /*
    500      1.29     perry  * wrapper linux_sys_new_select() -> linux_sys_select()
    501       1.1      manu  */
    502      1.29     perry int
    503      1.37       dsl linux_sys_new_select(struct lwp *l, const struct linux_sys_new_select_args *uap, register_t *retval)
    504       1.1      manu {
    505      1.37       dsl 	return linux_sys_select(l, (const void *)uap, retval);
    506       1.1      manu }
    507      1.30      fvdl 
    508      1.30      fvdl int
    509      1.30      fvdl linux_usertrap(struct lwp *l, vaddr_t trapaddr, void *arg)
    510      1.30      fvdl {
    511      1.30      fvdl 	return 0;
    512      1.30      fvdl }
    513