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