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