linux_machdep.c revision 1.5.2.4 1 1.5.2.4 bouyer /* $NetBSD: linux_machdep.c,v 1.5.2.4 2001/04/21 17:46:18 bouyer Exp $ */
2 1.5.2.2 bouyer
3 1.5.2.2 bouyer /*-
4 1.5.2.2 bouyer * Copyright (c) 1995, 2000, 2001 The NetBSD Foundation, Inc.
5 1.5.2.2 bouyer * All rights reserved.
6 1.5.2.2 bouyer *
7 1.5.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.5.2.2 bouyer * by Frank van der Linden and Emmanuel Dreyfus.
9 1.5.2.2 bouyer *
10 1.5.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.5.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.5.2.2 bouyer * are met:
13 1.5.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.5.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.5.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.5.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.5.2.2 bouyer * must display the following acknowledgement:
20 1.5.2.2 bouyer * This product includes software developed by the NetBSD
21 1.5.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.5.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.5.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.5.2.2 bouyer * from this software without specific prior written permission.
25 1.5.2.2 bouyer *
26 1.5.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.5.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.5.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.5.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.5.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.5.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.5.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.5.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.5.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.5.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.5.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.5.2.2 bouyer */
38 1.5.2.2 bouyer
39 1.5.2.2 bouyer #include <sys/param.h>
40 1.5.2.2 bouyer #include <sys/systm.h>
41 1.5.2.2 bouyer #include <sys/signalvar.h>
42 1.5.2.2 bouyer #include <sys/kernel.h>
43 1.5.2.2 bouyer #include <sys/map.h>
44 1.5.2.2 bouyer #include <sys/proc.h>
45 1.5.2.2 bouyer #include <sys/user.h>
46 1.5.2.2 bouyer #include <sys/buf.h>
47 1.5.2.2 bouyer #include <sys/reboot.h>
48 1.5.2.2 bouyer #include <sys/conf.h>
49 1.5.2.2 bouyer #include <sys/exec.h>
50 1.5.2.2 bouyer #include <sys/file.h>
51 1.5.2.2 bouyer #include <sys/callout.h>
52 1.5.2.2 bouyer #include <sys/malloc.h>
53 1.5.2.2 bouyer #include <sys/mbuf.h>
54 1.5.2.2 bouyer #include <sys/msgbuf.h>
55 1.5.2.2 bouyer #include <sys/mount.h>
56 1.5.2.2 bouyer #include <sys/vnode.h>
57 1.5.2.2 bouyer #include <sys/device.h>
58 1.5.2.2 bouyer #include <sys/syscallargs.h>
59 1.5.2.2 bouyer #include <sys/filedesc.h>
60 1.5.2.2 bouyer #include <sys/exec_elf.h>
61 1.5.2.2 bouyer #include <sys/disklabel.h>
62 1.5.2.2 bouyer #include <sys/ioctl.h>
63 1.5.2.2 bouyer #include <miscfs/specfs/specdev.h>
64 1.5.2.2 bouyer
65 1.5.2.2 bouyer #include <compat/linux/common/linux_types.h>
66 1.5.2.2 bouyer #include <compat/linux/common/linux_signal.h>
67 1.5.2.2 bouyer #include <compat/linux/common/linux_util.h>
68 1.5.2.2 bouyer #include <compat/linux/common/linux_ioctl.h>
69 1.5.2.2 bouyer #include <compat/linux/common/linux_hdio.h>
70 1.5.2.2 bouyer #include <compat/linux/common/linux_exec.h>
71 1.5.2.2 bouyer #include <compat/linux/common/linux_machdep.h>
72 1.5.2.2 bouyer
73 1.5.2.2 bouyer #include <compat/linux/linux_syscallargs.h>
74 1.5.2.2 bouyer
75 1.5.2.2 bouyer #include <machine/cpu.h>
76 1.5.2.2 bouyer #include <machine/psl.h>
77 1.5.2.2 bouyer #include <machine/reg.h>
78 1.5.2.2 bouyer #include <machine/vmparam.h>
79 1.5.2.2 bouyer
80 1.5.2.2 bouyer /*
81 1.5.2.2 bouyer * To see whether wscons is configured (for virtual console ioctl calls).
82 1.5.2.2 bouyer */
83 1.5.2.2 bouyer #if defined(_KERNEL) && !defined(_LKM)
84 1.5.2.2 bouyer #include "wsdisplay.h"
85 1.5.2.2 bouyer #endif
86 1.5.2.2 bouyer #if (NWSDISPLAY > 0)
87 1.5.2.2 bouyer #include <dev/wscons/wsconsio.h>
88 1.5.2.2 bouyer #include <dev/wscons/wsdisplay_usl_io.h>
89 1.5.2.2 bouyer #if defined(_KERNEL) && !defined(_LKM)
90 1.5.2.2 bouyer #endif
91 1.5.2.2 bouyer #endif
92 1.5.2.2 bouyer
93 1.5.2.2 bouyer /*
94 1.5.2.2 bouyer * Set set up registers on exec.
95 1.5.2.2 bouyer * XXX not used at the moment since in sys/kern/exec_conf, LINUX_COMPAT
96 1.5.2.2 bouyer * entry uses NetBSD's native setregs instead of linux_setregs
97 1.5.2.2 bouyer */
98 1.5.2.2 bouyer void
99 1.5.2.2 bouyer linux_setregs(p, pack, stack)
100 1.5.2.2 bouyer struct proc *p;
101 1.5.2.2 bouyer struct exec_package *pack;
102 1.5.2.2 bouyer u_long stack;
103 1.5.2.2 bouyer {
104 1.5.2.2 bouyer setregs(p, pack, stack);
105 1.5.2.2 bouyer }
106 1.5.2.2 bouyer
107 1.5.2.2 bouyer /*
108 1.5.2.2 bouyer * Send an interrupt to process.
109 1.5.2.2 bouyer *
110 1.5.2.2 bouyer * Adapted from arch/powerpc/powerpc/sig_machdep.c:sendsig and
111 1.5.2.2 bouyer * compat/linux/arch/i386/linux_machdep.c:linux_sendsig
112 1.5.2.2 bouyer *
113 1.5.2.3 bouyer * XXX Does not work well yet with RT signals
114 1.5.2.2 bouyer *
115 1.5.2.2 bouyer */
116 1.5.2.2 bouyer
117 1.5.2.2 bouyer void
118 1.5.2.2 bouyer linux_sendsig(catcher, sig, mask, code) /* XXX Check me */
119 1.5.2.2 bouyer sig_t catcher;
120 1.5.2.2 bouyer int sig;
121 1.5.2.2 bouyer sigset_t *mask;
122 1.5.2.2 bouyer u_long code;
123 1.5.2.2 bouyer {
124 1.5.2.2 bouyer struct proc *p = curproc;
125 1.5.2.2 bouyer struct trapframe *tf;
126 1.5.2.4 bouyer struct linux_sigregs frame;
127 1.5.2.2 bouyer struct linux_pt_regs linux_regs;
128 1.5.2.2 bouyer struct linux_sigcontext sc;
129 1.5.2.4 bouyer register_t fp;
130 1.5.2.2 bouyer int onstack;
131 1.5.2.2 bouyer int i;
132 1.5.2.2 bouyer
133 1.5.2.2 bouyer tf = trapframe(p);
134 1.5.2.2 bouyer
135 1.5.2.2 bouyer /*
136 1.5.2.2 bouyer * Do we need to jump onto the signal stack?
137 1.5.2.2 bouyer */
138 1.5.2.2 bouyer onstack =
139 1.5.2.2 bouyer (p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
140 1.5.2.2 bouyer (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
141 1.5.2.2 bouyer
142 1.5.2.2 bouyer /*
143 1.5.2.2 bouyer * Signal stack is broken (see at the end of linux_sigreturn), so we do
144 1.5.2.2 bouyer * not use it yet. XXX fix this.
145 1.5.2.2 bouyer */
146 1.5.2.2 bouyer onstack=0;
147 1.5.2.2 bouyer
148 1.5.2.2 bouyer /*
149 1.5.2.2 bouyer * Allocate space for the signal handler context.
150 1.5.2.2 bouyer */
151 1.5.2.2 bouyer if (onstack) {
152 1.5.2.4 bouyer fp = (register_t)
153 1.5.2.2 bouyer ((caddr_t)p->p_sigctx.ps_sigstk.ss_sp +
154 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_size);
155 1.5.2.2 bouyer } else {
156 1.5.2.4 bouyer fp = tf->fixreg[1];
157 1.5.2.2 bouyer }
158 1.5.2.4 bouyer #ifdef DEBUG_LINUX
159 1.5.2.4 bouyer printf("fp at start of linux_sendsig = %x\n", fp);
160 1.5.2.4 bouyer #endif
161 1.5.2.4 bouyer fp -= sizeof(struct linux_sigregs);
162 1.5.2.4 bouyer fp &= ~0xf;
163 1.5.2.2 bouyer
164 1.5.2.2 bouyer /*
165 1.5.2.2 bouyer * Prepare a sigcontext for later.
166 1.5.2.2 bouyer */
167 1.5.2.4 bouyer memset(&sc, 0, sizeof sc);
168 1.5.2.2 bouyer sc.lsignal = (int)native_to_linux_sig[sig];
169 1.5.2.2 bouyer sc.lhandler = (unsigned long)catcher;
170 1.5.2.4 bouyer native_to_linux_old_extra_sigset(mask, &sc.lmask, &sc._unused[3]);
171 1.5.2.2 bouyer sc.lregs = (struct linux_pt_regs*)fp;
172 1.5.2.2 bouyer
173 1.5.2.2 bouyer /*
174 1.5.2.2 bouyer * Setup the signal stack frame as Linux does it in
175 1.5.2.2 bouyer * arch/ppc/kernel/signal.c:setup_frame()
176 1.5.2.2 bouyer *
177 1.5.2.2 bouyer * Save register context.
178 1.5.2.2 bouyer */
179 1.5.2.2 bouyer for (i = 0; i < 32; i++)
180 1.5.2.2 bouyer linux_regs.lgpr[i] = tf->fixreg[i];
181 1.5.2.2 bouyer linux_regs.lnip = tf->srr0;
182 1.5.2.2 bouyer linux_regs.lmsr = tf->srr1;
183 1.5.2.2 bouyer linux_regs.lorig_gpr3 = tf->fixreg[3]; /* XXX Is that right? */
184 1.5.2.2 bouyer linux_regs.lctr = tf->ctr;
185 1.5.2.2 bouyer linux_regs.llink = tf->lr;
186 1.5.2.2 bouyer linux_regs.lxer = tf->xer;
187 1.5.2.2 bouyer linux_regs.lccr = tf->cr;
188 1.5.2.2 bouyer linux_regs.lmq = 0; /* Unused, 601 only */
189 1.5.2.4 bouyer linux_regs.ltrap = tf->exc;
190 1.5.2.2 bouyer linux_regs.ldar = tf->dar;
191 1.5.2.4 bouyer linux_regs.ldsisr = tf->dsisr;
192 1.5.2.4 bouyer linux_regs.lresult = 0;
193 1.5.2.2 bouyer
194 1.5.2.4 bouyer memset(&frame, 0, sizeof(frame));
195 1.5.2.4 bouyer memcpy(&frame.lgp_regs, &linux_regs, sizeof(linux_regs));
196 1.5.2.4 bouyer
197 1.5.2.4 bouyer if (curproc == fpuproc)
198 1.5.2.4 bouyer save_fpu(curproc);
199 1.5.2.4 bouyer memcpy(&frame.lfp_regs, curpcb->pcb_fpu.fpr, sizeof(frame.lfp_regs));
200 1.5.2.2 bouyer
201 1.5.2.2 bouyer /*
202 1.5.2.2 bouyer * Copy Linux's signal trampoline on the user stack It should not
203 1.5.2.3 bouyer * be used, but Linux binaries might expect it to be there.
204 1.5.2.2 bouyer */
205 1.5.2.2 bouyer frame.ltramp[0] = 0x38997777; /* li r0, 0x7777 */
206 1.5.2.2 bouyer frame.ltramp[1] = 0x44000002; /* sc */
207 1.5.2.2 bouyer
208 1.5.2.2 bouyer /*
209 1.5.2.2 bouyer * Move it to the user stack
210 1.5.2.2 bouyer * There is a little trick here, about the LINUX_ABIGAP: the
211 1.5.2.2 bouyer * linux_sigreg structure has a 56 int gap to support rs6000/xcoff
212 1.5.2.2 bouyer * binaries. But the Linux kernel seems to do without it, and it
213 1.5.2.2 bouyer * just skip it when building the stack frame. Hence the LINUX_ABIGAP.
214 1.5.2.2 bouyer */
215 1.5.2.4 bouyer if (copyout(&frame, (caddr_t)fp, sizeof (frame) - LINUX_ABIGAP) != 0) {
216 1.5.2.2 bouyer /*
217 1.5.2.2 bouyer * Process has trashed its stack; give it an illegal
218 1.5.2.2 bouyer * instructoin to halt it in its tracks.
219 1.5.2.2 bouyer */
220 1.5.2.2 bouyer sigexit(p, SIGILL);
221 1.5.2.2 bouyer /* NOTREACHED */
222 1.5.2.2 bouyer }
223 1.5.2.2 bouyer
224 1.5.2.2 bouyer /*
225 1.5.2.2 bouyer * Add a sigcontext on the stack
226 1.5.2.2 bouyer */
227 1.5.2.4 bouyer fp -= sizeof(struct linux_sigcontext);
228 1.5.2.4 bouyer if (copyout(&sc, (caddr_t)fp, sizeof (struct linux_sigcontext)) != 0) {
229 1.5.2.2 bouyer /*
230 1.5.2.2 bouyer * Process has trashed its stack; give it an illegal
231 1.5.2.2 bouyer * instructoin to halt it in its tracks.
232 1.5.2.2 bouyer */
233 1.5.2.2 bouyer sigexit(p, SIGILL);
234 1.5.2.2 bouyer /* NOTREACHED */
235 1.5.2.2 bouyer }
236 1.5.2.2 bouyer
237 1.5.2.2 bouyer /*
238 1.5.2.4 bouyer * Set the registers according to how the Linux process expects them.
239 1.5.2.4 bouyer * "Mind the gap" Linux expects a gap here.
240 1.5.2.2 bouyer */
241 1.5.2.4 bouyer tf->fixreg[1] = fp - LINUX__SIGNAL_FRAMESIZE;
242 1.5.2.2 bouyer tf->lr = (int)catcher;
243 1.5.2.3 bouyer tf->fixreg[3] = (int)native_to_linux_sig[sig];
244 1.5.2.4 bouyer tf->fixreg[4] = fp;
245 1.5.2.2 bouyer tf->srr0 = (int)p->p_sigctx.ps_sigcode;
246 1.5.2.2 bouyer
247 1.5.2.4 bouyer #ifdef DEBUG_LINUX
248 1.5.2.4 bouyer printf("fp at end of linux_sendsig = %x\n", fp);
249 1.5.2.4 bouyer #endif
250 1.5.2.2 bouyer /*
251 1.5.2.2 bouyer * Remember that we're now on the signal stack.
252 1.5.2.2 bouyer */
253 1.5.2.2 bouyer if (onstack)
254 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
255 1.5.2.2 bouyer #ifdef DEBUG_LINUX
256 1.5.2.2 bouyer printf("linux_sendsig: exitting. fp=0x%lx\n",(long)fp);
257 1.5.2.2 bouyer #endif
258 1.5.2.2 bouyer }
259 1.5.2.2 bouyer
260 1.5.2.2 bouyer /*
261 1.5.2.2 bouyer * System call to cleanup state after a signal
262 1.5.2.2 bouyer * has been taken. Reset signal mask and
263 1.5.2.2 bouyer * stack state from context left by sendsig (above).
264 1.5.2.2 bouyer * Return to previous pc and psl as specified by
265 1.5.2.2 bouyer * context left by sendsig. Check carefully to
266 1.5.2.2 bouyer * make sure that the user has not modified the
267 1.5.2.2 bouyer * psl to gain improper privileges or to cause
268 1.5.2.2 bouyer * a machine fault.
269 1.5.2.2 bouyer *
270 1.5.2.2 bouyer * XXX not tested
271 1.5.2.2 bouyer */
272 1.5.2.2 bouyer int
273 1.5.2.2 bouyer linux_sys_rt_sigreturn(p, v, retval)
274 1.5.2.2 bouyer struct proc *p;
275 1.5.2.2 bouyer void *v;
276 1.5.2.2 bouyer register_t *retval;
277 1.5.2.2 bouyer {
278 1.5.2.2 bouyer struct linux_sys_rt_sigreturn_args /* {
279 1.5.2.2 bouyer syscallarg(struct linux_rt_sigframe *) sfp;
280 1.5.2.2 bouyer } */ *uap = v;
281 1.5.2.2 bouyer struct linux_rt_sigframe *scp, sigframe;
282 1.5.2.4 bouyer struct linux_sigregs sregs;
283 1.5.2.4 bouyer struct linux_pt_regs *lregs;
284 1.5.2.2 bouyer struct trapframe *tf;
285 1.5.2.2 bouyer sigset_t mask;
286 1.5.2.2 bouyer int i;
287 1.5.2.2 bouyer
288 1.5.2.2 bouyer /*
289 1.5.2.2 bouyer * The trampoline code hands us the context.
290 1.5.2.2 bouyer * It is unsafe to keep track of it ourselves, in the event that a
291 1.5.2.2 bouyer * program jumps out of a signal handler.
292 1.5.2.2 bouyer */
293 1.5.2.2 bouyer scp = SCARG(uap, sfp);
294 1.5.2.2 bouyer
295 1.5.2.2 bouyer /*
296 1.5.2.2 bouyer * Get the context from user stack
297 1.5.2.2 bouyer */
298 1.5.2.4 bouyer if (copyin((caddr_t)scp, &sigframe, sizeof(*scp)))
299 1.5.2.2 bouyer return (EFAULT);
300 1.5.2.2 bouyer
301 1.5.2.2 bouyer /*
302 1.5.2.4 bouyer * Make sure, fpu is sync'ed
303 1.5.2.2 bouyer */
304 1.5.2.4 bouyer if (curproc == fpuproc)
305 1.5.2.4 bouyer save_fpu(curproc);
306 1.5.2.2 bouyer
307 1.5.2.2 bouyer /*
308 1.5.2.4 bouyer * Restore register context.
309 1.5.2.2 bouyer */
310 1.5.2.4 bouyer if (copyin((caddr_t)sigframe.luc.luc_context.lregs,
311 1.5.2.4 bouyer &sregs, sizeof(sregs)))
312 1.5.2.4 bouyer return (EFAULT);
313 1.5.2.4 bouyer lregs = (struct linux_pt_regs *)&sregs.lgp_regs;
314 1.5.2.4 bouyer
315 1.5.2.2 bouyer tf = trapframe(p);
316 1.5.2.2 bouyer #ifdef DEBUG_LINUX
317 1.5.2.2 bouyer printf("linux_sys_sigreturn: trapframe=0x%lx scp=0x%lx\n",
318 1.5.2.2 bouyer (unsigned long)tf, (unsigned long)scp);
319 1.5.2.2 bouyer #endif
320 1.5.2.2 bouyer
321 1.5.2.4 bouyer if ((lregs->lmsr & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
322 1.5.2.2 bouyer return (EINVAL);
323 1.5.2.2 bouyer
324 1.5.2.2 bouyer for (i = 0; i < 32; i++)
325 1.5.2.4 bouyer tf->fixreg[i] = lregs->lgpr[i];
326 1.5.2.4 bouyer tf->lr = lregs->llink;
327 1.5.2.4 bouyer tf->cr = lregs->lccr;
328 1.5.2.4 bouyer tf->xer = lregs->lxer;
329 1.5.2.4 bouyer tf->ctr = lregs->lctr;
330 1.5.2.4 bouyer tf->srr0 = lregs->lnip;
331 1.5.2.4 bouyer tf->srr1 = lregs->lmsr;
332 1.5.2.4 bouyer
333 1.5.2.4 bouyer memcpy(curpcb->pcb_fpu.fpr, (caddr_t)&sregs.lfp_regs,
334 1.5.2.4 bouyer sizeof(curpcb->pcb_fpu.fpr));
335 1.5.2.2 bouyer
336 1.5.2.2 bouyer /*
337 1.5.2.2 bouyer * Restore signal stack.
338 1.5.2.2 bouyer *
339 1.5.2.2 bouyer * XXX cannot find the onstack information in Linux sig context.
340 1.5.2.2 bouyer * Is signal stack really supported on Linux?
341 1.5.2.2 bouyer *
342 1.5.2.2 bouyer * It seems to be supported in libc6...
343 1.5.2.2 bouyer */
344 1.5.2.2 bouyer /* if (sc.sc_onstack & SS_ONSTACK)
345 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
346 1.5.2.2 bouyer else */
347 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
348 1.5.2.2 bouyer
349 1.5.2.4 bouyer /*
350 1.5.2.4 bouyer * Grab the signal mask
351 1.5.2.4 bouyer */
352 1.5.2.4 bouyer linux_to_native_sigset(&sigframe.luc.luc_sigmask, &mask);
353 1.5.2.4 bouyer (void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
354 1.5.2.4 bouyer
355 1.5.2.2 bouyer return (EJUSTRETURN);
356 1.5.2.2 bouyer }
357 1.5.2.2 bouyer
358 1.5.2.2 bouyer
359 1.5.2.2 bouyer /*
360 1.5.2.2 bouyer * The following needs code review for potential security issues
361 1.5.2.2 bouyer */
362 1.5.2.2 bouyer int
363 1.5.2.2 bouyer linux_sys_sigreturn(p, v, retval)
364 1.5.2.2 bouyer struct proc *p;
365 1.5.2.2 bouyer void *v;
366 1.5.2.2 bouyer register_t *retval;
367 1.5.2.2 bouyer {
368 1.5.2.2 bouyer struct linux_sys_sigreturn_args /* {
369 1.5.2.2 bouyer syscallarg(struct linux_sigcontext *) scp;
370 1.5.2.2 bouyer } */ *uap = v;
371 1.5.2.2 bouyer struct linux_sigcontext *scp, context;
372 1.5.2.4 bouyer struct linux_sigregs sregs;
373 1.5.2.4 bouyer struct linux_pt_regs *lregs;
374 1.5.2.2 bouyer struct trapframe *tf;
375 1.5.2.2 bouyer sigset_t mask;
376 1.5.2.2 bouyer int i;
377 1.5.2.2 bouyer
378 1.5.2.2 bouyer /*
379 1.5.2.2 bouyer * The trampoline code hands us the context.
380 1.5.2.2 bouyer * It is unsafe to keep track of it ourselves, in the event that a
381 1.5.2.2 bouyer * program jumps out of a signal handler.
382 1.5.2.2 bouyer */
383 1.5.2.2 bouyer scp = SCARG(uap, scp);
384 1.5.2.2 bouyer
385 1.5.2.2 bouyer /*
386 1.5.2.4 bouyer * Get the context from user stack
387 1.5.2.2 bouyer */
388 1.5.2.4 bouyer if (copyin(scp, &context, sizeof(*scp)))
389 1.5.2.4 bouyer return (EFAULT);
390 1.5.2.2 bouyer
391 1.5.2.2 bouyer /*
392 1.5.2.4 bouyer * Make sure, fpu is in sync
393 1.5.2.2 bouyer */
394 1.5.2.4 bouyer if (curproc == fpuproc)
395 1.5.2.4 bouyer save_fpu(curproc);
396 1.5.2.2 bouyer
397 1.5.2.2 bouyer /*
398 1.5.2.4 bouyer * Restore register context.
399 1.5.2.2 bouyer */
400 1.5.2.4 bouyer if (copyin((caddr_t)context.lregs, &sregs, sizeof(sregs)))
401 1.5.2.4 bouyer return (EFAULT);
402 1.5.2.4 bouyer lregs = (struct linux_pt_regs *)&sregs.lgp_regs;
403 1.5.2.4 bouyer
404 1.5.2.2 bouyer tf = trapframe(p);
405 1.5.2.2 bouyer #ifdef DEBUG_LINUX
406 1.5.2.2 bouyer printf("linux_sys_sigreturn: trapframe=0x%lx scp=0x%lx\n",
407 1.5.2.2 bouyer (unsigned long)tf, (unsigned long)scp);
408 1.5.2.2 bouyer #endif
409 1.5.2.2 bouyer
410 1.5.2.4 bouyer if ((lregs->lmsr & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
411 1.5.2.2 bouyer return (EINVAL);
412 1.5.2.2 bouyer
413 1.5.2.2 bouyer for (i = 0; i < 32; i++)
414 1.5.2.4 bouyer tf->fixreg[i] = lregs->lgpr[i];
415 1.5.2.4 bouyer tf->lr = lregs->llink;
416 1.5.2.4 bouyer tf->cr = lregs->lccr;
417 1.5.2.4 bouyer tf->xer = lregs->lxer;
418 1.5.2.4 bouyer tf->ctr = lregs->lctr;
419 1.5.2.4 bouyer tf->srr0 = lregs->lnip;
420 1.5.2.4 bouyer tf->srr1 = lregs->lmsr;
421 1.5.2.4 bouyer
422 1.5.2.4 bouyer memcpy(curpcb->pcb_fpu.fpr, (caddr_t)&sregs.lfp_regs,
423 1.5.2.4 bouyer sizeof(curpcb->pcb_fpu.fpr));
424 1.5.2.2 bouyer
425 1.5.2.2 bouyer /*
426 1.5.2.2 bouyer * Restore signal stack.
427 1.5.2.2 bouyer *
428 1.5.2.2 bouyer * XXX cannot find the onstack information in Linux sig context.
429 1.5.2.2 bouyer * Is signal stack really supported on Linux?
430 1.5.2.2 bouyer */
431 1.5.2.2 bouyer #if 0
432 1.5.2.2 bouyer if (sc.sc_onstack & SS_ONSTACK)
433 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
434 1.5.2.2 bouyer else
435 1.5.2.2 bouyer #endif
436 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
437 1.5.2.2 bouyer
438 1.5.2.2 bouyer /* Restore signal mask. */
439 1.5.2.4 bouyer linux_old_extra_to_native_sigset(&context.lmask,
440 1.5.2.4 bouyer &context._unused[3],
441 1.5.2.4 bouyer &mask);
442 1.5.2.2 bouyer (void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
443 1.5.2.2 bouyer
444 1.5.2.2 bouyer return (EJUSTRETURN);
445 1.5.2.2 bouyer }
446 1.5.2.2 bouyer
447 1.5.2.2 bouyer
448 1.5.2.2 bouyer int
449 1.5.2.2 bouyer linux_sys_modify_ldt(p, v, retval)
450 1.5.2.2 bouyer struct proc *p;
451 1.5.2.2 bouyer void *v;
452 1.5.2.2 bouyer register_t *retval;
453 1.5.2.2 bouyer {
454 1.5.2.2 bouyer /*
455 1.5.2.2 bouyer * This syscall is not implemented in Linux/PowerPC: we should not
456 1.5.2.2 bouyer * be here
457 1.5.2.2 bouyer */
458 1.5.2.2 bouyer #ifdef DEBUG_LINUX
459 1.5.2.2 bouyer printf("linux_sys_modify_ldt: should not be here.\n");
460 1.5.2.2 bouyer #endif
461 1.5.2.2 bouyer return 0;
462 1.5.2.2 bouyer }
463 1.5.2.2 bouyer
464 1.5.2.3 bouyer /*
465 1.5.2.3 bouyer * major device numbers remapping
466 1.5.2.3 bouyer */
467 1.5.2.2 bouyer dev_t
468 1.5.2.2 bouyer linux_fakedev(dev)
469 1.5.2.2 bouyer dev_t dev;
470 1.5.2.2 bouyer {
471 1.5.2.2 bouyer /* XXX write me */
472 1.5.2.2 bouyer return dev;
473 1.5.2.2 bouyer }
474 1.5.2.2 bouyer
475 1.5.2.2 bouyer /*
476 1.5.2.2 bouyer * We come here in a last attempt to satisfy a Linux ioctl() call
477 1.5.2.2 bouyer */
478 1.5.2.2 bouyer int
479 1.5.2.2 bouyer linux_machdepioctl(p, v, retval)
480 1.5.2.2 bouyer struct proc *p;
481 1.5.2.2 bouyer void *v;
482 1.5.2.2 bouyer register_t *retval;
483 1.5.2.2 bouyer {
484 1.5.2.2 bouyer struct linux_sys_ioctl_args /* {
485 1.5.2.2 bouyer syscallarg(int) fd;
486 1.5.2.2 bouyer syscallarg(u_long) com;
487 1.5.2.2 bouyer syscallarg(caddr_t) data;
488 1.5.2.2 bouyer } */ *uap = v;
489 1.5.2.2 bouyer struct sys_ioctl_args bia;
490 1.5.2.2 bouyer u_long com;
491 1.5.2.2 bouyer
492 1.5.2.2 bouyer SCARG(&bia, fd) = SCARG(uap, fd);
493 1.5.2.2 bouyer SCARG(&bia, data) = SCARG(uap, data);
494 1.5.2.2 bouyer com = SCARG(uap, com);
495 1.5.2.2 bouyer
496 1.5.2.2 bouyer switch (com) {
497 1.5.2.2 bouyer default:
498 1.5.2.2 bouyer printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
499 1.5.2.2 bouyer return EINVAL;
500 1.5.2.2 bouyer }
501 1.5.2.2 bouyer SCARG(&bia, com) = com;
502 1.5.2.2 bouyer return sys_ioctl(p, &bia, retval);
503 1.5.2.2 bouyer }
504 1.5.2.2 bouyer /*
505 1.5.2.2 bouyer * Set I/O permissions for a process. Just set the maximum level
506 1.5.2.2 bouyer * right away (ignoring the argument), otherwise we would have
507 1.5.2.2 bouyer * to rely on I/O permission maps, which are not implemented.
508 1.5.2.2 bouyer */
509 1.5.2.2 bouyer int
510 1.5.2.2 bouyer linux_sys_iopl(p, v, retval)
511 1.5.2.2 bouyer struct proc *p;
512 1.5.2.2 bouyer void *v;
513 1.5.2.2 bouyer register_t *retval;
514 1.5.2.2 bouyer {
515 1.5.2.2 bouyer /*
516 1.5.2.2 bouyer * This syscall is not implemented in Linux/PowerPC: we should not be here
517 1.5.2.2 bouyer */
518 1.5.2.2 bouyer #ifdef DEBUG_LINUX
519 1.5.2.2 bouyer printf("linux_sys_iopl: should not be here.\n");
520 1.5.2.2 bouyer #endif
521 1.5.2.2 bouyer return 0;
522 1.5.2.2 bouyer }
523 1.5.2.2 bouyer
524 1.5.2.2 bouyer /*
525 1.5.2.2 bouyer * See above. If a root process tries to set access to an I/O port,
526 1.5.2.2 bouyer * just let it have the whole range.
527 1.5.2.2 bouyer */
528 1.5.2.2 bouyer int
529 1.5.2.2 bouyer linux_sys_ioperm(p, v, retval)
530 1.5.2.2 bouyer struct proc *p;
531 1.5.2.2 bouyer void *v;
532 1.5.2.2 bouyer register_t *retval;
533 1.5.2.2 bouyer {
534 1.5.2.2 bouyer /*
535 1.5.2.2 bouyer * This syscall is not implemented in Linux/PowerPC: we should not be here
536 1.5.2.2 bouyer */
537 1.5.2.2 bouyer #ifdef DEBUG_LINUX
538 1.5.2.2 bouyer printf("linux_sys_ioperm: should not be here.\n");
539 1.5.2.2 bouyer #endif
540 1.5.2.2 bouyer return 0;
541 1.5.2.2 bouyer }
542 1.5.2.2 bouyer
543 1.5.2.2 bouyer /*
544 1.5.2.2 bouyer * wrapper linux_sys_new_uname() -> linux_sys_uname()
545 1.5.2.2 bouyer */
546 1.5.2.2 bouyer int
547 1.5.2.2 bouyer linux_sys_new_uname(p, v, retval)
548 1.5.2.2 bouyer struct proc *p;
549 1.5.2.2 bouyer void *v;
550 1.5.2.2 bouyer register_t *retval;
551 1.5.2.2 bouyer {
552 1.5.2.2 bouyer return linux_sys_uname(p, v, retval);
553 1.5.2.2 bouyer }
554 1.5.2.2 bouyer
555 1.5.2.2 bouyer /*
556 1.5.2.2 bouyer * wrapper linux_sys_new_select() -> linux_sys_select()
557 1.5.2.2 bouyer */
558 1.5.2.2 bouyer int
559 1.5.2.2 bouyer linux_sys_new_select(p, v, retval)
560 1.5.2.2 bouyer struct proc *p;
561 1.5.2.2 bouyer void *v;
562 1.5.2.2 bouyer register_t *retval;
563 1.5.2.2 bouyer {
564 1.5.2.2 bouyer return linux_sys_select(p, v, retval);
565 1.5.2.2 bouyer }
566