Home | History | Annotate | Line # | Download | only in m68k
linux_machdep.c revision 1.38.8.1
      1  1.38.8.1     skrll /*	$NetBSD: linux_machdep.c,v 1.38.8.1 2009/04/28 07:35:06 skrll Exp $	*/
      2       1.1     itohy 
      3       1.1     itohy /*-
      4       1.1     itohy  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1     itohy  * All rights reserved.
      6       1.1     itohy  *
      7       1.1     itohy  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1     itohy  * by ITOH Yasufumi.
      9       1.1     itohy  *
     10       1.1     itohy  * Redistribution and use in source and binary forms, with or without
     11       1.1     itohy  * modification, are permitted provided that the following conditions
     12       1.1     itohy  * are met:
     13       1.1     itohy  * 1. Redistributions of source code must retain the above copyright
     14       1.1     itohy  *    notice, this list of conditions and the following disclaimer.
     15       1.1     itohy  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     itohy  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     itohy  *    documentation and/or other materials provided with the distribution.
     18       1.1     itohy  *
     19       1.1     itohy  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1     itohy  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1     itohy  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1     itohy  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1     itohy  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1     itohy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1     itohy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1     itohy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1     itohy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1     itohy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1     itohy  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1     itohy  */
     31       1.9     lukem 
     32       1.9     lukem #include <sys/cdefs.h>
     33  1.38.8.1     skrll __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.38.8.1 2009/04/28 07:35:06 skrll Exp $");
     34       1.2  drochner 
     35       1.2  drochner #define COMPAT_LINUX 1
     36       1.1     itohy 
     37       1.1     itohy #include <sys/param.h>
     38       1.1     itohy #include <sys/systm.h>
     39       1.1     itohy #include <sys/kernel.h>
     40       1.1     itohy #include <sys/proc.h>
     41       1.1     itohy #include <sys/exec.h>
     42       1.1     itohy #include <sys/ioctl.h>
     43       1.1     itohy #include <sys/mount.h>
     44       1.1     itohy #include <sys/signal.h>
     45       1.1     itohy #include <sys/signalvar.h>
     46       1.1     itohy #include <sys/syscallargs.h>
     47      1.27      yamt #include <sys/kauth.h>
     48       1.1     itohy 
     49      1.33        ad #include <sys/cpu.h>
     50       1.1     itohy #include <machine/reg.h>
     51       1.1     itohy 
     52       1.1     itohy #include <compat/linux/common/linux_types.h>
     53       1.1     itohy #include <compat/linux/common/linux_signal.h>
     54       1.1     itohy #include <compat/linux/common/linux_ioctl.h>
     55       1.1     itohy #include <compat/linux/common/linux_exec.h>
     56       1.1     itohy #include <compat/linux/common/linux_machdep.h>
     57       1.1     itohy 
     58       1.1     itohy #include <compat/linux/linux_syscall.h>
     59       1.1     itohy #include <compat/linux/linux_syscallargs.h>
     60       1.1     itohy 
     61       1.1     itohy /* XXX should be in an include file somewhere */
     62       1.1     itohy #define CC_PURGE	1
     63       1.1     itohy #define CC_FLUSH	2
     64       1.1     itohy #define CC_IPURGE	4
     65       1.1     itohy #define CC_EXTPURGE	0x80000000
     66       1.1     itohy /* XXX end should be */
     67       1.1     itohy 
     68       1.1     itohy extern short exframesize[];
     69       1.1     itohy 
     70       1.1     itohy #ifdef DEBUG
     71       1.1     itohy extern int sigdebug;
     72       1.1     itohy extern int sigpid;
     73       1.1     itohy #define SDB_FOLLOW	0x01
     74       1.1     itohy #define SDB_KSTACK	0x02
     75       1.1     itohy #define SDB_FPSTATE	0x04
     76       1.1     itohy #endif
     77       1.1     itohy 
     78      1.34       dsl void setup_linux_sigframe(struct frame *frame, int sig,
     79      1.34       dsl     const sigset_t *mask, void *usp);
     80      1.34       dsl void setup_linux_rt_sigframe(struct frame *frame, int sig,
     81      1.34       dsl     const sigset_t *mask, void *usp, struct lwp *l);
     82       1.1     itohy 
     83       1.1     itohy /*
     84       1.1     itohy  * Deal with some m68k-specific things in the Linux emulation code.
     85       1.1     itohy  */
     86       1.1     itohy 
     87       1.1     itohy /*
     88       1.1     itohy  * Setup registers on program execution.
     89       1.1     itohy  */
     90       1.1     itohy void
     91      1.35       dsl linux_setregs(struct lwp *l, struct exec_package *epp, u_long stack)
     92       1.1     itohy {
     93       1.1     itohy 
     94      1.15   thorpej 	setregs(l, epp, stack);
     95       1.1     itohy }
     96       1.1     itohy 
     97       1.1     itohy /*
     98       1.1     itohy  * Setup signal frame for old signal interface.
     99       1.1     itohy  */
    100       1.1     itohy void
    101      1.35       dsl setup_linux_sigframe(struct frame *frame, int sig, const sigset_t *mask, void *usp)
    102       1.1     itohy {
    103      1.15   thorpej 	struct lwp *l = curlwp;
    104      1.15   thorpej 	struct proc *p = l->l_proc;
    105       1.1     itohy 	struct linux_sigframe *fp, kf;
    106       1.1     itohy 	short ft;
    107      1.30        ad 	int error;
    108       1.1     itohy 
    109       1.1     itohy 	ft = frame->f_format;
    110       1.1     itohy 
    111       1.1     itohy 	/* Allocate space for the signal handler context on the user stack. */
    112       1.1     itohy 	fp = (struct linux_sigframe *) usp;
    113       1.1     itohy 	fp--;
    114       1.1     itohy 
    115       1.1     itohy #ifdef DEBUG
    116       1.1     itohy 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    117       1.1     itohy 		printf("setup_linux_sigframe(%d): sig %d ssp %p usp %p scp %p ft %d\n",
    118       1.1     itohy 		       p->p_pid, sig, &ft, fp, &fp->sf_c.c_sc, ft);
    119       1.1     itohy #endif
    120       1.1     itohy 
    121       1.1     itohy 	/* Build stack frame. */
    122       1.1     itohy 	kf.sf_psigtramp = fp->sf_sigtramp;	/* return addr for handler */
    123      1.12  christos 	kf.sf_signum = native_to_linux_signo[sig];
    124       1.1     itohy 	kf.sf_code = frame->f_vector;		/* Does anyone use it? */
    125       1.1     itohy 	kf.sf_scp = &fp->sf_c.c_sc;
    126       1.1     itohy 
    127       1.1     itohy 	/* The sigtramp code is on the stack frame on Linux/m68k. */
    128       1.1     itohy 	kf.sf_sigtramp[0] = LINUX_SF_SIGTRAMP0;
    129       1.1     itohy 	kf.sf_sigtramp[1] = LINUX_SF_SIGTRAMP1;
    130       1.1     itohy 
    131       1.1     itohy 	/*
    132       1.1     itohy 	 * Save necessary hardware state.  Currently this includes:
    133       1.1     itohy 	 *	- scratch registers
    134       1.1     itohy 	 *	- original exception frame (if not a "normal" frame)
    135       1.1     itohy 	 *	- FP coprocessor state
    136       1.1     itohy 	 */
    137       1.1     itohy 	kf.sf_c.c_sc.sc_d0 = frame->f_regs[D0];
    138       1.1     itohy 	kf.sf_c.c_sc.sc_d1 = frame->f_regs[D1];
    139       1.1     itohy 	kf.sf_c.c_sc.sc_a0 = frame->f_regs[A0];
    140       1.1     itohy 	kf.sf_c.c_sc.sc_a1 = frame->f_regs[A1];
    141       1.1     itohy 
    142       1.1     itohy 	/* Clear for security (and initialize ss_format). */
    143  1.38.8.1     skrll 	memset(&kf.sf_c.c_sc.sc_ss, 0, sizeof kf.sf_c.c_sc.sc_ss);
    144       1.1     itohy 
    145       1.1     itohy 	if (ft >= FMT4) {
    146       1.1     itohy #ifdef DEBUG
    147       1.1     itohy 		if (ft > 15 || exframesize[ft] < 0)
    148       1.1     itohy 			panic("setup_linux_sigframe: bogus frame type");
    149       1.1     itohy #endif
    150       1.1     itohy 		kf.sf_c.c_sc.sc_ss.ss_format = ft;
    151       1.1     itohy 		kf.sf_c.c_sc.sc_ss.ss_vector = frame->f_vector;
    152  1.38.8.1     skrll 		memcpy( &kf.sf_c.c_sc.sc_ss.ss_frame, &frame->F_u,
    153       1.1     itohy 			(size_t) exframesize[ft]);
    154       1.1     itohy 		/*
    155       1.1     itohy 		 * Leave an indicator that we need to clean up the kernel
    156       1.1     itohy 		 * stack.  We do this by setting the "pad word" above the
    157       1.1     itohy 		 * hardware stack frame to the amount the stack must be
    158       1.1     itohy 		 * adjusted by.
    159       1.1     itohy 		 *
    160       1.1     itohy 		 * N.B. we increment rather than just set f_stackadj in
    161       1.1     itohy 		 * case we are called from syscall when processing a
    162       1.1     itohy 		 * sigreturn.  In that case, f_stackadj may be non-zero.
    163       1.1     itohy 		 */
    164       1.1     itohy 		frame->f_stackadj += exframesize[ft];
    165       1.1     itohy 		frame->f_format = frame->f_vector = 0;
    166       1.1     itohy #ifdef DEBUG
    167       1.1     itohy 		if (sigdebug & SDB_FOLLOW)
    168       1.1     itohy 			printf("setup_linux_sigframe(%d): copy out %d of frame %d\n",
    169       1.1     itohy 			       p->p_pid, exframesize[ft], ft);
    170       1.1     itohy #endif
    171       1.1     itohy 	}
    172       1.1     itohy 
    173       1.1     itohy 	switch (fputype) {
    174       1.1     itohy 	case FPU_NONE:
    175       1.1     itohy 		break;
    176       1.1     itohy #ifdef M68060
    177       1.1     itohy 	case FPU_68060:
    178      1.25     perry 		__asm("fsave %0" : "=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.FPF_u1)
    179       1.1     itohy 			: : "memory");
    180       1.1     itohy 		if (((struct fpframe060 *)&kf.sf_c.c_sc.sc_ss.ss_fpstate.FPF_u1)
    181       1.1     itohy 					->fpf6_frmfmt != FPF6_FMT_NULL) {
    182      1.25     perry 			__asm("fmovem %%fp0-%%fp1,%0" :
    183      1.22        cl 				"=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_regs[0][0]));
    184       1.1     itohy 			/*
    185       1.1     itohy 			 * On 060,  "fmovem fpcr/fpsr/fpi,<ea>"  is
    186       1.1     itohy 			 * emulated by software and slow.
    187       1.1     itohy 			 */
    188      1.25     perry 			__asm("fmovem %%fpcr,%0; fmovem %%fpsr,%1; fmovem %%fpi,%2" :
    189       1.1     itohy 				"=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_fpcr),
    190       1.1     itohy 				"=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_fpsr),
    191       1.1     itohy 				"=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_fpiar));
    192       1.1     itohy 		}
    193       1.1     itohy 		break;
    194       1.1     itohy #endif
    195       1.1     itohy 	default:
    196      1.25     perry 		__asm("fsave %0" : "=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.FPF_u1)
    197       1.1     itohy 			: : "memory");
    198       1.1     itohy 		if (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_version) {
    199      1.25     perry 			__asm("fmovem %%fp0-%%fp1,%0; fmovem %%fpcr/%%fpsr/%%fpi,%1" :
    200      1.22        cl 				"=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_regs[0][0]),
    201       1.1     itohy 				"=m" (kf.sf_c.c_sc.sc_ss.ss_fpstate.fpf_fpcr)
    202       1.1     itohy 				: : "memory");
    203       1.1     itohy 		}
    204       1.1     itohy 		break;
    205       1.1     itohy 	}
    206       1.1     itohy #ifdef DEBUG
    207       1.1     itohy 	if ((sigdebug & SDB_FPSTATE) && *(char *)&kf.sf_c.c_sc.sc_ss.ss_fpstate)
    208       1.1     itohy 		printf("setup_linux_sigframe(%d): copy out FP state (%x) to %p\n",
    209       1.1     itohy 		       p->p_pid, *(u_int *)&kf.sf_c.c_sc.sc_ss.ss_fpstate,
    210       1.1     itohy 		       &kf.sf_c.c_sc.sc_ss.ss_fpstate);
    211       1.1     itohy #endif
    212       1.1     itohy 
    213       1.1     itohy 	/* Build the signal context to be used by sigreturn. */
    214       1.1     itohy #if LINUX__NSIG_WORDS > 1
    215      1.10  christos 	native_to_linux_old_extra_sigset(&kf.sf_c.c_sc.sc_mask,
    216      1.10  christos 	    kf.sf_c.c_extrasigmask, mask);
    217       1.1     itohy #else
    218      1.10  christos 	native_to_linux_old_sigset(&kf.sf_c.c_sc.sc_mask, mask);
    219       1.1     itohy #endif
    220       1.1     itohy 	kf.sf_c.c_sc.sc_sp = frame->f_regs[SP];
    221       1.1     itohy 	kf.sf_c.c_sc.sc_pc = frame->f_pc;
    222       1.1     itohy 	kf.sf_c.c_sc.sc_ps = frame->f_sr;
    223      1.30        ad 	sendsig_reset(l, sig);
    224      1.30        ad 
    225      1.37        ad 	mutex_exit(p->p_lock);
    226      1.30        ad 	error = copyout(&kf, fp, sizeof(struct linux_sigframe));
    227      1.37        ad 	mutex_enter(p->p_lock);
    228       1.1     itohy 
    229      1.30        ad 	if (error) {
    230       1.1     itohy #ifdef DEBUG
    231       1.1     itohy 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    232       1.1     itohy 			printf("setup_linux_sigframe(%d): copyout failed on sig %d\n",
    233       1.1     itohy 			       p->p_pid, sig);
    234       1.1     itohy #endif
    235       1.1     itohy 		/*
    236       1.1     itohy 		 * Process has trashed its stack; give it a segmentation
    237       1.1     itohy 		 * violation to halt it in its tracks.
    238       1.1     itohy 		 */
    239      1.15   thorpej 		sigexit(l, SIGSEGV);
    240       1.1     itohy 		/* NOTREACHED */
    241       1.1     itohy 	}
    242       1.1     itohy 
    243       1.1     itohy 	/*
    244       1.1     itohy 	 * The signal trampoline is on the signal frame.
    245       1.1     itohy 	 * Clear the instruction cache in case of cached.
    246       1.1     itohy 	 */
    247       1.3     itohy 	cachectl1(CC_EXTPURGE | CC_IPURGE,
    248       1.3     itohy 			(vaddr_t) fp->sf_sigtramp, sizeof fp->sf_sigtramp, p);
    249       1.1     itohy 
    250       1.1     itohy 	/* Set up the user stack pointer. */
    251       1.1     itohy 	frame->f_regs[SP] = (int)fp;
    252       1.1     itohy 
    253       1.1     itohy #ifdef DEBUG
    254       1.1     itohy 	if (sigdebug & SDB_FOLLOW)
    255       1.1     itohy 		printf("setup_linux_sigframe(%d): sig %d scp %p fp %p sc_sp %x\n",
    256       1.1     itohy 		       p->p_pid, sig, kf.sf_scp, fp, kf.sf_c.c_sc.sc_sp);
    257       1.1     itohy #endif
    258       1.1     itohy }
    259       1.1     itohy 
    260       1.1     itohy /*
    261       1.1     itohy  * Setup signal frame for new RT signal interface.
    262       1.1     itohy  */
    263       1.1     itohy void
    264      1.35       dsl setup_linux_rt_sigframe(struct frame *frame, int sig, const sigset_t *mask, void *usp, struct lwp *l)
    265       1.1     itohy {
    266      1.15   thorpej 	struct proc *p = l->l_proc;
    267       1.1     itohy 	struct linux_rt_sigframe *fp, kf;
    268      1.30        ad 	int error;
    269       1.1     itohy 	short ft;
    270       1.1     itohy 
    271       1.1     itohy 	ft = frame->f_format;
    272       1.1     itohy 
    273       1.1     itohy 	/* Allocate space for the signal handler context on the user stack. */
    274       1.1     itohy 	fp = (struct linux_rt_sigframe *) usp;
    275       1.1     itohy 	fp--;
    276       1.1     itohy 
    277       1.1     itohy #ifdef DEBUG
    278       1.1     itohy 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    279       1.1     itohy 		printf("setup_linux_rt_sigframe(%d): sig %d ssp %p usp %p ucp %p ft %d\n",
    280       1.1     itohy 		       p->p_pid, sig, &ft, fp, &fp->sf_uc, ft);
    281       1.1     itohy #endif
    282       1.1     itohy 
    283       1.1     itohy 	/* Build stack frame. */
    284       1.1     itohy 	kf.sf_psigtramp = fp->sf_sigtramp;	/* return addr for handler */
    285      1.12  christos 	kf.sf_signum = native_to_linux_signo[sig];
    286       1.1     itohy 	kf.sf_pinfo = &fp->sf_info;
    287       1.1     itohy 	kf.sf_puc = &fp->sf_uc;
    288       1.1     itohy 
    289       1.1     itohy 	/* The sigtramp code is on the stack frame on Linux/m68k. */
    290       1.1     itohy 	kf.sf_sigtramp[0] = LINUX_RT_SF_SIGTRAMP0;
    291       1.1     itohy 	kf.sf_sigtramp[1] = LINUX_RT_SF_SIGTRAMP1;
    292       1.1     itohy 
    293       1.1     itohy 	/* clear for security (and initialize uc_flags, ss_format, etc.). */
    294  1.38.8.1     skrll 	memset(&kf.sf_uc, 0, sizeof(struct linux_ucontext));
    295       1.1     itohy 
    296       1.1     itohy 	/*
    297       1.1     itohy 	 * Save necessary hardware state.  Currently this includes:
    298       1.1     itohy 	 *	- general registers
    299       1.1     itohy 	 *	- original exception frame (if not a "normal" frame)
    300       1.1     itohy 	 *	- FP coprocessor state
    301       1.1     itohy 	 */
    302       1.1     itohy 	/* version of mcontext */
    303       1.1     itohy 	kf.sf_uc.uc_mc.mc_version = LINUX_MCONTEXT_VERSION;
    304       1.1     itohy 
    305       1.1     itohy 	/* general registers and pc/sr */
    306  1.38.8.1     skrll 	memcpy( kf.sf_uc.uc_mc.mc_gregs.gr_regs, frame->f_regs, sizeof(u_int)*16);
    307       1.1     itohy 	kf.sf_uc.uc_mc.mc_gregs.gr_pc = frame->f_pc;
    308       1.1     itohy 	kf.sf_uc.uc_mc.mc_gregs.gr_sr = frame->f_sr;
    309       1.1     itohy 
    310       1.1     itohy 	if (ft >= FMT4) {
    311       1.1     itohy #ifdef DEBUG
    312       1.1     itohy 		if (ft > 15 || exframesize[ft] < 0)
    313       1.1     itohy 			panic("setup_linux_rt_sigframe: bogus frame type");
    314       1.1     itohy #endif
    315       1.1     itohy 		kf.sf_uc.uc_ss.ss_format = ft;
    316       1.1     itohy 		kf.sf_uc.uc_ss.ss_vector = frame->f_vector;
    317  1.38.8.1     skrll 		memcpy( &kf.sf_uc.uc_ss.ss_frame, &frame->F_u,
    318       1.1     itohy 			(size_t) exframesize[ft]);
    319       1.1     itohy 		/*
    320       1.1     itohy 		 * Leave an indicator that we need to clean up the kernel
    321       1.1     itohy 		 * stack.  We do this by setting the "pad word" above the
    322       1.1     itohy 		 * hardware stack frame to the amount the stack must be
    323       1.1     itohy 		 * adjusted by.
    324       1.1     itohy 		 *
    325       1.1     itohy 		 * N.B. we increment rather than just set f_stackadj in
    326       1.1     itohy 		 * case we are called from syscall when processing a
    327       1.1     itohy 		 * sigreturn.  In that case, f_stackadj may be non-zero.
    328       1.1     itohy 		 */
    329       1.1     itohy 		frame->f_stackadj += exframesize[ft];
    330       1.1     itohy 		frame->f_format = frame->f_vector = 0;
    331       1.1     itohy #ifdef DEBUG
    332       1.1     itohy 		if (sigdebug & SDB_FOLLOW)
    333       1.1     itohy 			printf("setup_linux_rt_sigframe(%d): copy out %d of frame %d\n",
    334       1.1     itohy 			       p->p_pid, exframesize[ft], ft);
    335       1.1     itohy #endif
    336       1.1     itohy 	}
    337       1.1     itohy 
    338       1.1     itohy 	switch (fputype) {
    339       1.1     itohy 	case FPU_NONE:
    340       1.1     itohy 		break;
    341       1.1     itohy #ifdef M68060
    342       1.1     itohy 	case FPU_68060:
    343      1.25     perry 		__asm("fsave %0" : "=m" (kf.sf_uc.uc_ss.ss_fpstate));
    344       1.1     itohy 				/* See note below. */
    345       1.1     itohy 		if (((struct fpframe060 *) &kf.sf_uc.uc_ss.ss_fpstate.FPF_u1)
    346       1.1     itohy 					->fpf6_frmfmt != FPF6_FMT_NULL) {
    347      1.25     perry 			__asm("fmovem %%fp0-%%fp7,%0" :
    348      1.22        cl 				"=m" (kf.sf_uc.uc_mc.mc_fpregs.fpr_regs[0][0]));
    349       1.1     itohy 			/*
    350       1.1     itohy 			 * On 060,  "fmovem fpcr/fpsr/fpi,<ea>"  is
    351       1.1     itohy 			 * emulated by software and slow.
    352       1.1     itohy 			 */
    353      1.25     perry 			__asm("fmovem %%fpcr,%0; fmovem %%fpsr,%1; fmovem %%fpi,%2" :
    354       1.1     itohy 				"=m" (kf.sf_uc.uc_mc.mc_fpregs.fpr_fpcr),
    355       1.1     itohy 				"=m" (kf.sf_uc.uc_mc.mc_fpregs.fpr_fpsr),
    356       1.1     itohy 				"=m" (kf.sf_uc.uc_mc.mc_fpregs.fpr_fpiar));
    357       1.1     itohy 		}
    358       1.1     itohy 		break;
    359       1.1     itohy #endif
    360       1.1     itohy 	default:
    361       1.1     itohy 		/*
    362       1.1     itohy 		 * NOTE:  We give whole of the  "struct linux_rt_fpframe"
    363      1.25     perry 		 * to the __asm("fsave") argument; not the FPF_u1 element only.
    364       1.1     itohy 		 * Unlike the non-RT version of this structure,
    365       1.1     itohy 		 * this contains only the FPU state used by "fsave"
    366       1.1     itohy 		 * (and whole of the information is in the structure).
    367      1.25     perry 		 * This gives the correct dependency information to the __asm(),
    368       1.1     itohy 		 * and no "memory" is required to the ``clobberd'' list.
    369       1.1     itohy 		 */
    370      1.25     perry 		__asm("fsave %0" : "=m" (kf.sf_uc.uc_ss.ss_fpstate));
    371       1.1     itohy 		if (kf.sf_uc.uc_ss.ss_fpstate.fpf_version) {
    372      1.25     perry 			__asm("fmovem %%fp0-%%fp7,%0; fmovem %%fpcr/%%fpsr/%%fpi,%1" :
    373      1.22        cl 				"=m" (kf.sf_uc.uc_mc.mc_fpregs.fpr_regs[0][0]),
    374       1.1     itohy 				"=m" (kf.sf_uc.uc_mc.mc_fpregs.fpr_fpcr)
    375       1.1     itohy 				: : "memory");
    376       1.1     itohy 		}
    377       1.1     itohy 		break;
    378       1.1     itohy 	}
    379       1.1     itohy #ifdef DEBUG
    380       1.1     itohy 	if ((sigdebug & SDB_FPSTATE) && *(char *)&kf.sf_uc.uc_ss.ss_fpstate)
    381       1.1     itohy 		printf("setup_linux_rt_sigframe(%d): copy out FP state (%x) to %p\n",
    382       1.1     itohy 		       p->p_pid, *(u_int *)&kf.sf_uc.uc_ss.ss_fpstate,
    383       1.1     itohy 		       &kf.sf_uc.uc_ss.ss_fpstate);
    384       1.1     itohy #endif
    385       1.1     itohy 
    386       1.1     itohy 	/*
    387       1.1     itohy 	 * XXX XAX Create bogus siginfo data.  This can't really
    388       1.1     itohy 	 * XXX be fixed until NetBSD has realtime signals.
    389       1.1     itohy 	 * XXX Or we do the emuldata thing.
    390       1.1     itohy 	 * XXX -erh
    391       1.1     itohy 	 */
    392  1.38.8.1     skrll 	memset(&kf.sf_info, 0, sizeof(struct linux_siginfo));
    393      1.13  christos 	kf.sf_info.lsi_signo = sig;
    394      1.13  christos 	kf.sf_info.lsi_code = LINUX_SI_USER;
    395      1.13  christos 	kf.sf_info.lsi_pid = p->p_pid;
    396      1.28        ad 	kf.sf_info.lsi_uid = kauth_cred_geteuid(l->l_cred);	/* Use real uid here? */
    397       1.1     itohy 
    398       1.1     itohy 	/* Build the signal context to be used by sigreturn. */
    399      1.10  christos 	native_to_linux_sigset(&kf.sf_uc.uc_sigmask, mask);
    400      1.30        ad 	kf.sf_uc.uc_stack.ss_sp = l->l_sigstk.ss_sp;
    401       1.1     itohy 	kf.sf_uc.uc_stack.ss_flags =
    402      1.30        ad 		(l->l_sigstk.ss_flags & SS_ONSTACK ? LINUX_SS_ONSTACK : 0) |
    403      1.30        ad 		(l->l_sigstk.ss_flags & SS_DISABLE ? LINUX_SS_DISABLE : 0);
    404      1.30        ad 	kf.sf_uc.uc_stack.ss_size = l->l_sigstk.ss_size;
    405      1.30        ad 	sendsig_reset(l, sig);
    406      1.30        ad 
    407      1.37        ad 	mutex_exit(p->p_lock);
    408      1.30        ad 	error = copyout(&kf, fp, sizeof(struct linux_rt_sigframe));
    409      1.37        ad 	mutex_enter(p->p_lock);
    410       1.1     itohy 
    411      1.30        ad 	if (error) {
    412       1.1     itohy #ifdef DEBUG
    413       1.1     itohy 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    414       1.1     itohy 			printf("setup_linux_rt_sigframe(%d): copyout failed on sig %d\n",
    415       1.1     itohy 			       p->p_pid, sig);
    416       1.1     itohy #endif
    417       1.1     itohy 		/*
    418       1.1     itohy 		 * Process has trashed its stack; give it a segmentation
    419       1.1     itohy 		 * violation to halt it in its tracks.
    420       1.1     itohy 		 */
    421      1.15   thorpej 		sigexit(l, SIGSEGV);
    422       1.1     itohy 		/* NOTREACHED */
    423       1.1     itohy 	}
    424       1.1     itohy 
    425       1.1     itohy 	/*
    426       1.1     itohy 	 * The signal trampoline is on the signal frame.
    427       1.1     itohy 	 * Clear the instruction cache in case of cached.
    428       1.1     itohy 	 */
    429       1.3     itohy 	cachectl1(CC_EXTPURGE | CC_IPURGE,
    430       1.3     itohy 			(vaddr_t) fp->sf_sigtramp, sizeof fp->sf_sigtramp, p);
    431       1.1     itohy 
    432       1.1     itohy 	/* Set up the user stack pointer. */
    433       1.1     itohy 	frame->f_regs[SP] = (int)fp;
    434       1.1     itohy 
    435       1.1     itohy #ifdef DEBUG
    436       1.1     itohy 	if (sigdebug & SDB_FOLLOW)
    437       1.1     itohy 		printf("setup_linux_rt_sigframe(%d): sig %d puc %p fp %p sc_sp %x\n",
    438       1.1     itohy 		       p->p_pid, sig, kf.sf_puc, fp,
    439       1.1     itohy 		       kf.sf_uc.uc_mc.mc_gregs.gr_regs[SP]);
    440       1.1     itohy #endif
    441       1.1     itohy }
    442       1.1     itohy 
    443       1.1     itohy /*
    444       1.1     itohy  * Send an interrupt to Linux process.
    445       1.1     itohy  */
    446       1.1     itohy void
    447      1.20  christos linux_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
    448       1.1     itohy {
    449      1.19        cl 	/* u_long code = ksi->ksi_trap; */
    450      1.19        cl 	int sig = ksi->ksi_signo;
    451      1.15   thorpej 	struct lwp *l = curlwp;
    452      1.15   thorpej 	struct proc *p = l->l_proc;
    453      1.19        cl 	struct frame *frame = (struct frame *)l->l_md.md_regs;
    454       1.1     itohy 	int onstack;
    455      1.19        cl 	/* user stack for signal context */
    456      1.31  christos 	void *usp = getframe(l, sig, &onstack);
    457      1.14   thorpej 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    458       1.1     itohy 
    459       1.1     itohy 	/* Setup the signal frame (and part of the trapframe). */
    460       1.6  jdolecek 	if (SIGACTION(p, sig).sa_flags & SA_SIGINFO)
    461      1.15   thorpej 		setup_linux_rt_sigframe(frame, sig, mask, usp, l);
    462       1.1     itohy 	else
    463       1.1     itohy 		setup_linux_sigframe(frame, sig, mask, usp);
    464       1.1     itohy 
    465       1.1     itohy 	/* Call the signal handler. */
    466       1.1     itohy 	frame->f_pc = (u_int) catcher;
    467       1.1     itohy 
    468       1.1     itohy 	/* Remember that we're now on the signal stack. */
    469       1.1     itohy 	if (onstack)
    470      1.30        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    471       1.1     itohy 
    472       1.1     itohy #ifdef DEBUG
    473       1.1     itohy 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    474       1.1     itohy 		printf("linux_sendsig(%d): sig %d returns\n",
    475       1.1     itohy 		       p->p_pid, sig);
    476       1.1     itohy #endif
    477       1.1     itohy }
    478       1.1     itohy 
    479       1.1     itohy /*
    480       1.1     itohy  * The linux_sys_sigreturn and linux_sys_rt_sigreturn
    481       1.1     itohy  * system calls cleanup state after a signal
    482       1.1     itohy  * has been taken.  Reset signal mask and stack
    483       1.1     itohy  * state from context left by linux_sendsig (above).
    484       1.1     itohy  * Return to previous pc and psl as specified by
    485       1.1     itohy  * context left by linux_sendsig. Check carefully to
    486       1.1     itohy  * make sure that the user has not modified the
    487       1.1     itohy  * psl to gain improper privileges or to cause
    488       1.1     itohy  * a machine fault.
    489       1.1     itohy  *
    490       1.1     itohy  * Note that the sigreturn system calls of Linux/m68k
    491       1.1     itohy  * do not return on errors, but issue segmentation
    492       1.1     itohy  * violation and terminate the process.
    493       1.1     itohy  */
    494       1.1     itohy /* ARGSUSED */
    495       1.1     itohy int
    496      1.36       dsl linux_sys_sigreturn(struct lwp *l, const void *v, register_t *retval)
    497       1.1     itohy {
    498      1.15   thorpej 	struct proc *p = l->l_proc;
    499       1.1     itohy 	struct frame *frame;
    500       1.1     itohy 	struct linux_sigc2 tsigc2;	/* extra mask and sigcontext */
    501       1.1     itohy 	struct linux_sigcontext *scp;	/* pointer to sigcontext */
    502       1.1     itohy 	sigset_t mask;
    503       1.1     itohy 	int sz = 0;			/* extra frame size */
    504       1.1     itohy 	int usp;
    505       1.1     itohy 
    506       1.1     itohy 	/*
    507       1.1     itohy 	 * sigreturn of Linux/m68k takes no arguments.
    508       1.1     itohy 	 * The user stack points at struct linux_sigc2.
    509       1.1     itohy 	 */
    510      1.15   thorpej 	frame = (struct frame *) l->l_md.md_regs;
    511       1.1     itohy 	usp = frame->f_regs[SP];
    512       1.1     itohy 	if (usp & 1)
    513       1.1     itohy 		goto bad;
    514       1.1     itohy 
    515       1.1     itohy #ifdef DEBUG
    516       1.1     itohy 	if (sigdebug & SDB_FOLLOW)
    517       1.1     itohy 		printf("linux_sys_sigreturn: pid %d, usp %p\n",
    518      1.31  christos 			p->p_pid, (void *) usp);
    519       1.1     itohy #endif
    520       1.1     itohy 
    521       1.1     itohy 	/* Grab whole of the sigcontext. */
    522      1.31  christos 	if (copyin((void *) usp, &tsigc2, sizeof tsigc2)) {
    523      1.30        ad bad:
    524      1.37        ad 		mutex_enter(p->p_lock);
    525      1.30        ad 		sigexit(l, SIGSEGV);
    526      1.30        ad 	}
    527       1.1     itohy 
    528       1.1     itohy 	scp = &tsigc2.c_sc;
    529       1.1     itohy 
    530       1.1     itohy 	/*
    531       1.1     itohy 	 * Check kernel stack and re-enter to syscall() if needed.
    532       1.1     itohy 	 */
    533       1.1     itohy 	if ((sz = scp->sc_ss.ss_format) != 0) {
    534       1.1     itohy 		if ((sz = exframesize[sz]) < 0)
    535       1.1     itohy 			goto bad;
    536       1.1     itohy 		if (sz && frame->f_stackadj == 0) {
    537       1.1     itohy 			/*
    538       1.1     itohy 			 * Extra stack space is required but not allocated.
    539       1.1     itohy 			 * Allocate and re-enter syscall().
    540       1.1     itohy 			 */
    541       1.4    kleink 			reenter_syscall(frame, sz);
    542       1.1     itohy 			/* NOTREACHED */
    543       1.1     itohy 		}
    544       1.1     itohy 	}
    545       1.1     itohy #ifdef DEBUG
    546       1.4    kleink 	/* reenter_syscall() doesn't adjust stack. */
    547       1.1     itohy 	if (sz != frame->f_stackadj)
    548       1.1     itohy 		panic("linux_sys_sigreturn: adj: %d != %d",
    549       1.1     itohy 			sz, frame->f_stackadj);
    550       1.1     itohy #endif
    551       1.1     itohy 
    552      1.37        ad 	mutex_enter(p->p_lock);
    553      1.30        ad 
    554       1.1     itohy 	/* Restore signal stack. */
    555      1.30        ad 	l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    556       1.1     itohy 
    557       1.1     itohy 	/* Restore signal mask. */
    558       1.1     itohy #if LINUX__NSIG_WORDS > 1
    559      1.11        is 	linux_old_extra_to_native_sigset(&mask, &scp->sc_mask,
    560      1.11        is 					 tsigc2.c_extrasigmask);
    561       1.1     itohy #else
    562       1.1     itohy 	linux_old_to_native_sigset(&scp->sc_mask, &mask);
    563       1.1     itohy #endif
    564      1.30        ad 	(void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
    565      1.30        ad 
    566      1.37        ad 	mutex_exit(p->p_lock);
    567       1.1     itohy 
    568       1.1     itohy 	/*
    569       1.1     itohy 	 * Restore the user supplied information.
    570       1.1     itohy 	 */
    571       1.1     itohy 	frame->f_regs[SP] = scp->sc_sp;
    572       1.1     itohy 	frame->f_regs[D0] = scp->sc_d0;
    573       1.1     itohy 	frame->f_regs[D1] = scp->sc_d1;
    574       1.1     itohy 	frame->f_regs[A0] = scp->sc_a0;
    575       1.1     itohy 	frame->f_regs[A1] = scp->sc_a1;
    576       1.1     itohy 	frame->f_pc = scp->sc_pc;
    577       1.1     itohy 	/* Privileged bits of  sr  are silently ignored on Linux/m68k. */
    578       1.1     itohy 	frame->f_sr = scp->sc_ps & ~(PSL_MBZ|PSL_IPL|PSL_S);
    579       1.1     itohy 	/*
    580       1.1     itohy 	 * Other registers are assumed to be unchanged,
    581       1.1     itohy 	 * and not restored.
    582       1.1     itohy 	 */
    583       1.1     itohy 
    584       1.1     itohy 	/*
    585       1.1     itohy 	 * Restore long stack frames.  Note that we do not copy
    586       1.1     itohy 	 * back the saved SR or PC, they were picked up above from
    587       1.1     itohy 	 * the sigcontext structure.
    588       1.1     itohy 	 */
    589       1.1     itohy 	if (scp->sc_ss.ss_format) {
    590       1.1     itohy 		frame->f_format = scp->sc_ss.ss_format;
    591       1.1     itohy 		frame->f_vector = scp->sc_ss.ss_vector;
    592       1.1     itohy 		if (frame->f_stackadj < sz)	/* just in case... */
    593       1.1     itohy 			goto bad;
    594       1.1     itohy 		frame->f_stackadj -= sz;
    595  1.38.8.1     skrll 		memcpy( &frame->F_u, &scp->sc_ss.ss_frame, sz);
    596       1.1     itohy #ifdef DEBUG
    597       1.1     itohy 		if (sigdebug & SDB_FOLLOW)
    598       1.1     itohy 			printf("linux_sys_sigreturn(%d): copy in %d of frame type %d\n",
    599       1.1     itohy 			       p->p_pid, sz, scp->sc_ss.ss_format);
    600       1.1     itohy #endif
    601       1.1     itohy 	}
    602       1.1     itohy 
    603       1.1     itohy 	/*
    604       1.1     itohy 	 * Finally we restore the original FP context.
    605       1.1     itohy 	 */
    606       1.1     itohy 	switch (fputype) {
    607       1.1     itohy 	case FPU_NONE:
    608       1.1     itohy 		break;
    609       1.1     itohy #ifdef M68060
    610       1.1     itohy 	case FPU_68060:
    611       1.1     itohy 		if (((struct fpframe060*)&scp->sc_ss.ss_fpstate.FPF_u1)
    612       1.1     itohy 					->fpf6_frmfmt != FPF6_FMT_NULL) {
    613       1.1     itohy 			/*
    614       1.1     itohy 			 * On 060,  "fmovem <ea>,fpcr/fpsr/fpi"  is
    615       1.1     itohy 			 * emulated by software and slow.
    616       1.1     itohy 			 */
    617      1.25     perry 			__asm("fmovem %0,%%fpcr; fmovem %1,%%fpsr; fmovem %2,%%fpi"::
    618       1.1     itohy 				"m" (scp->sc_ss.ss_fpstate.fpf_fpcr),
    619       1.1     itohy 				"m" (scp->sc_ss.ss_fpstate.fpf_fpsr),
    620       1.1     itohy 				"m" (scp->sc_ss.ss_fpstate.fpf_fpiar));
    621      1.25     perry 			__asm("fmovem %0,%%fp0-%%fp1" : :
    622      1.22        cl 				"m" (scp->sc_ss.ss_fpstate.fpf_regs[0][0]));
    623       1.1     itohy 		}
    624      1.25     perry 		__asm("frestore %0" : : "m" (scp->sc_ss.ss_fpstate.FPF_u1));
    625       1.1     itohy 		break;
    626       1.1     itohy #endif
    627       1.1     itohy 	default:
    628       1.1     itohy 		if (scp->sc_ss.ss_fpstate.fpf_version) {
    629      1.25     perry 			__asm("fmovem %0,%%fpcr/%%fpsr/%%fpi; fmovem %1,%%fp0-%%fp1"::
    630       1.1     itohy 				"m" (scp->sc_ss.ss_fpstate.fpf_fpcr),
    631      1.22        cl 				"m" (scp->sc_ss.ss_fpstate.fpf_regs[0][0]));
    632       1.1     itohy 		}
    633      1.25     perry 		__asm("frestore %0" : : "m" (scp->sc_ss.ss_fpstate.FPF_u1));
    634       1.1     itohy 		break;
    635       1.1     itohy 	}
    636       1.1     itohy 
    637       1.1     itohy #ifdef DEBUG
    638       1.1     itohy 	if ((sigdebug & SDB_FPSTATE) && *(char *)&scp->sc_ss.ss_fpstate)
    639       1.1     itohy 		printf("linux_sys_sigreturn(%d): copied in FP state (%x) at %p\n",
    640       1.1     itohy 		       p->p_pid, *(u_int *)&scp->sc_ss.ss_fpstate,
    641       1.1     itohy 		       &scp->sc_ss.ss_fpstate);
    642       1.1     itohy 	if ((sigdebug & SDB_FOLLOW) ||
    643       1.1     itohy 	    ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
    644       1.1     itohy 		printf("linux_sys_sigreturn(%d): returns\n", p->p_pid);
    645       1.1     itohy #endif
    646       1.1     itohy 
    647       1.1     itohy 	return EJUSTRETURN;
    648       1.1     itohy }
    649       1.1     itohy 
    650       1.1     itohy /* ARGSUSED */
    651       1.1     itohy int
    652      1.36       dsl linux_sys_rt_sigreturn(struct lwp *l, const void *v, register_t *retval)
    653       1.1     itohy {
    654      1.15   thorpej 	struct proc *p = l->l_proc;
    655       1.1     itohy 	struct frame *frame;
    656       1.1     itohy 	struct linux_ucontext *ucp;	/* ucontext in user space */
    657       1.1     itohy 	struct linux_ucontext tuc;	/* copy of *ucp */
    658       1.1     itohy 	sigset_t mask;
    659      1.18  jdolecek 	int sz = 0, error;		/* extra frame size */
    660       1.1     itohy 
    661       1.1     itohy 	/*
    662       1.1     itohy 	 * rt_sigreturn of Linux/m68k takes no arguments.
    663       1.1     itohy 	 * usp + 4 is a pointer to siginfo structure,
    664       1.1     itohy 	 * usp + 8 is a pointer to ucontext structure.
    665       1.1     itohy 	 */
    666      1.15   thorpej 	frame = (struct frame *) l->l_md.md_regs;
    667      1.32   tsutsui 	error = copyin((char *)frame->f_regs[SP] + 8, (void *)&ucp,
    668      1.32   tsutsui 	    sizeof(void *));
    669      1.18  jdolecek 	if (error || (int) ucp & 1)
    670      1.18  jdolecek 		goto bad;		/* error or odd address */
    671       1.1     itohy 
    672       1.1     itohy #ifdef DEBUG
    673       1.1     itohy 	if (sigdebug & SDB_FOLLOW)
    674       1.1     itohy 		printf("linux_rt_sigreturn: pid %d, ucp %p\n", p->p_pid, ucp);
    675       1.1     itohy #endif
    676       1.1     itohy 
    677       1.1     itohy 	/* Grab whole of the ucontext. */
    678      1.30        ad 	if (copyin(ucp, &tuc, sizeof tuc)) {
    679      1.30        ad bad:
    680      1.37        ad 		mutex_enter(p->p_lock);
    681      1.30        ad 		sigexit(l, SIGSEGV);
    682      1.30        ad 	}
    683       1.1     itohy 
    684       1.1     itohy 	/*
    685       1.1     itohy 	 * Check kernel stack and re-enter to syscall() if needed.
    686       1.1     itohy 	 */
    687       1.1     itohy 	if ((sz = tuc.uc_ss.ss_format) != 0) {
    688       1.1     itohy 		if ((sz = exframesize[sz]) < 0)
    689       1.1     itohy 			goto bad;
    690       1.1     itohy 		if (sz && frame->f_stackadj == 0) {
    691       1.1     itohy 			/*
    692       1.1     itohy 			 * Extra stack space is required but not allocated.
    693       1.1     itohy 			 * Allocate and re-enter syscall().
    694       1.1     itohy 			 */
    695       1.4    kleink 			reenter_syscall(frame, sz);
    696       1.1     itohy 			/* NOTREACHED */
    697       1.1     itohy 		}
    698       1.1     itohy 	}
    699       1.1     itohy #ifdef DEBUG
    700       1.4    kleink 	/* reenter_syscall() doesn't adjust stack. */
    701       1.1     itohy 	if (sz != frame->f_stackadj)
    702       1.1     itohy 		panic("linux_sys_rt_sigreturn: adj: %d != %d",
    703       1.1     itohy 			sz, frame->f_stackadj);
    704       1.1     itohy #endif
    705       1.1     itohy 
    706       1.1     itohy 	if (tuc.uc_mc.mc_version != LINUX_MCONTEXT_VERSION)
    707       1.1     itohy 		goto bad;
    708       1.1     itohy 
    709      1.37        ad 	mutex_enter(p->p_lock);
    710      1.30        ad 
    711       1.1     itohy 	/* Restore signal stack. */
    712      1.30        ad 	l->l_sigstk.ss_flags =
    713      1.30        ad 		(l->l_sigstk.ss_flags & ~SS_ONSTACK) |
    714       1.1     itohy 		(tuc.uc_stack.ss_flags & LINUX_SS_ONSTACK ? SS_ONSTACK : 0);
    715       1.1     itohy 
    716       1.1     itohy 	/* Restore signal mask. */
    717      1.11        is 	linux_to_native_sigset(&mask, &tuc.uc_sigmask);
    718      1.30        ad 	(void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
    719      1.30        ad 
    720      1.37        ad 	mutex_exit(p->p_lock);
    721       1.1     itohy 
    722       1.1     itohy 	/*
    723       1.1     itohy 	 * Restore the user supplied information.
    724       1.1     itohy 	 */
    725  1.38.8.1     skrll 	memcpy( frame->f_regs, tuc.uc_mc.mc_gregs.gr_regs, sizeof(u_int)*16);
    726       1.1     itohy 	frame->f_pc = tuc.uc_mc.mc_gregs.gr_pc;
    727       1.1     itohy 	/* Privileged bits of  sr  are silently ignored on Linux/m68k. */
    728       1.1     itohy 	frame->f_sr = tuc.uc_mc.mc_gregs.gr_sr & ~(PSL_MBZ|PSL_IPL|PSL_S);
    729       1.1     itohy 
    730       1.1     itohy 	/*
    731       1.1     itohy 	 * Restore long stack frames.  Note that we do not copy
    732       1.1     itohy 	 * back the saved SR or PC, they were picked up above from
    733       1.1     itohy 	 * the ucontext structure.
    734       1.1     itohy 	 */
    735       1.1     itohy 	if (tuc.uc_ss.ss_format) {
    736       1.1     itohy 		frame->f_format = tuc.uc_ss.ss_format;
    737       1.1     itohy 		frame->f_vector = tuc.uc_ss.ss_vector;
    738       1.1     itohy 		if (frame->f_stackadj < sz)	/* just in case... */
    739       1.1     itohy 			goto bad;
    740       1.1     itohy 		frame->f_stackadj -= sz;
    741  1.38.8.1     skrll 		memcpy( &frame->F_u, &tuc.uc_ss.ss_frame, sz);
    742       1.1     itohy #ifdef DEBUG
    743       1.1     itohy 		if (sigdebug & SDB_FOLLOW)
    744       1.1     itohy 			printf("linux_sys_rt_sigreturn(%d): copy in %d of frame type %d\n",
    745       1.1     itohy 			       p->p_pid, sz, tuc.uc_ss.ss_format);
    746       1.1     itohy #endif
    747       1.1     itohy 	}
    748       1.1     itohy 
    749       1.1     itohy 	/*
    750       1.1     itohy 	 * Finally we restore the original FP context.
    751       1.1     itohy 	 */
    752       1.1     itohy 	switch (fputype) {
    753       1.1     itohy 	case FPU_NONE:
    754       1.1     itohy 		break;
    755       1.1     itohy #ifdef M68060
    756       1.1     itohy 	case FPU_68060:
    757       1.1     itohy 		if (((struct fpframe060*)&tuc.uc_ss.ss_fpstate.FPF_u1)
    758       1.1     itohy 					->fpf6_frmfmt != FPF6_FMT_NULL) {
    759       1.1     itohy 			/*
    760       1.1     itohy 			 * On 060,  "fmovem <ea>,fpcr/fpsr/fpi"  is
    761       1.1     itohy 			 * emulated by software and slow.
    762       1.1     itohy 			 */
    763      1.25     perry 			__asm("fmovem %0,%%fpcr; fmovem %1,%%fpsr; fmovem %2,%%fpi"::
    764       1.1     itohy 				"m" (tuc.uc_mc.mc_fpregs.fpr_fpcr),
    765       1.1     itohy 				"m" (tuc.uc_mc.mc_fpregs.fpr_fpsr),
    766       1.1     itohy 				"m" (tuc.uc_mc.mc_fpregs.fpr_fpiar));
    767      1.25     perry 			__asm("fmovem %0,%%fp0-%%fp1" : :
    768      1.22        cl 				"m" (tuc.uc_mc.mc_fpregs.fpr_regs[0][0]));
    769       1.1     itohy 		}
    770      1.25     perry 		__asm("frestore %0" : : "m" (tuc.uc_ss.ss_fpstate.FPF_u1));
    771       1.1     itohy 		break;
    772       1.1     itohy #endif
    773       1.1     itohy 	default:
    774       1.1     itohy 		if (tuc.uc_ss.ss_fpstate.fpf_version) {
    775      1.25     perry 			__asm("fmovem %0,%%fpcr/%%fpsr/%%fpi; fmovem %1,%%fp0-%%fp1"::
    776       1.1     itohy 				"m" (tuc.uc_mc.mc_fpregs.fpr_fpcr),
    777      1.22        cl 				"m" (tuc.uc_mc.mc_fpregs.fpr_regs[0][0]));
    778       1.1     itohy 		}
    779      1.25     perry 		__asm("frestore %0" : : "m" (tuc.uc_ss.ss_fpstate.FPF_u1));
    780       1.1     itohy 		break;
    781       1.1     itohy 	}
    782       1.1     itohy 
    783       1.1     itohy #ifdef DEBUG
    784       1.1     itohy 	if ((sigdebug & SDB_FPSTATE) && *(char *)&tuc.uc_ss.ss_fpstate)
    785       1.1     itohy 		printf("linux_rt_sigreturn(%d): copied in FP state (%x) at %p\n",
    786       1.1     itohy 		       p->p_pid, *(u_int *)&tuc.uc_ss.ss_fpstate,
    787       1.1     itohy 		       &tuc.uc_ss.ss_fpstate);
    788       1.1     itohy 	if ((sigdebug & SDB_FOLLOW) ||
    789       1.1     itohy 	    ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
    790       1.1     itohy 		printf("linux_rt_sigreturn(%d): returns\n", p->p_pid);
    791       1.1     itohy #endif
    792       1.1     itohy 
    793       1.1     itohy 	return EJUSTRETURN;
    794       1.1     itohy }
    795       1.1     itohy 
    796       1.1     itohy /*
    797       1.1     itohy  * MPU cache operation of Linux/m68k,
    798       1.1     itohy  * mainly used for dynamic linking.
    799       1.1     itohy  */
    800       1.1     itohy 
    801       1.1     itohy /* scope */
    802       1.1     itohy #define LINUX_FLUSH_SCOPE_LINE	1	/* a cache line */
    803       1.1     itohy #define LINUX_FLUSH_SCOPE_PAGE	2	/* a page */
    804       1.1     itohy #define LINUX_FLUSH_SCOPE_ALL	3	/* the whole cache */
    805       1.1     itohy /* cache */
    806       1.1     itohy #define LINUX_FLUSH_CACHE_DATA	1	/* flush and purge data cache */
    807       1.1     itohy #define LINUX_FLUSH_CACHE_INSN	2	/* purge instruction cache */
    808       1.1     itohy #define LINUX_FLUSH_CACHE_BOTH	3	/* both */
    809       1.1     itohy 
    810       1.1     itohy /* ARGSUSED */
    811       1.1     itohy int
    812      1.36       dsl linux_sys_cacheflush(struct lwp *l, const struct linux_sys_cacheflush_args *uap, register_t *retval)
    813       1.1     itohy {
    814      1.36       dsl 	/* {
    815       1.1     itohy 		syscallarg(unsigned long)	addr;
    816       1.1     itohy 		syscallarg(int)			scope;
    817       1.1     itohy 		syscallarg(int)			cache;
    818       1.1     itohy 		syscallarg(unsigned long)	len;
    819      1.36       dsl 	} */
    820      1.15   thorpej 	struct proc *p = l->l_proc;
    821       1.1     itohy 	int scope, cache;
    822       1.3     itohy 	vaddr_t addr;
    823       1.1     itohy 	int len;
    824       1.1     itohy 	int error;
    825       1.1     itohy 
    826       1.1     itohy 	scope = SCARG(uap, scope);
    827       1.1     itohy 	cache = SCARG(uap, cache);
    828       1.1     itohy 
    829       1.1     itohy 	if (scope < LINUX_FLUSH_SCOPE_LINE || scope > LINUX_FLUSH_SCOPE_ALL
    830       1.1     itohy 				|| cache & ~LINUX_FLUSH_CACHE_BOTH)
    831       1.1     itohy 		return EINVAL;
    832       1.1     itohy 
    833       1.1     itohy #if defined(M68040) || defined(M68060)
    834       1.3     itohy 	addr = (vaddr_t) SCARG(uap, addr);
    835       1.1     itohy 	len = (int) SCARG(uap, len);
    836       1.1     itohy #else
    837       1.1     itohy 	/*
    838       1.1     itohy 	 * We always flush entire cache on 68020/030
    839       1.1     itohy 	 * and these values are not used afterwards.
    840       1.1     itohy 	 */
    841       1.3     itohy 	addr = 0;
    842       1.1     itohy 	len = 0;
    843       1.1     itohy #endif
    844       1.1     itohy 
    845       1.1     itohy 	/*
    846       1.1     itohy 	 * LINUX_FLUSH_SCOPE_ALL (flush whole cache) is limited to super users.
    847       1.1     itohy 	 */
    848       1.1     itohy 	if (scope == LINUX_FLUSH_SCOPE_ALL) {
    849  1.38.8.1     skrll 		if ((error = kauth_authorize_machdep(l->l_cred,
    850  1.38.8.1     skrll 		    KAUTH_MACHDEP_CACHEFLUSH, NULL, NULL, NULL, NULL)) != 0)
    851       1.1     itohy 			return error;
    852       1.1     itohy #if defined(M68040) || defined(M68060)
    853       1.1     itohy 		/* entire cache */
    854       1.1     itohy 		len = INT_MAX;
    855       1.1     itohy #endif
    856       1.1     itohy 	}
    857       1.1     itohy 
    858       1.1     itohy 	error = 0;
    859       1.1     itohy 	if (cache & LINUX_FLUSH_CACHE_DATA)
    860       1.3     itohy 		if ((error = cachectl1(CC_EXTPURGE|CC_PURGE, addr, len, p)) !=0)
    861       1.1     itohy 			return error;
    862       1.1     itohy 	if (cache & LINUX_FLUSH_CACHE_INSN)
    863       1.3     itohy 		error = cachectl1(CC_EXTPURGE|CC_IPURGE, addr, len, p);
    864       1.1     itohy 
    865       1.1     itohy 	return error;
    866       1.1     itohy }
    867       1.1     itohy 
    868       1.1     itohy /*
    869       1.1     itohy  * Convert NetBSD's devices to Linux's.
    870       1.1     itohy  */
    871       1.1     itohy dev_t
    872      1.35       dsl linux_fakedev(dev_t dev, int raw)
    873       1.1     itohy {
    874       1.1     itohy 
    875       1.1     itohy 	/* do nothing for now */
    876       1.1     itohy 	return dev;
    877       1.1     itohy }
    878       1.1     itohy 
    879       1.1     itohy /*
    880       1.1     itohy  * We come here in a last attempt to satisfy a Linux ioctl() call.
    881       1.1     itohy  */
    882       1.1     itohy int
    883      1.36       dsl linux_machdepioctl(struct lwp *l, const struct linux_sys_ioctl_args *uap, register_t *retval)
    884       1.1     itohy {
    885      1.36       dsl 	/* {
    886       1.1     itohy 		syscallarg(int) fd;
    887       1.1     itohy 		syscallarg(u_long) com;
    888      1.31  christos 		syscallarg(void *) data;
    889      1.36       dsl 	} */
    890       1.1     itohy 	struct sys_ioctl_args bia;
    891       1.1     itohy 	u_long com;
    892       1.1     itohy 
    893       1.1     itohy 	SCARG(&bia, fd) = SCARG(uap, fd);
    894       1.1     itohy 	SCARG(&bia, data) = SCARG(uap, data);
    895       1.1     itohy 	com = SCARG(uap, com);
    896       1.1     itohy 
    897       1.1     itohy 	switch (com) {
    898       1.1     itohy 
    899       1.1     itohy 	/* do nothing for now */
    900       1.1     itohy 
    901       1.1     itohy 	default:
    902       1.1     itohy 		printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
    903       1.1     itohy 		return EINVAL;
    904       1.1     itohy 	}
    905       1.1     itohy 	SCARG(&bia, com) = com;
    906      1.24  christos 	return sys_ioctl(l, &bia, retval);
    907       1.1     itohy }
    908      1.23      fvdl 
    909      1.23      fvdl int
    910      1.23      fvdl linux_usertrap(struct lwp *l, vaddr_t trapaddr, void *arg)
    911      1.23      fvdl {
    912      1.23      fvdl 	return 0;
    913      1.23      fvdl }
    914