linux_machdep.c revision 1.1 1 1.1 manu /* $NetBSD: linux_machdep.c,v 1.1 2005/05/03 16:26:30 manu Exp $ */
2 1.1 manu
3 1.1 manu /*-
4 1.1 manu * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved.
5 1.1 manu *
6 1.1 manu * Redistribution and use in source and binary forms, with or without
7 1.1 manu * modification, are permitted provided that the following conditions
8 1.1 manu * are met:
9 1.1 manu * 1. Redistributions of source code must retain the above copyright
10 1.1 manu * notice, this list of conditions and the following disclaimer.
11 1.1 manu * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 manu * notice, this list of conditions and the following disclaimer in the
13 1.1 manu * documentation and/or other materials provided with the distribution.
14 1.1 manu * 3. All advertising materials mentioning features or use of this software
15 1.1 manu * must display the following acknowledgement:
16 1.1 manu * This product includes software developed by Emmanuel Dreyfus
17 1.1 manu * 4. The name of the author may not be used to endorse or promote
18 1.1 manu * products derived from this software without specific prior written
19 1.1 manu * permission.
20 1.1 manu *
21 1.1 manu * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 1.1 manu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 1.1 manu * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 manu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 1.1 manu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 manu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 manu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 manu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 manu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 manu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 manu * POSSIBILITY OF SUCH DAMAGE.
32 1.1 manu */
33 1.1 manu
34 1.1 manu #include <sys/cdefs.h>
35 1.1 manu
36 1.1 manu __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.1 2005/05/03 16:26:30 manu Exp $");
37 1.1 manu
38 1.1 manu #include <sys/param.h>
39 1.1 manu #include <sys/types.h>
40 1.1 manu #include <sys/systm.h>
41 1.1 manu #include <sys/signal.h>
42 1.1 manu #include <sys/exec.h>
43 1.1 manu #include <sys/proc.h>
44 1.1 manu #include <sys/ptrace.h> /* for process_read_fpregs() */
45 1.1 manu #include <sys/user.h>
46 1.1 manu #include <sys/ucontext.h>
47 1.1 manu
48 1.1 manu #include <machine/reg.h>
49 1.1 manu #include <machine/pcb.h>
50 1.1 manu #include <machine/fpu.h>
51 1.1 manu #include <machine/mcontext.h>
52 1.1 manu
53 1.1 manu #include <compat/linux/common/linux_signal.h>
54 1.1 manu #include <compat/linux/common/linux_errno.h>
55 1.1 manu #include <compat/linux/common/linux_exec.h>
56 1.1 manu #include <compat/linux/common/linux_ioctl.h>
57 1.1 manu #include <compat/linux/common/linux_prctl.h>
58 1.1 manu #include <compat/linux/common/linux_machdep.h>
59 1.1 manu #include <compat/linux/linux_syscallargs.h>
60 1.1 manu
61 1.1 manu
62 1.1 manu void
63 1.1 manu linux_setregs(l, epp, stack)
64 1.1 manu struct lwp *l;
65 1.1 manu struct exec_package *epp;
66 1.1 manu u_long stack;
67 1.1 manu {
68 1.1 manu struct pcb *pcb = &l->l_addr->u_pcb;
69 1.1 manu struct trapframe *tf;
70 1.1 manu
71 1.1 manu /* If we were using the FPU, forget about it. */
72 1.1 manu if (l->l_addr->u_pcb.pcb_fpcpu != NULL)
73 1.1 manu fpusave_lwp(l, 0);
74 1.1 manu
75 1.1 manu l->l_md.md_flags &= ~MDP_USEDFPU;
76 1.1 manu pcb->pcb_flags = 0;
77 1.1 manu pcb->pcb_savefpu.fp_fxsave.fx_fcw = __NetBSD_NPXCW__;
78 1.1 manu pcb->pcb_savefpu.fp_fxsave.fx_mxcsr = __INITIAL_MXCSR__;
79 1.1 manu pcb->pcb_savefpu.fp_fxsave.fx_mxcsr_mask = __INITIAL_MXCSR_MASK__;
80 1.1 manu
81 1.1 manu l->l_proc->p_flag &= ~P_32;
82 1.1 manu
83 1.1 manu printf("stack = 0x%lx, entry = 0x%lx\n", stack, epp->ep_entry);
84 1.1 manu tf = l->l_md.md_regs;
85 1.1 manu tf->tf_rax = 0;
86 1.1 manu tf->tf_rbx = 0;
87 1.1 manu tf->tf_rcx = epp->ep_entry;
88 1.1 manu tf->tf_rdx = 0;
89 1.1 manu tf->tf_rsi = 0;
90 1.1 manu tf->tf_rdi = 0;
91 1.1 manu tf->tf_rbp = 0;
92 1.1 manu tf->tf_rsp = stack;
93 1.1 manu tf->tf_r8 = 0;
94 1.1 manu tf->tf_r9 = 0;
95 1.1 manu tf->tf_r10 = 0;
96 1.1 manu tf->tf_r11 = 0;
97 1.1 manu tf->tf_r12 = 0;
98 1.1 manu tf->tf_r13 = 0;
99 1.1 manu tf->tf_r14 = 0;
100 1.1 manu tf->tf_r15 = 0;
101 1.1 manu tf->tf_rip = epp->ep_entry;
102 1.1 manu tf->tf_rflags = PSL_MBO | PSL_I;
103 1.1 manu tf->tf_cs = LSEL(LUCODE_SEL, SEL_UPL);
104 1.1 manu tf->tf_ss = LSEL(LUDATA_SEL, SEL_UPL);
105 1.1 manu tf->tf_ds = 0;
106 1.1 manu tf->tf_es = 0;
107 1.1 manu tf->tf_fs = 0;
108 1.1 manu tf->tf_gs = 0;
109 1.1 manu
110 1.1 manu return;
111 1.1 manu }
112 1.1 manu
113 1.1 manu void
114 1.1 manu linux_sendsig(ksi, mask)
115 1.1 manu const ksiginfo_t *ksi;
116 1.1 manu const sigset_t *mask;
117 1.1 manu {
118 1.1 manu struct lwp *l = curlwp;
119 1.1 manu struct proc *p = l->l_proc;
120 1.1 manu struct sigacts *ps = p->p_sigacts;
121 1.1 manu int onstack;
122 1.1 manu int sig = ksi->ksi_signo;
123 1.1 manu struct linux_rt_sigframe *sfp, sigframe;
124 1.1 manu struct linux__fpstate *fpsp, fpstate;
125 1.1 manu struct fpreg fpregs;
126 1.1 manu struct trapframe *tf = l->l_md.md_regs;
127 1.1 manu sig_t catcher = SIGACTION(p, sig).sa_handler;
128 1.1 manu linux_sigset_t lmask;
129 1.1 manu char *sp;
130 1.1 manu int error;
131 1.1 manu
132 1.1 manu /* Do we need to jump onto the signal stack? */
133 1.1 manu onstack =
134 1.1 manu (p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
135 1.1 manu (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
136 1.1 manu
137 1.1 manu /* Allocate space for the signal handler context. */
138 1.1 manu if (onstack)
139 1.1 manu sp = ((caddr_t)p->p_sigctx.ps_sigstk.ss_sp +
140 1.1 manu p->p_sigctx.ps_sigstk.ss_size);
141 1.1 manu else
142 1.1 manu sp = (caddr_t)tf->tf_rsp - 128;
143 1.1 manu
144 1.1 manu
145 1.1 manu /*
146 1.1 manu * Save FPU state, if any
147 1.1 manu */
148 1.1 manu if (l->l_md.md_flags & MDP_USEDFPU) {
149 1.1 manu sp = (char *)
150 1.1 manu (((long)sp - sizeof(struct linux__fpstate)) & ~0xfUL);
151 1.1 manu fpsp = (struct linux__fpstate *)sp;
152 1.1 manu
153 1.1 manu (void)process_read_fpregs(l, &fpregs);
154 1.1 manu bzero(&fpstate, sizeof(fpstate));
155 1.1 manu
156 1.1 manu fpstate.cwd = fpregs.fp_fcw;
157 1.1 manu fpstate.swd = fpregs.fp_fsw;
158 1.1 manu fpstate.twd = fpregs.fp_ftw;
159 1.1 manu fpstate.fop = fpregs.fp_fop;
160 1.1 manu fpstate.rip = fpregs.fp_rip;
161 1.1 manu fpstate.rdp = fpregs.fp_rdp;
162 1.1 manu fpstate.mxcsr = fpregs.fp_mxcsr;
163 1.1 manu fpstate.mxcsr_mask = fpregs.fp_mxcsr_mask;
164 1.1 manu memcpy(&fpstate.st_space, &fpregs.fp_st,
165 1.1 manu sizeof(fpstate.st_space));
166 1.1 manu memcpy(&fpstate.xmm_space, &fpregs.fp_xmm,
167 1.1 manu sizeof(fpstate.xmm_space));
168 1.1 manu
169 1.1 manu if ((error = copyout(&fpstate, fpsp, sizeof(fpstate))) != 0) {
170 1.1 manu sigexit(l, SIGILL);
171 1.1 manu return;
172 1.1 manu }
173 1.1 manu } else {
174 1.1 manu fpsp = NULL;
175 1.1 manu }
176 1.1 manu
177 1.1 manu /*
178 1.1 manu * Populate the rt_sigframe
179 1.1 manu */
180 1.1 manu sp = (char *)
181 1.1 manu ((((long)sp - sizeof(struct linux_rt_sigframe)) & ~0xfUL) - 8);
182 1.1 manu sfp = (struct linux_rt_sigframe *)sp;
183 1.1 manu
184 1.1 manu bzero(&sigframe, sizeof(sigframe));
185 1.1 manu sigframe.pretcode = (char *)ps->sa_sigdesc[sig].sd_tramp;
186 1.1 manu
187 1.1 manu /*
188 1.1 manu * The user context
189 1.1 manu */
190 1.1 manu sigframe.uc.luc_flags = 0;
191 1.1 manu sigframe.uc.luc_link = NULL;
192 1.1 manu
193 1.1 manu /* This is used regardless of SA_ONSTACK in Linux */
194 1.1 manu sigframe.uc.luc_stack.ss_sp = p->p_sigctx.ps_sigstk.ss_sp;
195 1.1 manu sigframe.uc.luc_stack.ss_size = p->p_sigctx.ps_sigstk.ss_size;
196 1.1 manu sigframe.uc.luc_stack.ss_flags = 0;
197 1.1 manu if (p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK)
198 1.1 manu sigframe.uc.luc_stack.ss_flags |= LINUX_SS_ONSTACK;
199 1.1 manu if (p->p_sigctx.ps_sigstk.ss_flags & SS_DISABLE)
200 1.1 manu sigframe.uc.luc_stack.ss_flags |= LINUX_SS_DISABLE;
201 1.1 manu
202 1.1 manu sigframe.uc.luc_mcontext.r8 = tf->tf_r8;
203 1.1 manu sigframe.uc.luc_mcontext.r9 = tf->tf_r9;
204 1.1 manu sigframe.uc.luc_mcontext.r10 = tf->tf_r10;
205 1.1 manu sigframe.uc.luc_mcontext.r11 = tf->tf_r11;
206 1.1 manu sigframe.uc.luc_mcontext.r12 = tf->tf_r12;
207 1.1 manu sigframe.uc.luc_mcontext.r13 = tf->tf_r13;
208 1.1 manu sigframe.uc.luc_mcontext.r14 = tf->tf_r14;
209 1.1 manu sigframe.uc.luc_mcontext.r15 = tf->tf_r15;
210 1.1 manu sigframe.uc.luc_mcontext.rdi = tf->tf_rdi;
211 1.1 manu sigframe.uc.luc_mcontext.rsi = tf->tf_rsi;
212 1.1 manu sigframe.uc.luc_mcontext.rbp = tf->tf_rbp;
213 1.1 manu sigframe.uc.luc_mcontext.rbx = tf->tf_rbx;
214 1.1 manu sigframe.uc.luc_mcontext.rdx = tf->tf_rdx;
215 1.1 manu sigframe.uc.luc_mcontext.rcx = tf->tf_rcx;
216 1.1 manu sigframe.uc.luc_mcontext.rsp = tf->tf_rsp;
217 1.1 manu sigframe.uc.luc_mcontext.eflags = tf->tf_rflags;
218 1.1 manu sigframe.uc.luc_mcontext.cs = tf->tf_cs;
219 1.1 manu sigframe.uc.luc_mcontext.gs = tf->tf_gs;
220 1.1 manu sigframe.uc.luc_mcontext.fs = tf->tf_fs;
221 1.1 manu sigframe.uc.luc_mcontext.err = tf->tf_err;
222 1.1 manu sigframe.uc.luc_mcontext.trapno = tf->tf_trapno;
223 1.1 manu native_to_linux_sigset(&lmask, mask);
224 1.1 manu sigframe.uc.luc_mcontext.oldmask = lmask.sig[0];
225 1.1 manu sigframe.uc.luc_mcontext.cr2 = (long)l->l_addr->u_pcb.pcb_onfault;
226 1.1 manu sigframe.uc.luc_mcontext.fpstate = fpsp;
227 1.1 manu native_to_linux_sigset(&sigframe.uc.luc_sigmask, mask);
228 1.1 manu
229 1.1 manu /*
230 1.1 manu * the siginfo structure
231 1.1 manu */
232 1.1 manu sigframe.info.lsi_signo = native_to_linux_signo[sig];
233 1.1 manu sigframe.info.lsi_errno = native_to_linux_errno[ksi->ksi_errno];
234 1.1 manu sigframe.info.lsi_code = ksi->ksi_code;
235 1.1 manu
236 1.1 manu /* XXX This is a rought conversion, taken from i386 code */
237 1.1 manu switch (sigframe.info.lsi_signo) {
238 1.1 manu case LINUX_SIGILL:
239 1.1 manu case LINUX_SIGFPE:
240 1.1 manu case LINUX_SIGSEGV:
241 1.1 manu case LINUX_SIGBUS:
242 1.1 manu case LINUX_SIGTRAP:
243 1.1 manu sigframe.info._sifields._sigfault._addr = ksi->ksi_addr;
244 1.1 manu break;
245 1.1 manu case LINUX_SIGCHLD:
246 1.1 manu sigframe.info._sifields._sigchld._pid = ksi->ksi_pid;
247 1.1 manu sigframe.info._sifields._sigchld._uid = ksi->ksi_uid;
248 1.1 manu sigframe.info._sifields._sigchld._status = ksi->ksi_status;
249 1.1 manu sigframe.info._sifields._sigchld._utime = ksi->ksi_utime;
250 1.1 manu sigframe.info._sifields._sigchld._stime = ksi->ksi_stime;
251 1.1 manu break;
252 1.1 manu case LINUX_SIGIO:
253 1.1 manu sigframe.info._sifields._sigpoll._band = ksi->ksi_band;
254 1.1 manu sigframe.info._sifields._sigpoll._fd = ksi->ksi_fd;
255 1.1 manu break;
256 1.1 manu default:
257 1.1 manu sigframe.info._sifields._sigchld._pid = ksi->ksi_pid;
258 1.1 manu sigframe.info._sifields._sigchld._uid = ksi->ksi_uid;
259 1.1 manu if ((sigframe.info.lsi_signo == LINUX_SIGALRM) ||
260 1.1 manu (sigframe.info.lsi_signo >= LINUX_SIGRTMIN))
261 1.1 manu sigframe.info._sifields._timer._sigval.sival_ptr =
262 1.1 manu ksi->ksi_sigval.sival_ptr;
263 1.1 manu break;
264 1.1 manu }
265 1.1 manu
266 1.1 manu if ((error = copyout(&sigframe, sp, sizeof(sigframe))) != 0) {
267 1.1 manu sigexit(l, SIGILL);
268 1.1 manu return;
269 1.1 manu }
270 1.1 manu
271 1.1 manu /*
272 1.1 manu * Setup registers
273 1.1 manu */
274 1.1 manu buildcontext(l, catcher, sp);
275 1.1 manu tf->tf_rdi = sigframe.info.lsi_signo;
276 1.1 manu tf->tf_rax = 0;
277 1.1 manu tf->tf_rsi = (long)&sfp->info;
278 1.1 manu tf->tf_rdx = (long)&sfp->uc;
279 1.1 manu
280 1.1 manu /*
281 1.1 manu * Remember we use signal stack
282 1.1 manu */
283 1.1 manu if (onstack)
284 1.1 manu p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
285 1.1 manu return;
286 1.1 manu }
287 1.1 manu
288 1.1 manu int
289 1.1 manu linux_sys_modify_ldt(l, v, retval)
290 1.1 manu struct lwp *l;
291 1.1 manu void *v;
292 1.1 manu register_t *retval;
293 1.1 manu {
294 1.1 manu return 0;
295 1.1 manu }
296 1.1 manu
297 1.1 manu int
298 1.1 manu linux_sys_iopl(l, v, retval)
299 1.1 manu struct lwp *l;
300 1.1 manu void *v;
301 1.1 manu register_t *retval;
302 1.1 manu {
303 1.1 manu return 0;
304 1.1 manu }
305 1.1 manu
306 1.1 manu int
307 1.1 manu linux_sys_ioperm(l, v, retval)
308 1.1 manu struct lwp *l;
309 1.1 manu void *v;
310 1.1 manu register_t *retval;
311 1.1 manu {
312 1.1 manu return 0;
313 1.1 manu }
314 1.1 manu
315 1.1 manu dev_t
316 1.1 manu linux_fakedev(dev, raw)
317 1.1 manu dev_t dev;
318 1.1 manu int raw;
319 1.1 manu {
320 1.1 manu return 0;
321 1.1 manu }
322 1.1 manu
323 1.1 manu int
324 1.1 manu linux_machdepioctl(p, v, retval)
325 1.1 manu struct proc *p;
326 1.1 manu void *v;
327 1.1 manu register_t *retval;
328 1.1 manu {
329 1.1 manu return 0;
330 1.1 manu }
331 1.1 manu
332 1.1 manu int
333 1.1 manu linux_sys_rt_sigreturn(l, v, retval)
334 1.1 manu struct lwp *l;
335 1.1 manu void *v;
336 1.1 manu register_t *retval;
337 1.1 manu {
338 1.1 manu struct linux_sys_rt_sigreturn_args /* {
339 1.1 manu syscallarg(struct linux_ucontext *) ucp;
340 1.1 manu } */ *uap = v;
341 1.1 manu struct linux_ucontext luctx;
342 1.1 manu struct trapframe *tf = l->l_md.md_regs;
343 1.1 manu struct linux_sigcontext *lsigctx;
344 1.1 manu struct linux__fpstate fpstate;
345 1.1 manu ucontext_t uctx;
346 1.1 manu mcontext_t *mctx;
347 1.1 manu struct fxsave64 *fxsave;
348 1.1 manu int error;
349 1.1 manu
350 1.1 manu if ((error = copyin(SCARG(uap, ucp), &luctx, sizeof(luctx))) != 0) {
351 1.1 manu sigexit(l, SIGILL);
352 1.1 manu return error;
353 1.1 manu }
354 1.1 manu lsigctx = &luctx.luc_mcontext;
355 1.1 manu
356 1.1 manu bzero(&uctx, sizeof(uctx));
357 1.1 manu mctx = (mcontext_t *)&uctx.uc_mcontext;
358 1.1 manu fxsave = (struct fxsave64 *)&mctx->__fpregs;
359 1.1 manu
360 1.1 manu /*
361 1.1 manu * Set the flags. Linux always have CPU, stack and signal state,
362 1.1 manu * FPU is optional. uc_flags is not used to tell what we have.
363 1.1 manu */
364 1.1 manu uctx.uc_flags = (_UC_SIGMASK|_UC_CPU|_UC_STACK|_UC_CLRSTACK);
365 1.1 manu if (lsigctx->fpstate != NULL)
366 1.1 manu uctx.uc_flags |= _UC_FPU;
367 1.1 manu uctx.uc_link = NULL;
368 1.1 manu
369 1.1 manu /*
370 1.1 manu * Signal set
371 1.1 manu */
372 1.1 manu linux_to_native_sigset(&uctx.uc_sigmask, &luctx.luc_sigmask);
373 1.1 manu
374 1.1 manu /*
375 1.1 manu * CPU state
376 1.1 manu */
377 1.1 manu mctx->__gregs[_REG_R8] = lsigctx->r8;
378 1.1 manu mctx->__gregs[_REG_R9] = lsigctx->r9;
379 1.1 manu mctx->__gregs[_REG_R10] = lsigctx->r10;
380 1.1 manu mctx->__gregs[_REG_R11] = lsigctx->r11;
381 1.1 manu mctx->__gregs[_REG_R12] = lsigctx->r12;
382 1.1 manu mctx->__gregs[_REG_R13] = lsigctx->r13;
383 1.1 manu mctx->__gregs[_REG_R14] = lsigctx->r14;
384 1.1 manu mctx->__gregs[_REG_R15] = lsigctx->r15;
385 1.1 manu mctx->__gregs[_REG_RDI] = lsigctx->rdi;
386 1.1 manu mctx->__gregs[_REG_RSI] = lsigctx->rsi;
387 1.1 manu mctx->__gregs[_REG_RBP] = lsigctx->rbp;
388 1.1 manu mctx->__gregs[_REG_RBX] = lsigctx->rbx;
389 1.1 manu mctx->__gregs[_REG_RAX] = tf->tf_rax;
390 1.1 manu mctx->__gregs[_REG_RDX] = lsigctx->rdx;
391 1.1 manu mctx->__gregs[_REG_RCX] = lsigctx->rcx;
392 1.1 manu mctx->__gregs[_REG_RIP] = lsigctx->rip;
393 1.1 manu mctx->__gregs[_REG_RFL] = lsigctx->eflags;
394 1.1 manu mctx->__gregs[_REG_CS] = lsigctx->cs;
395 1.1 manu mctx->__gregs[_REG_GS] = lsigctx->gs;
396 1.1 manu mctx->__gregs[_REG_FS] = lsigctx->fs;
397 1.1 manu mctx->__gregs[_REG_ERR] = lsigctx->err;
398 1.1 manu mctx->__gregs[_REG_TRAPNO] = lsigctx->trapno;
399 1.1 manu mctx->__gregs[_REG_ES] = tf->tf_es;
400 1.1 manu mctx->__gregs[_REG_DS] = tf->tf_ds;
401 1.1 manu mctx->__gregs[_REG_URSP] = lsigctx->rsp; /* XXX */
402 1.1 manu mctx->__gregs[_REG_SS] = tf->tf_ss;
403 1.1 manu
404 1.1 manu /*
405 1.1 manu * FPU state
406 1.1 manu */
407 1.1 manu if (lsigctx->fpstate != NULL) {
408 1.1 manu error = copyin(lsigctx->fpstate, &fpstate, sizeof(fpstate));
409 1.1 manu if (error != 0) {
410 1.1 manu sigexit(l, SIGILL);
411 1.1 manu return error;
412 1.1 manu }
413 1.1 manu
414 1.1 manu fxsave->fx_fcw = fpstate.cwd;
415 1.1 manu fxsave->fx_fsw = fpstate.swd;
416 1.1 manu fxsave->fx_ftw = fpstate.twd;
417 1.1 manu fxsave->fx_fop = fpstate.fop;
418 1.1 manu fxsave->fx_rip = fpstate.rip;
419 1.1 manu fxsave->fx_rdp = fpstate.rdp;
420 1.1 manu fxsave->fx_mxcsr = fpstate.mxcsr;
421 1.1 manu fxsave->fx_mxcsr_mask = fpstate.mxcsr_mask;
422 1.1 manu memcpy(&fxsave->fx_st, &fpstate.st_space,
423 1.1 manu sizeof(fxsave->fx_st));
424 1.1 manu memcpy(&fxsave->fx_xmm, &fpstate.xmm_space,
425 1.1 manu sizeof(fxsave->fx_xmm));
426 1.1 manu }
427 1.1 manu
428 1.1 manu /*
429 1.1 manu * And the stack
430 1.1 manu */
431 1.1 manu uctx.uc_stack.ss_flags = 0;
432 1.1 manu if (luctx.luc_stack.ss_flags & LINUX_SS_ONSTACK);
433 1.1 manu uctx.uc_stack.ss_flags = SS_ONSTACK;
434 1.1 manu
435 1.1 manu if (luctx.luc_stack.ss_flags & LINUX_SS_DISABLE);
436 1.1 manu uctx.uc_stack.ss_flags = SS_DISABLE;
437 1.1 manu
438 1.1 manu uctx.uc_stack.ss_sp = luctx.luc_stack.ss_sp;
439 1.1 manu uctx.uc_stack.ss_size = luctx.luc_stack.ss_size;
440 1.1 manu
441 1.1 manu /*
442 1.1 manu * And let setucontext deal with that.
443 1.1 manu */
444 1.1 manu return setucontext(l, &uctx);
445 1.1 manu }
446 1.1 manu
447 1.1 manu int
448 1.1 manu linux_sys_arch_prctl(l, v, retval)
449 1.1 manu struct lwp *l;
450 1.1 manu void *v;
451 1.1 manu register_t *retval;
452 1.1 manu {
453 1.1 manu struct linux_sys_arch_prctl_args /* {
454 1.1 manu syscallarg(int) code;
455 1.1 manu syscallarg(unsigned long) addr;
456 1.1 manu } */ *uap = v;
457 1.1 manu ucontext_t uctx;
458 1.1 manu int error;
459 1.1 manu
460 1.1 manu getucontext(l, &uctx);
461 1.1 manu
462 1.1 manu switch(SCARG(uap, code)) {
463 1.1 manu case LINUX_ARCH_SET_GS:
464 1.1 manu #ifndef tmp_hack
465 1.1 manu return 0; /* XXX */
466 1.1 manu #endif
467 1.1 manu uctx.uc_mcontext.__gregs[_REG_GS] = (u_int64_t)SCARG(uap, addr);
468 1.1 manu if ((error = setucontext(l, &uctx)) != 0)
469 1.1 manu return error;
470 1.1 manu break;
471 1.1 manu
472 1.1 manu case LINUX_ARCH_GET_GS:
473 1.1 manu if ((error = copyout(&uctx.uc_mcontext.__gregs[_REG_GS],
474 1.1 manu (char *)SCARG(uap, addr),
475 1.1 manu sizeof(uctx.uc_mcontext.__gregs[_REG_GS]))) != 0)
476 1.1 manu return error;
477 1.1 manu break;
478 1.1 manu
479 1.1 manu case LINUX_ARCH_SET_FS:
480 1.1 manu #ifndef tmp_hack
481 1.1 manu return 0; /* XXX */
482 1.1 manu #endif
483 1.1 manu uctx.uc_mcontext.__gregs[_REG_FS] = (u_int64_t)SCARG(uap, addr);
484 1.1 manu if ((error = setucontext(l, &uctx)) != 0)
485 1.1 manu return error;
486 1.1 manu break;
487 1.1 manu
488 1.1 manu case LINUX_ARCH_GET_FS:
489 1.1 manu if ((error = copyout(&uctx.uc_mcontext.__gregs[_REG_FS],
490 1.1 manu (char *)SCARG(uap, addr),
491 1.1 manu sizeof(uctx.uc_mcontext.__gregs[_REG_FS]))) != 0)
492 1.1 manu return error;
493 1.1 manu break;
494 1.1 manu
495 1.1 manu default:
496 1.1 manu #ifdef DEBUG_LINUX
497 1.1 manu printf("linux_sys_arch_prctl: unexpected code %d\n",
498 1.1 manu SCARG(uap, code));
499 1.1 manu #endif
500 1.1 manu return EINVAL;
501 1.1 manu break;
502 1.1 manu }
503 1.1 manu
504 1.1 manu return 0;
505 1.1 manu }
506