Home | History | Annotate | Line # | Download | only in mips
linux_machdep.c revision 1.1.2.13
      1  1.1.2.13  nathanw /*	$NetBSD: linux_machdep.c,v 1.1.2.13 2002/08/01 02:44:16 nathanw Exp $ */
      2   1.1.2.2  nathanw 
      3   1.1.2.2  nathanw /*-
      4   1.1.2.2  nathanw  * Copyright (c) 1995, 2000, 2001 The NetBSD Foundation, Inc.
      5   1.1.2.2  nathanw  * All rights reserved.
      6   1.1.2.2  nathanw  *
      7   1.1.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1.2.2  nathanw  * by Frank van der Linden and Emmanuel Dreyfus.
      9   1.1.2.2  nathanw  *
     10   1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11   1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     12   1.1.2.2  nathanw  * are met:
     13   1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14   1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15   1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18   1.1.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19   1.1.2.2  nathanw  *    must display the following acknowledgement:
     20   1.1.2.2  nathanw  *	This product includes software developed by the NetBSD
     21   1.1.2.2  nathanw  *	Foundation, Inc. and its contributors.
     22   1.1.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24   1.1.2.2  nathanw  *    from this software without specific prior written permission.
     25   1.1.2.2  nathanw  *
     26   1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1.2.2  nathanw  */
     38   1.1.2.2  nathanw 
     39   1.1.2.5  nathanw #include <sys/cdefs.h>
     40  1.1.2.13  nathanw __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.1.2.13 2002/08/01 02:44:16 nathanw Exp $");
     41   1.1.2.5  nathanw 
     42   1.1.2.2  nathanw #include <sys/param.h>
     43   1.1.2.2  nathanw #include <sys/systm.h>
     44   1.1.2.2  nathanw #include <sys/signalvar.h>
     45   1.1.2.2  nathanw #include <sys/kernel.h>
     46   1.1.2.2  nathanw #include <sys/map.h>
     47   1.1.2.2  nathanw #include <sys/proc.h>
     48   1.1.2.2  nathanw #include <sys/user.h>
     49   1.1.2.2  nathanw #include <sys/buf.h>
     50   1.1.2.2  nathanw #include <sys/reboot.h>
     51   1.1.2.2  nathanw #include <sys/conf.h>
     52   1.1.2.2  nathanw #include <sys/exec.h>
     53   1.1.2.2  nathanw #include <sys/file.h>
     54   1.1.2.2  nathanw #include <sys/callout.h>
     55   1.1.2.2  nathanw #include <sys/malloc.h>
     56   1.1.2.2  nathanw #include <sys/mbuf.h>
     57   1.1.2.2  nathanw #include <sys/msgbuf.h>
     58   1.1.2.2  nathanw #include <sys/mount.h>
     59   1.1.2.2  nathanw #include <sys/vnode.h>
     60   1.1.2.2  nathanw #include <sys/device.h>
     61  1.1.2.10  nathanw #include <sys/sa.h>
     62   1.1.2.2  nathanw #include <sys/syscallargs.h>
     63   1.1.2.2  nathanw #include <sys/filedesc.h>
     64   1.1.2.2  nathanw #include <sys/exec_elf.h>
     65   1.1.2.2  nathanw #include <sys/disklabel.h>
     66   1.1.2.2  nathanw #include <sys/ioctl.h>
     67   1.1.2.3  nathanw #include <sys/sysctl.h>
     68   1.1.2.2  nathanw #include <miscfs/specfs/specdev.h>
     69   1.1.2.2  nathanw 
     70   1.1.2.2  nathanw #include <compat/linux/common/linux_types.h>
     71   1.1.2.2  nathanw #include <compat/linux/common/linux_signal.h>
     72   1.1.2.2  nathanw #include <compat/linux/common/linux_util.h>
     73   1.1.2.2  nathanw #include <compat/linux/common/linux_ioctl.h>
     74   1.1.2.2  nathanw #include <compat/linux/common/linux_hdio.h>
     75   1.1.2.2  nathanw #include <compat/linux/common/linux_exec.h>
     76   1.1.2.2  nathanw #include <compat/linux/common/linux_machdep.h>
     77   1.1.2.2  nathanw 
     78   1.1.2.2  nathanw #include <compat/linux/linux_syscallargs.h>
     79   1.1.2.2  nathanw 
     80   1.1.2.2  nathanw #include <machine/cpu.h>
     81   1.1.2.2  nathanw #include <machine/psl.h>
     82   1.1.2.2  nathanw #include <machine/reg.h>
     83   1.1.2.2  nathanw #include <machine/regnum.h>
     84   1.1.2.2  nathanw #include <machine/vmparam.h>
     85   1.1.2.2  nathanw #include <machine/locore.h>
     86   1.1.2.7  nathanw 
     87   1.1.2.6      wdk #include <mips/cache.h>
     88   1.1.2.2  nathanw 
     89   1.1.2.2  nathanw /*
     90   1.1.2.2  nathanw  * To see whether wscons is configured (for virtual console ioctl calls).
     91   1.1.2.2  nathanw  */
     92   1.1.2.2  nathanw #if defined(_KERNEL_OPT)
     93   1.1.2.2  nathanw #include "wsdisplay.h"
     94   1.1.2.2  nathanw #endif
     95   1.1.2.2  nathanw #if (NWSDISPLAY > 0)
     96   1.1.2.2  nathanw #include <dev/wscons/wsconsio.h>
     97   1.1.2.2  nathanw #include <dev/wscons/wsdisplay_usl_io.h>
     98   1.1.2.2  nathanw #endif
     99   1.1.2.2  nathanw 
    100   1.1.2.2  nathanw /*
    101   1.1.2.2  nathanw  * Set set up registers on exec.
    102   1.1.2.2  nathanw  * XXX not used at the moment since in sys/kern/exec_conf, LINUX_COMPAT
    103   1.1.2.2  nathanw  * entry uses NetBSD's native setregs instead of linux_setregs
    104   1.1.2.2  nathanw  */
    105   1.1.2.2  nathanw void
    106   1.1.2.6      wdk linux_setregs(l, pack, stack)
    107   1.1.2.6      wdk 	struct lwp *l;
    108   1.1.2.2  nathanw 	struct exec_package *pack;
    109   1.1.2.2  nathanw 	u_long stack;
    110   1.1.2.2  nathanw {
    111   1.1.2.6      wdk 	setregs(l, pack, stack);
    112   1.1.2.2  nathanw 	return;
    113   1.1.2.2  nathanw }
    114   1.1.2.2  nathanw 
    115   1.1.2.2  nathanw /*
    116   1.1.2.2  nathanw  * Send an interrupt to process.
    117   1.1.2.2  nathanw  *
    118   1.1.2.2  nathanw  * Adapted from sys/arch/mips/mips/mips_machdep.c
    119   1.1.2.2  nathanw  *
    120   1.1.2.2  nathanw  * XXX Does not work well yet with RT signals
    121   1.1.2.2  nathanw  *
    122   1.1.2.2  nathanw  */
    123   1.1.2.2  nathanw 
    124   1.1.2.2  nathanw void
    125  1.1.2.13  nathanw linux_sendsig(sig, mask, code)  /* XXX Check me */
    126   1.1.2.2  nathanw 	int sig;
    127   1.1.2.2  nathanw 	sigset_t *mask;
    128   1.1.2.2  nathanw 	u_long code;
    129   1.1.2.2  nathanw {
    130  1.1.2.12  nathanw 	struct lwp *l = curlwp;
    131   1.1.2.6      wdk 	struct proc *p = l->l_proc;
    132   1.1.2.2  nathanw 	struct linux_sigframe *fp;
    133   1.1.2.2  nathanw 	struct frame *f;
    134   1.1.2.2  nathanw 	int i,onstack;
    135  1.1.2.13  nathanw 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    136   1.1.2.2  nathanw 	struct linux_sigframe sf;
    137   1.1.2.2  nathanw 
    138   1.1.2.4  nathanw #ifdef DEBUG_LINUX
    139   1.1.2.2  nathanw 	printf("linux_sendsig()\n");
    140   1.1.2.4  nathanw #endif /* DEBUG_LINUX */
    141   1.1.2.6      wdk 	f = (struct frame *)l->l_md.md_regs;
    142   1.1.2.2  nathanw 
    143   1.1.2.2  nathanw 	/*
    144   1.1.2.2  nathanw 	 * Do we need to jump onto the signal stack?
    145   1.1.2.2  nathanw 	 */
    146   1.1.2.2  nathanw 	onstack =
    147   1.1.2.2  nathanw 	    (p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    148   1.1.2.2  nathanw 	    (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    149   1.1.2.2  nathanw 
    150   1.1.2.2  nathanw 	/*
    151   1.1.2.7  nathanw 	 * Signal stack is broken (see at the end of linux_sigreturn), so we do
    152   1.1.2.2  nathanw 	 * not use it yet. XXX fix this.
    153   1.1.2.2  nathanw 	 */
    154   1.1.2.2  nathanw 	onstack=0;
    155   1.1.2.2  nathanw 
    156   1.1.2.2  nathanw 	/*
    157   1.1.2.2  nathanw 	 * Allocate space for the signal handler context.
    158   1.1.2.2  nathanw 	 */
    159   1.1.2.2  nathanw 	if (onstack)
    160   1.1.2.2  nathanw 		fp = (struct linux_sigframe *)
    161   1.1.2.2  nathanw 		    ((caddr_t)p->p_sigctx.ps_sigstk.ss_sp
    162   1.1.2.2  nathanw 		    + p->p_sigctx.ps_sigstk.ss_size);
    163   1.1.2.2  nathanw 	else
    164   1.1.2.2  nathanw 		/* cast for _MIPS_BSD_API == _MIPS_BSD_API_LP32_64CLEAN case */
    165   1.1.2.2  nathanw 		fp = (struct linux_sigframe *)(u_int32_t)f->f_regs[SP];
    166   1.1.2.2  nathanw 
    167   1.1.2.4  nathanw 	/*
    168   1.1.2.4  nathanw 	 * Build stack frame for signal trampoline.
    169   1.1.2.4  nathanw 	 */
    170   1.1.2.2  nathanw 	memset(&sf, 0, sizeof sf);
    171   1.1.2.4  nathanw 
    172   1.1.2.4  nathanw 	/*
    173   1.1.2.4  nathanw 	 * This is the signal trampoline used by Linux, we don't use it,
    174   1.1.2.7  nathanw 	 * but we set it up in case an application expects it to be there
    175   1.1.2.4  nathanw 	 */
    176   1.1.2.2  nathanw 	sf.lsf_code[0] = 0x24020000;	/* li	v0, __NR_sigreturn	*/
    177   1.1.2.4  nathanw 	sf.lsf_code[1] = 0x0000000c;	/* syscall			*/
    178   1.1.2.4  nathanw 
    179   1.1.2.8  nathanw 	native_to_linux_sigset(&sf.lsf_mask, mask);
    180   1.1.2.7  nathanw 	for (i=0; i<32; i++) {
    181   1.1.2.2  nathanw 		sf.lsf_sc.lsc_regs[i] = f->f_regs[i];
    182   1.1.2.7  nathanw 	}
    183   1.1.2.2  nathanw 	sf.lsf_sc.lsc_mdhi = f->f_regs[MULHI];
    184   1.1.2.2  nathanw 	sf.lsf_sc.lsc_mdlo = f->f_regs[MULLO];
    185   1.1.2.2  nathanw 	sf.lsf_sc.lsc_pc = f->f_regs[PC];
    186   1.1.2.9  nathanw 	sf.lsf_sc.lsc_status = f->f_regs[SR];
    187   1.1.2.2  nathanw 	sf.lsf_sc.lsc_cause = f->f_regs[CAUSE];
    188   1.1.2.9  nathanw 	sf.lsf_sc.lsc_badvaddr = f->f_regs[BADVADDR];
    189   1.1.2.2  nathanw 
    190   1.1.2.2  nathanw 	/*
    191   1.1.2.2  nathanw 	 * Save signal stack.  XXX broken
    192   1.1.2.2  nathanw 	 */
    193   1.1.2.2  nathanw 	/* kregs.sc_onstack = p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK; */
    194   1.1.2.2  nathanw 
    195   1.1.2.2  nathanw 	/*
    196   1.1.2.2  nathanw 	 * Install the sigframe onto the stack
    197   1.1.2.2  nathanw 	 */
    198   1.1.2.2  nathanw 	fp -= sizeof(struct linux_sigframe);
    199   1.1.2.2  nathanw 	if (copyout(&sf, fp, sizeof(sf)) != 0) {
    200   1.1.2.2  nathanw 		/*
    201   1.1.2.2  nathanw 		 * Process has trashed its stack; give it an illegal
    202   1.1.2.2  nathanw 		 * instruction to halt it in its tracks.
    203   1.1.2.2  nathanw 		 */
    204   1.1.2.4  nathanw #ifdef DEBUG_LINUX
    205   1.1.2.4  nathanw 		printf("linux_sendsig: stack trashed\n");
    206   1.1.2.4  nathanw #endif /* DEBUG_LINUX */
    207   1.1.2.6      wdk 		sigexit(l, SIGILL);
    208   1.1.2.2  nathanw 		/* NOTREACHED */
    209   1.1.2.2  nathanw 	}
    210   1.1.2.2  nathanw 
    211   1.1.2.2  nathanw 	/* Set up the registers to return to sigcode. */
    212   1.1.2.9  nathanw 	f->f_regs[A0] = native_to_linux_signo[sig];
    213   1.1.2.2  nathanw 	f->f_regs[A1] = 0;
    214   1.1.2.4  nathanw 	f->f_regs[A2] = (unsigned long)&fp->lsf_sc;
    215   1.1.2.2  nathanw 
    216   1.1.2.4  nathanw #ifdef DEBUG_LINUX
    217   1.1.2.4  nathanw 	printf("sigcontext is at %p\n", &fp->lsf_sc);
    218   1.1.2.4  nathanw #endif /* DEBUG_LINUX */
    219   1.1.2.2  nathanw 
    220   1.1.2.4  nathanw 	f->f_regs[SP] = (unsigned long)fp;
    221   1.1.2.2  nathanw 	/* Signal trampoline code is at base of user stack. */
    222   1.1.2.4  nathanw 	f->f_regs[RA] = (unsigned long)p->p_sigctx.ps_sigcode;
    223   1.1.2.4  nathanw 	f->f_regs[T9] = (unsigned long)catcher;
    224   1.1.2.4  nathanw 	f->f_regs[PC] = (unsigned long)catcher;
    225   1.1.2.2  nathanw 
    226   1.1.2.2  nathanw 	/* Remember that we're now on the signal stack. */
    227   1.1.2.2  nathanw 	if (onstack)
    228   1.1.2.2  nathanw 		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
    229   1.1.2.2  nathanw 
    230   1.1.2.2  nathanw 	return;
    231   1.1.2.2  nathanw }
    232   1.1.2.2  nathanw 
    233   1.1.2.2  nathanw /*
    234   1.1.2.2  nathanw  * System call to cleanup state after a signal
    235   1.1.2.2  nathanw  * has been taken.  Reset signal mask and
    236   1.1.2.2  nathanw  * stack state from context left by sendsig (above).
    237   1.1.2.2  nathanw  */
    238   1.1.2.2  nathanw int
    239   1.1.2.6      wdk linux_sys_sigreturn(l, v, retval)
    240   1.1.2.6      wdk 	struct lwp *l;
    241   1.1.2.2  nathanw 	void *v;
    242   1.1.2.2  nathanw 	register_t *retval;
    243   1.1.2.2  nathanw {
    244   1.1.2.2  nathanw 	struct linux_sys_sigreturn_args /* {
    245   1.1.2.7  nathanw 		syscallarg(struct linux_sigframe *) sf;
    246   1.1.2.2  nathanw 	} */ *uap = v;
    247   1.1.2.6      wdk 	struct proc *p = l->l_proc;
    248   1.1.2.2  nathanw 	struct linux_sigframe *sf, ksf;
    249   1.1.2.2  nathanw 	struct frame *f;
    250   1.1.2.2  nathanw 	sigset_t mask;
    251   1.1.2.2  nathanw 	int i, error;
    252   1.1.2.2  nathanw 
    253   1.1.2.4  nathanw #ifdef DEBUG_LINUX
    254   1.1.2.2  nathanw 	printf("linux_sys_sigreturn()\n");
    255   1.1.2.4  nathanw #endif /* DEBUG_LINUX */
    256   1.1.2.4  nathanw 
    257   1.1.2.2  nathanw 	/*
    258   1.1.2.2  nathanw 	 * The trampoline code hands us the context.
    259   1.1.2.2  nathanw 	 * It is unsafe to keep track of it ourselves, in the event that a
    260   1.1.2.2  nathanw 	 * program jumps out of a signal handler.
    261   1.1.2.2  nathanw 	 */
    262   1.1.2.7  nathanw 	sf = SCARG(uap, sf);
    263   1.1.2.2  nathanw 
    264   1.1.2.2  nathanw 	if ((error = copyin(sf, &ksf, sizeof(ksf))) != 0)
    265   1.1.2.2  nathanw 		return (error);
    266   1.1.2.2  nathanw 
    267   1.1.2.2  nathanw 	/* Restore the register context. */
    268   1.1.2.6      wdk 	f = (struct frame *)l->l_md.md_regs;
    269   1.1.2.2  nathanw 	for (i=0; i<32; i++)
    270   1.1.2.7  nathanw 		f->f_regs[i] = ksf.lsf_sc.lsc_regs[i];
    271   1.1.2.7  nathanw 	f->f_regs[MULLO] = ksf.lsf_sc.lsc_mdlo;
    272   1.1.2.7  nathanw 	f->f_regs[MULHI] = ksf.lsf_sc.lsc_mdhi;
    273   1.1.2.7  nathanw 	f->f_regs[PC] = ksf.lsf_sc.lsc_pc;
    274   1.1.2.7  nathanw 	f->f_regs[BADVADDR] = ksf.lsf_sc.lsc_badvaddr;
    275   1.1.2.7  nathanw 	f->f_regs[CAUSE] = ksf.lsf_sc.lsc_cause;
    276   1.1.2.2  nathanw 
    277   1.1.2.2  nathanw 	/* Restore signal stack. */
    278   1.1.2.2  nathanw 	p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
    279   1.1.2.2  nathanw 
    280   1.1.2.2  nathanw 	/* Restore signal mask. */
    281   1.1.2.8  nathanw 	linux_to_native_sigset(&mask, (linux_sigset_t *)&ksf.lsf_mask);
    282   1.1.2.2  nathanw 	(void)sigprocmask1(p, SIG_SETMASK, &mask, 0);
    283   1.1.2.2  nathanw 
    284   1.1.2.2  nathanw 	return (EJUSTRETURN);
    285   1.1.2.2  nathanw }
    286   1.1.2.2  nathanw 
    287   1.1.2.2  nathanw 
    288   1.1.2.2  nathanw int
    289   1.1.2.6      wdk linux_sys_rt_sigreturn(l, v, retval)
    290   1.1.2.6      wdk 	struct lwp *l;
    291   1.1.2.2  nathanw 	void *v;
    292   1.1.2.2  nathanw 	register_t *retval;
    293   1.1.2.2  nathanw {
    294   1.1.2.6      wdk 	return (ENOSYS);
    295   1.1.2.2  nathanw }
    296   1.1.2.2  nathanw 
    297   1.1.2.2  nathanw 
    298   1.1.2.2  nathanw #if 0
    299   1.1.2.2  nathanw int
    300   1.1.2.6      wdk linux_sys_modify_ldt(l, v, retval)
    301   1.1.2.6      wdk 	struct lwp *l;
    302   1.1.2.2  nathanw 	void *v;
    303   1.1.2.2  nathanw 	register_t *retval;
    304   1.1.2.2  nathanw {
    305   1.1.2.2  nathanw 	/*
    306   1.1.2.2  nathanw 	 * This syscall is not implemented in Linux/Mips: we should not
    307   1.1.2.2  nathanw 	 * be here
    308   1.1.2.2  nathanw 	 */
    309   1.1.2.2  nathanw #ifdef DEBUG_LINUX
    310   1.1.2.2  nathanw 	printf("linux_sys_modify_ldt: should not be here.\n");
    311   1.1.2.4  nathanw #endif /* DEBUG_LINUX */
    312   1.1.2.2  nathanw   return 0;
    313   1.1.2.2  nathanw }
    314   1.1.2.2  nathanw #endif
    315   1.1.2.2  nathanw 
    316   1.1.2.2  nathanw /*
    317   1.1.2.2  nathanw  * major device numbers remapping
    318   1.1.2.2  nathanw  */
    319   1.1.2.2  nathanw dev_t
    320   1.1.2.8  nathanw linux_fakedev(dev, raw)
    321   1.1.2.2  nathanw 	dev_t dev;
    322   1.1.2.8  nathanw 	int raw;
    323   1.1.2.2  nathanw {
    324  1.1.2.11  nathanw 	/* XXX write me */
    325  1.1.2.11  nathanw 	return dev;
    326   1.1.2.2  nathanw }
    327   1.1.2.2  nathanw 
    328   1.1.2.2  nathanw /*
    329   1.1.2.2  nathanw  * We come here in a last attempt to satisfy a Linux ioctl() call
    330   1.1.2.2  nathanw  */
    331   1.1.2.2  nathanw int
    332   1.1.2.2  nathanw linux_machdepioctl(p, v, retval)
    333   1.1.2.2  nathanw 	struct proc *p;
    334   1.1.2.2  nathanw 	void *v;
    335   1.1.2.2  nathanw 	register_t *retval;
    336   1.1.2.2  nathanw {
    337   1.1.2.2  nathanw 	return 0;
    338   1.1.2.2  nathanw }
    339   1.1.2.2  nathanw 
    340   1.1.2.2  nathanw /*
    341   1.1.2.2  nathanw  * See above. If a root process tries to set access to an I/O port,
    342   1.1.2.2  nathanw  * just let it have the whole range.
    343   1.1.2.2  nathanw  */
    344   1.1.2.2  nathanw int
    345   1.1.2.6      wdk linux_sys_ioperm(l, v, retval)
    346   1.1.2.6      wdk 	struct lwp *l;
    347   1.1.2.2  nathanw 	void *v;
    348   1.1.2.2  nathanw 	register_t *retval;
    349   1.1.2.2  nathanw {
    350   1.1.2.2  nathanw 	/*
    351   1.1.2.2  nathanw 	 * This syscall is not implemented in Linux/Mips: we should not be here
    352   1.1.2.2  nathanw 	 */
    353   1.1.2.2  nathanw #ifdef DEBUG_LINUX
    354   1.1.2.2  nathanw 	printf("linux_sys_ioperm: should not be here.\n");
    355   1.1.2.4  nathanw #endif /* DEBUG_LINUX */
    356   1.1.2.2  nathanw 	return 0;
    357   1.1.2.2  nathanw }
    358   1.1.2.2  nathanw 
    359   1.1.2.2  nathanw /*
    360   1.1.2.2  nathanw  * wrapper linux_sys_new_uname() -> linux_sys_uname()
    361   1.1.2.2  nathanw  */
    362   1.1.2.2  nathanw int
    363   1.1.2.6      wdk linux_sys_new_uname(l, v, retval)
    364   1.1.2.6      wdk 	struct lwp *l;
    365   1.1.2.2  nathanw 	void *v;
    366   1.1.2.2  nathanw 	register_t *retval;
    367   1.1.2.2  nathanw {
    368   1.1.2.4  nathanw /*
    369   1.1.2.4  nathanw  * Use this if you want to try Linux emulation with a glibc-2.2
    370   1.1.2.4  nathanw  * or higher. Note that signals will not work
    371   1.1.2.4  nathanw  */
    372   1.1.2.4  nathanw #if 0
    373   1.1.2.4  nathanw         struct linux_sys_uname_args /* {
    374   1.1.2.4  nathanw                 syscallarg(struct linux_utsname *) up;
    375   1.1.2.4  nathanw         } */ *uap = v;
    376   1.1.2.4  nathanw         struct linux_utsname luts;
    377   1.1.2.4  nathanw 
    378   1.1.2.4  nathanw         strncpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname));
    379   1.1.2.4  nathanw         strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
    380   1.1.2.4  nathanw         strncpy(luts.l_release, "2.4.0", sizeof(luts.l_release));
    381   1.1.2.4  nathanw         strncpy(luts.l_version, linux_version, sizeof(luts.l_version));
    382   1.1.2.4  nathanw         strncpy(luts.l_machine, machine, sizeof(luts.l_machine));
    383   1.1.2.4  nathanw         strncpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
    384   1.1.2.4  nathanw 
    385   1.1.2.4  nathanw         return copyout(&luts, SCARG(uap, up), sizeof(luts));
    386   1.1.2.4  nathanw #else
    387   1.1.2.6      wdk 	return linux_sys_uname(l, v, retval);
    388   1.1.2.4  nathanw #endif
    389   1.1.2.2  nathanw }
    390   1.1.2.2  nathanw 
    391   1.1.2.2  nathanw /*
    392   1.1.2.6      wdk  * In Linux, cacheflush is currently implemented
    393   1.1.2.2  nathanw  * as a whole cache flush (arguments are ignored)
    394   1.1.2.2  nathanw  * we emulate this broken beahior.
    395   1.1.2.2  nathanw  */
    396   1.1.2.2  nathanw int
    397   1.1.2.6      wdk linux_sys_cacheflush(l, v, retval)
    398   1.1.2.6      wdk 	struct lwp *l;
    399   1.1.2.2  nathanw 	void *v;
    400   1.1.2.2  nathanw 	register_t *retval;
    401   1.1.2.2  nathanw {
    402   1.1.2.6      wdk 	mips_icache_sync_all();
    403   1.1.2.6      wdk 	mips_dcache_wbinv_all();
    404   1.1.2.2  nathanw 	return 0;
    405   1.1.2.2  nathanw }
    406   1.1.2.2  nathanw 
    407   1.1.2.3  nathanw /*
    408   1.1.2.3  nathanw  * This system call is depecated in Linux, but
    409   1.1.2.3  nathanw  * some binaries and some libraries use it.
    410   1.1.2.3  nathanw  */
    411   1.1.2.3  nathanw int
    412   1.1.2.6      wdk linux_sys_sysmips(l, v, retval)
    413   1.1.2.6      wdk 	struct lwp *l;
    414   1.1.2.3  nathanw 	void *v;
    415   1.1.2.3  nathanw 	register_t *retval;
    416   1.1.2.3  nathanw {
    417   1.1.2.3  nathanw 	struct linux_sys_sysmips_args {
    418   1.1.2.3  nathanw 		syscallarg(int) cmd;
    419   1.1.2.3  nathanw 		syscallarg(int) arg1;
    420   1.1.2.3  nathanw 		syscallarg(int) arg2;
    421   1.1.2.3  nathanw 		syscallarg(int) arg3;
    422   1.1.2.3  nathanw 	} *uap = v;
    423   1.1.2.6      wdk 	struct proc *p = l->l_proc;
    424   1.1.2.3  nathanw 	int error;
    425   1.1.2.3  nathanw 
    426   1.1.2.3  nathanw 	switch (SCARG(uap, cmd)) {
    427   1.1.2.3  nathanw 	case LINUX_SETNAME: {
    428   1.1.2.3  nathanw 		char nodename [LINUX___NEW_UTS_LEN + 1];
    429   1.1.2.3  nathanw 		int name;
    430   1.1.2.3  nathanw 		size_t len;
    431   1.1.2.3  nathanw 
    432   1.1.2.3  nathanw 		if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    433   1.1.2.3  nathanw 			return error;
    434   1.1.2.3  nathanw 		if ((error = copyinstr((char *)SCARG(uap, arg1), nodename,
    435   1.1.2.3  nathanw 		    LINUX___NEW_UTS_LEN, &len)) != 0)
    436   1.1.2.3  nathanw 			return error;
    437   1.1.2.3  nathanw 
    438   1.1.2.3  nathanw 		name = KERN_HOSTNAME;
    439   1.1.2.3  nathanw 		return (kern_sysctl(&name, 1, 0, 0, nodename, len, p));
    440   1.1.2.3  nathanw 
    441   1.1.2.3  nathanw 		break;
    442   1.1.2.3  nathanw 	}
    443   1.1.2.4  nathanw 	case LINUX_MIPS_ATOMIC_SET: {
    444   1.1.2.4  nathanw 		void *addr;
    445   1.1.2.4  nathanw 		int s;
    446   1.1.2.4  nathanw 
    447   1.1.2.4  nathanw 		addr = (void *)SCARG(uap, arg1);
    448   1.1.2.4  nathanw 
    449   1.1.2.4  nathanw 		if ((uvm_useracc((caddr_t)addr, sizeof(int),
    450   1.1.2.4  nathanw 		    B_READ | B_WRITE)) != 1)
    451   1.1.2.4  nathanw 			return EFAULT;
    452   1.1.2.4  nathanw 
    453   1.1.2.4  nathanw 		s = splhigh();
    454   1.1.2.4  nathanw 		/*
    455   1.1.2.4  nathanw 		 * No error testing here. This is bad, but Linux does
    456   1.1.2.4  nathanw 		 * it like this. The source aknowledge "This is broken"
    457   1.1.2.4  nathanw 		 * in a comment...
    458   1.1.2.4  nathanw 		 */
    459   1.1.2.4  nathanw 		*retval = (register_t)fubyte(addr);
    460   1.1.2.4  nathanw 		error = subyte(addr, SCARG(uap, arg2));
    461   1.1.2.4  nathanw 		splx(s);
    462   1.1.2.4  nathanw 
    463   1.1.2.4  nathanw 		return 0;
    464   1.1.2.3  nathanw 		break;
    465   1.1.2.4  nathanw 	}
    466   1.1.2.3  nathanw 	case LINUX_MIPS_FIXADE:		/* XXX not implemented */
    467   1.1.2.3  nathanw 		break;
    468   1.1.2.3  nathanw 	case LINUX_FLUSH_CACHE:
    469   1.1.2.6      wdk 		mips_icache_sync_all();
    470   1.1.2.6      wdk 		mips_dcache_wbinv_all();
    471   1.1.2.3  nathanw 		break;
    472   1.1.2.3  nathanw 	case LINUX_MIPS_RDNVRAM:
    473   1.1.2.3  nathanw 		return EIO;
    474   1.1.2.3  nathanw 		break;
    475   1.1.2.3  nathanw 	default:
    476   1.1.2.3  nathanw 		return EINVAL;
    477   1.1.2.3  nathanw 		break;
    478   1.1.2.3  nathanw 	}
    479   1.1.2.4  nathanw #ifdef DEBUG_LINUX
    480   1.1.2.3  nathanw 	printf("linux_sys_sysmips(): unimplemented command %d\n",
    481   1.1.2.3  nathanw 	    SCARG(uap,cmd));
    482   1.1.2.3  nathanw #endif /* DEBUG_LINUX */
    483   1.1.2.3  nathanw 	return 0;
    484   1.1.2.3  nathanw }
    485