Home | History | Annotate | Line # | Download | only in mips
linux_machdep.c revision 1.32.2.1
      1  1.32.2.1       mjf /*	$NetBSD: linux_machdep.c,v 1.32.2.1 2007/11/19 00:47:23 mjf 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     lukem 
     39       1.5     lukem #include <sys/cdefs.h>
     40  1.32.2.1       mjf __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.32.2.1 2007/11/19 00:47:23 mjf Exp $");
     41       1.1      manu 
     42       1.1      manu #include <sys/param.h>
     43       1.1      manu #include <sys/systm.h>
     44       1.1      manu #include <sys/signalvar.h>
     45       1.1      manu #include <sys/kernel.h>
     46       1.1      manu #include <sys/proc.h>
     47       1.1      manu #include <sys/user.h>
     48       1.1      manu #include <sys/buf.h>
     49       1.1      manu #include <sys/reboot.h>
     50       1.1      manu #include <sys/conf.h>
     51       1.1      manu #include <sys/exec.h>
     52       1.1      manu #include <sys/file.h>
     53       1.1      manu #include <sys/callout.h>
     54       1.1      manu #include <sys/malloc.h>
     55       1.1      manu #include <sys/mbuf.h>
     56       1.1      manu #include <sys/msgbuf.h>
     57       1.1      manu #include <sys/mount.h>
     58       1.1      manu #include <sys/vnode.h>
     59       1.1      manu #include <sys/device.h>
     60       1.1      manu #include <sys/syscallargs.h>
     61       1.1      manu #include <sys/filedesc.h>
     62       1.1      manu #include <sys/exec_elf.h>
     63       1.1      manu #include <sys/disklabel.h>
     64       1.1      manu #include <sys/ioctl.h>
     65       1.2      manu #include <sys/sysctl.h>
     66      1.26      yamt #include <sys/kauth.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.32        ad #include <sys/cpu.h>
     80       1.1      manu #include <machine/psl.h>
     81       1.1      manu #include <machine/reg.h>
     82       1.1      manu #include <machine/regnum.h>
     83       1.1      manu #include <machine/vmparam.h>
     84       1.1      manu #include <machine/locore.h>
     85       1.1      manu 
     86       1.7      manu #include <mips/cache.h>
     87       1.7      manu 
     88       1.1      manu /*
     89       1.1      manu  * To see whether wscons is configured (for virtual console ioctl calls).
     90       1.1      manu  */
     91       1.1      manu #if defined(_KERNEL_OPT)
     92       1.1      manu #include "wsdisplay.h"
     93       1.1      manu #endif
     94       1.1      manu #if (NWSDISPLAY > 0)
     95       1.1      manu #include <dev/wscons/wsconsio.h>
     96       1.1      manu #include <dev/wscons/wsdisplay_usl_io.h>
     97       1.1      manu #endif
     98       1.1      manu 
     99      1.22     perry /*
    100       1.1      manu  * Set set up registers on exec.
    101       1.1      manu  * XXX not used at the moment since in sys/kern/exec_conf, LINUX_COMPAT
    102       1.1      manu  * entry uses NetBSD's native setregs instead of linux_setregs
    103       1.1      manu  */
    104       1.1      manu void
    105      1.22     perry linux_setregs(l, pack, stack)
    106      1.17   thorpej 	struct lwp *l;
    107       1.1      manu 	struct exec_package *pack;
    108       1.1      manu 	u_long stack;
    109      1.22     perry {
    110      1.17   thorpej 	setregs(l, pack, stack);
    111       1.1      manu 	return;
    112       1.1      manu }
    113       1.1      manu 
    114       1.1      manu /*
    115       1.1      manu  * Send an interrupt to process.
    116       1.1      manu  *
    117       1.1      manu  * Adapted from sys/arch/mips/mips/mips_machdep.c
    118       1.1      manu  *
    119       1.1      manu  * XXX Does not work well yet with RT signals
    120       1.1      manu  *
    121       1.1      manu  */
    122       1.1      manu 
    123       1.1      manu void
    124      1.21      manu linux_sendsig(ksi, mask)
    125      1.21      manu 	const ksiginfo_t *ksi;
    126      1.19    simonb 	const sigset_t *mask;
    127       1.1      manu {
    128      1.21      manu 	const int sig = ksi->ksi_signo;
    129      1.17   thorpej 	struct lwp *l = curlwp;
    130      1.17   thorpej 	struct proc *p = l->l_proc;
    131       1.1      manu 	struct linux_sigframe *fp;
    132       1.1      manu 	struct frame *f;
    133      1.29        ad 	int i, onstack, error;
    134      1.15   thorpej 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    135       1.1      manu 	struct linux_sigframe sf;
    136       1.1      manu 
    137       1.4      manu #ifdef DEBUG_LINUX
    138       1.1      manu 	printf("linux_sendsig()\n");
    139       1.4      manu #endif /* DEBUG_LINUX */
    140      1.17   thorpej 	f = (struct frame *)l->l_md.md_regs;
    141       1.1      manu 
    142      1.22     perry 	/*
    143      1.22     perry 	 * Do we need to jump onto the signal stack?
    144       1.1      manu 	 */
    145       1.1      manu 	onstack =
    146      1.29        ad 	    (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    147       1.1      manu 	    (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    148       1.1      manu 
    149       1.1      manu 	/*
    150       1.6      manu 	 * Signal stack is broken (see at the end of linux_sigreturn), so we do
    151       1.1      manu 	 * not use it yet. XXX fix this.
    152       1.1      manu 	 */
    153       1.1      manu 	onstack=0;
    154       1.1      manu 
    155      1.22     perry 	/*
    156      1.22     perry 	 * Allocate space for the signal handler context.
    157       1.1      manu 	 */
    158       1.1      manu 	if (onstack)
    159       1.1      manu 		fp = (struct linux_sigframe *)
    160      1.31  christos 		    ((uint8_t *)l->l_sigstk.ss_sp
    161      1.29        ad 		    + l->l_sigstk.ss_size);
    162       1.1      manu 	else
    163       1.1      manu 		/* cast for _MIPS_BSD_API == _MIPS_BSD_API_LP32_64CLEAN case */
    164      1.21      manu 		fp = (struct linux_sigframe *)(u_int32_t)f->f_regs[_R_SP];
    165       1.1      manu 
    166      1.22     perry 	/*
    167      1.22     perry 	 * Build stack frame for signal trampoline.
    168       1.4      manu 	 */
    169       1.1      manu 	memset(&sf, 0, sizeof sf);
    170       1.4      manu 
    171       1.4      manu 	/*
    172       1.4      manu 	 * This is the signal trampoline used by Linux, we don't use it,
    173       1.6      manu 	 * but we set it up in case an application expects it to be there
    174       1.4      manu 	 */
    175       1.1      manu 	sf.lsf_code[0] = 0x24020000;	/* li	v0, __NR_sigreturn	*/
    176       1.4      manu 	sf.lsf_code[1] = 0x0000000c;	/* syscall			*/
    177       1.4      manu 
    178      1.11     rafal 	native_to_linux_sigset(&sf.lsf_mask, mask);
    179       1.8      manu 	for (i=0; i<32; i++) {
    180       1.1      manu 		sf.lsf_sc.lsc_regs[i] = f->f_regs[i];
    181       1.8      manu 	}
    182      1.21      manu 	sf.lsf_sc.lsc_mdhi = f->f_regs[_R_MULHI];
    183      1.21      manu 	sf.lsf_sc.lsc_mdlo = f->f_regs[_R_MULLO];
    184      1.21      manu 	sf.lsf_sc.lsc_pc = f->f_regs[_R_PC];
    185      1.21      manu 	sf.lsf_sc.lsc_status = f->f_regs[_R_SR];
    186      1.21      manu 	sf.lsf_sc.lsc_cause = f->f_regs[_R_CAUSE];
    187      1.21      manu 	sf.lsf_sc.lsc_badvaddr = f->f_regs[_R_BADVADDR];
    188      1.29        ad 	sendsig_reset(l, sig);
    189       1.1      manu 
    190      1.22     perry 	/*
    191       1.1      manu 	 * Save signal stack.  XXX broken
    192       1.1      manu 	 */
    193      1.29        ad 	/* kregs.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK; */
    194       1.1      manu 
    195       1.1      manu 	/*
    196       1.1      manu 	 * Install the sigframe onto the stack
    197       1.1      manu 	 */
    198       1.1      manu 	fp -= sizeof(struct linux_sigframe);
    199      1.29        ad 	mutex_exit(&p->p_smutex);
    200      1.31  christos 	error = copyout(&sf, fp, sizeof(sf));
    201      1.29        ad 	mutex_enter(&p->p_smutex);
    202      1.29        ad 
    203      1.29        ad 	if (error != 0) {
    204       1.1      manu 		/*
    205       1.1      manu 		 * Process has trashed its stack; give it an illegal
    206       1.1      manu 		 * instruction to halt it in its tracks.
    207       1.1      manu 		 */
    208       1.4      manu #ifdef DEBUG_LINUX
    209       1.4      manu 		printf("linux_sendsig: stack trashed\n");
    210       1.4      manu #endif /* DEBUG_LINUX */
    211      1.17   thorpej 		sigexit(l, SIGILL);
    212       1.1      manu 		/* NOTREACHED */
    213       1.1      manu 	}
    214       1.1      manu 
    215       1.1      manu 	/* Set up the registers to return to sigcode. */
    216      1.21      manu 	f->f_regs[_R_A0] = native_to_linux_signo[sig];
    217      1.21      manu 	f->f_regs[_R_A1] = 0;
    218      1.21      manu 	f->f_regs[_R_A2] = (unsigned long)&fp->lsf_sc;
    219       1.1      manu 
    220       1.4      manu #ifdef DEBUG_LINUX
    221       1.4      manu 	printf("sigcontext is at %p\n", &fp->lsf_sc);
    222       1.4      manu #endif /* DEBUG_LINUX */
    223       1.1      manu 
    224      1.21      manu 	f->f_regs[_R_SP] = (unsigned long)fp;
    225       1.1      manu 	/* Signal trampoline code is at base of user stack. */
    226      1.21      manu 	f->f_regs[_R_RA] = (unsigned long)p->p_sigctx.ps_sigcode;
    227      1.21      manu 	f->f_regs[_R_T9] = (unsigned long)catcher;
    228      1.21      manu 	f->f_regs[_R_PC] = (unsigned long)catcher;
    229       1.1      manu 
    230       1.1      manu 	/* Remember that we're now on the signal stack. */
    231       1.1      manu 	if (onstack)
    232      1.29        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    233       1.8      manu 
    234       1.1      manu 	return;
    235       1.1      manu }
    236       1.1      manu 
    237       1.1      manu /*
    238       1.1      manu  * System call to cleanup state after a signal
    239       1.1      manu  * has been taken.  Reset signal mask and
    240       1.1      manu  * stack state from context left by sendsig (above).
    241       1.1      manu  */
    242       1.1      manu int
    243      1.17   thorpej linux_sys_sigreturn(l, v, retval)
    244      1.17   thorpej 	struct lwp *l;
    245       1.1      manu 	void *v;
    246       1.1      manu 	register_t *retval;
    247       1.1      manu {
    248       1.1      manu 	struct linux_sys_sigreturn_args /* {
    249       1.8      manu 		syscallarg(struct linux_sigframe *) sf;
    250       1.1      manu 	} */ *uap = v;
    251      1.17   thorpej 	struct proc *p = l->l_proc;
    252       1.1      manu 	struct linux_sigframe *sf, ksf;
    253       1.1      manu 	struct frame *f;
    254       1.1      manu 	sigset_t mask;
    255       1.1      manu 	int i, error;
    256       1.1      manu 
    257       1.4      manu #ifdef DEBUG_LINUX
    258       1.1      manu 	printf("linux_sys_sigreturn()\n");
    259       1.4      manu #endif /* DEBUG_LINUX */
    260       1.4      manu 
    261       1.1      manu 	/*
    262       1.1      manu 	 * The trampoline code hands us the context.
    263       1.1      manu 	 * It is unsafe to keep track of it ourselves, in the event that a
    264       1.1      manu 	 * program jumps out of a signal handler.
    265       1.1      manu 	 */
    266      1.22     perry 	sf = SCARG(uap, sf);
    267       1.1      manu 
    268       1.1      manu 	if ((error = copyin(sf, &ksf, sizeof(ksf))) != 0)
    269       1.1      manu 		return (error);
    270       1.1      manu 
    271       1.1      manu 	/* Restore the register context. */
    272      1.17   thorpej 	f = (struct frame *)l->l_md.md_regs;
    273       1.1      manu 	for (i=0; i<32; i++)
    274       1.8      manu 		f->f_regs[i] = ksf.lsf_sc.lsc_regs[i];
    275      1.21      manu 	f->f_regs[_R_MULLO] = ksf.lsf_sc.lsc_mdlo;
    276      1.21      manu 	f->f_regs[_R_MULHI] = ksf.lsf_sc.lsc_mdhi;
    277      1.21      manu 	f->f_regs[_R_PC] = ksf.lsf_sc.lsc_pc;
    278      1.21      manu 	f->f_regs[_R_BADVADDR] = ksf.lsf_sc.lsc_badvaddr;
    279      1.21      manu 	f->f_regs[_R_CAUSE] = ksf.lsf_sc.lsc_cause;
    280       1.1      manu 
    281      1.29        ad 	mutex_enter(&p->p_smutex);
    282      1.29        ad 
    283       1.1      manu 	/* Restore signal stack. */
    284      1.29        ad 	l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    285       1.1      manu 
    286       1.1      manu 	/* Restore signal mask. */
    287      1.11     rafal 	linux_to_native_sigset(&mask, (linux_sigset_t *)&ksf.lsf_mask);
    288      1.29        ad 	(void)sigprocmask1(l, SIG_SETMASK, &mask, 0);
    289      1.29        ad 
    290      1.29        ad 	mutex_exit(&p->p_smutex);
    291       1.1      manu 
    292       1.1      manu 	return (EJUSTRETURN);
    293       1.1      manu }
    294       1.1      manu 
    295       1.1      manu 
    296       1.1      manu int
    297      1.22     perry linux_sys_rt_sigreturn(l, v, retval)
    298      1.17   thorpej 	struct lwp *l;
    299       1.1      manu 	void *v;
    300       1.1      manu 	register_t *retval;
    301       1.1      manu {
    302      1.17   thorpej 	return (ENOSYS);
    303       1.1      manu }
    304       1.1      manu 
    305       1.1      manu 
    306       1.1      manu #if 0
    307       1.1      manu int
    308      1.17   thorpej linux_sys_modify_ldt(l, v, retval)
    309      1.17   thorpej 	struct lwp *l;
    310       1.1      manu 	void *v;
    311       1.1      manu 	register_t *retval;
    312       1.1      manu {
    313      1.22     perry 	/*
    314       1.1      manu 	 * This syscall is not implemented in Linux/Mips: we should not
    315       1.1      manu 	 * be here
    316       1.1      manu 	 */
    317       1.1      manu #ifdef DEBUG_LINUX
    318      1.22     perry 	printf("linux_sys_modify_ldt: should not be here.\n");
    319       1.4      manu #endif /* DEBUG_LINUX */
    320       1.1      manu   return 0;
    321       1.1      manu }
    322       1.1      manu #endif
    323       1.1      manu 
    324      1.22     perry /*
    325       1.1      manu  * major device numbers remapping
    326       1.1      manu  */
    327       1.1      manu dev_t
    328      1.10  christos linux_fakedev(dev, raw)
    329       1.1      manu 	dev_t dev;
    330      1.10  christos 	int raw;
    331       1.1      manu {
    332      1.14  jdolecek 	/* XXX write me */
    333      1.14  jdolecek 	return dev;
    334       1.1      manu }
    335       1.1      manu 
    336       1.1      manu /*
    337       1.1      manu  * We come here in a last attempt to satisfy a Linux ioctl() call
    338       1.1      manu  */
    339       1.1      manu int
    340      1.31  christos linux_machdepioctl(l, v, retval)
    341      1.31  christos 	struct lwp *l;
    342       1.1      manu 	void *v;
    343       1.1      manu 	register_t *retval;
    344      1.22     perry {
    345       1.1      manu 	return 0;
    346       1.1      manu }
    347       1.1      manu 
    348       1.1      manu /*
    349       1.1      manu  * See above. If a root process tries to set access to an I/O port,
    350       1.1      manu  * just let it have the whole range.
    351       1.1      manu  */
    352       1.1      manu int
    353      1.17   thorpej linux_sys_ioperm(l, v, retval)
    354      1.17   thorpej 	struct lwp *l;
    355       1.1      manu 	void *v;
    356       1.1      manu 	register_t *retval;
    357       1.1      manu {
    358      1.22     perry 	/*
    359       1.1      manu 	 * This syscall is not implemented in Linux/Mips: we should not be here
    360       1.1      manu 	 */
    361       1.1      manu #ifdef DEBUG_LINUX
    362      1.22     perry 	printf("linux_sys_ioperm: should not be here.\n");
    363       1.4      manu #endif /* DEBUG_LINUX */
    364       1.1      manu 	return 0;
    365       1.1      manu }
    366       1.1      manu 
    367       1.1      manu /*
    368      1.22     perry  * wrapper linux_sys_new_uname() -> linux_sys_uname()
    369       1.1      manu  */
    370      1.22     perry int
    371      1.22     perry linux_sys_new_uname(l, v, retval)
    372      1.17   thorpej 	struct lwp *l;
    373       1.1      manu 	void *v;
    374       1.1      manu 	register_t *retval;
    375       1.1      manu {
    376       1.4      manu /*
    377      1.22     perry  * Use this if you want to try Linux emulation with a glibc-2.2
    378       1.4      manu  * or higher. Note that signals will not work
    379       1.4      manu  */
    380       1.4      manu #if 0
    381       1.4      manu         struct linux_sys_uname_args /* {
    382       1.4      manu                 syscallarg(struct linux_utsname *) up;
    383       1.4      manu         } */ *uap = v;
    384       1.4      manu         struct linux_utsname luts;
    385       1.4      manu 
    386  1.32.2.1       mjf         strlcpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname));
    387  1.32.2.1       mjf         strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
    388  1.32.2.1       mjf         strlcpy(luts.l_release, "2.4.0", sizeof(luts.l_release));
    389  1.32.2.1       mjf         strlcpy(luts.l_version, linux_version, sizeof(luts.l_version));
    390  1.32.2.1       mjf         strlcpy(luts.l_machine, machine, sizeof(luts.l_machine));
    391  1.32.2.1       mjf         strlcpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
    392       1.4      manu 
    393       1.4      manu         return copyout(&luts, SCARG(uap, up), sizeof(luts));
    394       1.4      manu #else
    395      1.17   thorpej 	return linux_sys_uname(l, v, retval);
    396       1.4      manu #endif
    397       1.1      manu }
    398       1.1      manu 
    399       1.1      manu /*
    400      1.17   thorpej  * In Linux, cacheflush is currently implemented
    401       1.1      manu  * as a whole cache flush (arguments are ignored)
    402       1.1      manu  * we emulate this broken beahior.
    403       1.1      manu  */
    404       1.1      manu int
    405      1.17   thorpej linux_sys_cacheflush(l, v, retval)
    406      1.17   thorpej 	struct lwp *l;
    407       1.1      manu 	void *v;
    408       1.1      manu 	register_t *retval;
    409       1.1      manu {
    410       1.7      manu 	mips_icache_sync_all();
    411       1.7      manu 	mips_dcache_wbinv_all();
    412       1.1      manu 	return 0;
    413       1.1      manu }
    414       1.1      manu 
    415       1.2      manu /*
    416      1.22     perry  * This system call is depecated in Linux, but
    417       1.2      manu  * some binaries and some libraries use it.
    418       1.2      manu  */
    419       1.2      manu int
    420      1.17   thorpej linux_sys_sysmips(l, v, retval)
    421      1.17   thorpej 	struct lwp *l;
    422       1.2      manu 	void *v;
    423       1.2      manu 	register_t *retval;
    424       1.2      manu {
    425       1.2      manu 	struct linux_sys_sysmips_args {
    426       1.2      manu 		syscallarg(int) cmd;
    427       1.2      manu 		syscallarg(int) arg1;
    428       1.2      manu 		syscallarg(int) arg2;
    429       1.2      manu 		syscallarg(int) arg3;
    430       1.2      manu 	} *uap = v;
    431       1.2      manu 	int error;
    432      1.22     perry 
    433       1.2      manu 	switch (SCARG(uap, cmd)) {
    434       1.2      manu 	case LINUX_SETNAME: {
    435       1.2      manu 		char nodename [LINUX___NEW_UTS_LEN + 1];
    436      1.20    atatat 		int name[2];
    437       1.2      manu 		size_t len;
    438       1.2      manu 
    439      1.27        ad 		if ((error = kauth_authorize_generic(l->l_cred,
    440      1.28      elad 		    KAUTH_GENERIC_ISSUSER, NULL)) != 0)
    441       1.2      manu 			return error;
    442      1.22     perry 		if ((error = copyinstr((char *)SCARG(uap, arg1), nodename,
    443       1.2      manu 		    LINUX___NEW_UTS_LEN, &len)) != 0)
    444       1.2      manu 			return error;
    445       1.2      manu 
    446      1.20    atatat 		name[0] = CTL_KERN;
    447      1.20    atatat 		name[1] = KERN_HOSTNAME;
    448      1.20    atatat 		return (old_sysctl(&name[0], 2, 0, 0, nodename, len, NULL));
    449      1.22     perry 
    450       1.2      manu 		break;
    451       1.2      manu 	}
    452       1.3      manu 	case LINUX_MIPS_ATOMIC_SET: {
    453       1.3      manu 		void *addr;
    454       1.3      manu 		int s;
    455      1.18  jdolecek 		u_int8_t value = 0;
    456       1.3      manu 
    457       1.3      manu 		addr = (void *)SCARG(uap, arg1);
    458       1.3      manu 
    459       1.3      manu 		s = splhigh();
    460       1.3      manu 		/*
    461       1.3      manu 		 * No error testing here. This is bad, but Linux does
    462       1.3      manu 		 * it like this. The source aknowledge "This is broken"
    463       1.3      manu 		 * in a comment...
    464       1.3      manu 		 */
    465      1.18  jdolecek 		(void) copyin(addr, &value, 1);
    466      1.18  jdolecek 		*retval = value;
    467      1.18  jdolecek 		value = (u_int8_t) SCARG(uap, arg2);
    468      1.18  jdolecek 		error = copyout(&value, addr, 1);
    469       1.3      manu 		splx(s);
    470       1.3      manu 
    471       1.3      manu 		return 0;
    472       1.2      manu 		break;
    473       1.3      manu 	}
    474       1.2      manu 	case LINUX_MIPS_FIXADE:		/* XXX not implemented */
    475       1.2      manu 		break;
    476       1.2      manu 	case LINUX_FLUSH_CACHE:
    477       1.7      manu 		mips_icache_sync_all();
    478       1.7      manu 		mips_dcache_wbinv_all();
    479       1.2      manu 		break;
    480       1.2      manu 	case LINUX_MIPS_RDNVRAM:
    481       1.2      manu 		return EIO;
    482       1.2      manu 		break;
    483       1.2      manu 	default:
    484       1.2      manu 		return EINVAL;
    485       1.2      manu 		break;
    486       1.2      manu 	}
    487       1.3      manu #ifdef DEBUG_LINUX
    488      1.22     perry 	printf("linux_sys_sysmips(): unimplemented command %d\n",
    489      1.22     perry 	    SCARG(uap,cmd));
    490       1.2      manu #endif /* DEBUG_LINUX */
    491       1.2      manu 	return 0;
    492       1.2      manu }
    493      1.23      fvdl 
    494      1.23      fvdl int
    495      1.23      fvdl linux_usertrap(struct lwp *l, vaddr_t trapaddr, void *arg)
    496      1.23      fvdl {
    497      1.23      fvdl 	return 0;
    498      1.23      fvdl }
    499