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