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