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