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