linux_machdep.c revision 1.37 1 1.37 christos /* $NetBSD: linux_machdep.c,v 1.37 2007/03/04 06:01:18 christos Exp $ */
2 1.1 erh
3 1.1 erh /*-
4 1.1 erh * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 erh * All rights reserved.
6 1.1 erh *
7 1.1 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.1 erh * by Eric Haszlakiewicz.
9 1.1 erh *
10 1.1 erh * Redistribution and use in source and binary forms, with or without
11 1.1 erh * modification, are permitted provided that the following conditions
12 1.1 erh * are met:
13 1.1 erh * 1. Redistributions of source code must retain the above copyright
14 1.1 erh * notice, this list of conditions and the following disclaimer.
15 1.1 erh * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 erh * notice, this list of conditions and the following disclaimer in the
17 1.1 erh * documentation and/or other materials provided with the distribution.
18 1.1 erh * 3. All advertising materials mentioning features or use of this software
19 1.1 erh * must display the following acknowledgement:
20 1.1 erh * This product includes software developed by the NetBSD
21 1.1 erh * Foundation, Inc. and its contributors.
22 1.1 erh * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 erh * contributors may be used to endorse or promote products derived
24 1.1 erh * from this software without specific prior written permission.
25 1.1 erh *
26 1.1 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 erh * POSSIBILITY OF SUCH DAMAGE.
37 1.1 erh *
38 1.1 erh * Based on sys/arch/i386/i386/linux_machdep.c:
39 1.1 erh * linux_machdep.c,v 1.42 1998/09/11 12:50:06 mycroft Exp
40 1.1 erh * written by Frank van der Linden
41 1.1 erh *
42 1.1 erh */
43 1.19 lukem
44 1.19 lukem #include <sys/cdefs.h>
45 1.37 christos __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.37 2007/03/04 06:01:18 christos Exp $");
46 1.1 erh
47 1.1 erh #include <sys/param.h>
48 1.1 erh #include <sys/systm.h>
49 1.1 erh #include <sys/signalvar.h>
50 1.1 erh #include <sys/kernel.h>
51 1.1 erh #include <sys/proc.h>
52 1.1 erh #include <sys/user.h>
53 1.1 erh #include <sys/buf.h>
54 1.1 erh #include <sys/reboot.h>
55 1.1 erh #include <sys/conf.h>
56 1.1 erh #include <sys/exec.h>
57 1.1 erh #include <sys/file.h>
58 1.1 erh #include <sys/callout.h>
59 1.1 erh #include <sys/malloc.h>
60 1.1 erh #include <sys/mbuf.h>
61 1.1 erh #include <sys/msgbuf.h>
62 1.1 erh #include <sys/mount.h>
63 1.1 erh #include <sys/vnode.h>
64 1.1 erh #include <sys/device.h>
65 1.1 erh #include <sys/syscallargs.h>
66 1.1 erh #include <sys/filedesc.h>
67 1.1 erh #include <sys/exec_elf.h>
68 1.15 manu #include <sys/ioctl.h>
69 1.34 yamt #include <sys/kauth.h>
70 1.1 erh
71 1.1 erh #include <uvm/uvm_extern.h>
72 1.1 erh
73 1.2 christos #include <compat/linux/common/linux_types.h>
74 1.2 christos #include <compat/linux/common/linux_signal.h>
75 1.2 christos #include <compat/linux/common/linux_siginfo.h>
76 1.2 christos #include <compat/linux/common/linux_util.h>
77 1.2 christos #include <compat/linux/common/linux_ioctl.h>
78 1.2 christos #include <compat/linux/common/linux_exec.h>
79 1.2 christos #include <compat/linux/common/linux_machdep.h>
80 1.3 erh #include <compat/linux/common/linux_emuldata.h>
81 1.2 christos
82 1.1 erh #include <compat/linux/linux_syscallargs.h>
83 1.1 erh
84 1.3 erh #include <machine/alpha.h>
85 1.1 erh #include <machine/reg.h>
86 1.1 erh
87 1.17 mrg #if defined(_KERNEL_OPT)
88 1.1 erh #include "wsdisplay.h"
89 1.12 jdolecek #endif
90 1.1 erh #if (NWSDISPLAY >0)
91 1.1 erh #include <dev/wscons/wsdisplay_usl_io.h>
92 1.1 erh #endif
93 1.14 sommerfe #ifdef DEBUG
94 1.14 sommerfe #include <machine/sigdebug.h>
95 1.14 sommerfe #endif
96 1.1 erh
97 1.1 erh /*
98 1.1 erh * Deal with some alpha-specific things in the Linux emulation code.
99 1.1 erh */
100 1.1 erh
101 1.1 erh void
102 1.26 thorpej linux_setregs(l, epp, stack)
103 1.26 thorpej struct lwp *l;
104 1.1 erh struct exec_package *epp;
105 1.1 erh u_long stack;
106 1.1 erh {
107 1.18 simonb #ifdef DEBUG
108 1.26 thorpej struct trapframe *tfp = l->l_md.md_tf;
109 1.18 simonb #endif
110 1.18 simonb
111 1.26 thorpej setregs(l, epp, stack);
112 1.18 simonb #ifdef DEBUG
113 1.18 simonb /*
114 1.18 simonb * Linux has registers set to zero on entry; for DEBUG kernels
115 1.18 simonb * the alpha setregs() fills registers with 0xbabefacedeadbeef.
116 1.18 simonb */
117 1.18 simonb memset(tfp->tf_regs, 0, FRAME_SIZE * sizeof tfp->tf_regs[0]);
118 1.18 simonb #endif
119 1.1 erh }
120 1.1 erh
121 1.30 matt void
122 1.30 matt setup_linux_rt_sigframe(struct trapframe *tf, int sig, const sigset_t *mask)
123 1.1 erh {
124 1.26 thorpej struct lwp *l = curlwp;
125 1.26 thorpej struct proc *p = l->l_proc;
126 1.1 erh struct linux_rt_sigframe *sfp, sigframe;
127 1.36 ad int onstack, error;
128 1.1 erh int fsize, rndfsize;
129 1.1 erh extern char linux_rt_sigcode[], linux_rt_esigcode[];
130 1.1 erh
131 1.1 erh /* Do we need to jump onto the signal stack? */
132 1.36 ad onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
133 1.13 jdolecek (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
134 1.1 erh
135 1.1 erh /* Allocate space for the signal handler context. */
136 1.1 erh fsize = sizeof(struct linux_rt_sigframe);
137 1.1 erh rndfsize = ((fsize + 15) / 16) * 16;
138 1.1 erh
139 1.1 erh if (onstack)
140 1.1 erh sfp = (struct linux_rt_sigframe *)
141 1.37 christos ((void *)l->l_sigstk.ss_sp +
142 1.36 ad l->l_sigstk.ss_size);
143 1.1 erh else
144 1.1 erh sfp = (struct linux_rt_sigframe *)(alpha_pal_rdusp());
145 1.37 christos sfp = (struct linux_rt_sigframe *)((void *)sfp - rndfsize);
146 1.1 erh
147 1.1 erh #ifdef DEBUG
148 1.14 sommerfe if ((sigdebug & SDB_KSTACK) && (p->p_pid == sigpid))
149 1.1 erh printf("linux_sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
150 1.1 erh sig, &onstack, sfp);
151 1.1 erh #endif /* DEBUG */
152 1.1 erh
153 1.1 erh /*
154 1.1 erh * Build the signal context to be used by sigreturn.
155 1.1 erh */
156 1.30 matt memset(&sigframe.uc, 0, sizeof(struct linux_ucontext));
157 1.1 erh sigframe.uc.uc_mcontext.sc_onstack = onstack;
158 1.8 erh
159 1.8 erh /* Setup potentially partial signal mask in sc_mask. */
160 1.8 erh /* But get all of it in uc_sigmask */
161 1.20 christos native_to_linux_old_sigset(&sigframe.uc.uc_mcontext.sc_mask, mask);
162 1.20 christos native_to_linux_sigset(&sigframe.uc.uc_sigmask, mask);
163 1.8 erh
164 1.1 erh sigframe.uc.uc_mcontext.sc_pc = tf->tf_regs[FRAME_PC];
165 1.1 erh sigframe.uc.uc_mcontext.sc_ps = ALPHA_PSL_USERMODE;
166 1.1 erh frametoreg(tf, (struct reg *)sigframe.uc.uc_mcontext.sc_regs);
167 1.1 erh sigframe.uc.uc_mcontext.sc_regs[R_SP] = alpha_pal_rdusp();
168 1.1 erh
169 1.26 thorpej alpha_enable_fp(l, 1);
170 1.16 ross sigframe.uc.uc_mcontext.sc_fpcr = alpha_read_fpcr();
171 1.26 thorpej sigframe.uc.uc_mcontext.sc_fp_control = alpha_read_fp_c(l);
172 1.16 ross alpha_pal_wrfen(0);
173 1.1 erh
174 1.1 erh sigframe.uc.uc_mcontext.sc_traparg_a0 = tf->tf_regs[FRAME_A0];
175 1.1 erh sigframe.uc.uc_mcontext.sc_traparg_a1 = tf->tf_regs[FRAME_A1];
176 1.1 erh sigframe.uc.uc_mcontext.sc_traparg_a2 = tf->tf_regs[FRAME_A2];
177 1.1 erh
178 1.1 erh /*
179 1.1 erh * XXX XAX Create bogus siginfo data. This can't really
180 1.1 erh * XXX be fixed until NetBSD has realtime signals.
181 1.1 erh * XXX Or we do the emuldata thing.
182 1.1 erh * XXX -erh
183 1.1 erh */
184 1.30 matt memset(&sigframe.info, 0, sizeof(struct linux_siginfo));
185 1.5 erh sigframe.info.lsi_signo = sig;
186 1.5 erh sigframe.info.lsi_code = LINUX_SI_USER;
187 1.4 erh sigframe.info.lsi_pid = p->p_pid;
188 1.35 ad sigframe.info.lsi_uid = kauth_cred_geteuid(l->l_cred); /* Use real uid here? */
189 1.1 erh
190 1.36 ad sendsig_reset(l, sig);
191 1.36 ad mutex_exit(&p->p_smutex);
192 1.37 christos error = copyout((void *)&sigframe, (void *)sfp, fsize);
193 1.36 ad mutex_enter(&p->p_smutex);
194 1.36 ad
195 1.36 ad if (error != 0) {
196 1.1 erh #ifdef DEBUG
197 1.1 erh if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
198 1.1 erh printf("sendsig(%d): copyout failed on sig %d\n",
199 1.1 erh p->p_pid, sig);
200 1.1 erh #endif
201 1.1 erh /*
202 1.1 erh * Process has trashed its stack; give it an illegal
203 1.1 erh * instruction to halt it in its tracks.
204 1.1 erh */
205 1.26 thorpej sigexit(l, SIGILL);
206 1.1 erh /* NOTREACHED */
207 1.1 erh }
208 1.1 erh
209 1.1 erh /* Pass pointers to siginfo and ucontext in the regs */
210 1.1 erh tf->tf_regs[FRAME_A1] = (unsigned long)&sfp->info;
211 1.1 erh tf->tf_regs[FRAME_A2] = (unsigned long)&sfp->uc;
212 1.1 erh
213 1.1 erh /* Address of trampoline code. End up at this PC after mi_switch */
214 1.1 erh tf->tf_regs[FRAME_PC] =
215 1.22 chs (u_int64_t)(p->p_psstr - (linux_rt_esigcode - linux_rt_sigcode));
216 1.1 erh
217 1.1 erh /* Adjust the stack */
218 1.1 erh alpha_pal_wrusp((unsigned long)sfp);
219 1.1 erh
220 1.1 erh /* Remember that we're now on the signal stack. */
221 1.1 erh if (onstack)
222 1.36 ad l->l_sigstk.ss_flags |= SS_ONSTACK;
223 1.1 erh }
224 1.1 erh
225 1.1 erh void setup_linux_sigframe(tf, sig, mask)
226 1.1 erh struct trapframe *tf;
227 1.1 erh int sig;
228 1.29 simonb const sigset_t *mask;
229 1.1 erh {
230 1.26 thorpej struct lwp *l = curlwp;
231 1.26 thorpej struct proc *p = l->l_proc;
232 1.1 erh struct linux_sigframe *sfp, sigframe;
233 1.36 ad int onstack, error;
234 1.1 erh int fsize, rndfsize;
235 1.1 erh extern char linux_sigcode[], linux_esigcode[];
236 1.1 erh
237 1.1 erh /* Do we need to jump onto the signal stack? */
238 1.36 ad onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
239 1.13 jdolecek (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
240 1.1 erh
241 1.1 erh /* Allocate space for the signal handler context. */
242 1.1 erh fsize = sizeof(struct linux_sigframe);
243 1.1 erh rndfsize = ((fsize + 15) / 16) * 16;
244 1.1 erh
245 1.1 erh if (onstack)
246 1.1 erh sfp = (struct linux_sigframe *)
247 1.37 christos ((void *)l->l_sigstk.ss_sp +
248 1.36 ad l->l_sigstk.ss_size);
249 1.1 erh else
250 1.1 erh sfp = (struct linux_sigframe *)(alpha_pal_rdusp());
251 1.37 christos sfp = (struct linux_sigframe *)((void *)sfp - rndfsize);
252 1.1 erh
253 1.1 erh #ifdef DEBUG
254 1.14 sommerfe if ((sigdebug & SDB_KSTACK) && (p->p_pid == sigpid))
255 1.1 erh printf("linux_sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
256 1.1 erh sig, &onstack, sfp);
257 1.1 erh #endif /* DEBUG */
258 1.1 erh
259 1.1 erh /*
260 1.1 erh * Build the signal context to be used by sigreturn.
261 1.1 erh */
262 1.30 matt memset(&sigframe.sf_sc, 0, sizeof(struct linux_ucontext));
263 1.1 erh sigframe.sf_sc.sc_onstack = onstack;
264 1.20 christos native_to_linux_old_sigset(&sigframe.sf_sc.sc_mask, mask);
265 1.1 erh sigframe.sf_sc.sc_pc = tf->tf_regs[FRAME_PC];
266 1.1 erh sigframe.sf_sc.sc_ps = ALPHA_PSL_USERMODE;
267 1.1 erh frametoreg(tf, (struct reg *)sigframe.sf_sc.sc_regs);
268 1.1 erh sigframe.sf_sc.sc_regs[R_SP] = alpha_pal_rdusp();
269 1.1 erh
270 1.26 thorpej if (l == fpcurlwp) {
271 1.1 erh alpha_pal_wrfen(1);
272 1.26 thorpej savefpstate(&l->l_addr->u_pcb.pcb_fp);
273 1.1 erh alpha_pal_wrfen(0);
274 1.26 thorpej sigframe.sf_sc.sc_fpcr = l->l_addr->u_pcb.pcb_fp.fpr_cr;
275 1.26 thorpej fpcurlwp = NULL;
276 1.1 erh }
277 1.1 erh /* XXX ownedfp ? etc...? */
278 1.1 erh
279 1.1 erh sigframe.sf_sc.sc_traparg_a0 = tf->tf_regs[FRAME_A0];
280 1.1 erh sigframe.sf_sc.sc_traparg_a1 = tf->tf_regs[FRAME_A1];
281 1.1 erh sigframe.sf_sc.sc_traparg_a2 = tf->tf_regs[FRAME_A2];
282 1.1 erh
283 1.36 ad sendsig_reset(l, sig);
284 1.36 ad mutex_exit(&p->p_smutex);
285 1.37 christos error = copyout((void *)&sigframe, (void *)sfp, fsize);
286 1.36 ad mutex_enter(&p->p_smutex);
287 1.36 ad
288 1.36 ad if (error != 0) {
289 1.1 erh #ifdef DEBUG
290 1.1 erh if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
291 1.1 erh printf("sendsig(%d): copyout failed on sig %d\n",
292 1.1 erh p->p_pid, sig);
293 1.1 erh #endif
294 1.1 erh /*
295 1.1 erh * Process has trashed its stack; give it an illegal
296 1.1 erh * instruction to halt it in its tracks.
297 1.1 erh */
298 1.26 thorpej sigexit(l, SIGILL);
299 1.1 erh /* NOTREACHED */
300 1.1 erh }
301 1.1 erh
302 1.1 erh /* Pass pointers to sigcontext in the regs */
303 1.1 erh tf->tf_regs[FRAME_A1] = 0;
304 1.1 erh tf->tf_regs[FRAME_A2] = (unsigned long)&sfp->sf_sc;
305 1.1 erh
306 1.1 erh /* Address of trampoline code. End up at this PC after mi_switch */
307 1.1 erh tf->tf_regs[FRAME_PC] =
308 1.22 chs (u_int64_t)(p->p_psstr - (linux_esigcode - linux_sigcode));
309 1.1 erh
310 1.1 erh /* Adjust the stack */
311 1.1 erh alpha_pal_wrusp((unsigned long)sfp);
312 1.1 erh
313 1.1 erh /* Remember that we're now on the signal stack. */
314 1.1 erh if (onstack)
315 1.36 ad l->l_sigstk.ss_flags |= SS_ONSTACK;
316 1.1 erh }
317 1.1 erh
318 1.1 erh /*
319 1.1 erh * Send an interrupt to process.
320 1.1 erh *
321 1.1 erh * Stack is set up to allow sigcode stored
322 1.1 erh * in u. to call routine, followed by kcall
323 1.1 erh * to sigreturn routine below. After sigreturn
324 1.1 erh * resets the signal mask, the stack, and the
325 1.1 erh * frame pointer, it returns to the user
326 1.1 erh * specified pc, psl.
327 1.1 erh */
328 1.1 erh void
329 1.30 matt linux_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
330 1.1 erh {
331 1.26 thorpej struct lwp *l = curlwp;
332 1.26 thorpej struct proc *p = l->l_proc;
333 1.26 thorpej struct trapframe *tf = l->l_md.md_tf;
334 1.30 matt const int sig = ksi->ksi_signo;
335 1.24 thorpej sig_t catcher = SIGACTION(p, sig).sa_handler;
336 1.11 jdolecek #ifdef notyet
337 1.3 erh struct linux_emuldata *edp;
338 1.1 erh
339 1.1 erh /* Setup the signal frame (and part of the trapframe) */
340 1.1 erh /*OLD: if (p->p_sigacts->ps_siginfo & sigmask(sig))*/
341 1.3 erh /* XXX XAX this is broken now. need someplace to store what
342 1.3 erh XXX XAX kind of signal handler a signal has.*/
343 1.3 erh #if 0
344 1.3 erh edp = (struct linux_emuldata *)p->p_emuldata;
345 1.3 erh #else
346 1.3 erh edp = 0;
347 1.3 erh #endif
348 1.3 erh if (edp && sigismember(&edp->ps_siginfo, sig))
349 1.1 erh setup_linux_rt_sigframe(tf, sig, mask);
350 1.1 erh else
351 1.11 jdolecek #endif /* notyet */
352 1.1 erh setup_linux_sigframe(tf, sig, mask);
353 1.1 erh
354 1.1 erh /* Signal handler for trampoline code */
355 1.1 erh tf->tf_regs[FRAME_T12] = (u_int64_t)catcher;
356 1.23 christos tf->tf_regs[FRAME_A0] = native_to_linux_signo[sig];
357 1.1 erh
358 1.1 erh /*
359 1.1 erh * Linux has a custom restorer option. To support it we would
360 1.1 erh * need to store an array of restorers and a sigcode block
361 1.1 erh * which knew to use it. Doesn't seem worth the trouble.
362 1.1 erh * -erh
363 1.1 erh */
364 1.1 erh
365 1.1 erh #ifdef DEBUG
366 1.1 erh if (sigdebug & SDB_FOLLOW)
367 1.26 thorpej printf("sendsig(%d): pc %lx, catcher %lx\n", l->l_proc->p_pid,
368 1.1 erh tf->tf_regs[FRAME_PC], tf->tf_regs[FRAME_A3]);
369 1.26 thorpej if ((sigdebug & SDB_KSTACK) && l->l_proc->p_pid == sigpid)
370 1.26 thorpej printf("sendsig(%d): sig %d returns\n", l->l_proc->p_pid, sig);
371 1.1 erh #endif
372 1.1 erh }
373 1.1 erh
374 1.1 erh /*
375 1.1 erh * System call to cleanup state after a signal
376 1.1 erh * has been taken. Reset signal mask and
377 1.1 erh * stack state from context left by sendsig (above).
378 1.1 erh * Return to previous pc as specified by context
379 1.1 erh * left by sendsig.
380 1.1 erh * Linux real-time signals use a different sigframe,
381 1.1 erh * but the sigcontext is the same.
382 1.1 erh */
383 1.1 erh
384 1.1 erh int
385 1.26 thorpej linux_restore_sigcontext(struct lwp *l, struct linux_sigcontext context,
386 1.8 erh sigset_t *mask)
387 1.1 erh {
388 1.36 ad struct proc *p = l->l_proc;
389 1.1 erh
390 1.1 erh /*
391 1.1 erh * Linux doesn't (yet) have alternate signal stacks.
392 1.1 erh * However, the OSF/1 sigcontext which they use has
393 1.1 erh * an onstack member. This could be needed in the future.
394 1.1 erh */
395 1.36 ad mutex_enter(&p->p_smutex);
396 1.1 erh if (context.sc_onstack & LINUX_SA_ONSTACK)
397 1.36 ad l->l_sigstk.ss_flags |= SS_ONSTACK;
398 1.1 erh else
399 1.36 ad l->l_sigstk.ss_flags &= ~SS_ONSTACK;
400 1.1 erh
401 1.1 erh /* Reset the signal mask */
402 1.36 ad (void) sigprocmask1(l, SIG_SETMASK, mask, 0);
403 1.36 ad mutex_exit(&p->p_smutex);
404 1.1 erh
405 1.1 erh /*
406 1.1 erh * Check for security violations.
407 1.1 erh * Linux doesn't allow any changes to the PSL.
408 1.1 erh */
409 1.1 erh if (context.sc_ps != ALPHA_PSL_USERMODE)
410 1.1 erh return(EINVAL);
411 1.1 erh
412 1.26 thorpej l->l_md.md_tf->tf_regs[FRAME_PC] = context.sc_pc;
413 1.26 thorpej l->l_md.md_tf->tf_regs[FRAME_PS] = context.sc_ps;
414 1.1 erh
415 1.26 thorpej regtoframe((struct reg *)context.sc_regs, l->l_md.md_tf);
416 1.1 erh alpha_pal_wrusp(context.sc_regs[R_SP]);
417 1.1 erh
418 1.26 thorpej if (l == fpcurlwp)
419 1.26 thorpej fpcurlwp = NULL;
420 1.1 erh
421 1.1 erh /* Restore fp regs and fpr_cr */
422 1.26 thorpej bcopy((struct fpreg *)context.sc_fpregs, &l->l_addr->u_pcb.pcb_fp,
423 1.1 erh sizeof(struct fpreg));
424 1.1 erh /* XXX sc_ownedfp ? */
425 1.1 erh /* XXX sc_fp_control ? */
426 1.1 erh
427 1.1 erh #ifdef DEBUG
428 1.1 erh if (sigdebug & SDB_FOLLOW)
429 1.14 sommerfe printf("linux_rt_sigreturn(%d): returns\n", p->p_pid);
430 1.1 erh #endif
431 1.1 erh return (EJUSTRETURN);
432 1.1 erh }
433 1.1 erh
434 1.1 erh int
435 1.26 thorpej linux_sys_rt_sigreturn(l, v, retval)
436 1.26 thorpej struct lwp *l;
437 1.1 erh void *v;
438 1.1 erh register_t *retval;
439 1.1 erh {
440 1.1 erh struct linux_sys_rt_sigreturn_args /* {
441 1.1 erh syscallarg(struct linux_rt_sigframe *) sfp;
442 1.1 erh } */ *uap = v;
443 1.1 erh struct linux_rt_sigframe *sfp, sigframe;
444 1.8 erh sigset_t mask;
445 1.1 erh
446 1.1 erh /*
447 1.1 erh * The trampoline code hands us the context.
448 1.1 erh * It is unsafe to keep track of it ourselves, in the event that a
449 1.1 erh * program jumps out of a signal handler.
450 1.1 erh */
451 1.1 erh
452 1.1 erh sfp = SCARG(uap, sfp);
453 1.1 erh
454 1.1 erh if (ALIGN(sfp) != (u_int64_t)sfp)
455 1.1 erh return(EINVAL);
456 1.1 erh
457 1.1 erh /*
458 1.1 erh * Fetch the frame structure.
459 1.1 erh */
460 1.37 christos if (copyin((void *)sfp, &sigframe,
461 1.1 erh sizeof(struct linux_rt_sigframe)) != 0)
462 1.1 erh return (EFAULT);
463 1.1 erh
464 1.8 erh /* Grab the signal mask */
465 1.21 christos linux_to_native_sigset(&mask, &sigframe.uc.uc_sigmask);
466 1.8 erh
467 1.26 thorpej return(linux_restore_sigcontext(l, sigframe.uc.uc_mcontext, &mask));
468 1.1 erh }
469 1.1 erh
470 1.1 erh
471 1.1 erh int
472 1.26 thorpej linux_sys_sigreturn(l, v, retval)
473 1.26 thorpej struct lwp *l;
474 1.1 erh void *v;
475 1.1 erh register_t *retval;
476 1.1 erh {
477 1.1 erh struct linux_sys_sigreturn_args /* {
478 1.1 erh syscallarg(struct linux_sigframe *) sfp;
479 1.1 erh } */ *uap = v;
480 1.8 erh struct linux_sigframe *sfp, frame;
481 1.8 erh sigset_t mask;
482 1.1 erh
483 1.1 erh /*
484 1.1 erh * The trampoline code hands us the context.
485 1.1 erh * It is unsafe to keep track of it ourselves, in the event that a
486 1.1 erh * program jumps out of a signal handler.
487 1.1 erh */
488 1.1 erh
489 1.8 erh sfp = SCARG(uap, sfp);
490 1.8 erh if (ALIGN(sfp) != (u_int64_t)sfp)
491 1.1 erh return(EINVAL);
492 1.1 erh
493 1.1 erh /*
494 1.8 erh * Fetch the frame structure.
495 1.1 erh */
496 1.37 christos if (copyin((void *)sfp, &frame, sizeof(struct linux_sigframe)) != 0)
497 1.8 erh return(EFAULT);
498 1.8 erh
499 1.8 erh /* Grab the signal mask. */
500 1.8 erh /* XXX use frame.extramask */
501 1.21 christos linux_old_to_native_sigset(&mask, frame.sf_sc.sc_mask);
502 1.1 erh
503 1.26 thorpej return(linux_restore_sigcontext(l, frame.sf_sc, &mask));
504 1.1 erh }
505 1.1 erh
506 1.1 erh /*
507 1.1 erh * We come here in a last attempt to satisfy a Linux ioctl() call
508 1.1 erh */
509 1.1 erh /* XXX XAX update this, add maps, etc... */
510 1.1 erh int
511 1.32 christos linux_machdepioctl(l, v, retval)
512 1.32 christos struct lwp *l;
513 1.1 erh void *v;
514 1.1 erh register_t *retval;
515 1.1 erh {
516 1.1 erh struct linux_sys_ioctl_args /* {
517 1.1 erh syscallarg(int) fd;
518 1.1 erh syscallarg(u_long) com;
519 1.37 christos syscallarg(void *) data;
520 1.1 erh } */ *uap = v;
521 1.1 erh struct sys_ioctl_args bia;
522 1.1 erh u_long com;
523 1.1 erh
524 1.1 erh SCARG(&bia, fd) = SCARG(uap, fd);
525 1.1 erh SCARG(&bia, data) = SCARG(uap, data);
526 1.1 erh com = SCARG(uap, com);
527 1.1 erh
528 1.1 erh switch (com) {
529 1.1 erh default:
530 1.1 erh printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
531 1.1 erh return EINVAL;
532 1.1 erh }
533 1.1 erh SCARG(&bia, com) = com;
534 1.32 christos return sys_ioctl(l, &bia, retval);
535 1.1 erh }
536 1.1 erh
537 1.1 erh /* XXX XAX fix this */
538 1.1 erh dev_t
539 1.20 christos linux_fakedev(dev, raw)
540 1.1 erh dev_t dev;
541 1.20 christos int raw;
542 1.1 erh {
543 1.1 erh return dev;
544 1.1 erh }
545 1.1 erh
546 1.31 fvdl int
547 1.31 fvdl linux_usertrap(struct lwp *l, vaddr_t trapaddr, void *arg)
548 1.31 fvdl {
549 1.31 fvdl return 0;
550 1.31 fvdl }
551