xref: /openbmc/qemu/linux-user/sparc/signal.c (revision 9f172adb35123a093aec8feb74de0e126ae2138e)
1 /*
2  *  Emulation of Linux signals
3  *
4  *  Copyright (c) 2003 Fabrice Bellard
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "qemu/osdep.h"
20 #include "qemu.h"
21 #include "target_signal.h"
22 #include "signal-common.h"
23 #include "linux-user/trace.h"
24 
25 #define __SUNOS_MAXWIN   31
26 
27 /* This is what SunOS does, so shall I. */
28 struct target_sigcontext {
29     abi_ulong sigc_onstack;      /* state to restore */
30 
31     abi_ulong sigc_mask;         /* sigmask to restore */
32     abi_ulong sigc_sp;           /* stack pointer */
33     abi_ulong sigc_pc;           /* program counter */
34     abi_ulong sigc_npc;          /* next program counter */
35     abi_ulong sigc_psr;          /* for condition codes etc */
36     abi_ulong sigc_g1;           /* User uses these two registers */
37     abi_ulong sigc_o0;           /* within the trampoline code. */
38 
39     /* Now comes information regarding the users window set
40          * at the time of the signal.
41          */
42     abi_ulong sigc_oswins;       /* outstanding windows */
43 
44     /* stack ptrs for each regwin buf */
45     char *sigc_spbuf[__SUNOS_MAXWIN];
46 
47     /* Windows to restore after signal */
48     struct {
49         abi_ulong locals[8];
50         abi_ulong ins[8];
51     } sigc_wbuf[__SUNOS_MAXWIN];
52 };
53 /* A Sparc stack frame */
54 struct sparc_stackf {
55     abi_ulong locals[8];
56     abi_ulong ins[8];
57     /* It's simpler to treat fp and callers_pc as elements of ins[]
58          * since we never need to access them ourselves.
59          */
60     char *structptr;
61     abi_ulong xargs[6];
62     abi_ulong xxargs[1];
63 };
64 
65 typedef struct {
66     struct {
67         abi_ulong psr;
68         abi_ulong pc;
69         abi_ulong npc;
70         abi_ulong y;
71         abi_ulong u_regs[16]; /* globals and ins */
72     }               si_regs;
73     int             si_mask;
74 } __siginfo_t;
75 
76 typedef struct {
77     abi_ulong  si_float_regs[32];
78     unsigned   long si_fsr;
79     unsigned   long si_fpqdepth;
80     struct {
81         unsigned long *insn_addr;
82         unsigned long insn;
83     } si_fpqueue [16];
84 } qemu_siginfo_fpu_t;
85 
86 
87 struct target_signal_frame {
88     struct sparc_stackf ss;
89     __siginfo_t         info;
90     abi_ulong           fpu_save;
91     abi_ulong           insns[2] __attribute__ ((aligned (8)));
92     abi_ulong           extramask[TARGET_NSIG_WORDS - 1];
93     abi_ulong           extra_size; /* Should be 0 */
94     qemu_siginfo_fpu_t fpu_state;
95 };
96 struct target_rt_signal_frame {
97     struct sparc_stackf ss;
98     siginfo_t           info;
99     abi_ulong           regs[20];
100     sigset_t            mask;
101     abi_ulong           fpu_save;
102     unsigned int        insns[2];
103     stack_t             stack;
104     unsigned int        extra_size; /* Should be 0 */
105     qemu_siginfo_fpu_t  fpu_state;
106 };
107 
108 #define UREG_O0        16
109 #define UREG_O6        22
110 #define UREG_I0        0
111 #define UREG_I1        1
112 #define UREG_I2        2
113 #define UREG_I3        3
114 #define UREG_I4        4
115 #define UREG_I5        5
116 #define UREG_I6        6
117 #define UREG_I7        7
118 #define UREG_L0        8
119 #define UREG_FP        UREG_I6
120 #define UREG_SP        UREG_O6
121 
122 static inline abi_ulong get_sigframe(struct target_sigaction *sa,
123                                      CPUSPARCState *env,
124                                      unsigned long framesize)
125 {
126     abi_ulong sp;
127 
128     sp = env->regwptr[UREG_FP];
129 
130     /* This is the X/Open sanctioned signal stack switching.  */
131     if (sa->sa_flags & TARGET_SA_ONSTACK) {
132         if (!on_sig_stack(sp)
133                 && !((target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size) & 7)) {
134             sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
135         }
136     }
137     return sp - framesize;
138 }
139 
140 static int
141 setup___siginfo(__siginfo_t *si, CPUSPARCState *env, abi_ulong mask)
142 {
143     int err = 0, i;
144 
145     __put_user(env->psr, &si->si_regs.psr);
146     __put_user(env->pc, &si->si_regs.pc);
147     __put_user(env->npc, &si->si_regs.npc);
148     __put_user(env->y, &si->si_regs.y);
149     for (i=0; i < 8; i++) {
150         __put_user(env->gregs[i], &si->si_regs.u_regs[i]);
151     }
152     for (i=0; i < 8; i++) {
153         __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
154     }
155     __put_user(mask, &si->si_mask);
156     return err;
157 }
158 
159 #if 0
160 static int
161 setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
162                  CPUSPARCState *env, unsigned long mask)
163 {
164     int err = 0;
165 
166     __put_user(mask, &sc->sigc_mask);
167     __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
168     __put_user(env->pc, &sc->sigc_pc);
169     __put_user(env->npc, &sc->sigc_npc);
170     __put_user(env->psr, &sc->sigc_psr);
171     __put_user(env->gregs[1], &sc->sigc_g1);
172     __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
173 
174     return err;
175 }
176 #endif
177 #define NF_ALIGNEDSZ  (((sizeof(struct target_signal_frame) + 7) & (~7)))
178 
179 void setup_frame(int sig, struct target_sigaction *ka,
180                  target_sigset_t *set, CPUSPARCState *env)
181 {
182     abi_ulong sf_addr;
183     struct target_signal_frame *sf;
184     int sigframe_size, err, i;
185 
186     /* 1. Make sure everything is clean */
187     //synchronize_user_stack();
188 
189     sigframe_size = NF_ALIGNEDSZ;
190     sf_addr = get_sigframe(ka, env, sigframe_size);
191     trace_user_setup_frame(env, sf_addr);
192 
193     sf = lock_user(VERIFY_WRITE, sf_addr,
194                    sizeof(struct target_signal_frame), 0);
195     if (!sf) {
196         goto sigsegv;
197     }
198 #if 0
199     if (invalid_frame_pointer(sf, sigframe_size))
200         goto sigill_and_return;
201 #endif
202     /* 2. Save the current process state */
203     err = setup___siginfo(&sf->info, env, set->sig[0]);
204     __put_user(0, &sf->extra_size);
205 
206     //save_fpu_state(regs, &sf->fpu_state);
207     //__put_user(&sf->fpu_state, &sf->fpu_save);
208 
209     __put_user(set->sig[0], &sf->info.si_mask);
210     for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) {
211         __put_user(set->sig[i + 1], &sf->extramask[i]);
212     }
213 
214     for (i = 0; i < 8; i++) {
215         __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]);
216     }
217     for (i = 0; i < 8; i++) {
218         __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]);
219     }
220     if (err)
221         goto sigsegv;
222 
223     /* 3. signal handler back-trampoline and parameters */
224     env->regwptr[UREG_FP] = sf_addr;
225     env->regwptr[UREG_I0] = sig;
226     env->regwptr[UREG_I1] = sf_addr +
227             offsetof(struct target_signal_frame, info);
228     env->regwptr[UREG_I2] = sf_addr +
229             offsetof(struct target_signal_frame, info);
230 
231     /* 4. signal handler */
232     env->pc = ka->_sa_handler;
233     env->npc = (env->pc + 4);
234     /* 5. return to kernel instructions */
235     if (ka->ka_restorer) {
236         env->regwptr[UREG_I7] = ka->ka_restorer;
237     } else {
238         uint32_t val32;
239 
240         env->regwptr[UREG_I7] = sf_addr +
241                 offsetof(struct target_signal_frame, insns) - 2 * 4;
242 
243         /* mov __NR_sigreturn, %g1 */
244         val32 = 0x821020d8;
245         __put_user(val32, &sf->insns[0]);
246 
247         /* t 0x10 */
248         val32 = 0x91d02010;
249         __put_user(val32, &sf->insns[1]);
250         if (err)
251             goto sigsegv;
252 
253         /* Flush instruction space. */
254         // flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
255         // tb_flush(env);
256     }
257     unlock_user(sf, sf_addr, sizeof(struct target_signal_frame));
258     return;
259 #if 0
260 sigill_and_return:
261     force_sig(TARGET_SIGILL);
262 #endif
263 sigsegv:
264     unlock_user(sf, sf_addr, sizeof(struct target_signal_frame));
265     force_sigsegv(sig);
266 }
267 
268 void setup_rt_frame(int sig, struct target_sigaction *ka,
269                     target_siginfo_t *info,
270                     target_sigset_t *set, CPUSPARCState *env)
271 {
272     fprintf(stderr, "setup_rt_frame: not implemented\n");
273 }
274 
275 long do_sigreturn(CPUSPARCState *env)
276 {
277     abi_ulong sf_addr;
278     struct target_signal_frame *sf;
279     uint32_t up_psr, pc, npc;
280     target_sigset_t set;
281     sigset_t host_set;
282     int err=0, i;
283 
284     sf_addr = env->regwptr[UREG_FP];
285     trace_user_do_sigreturn(env, sf_addr);
286     if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) {
287         goto segv_and_exit;
288     }
289 
290     /* 1. Make sure we are not getting garbage from the user */
291 
292     if (sf_addr & 3)
293         goto segv_and_exit;
294 
295     __get_user(pc,  &sf->info.si_regs.pc);
296     __get_user(npc, &sf->info.si_regs.npc);
297 
298     if ((pc | npc) & 3) {
299         goto segv_and_exit;
300     }
301 
302     /* 2. Restore the state */
303     __get_user(up_psr, &sf->info.si_regs.psr);
304 
305     /* User can only change condition codes and FPU enabling in %psr. */
306     env->psr = (up_psr & (PSR_ICC /* | PSR_EF */))
307             | (env->psr & ~(PSR_ICC /* | PSR_EF */));
308 
309     env->pc = pc;
310     env->npc = npc;
311     __get_user(env->y, &sf->info.si_regs.y);
312     for (i=0; i < 8; i++) {
313         __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]);
314     }
315     for (i=0; i < 8; i++) {
316         __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
317     }
318 
319     /* FIXME: implement FPU save/restore:
320          * __get_user(fpu_save, &sf->fpu_save);
321          * if (fpu_save)
322          *        err |= restore_fpu_state(env, fpu_save);
323          */
324 
325     /* This is pretty much atomic, no amount locking would prevent
326          * the races which exist anyways.
327          */
328     __get_user(set.sig[0], &sf->info.si_mask);
329     for(i = 1; i < TARGET_NSIG_WORDS; i++) {
330         __get_user(set.sig[i], &sf->extramask[i - 1]);
331     }
332 
333     target_to_host_sigset_internal(&host_set, &set);
334     set_sigmask(&host_set);
335 
336     if (err) {
337         goto segv_and_exit;
338     }
339     unlock_user_struct(sf, sf_addr, 0);
340     return -TARGET_QEMU_ESIGRETURN;
341 
342 segv_and_exit:
343     unlock_user_struct(sf, sf_addr, 0);
344     force_sig(TARGET_SIGSEGV);
345     return -TARGET_QEMU_ESIGRETURN;
346 }
347 
348 long do_rt_sigreturn(CPUSPARCState *env)
349 {
350     trace_user_do_rt_sigreturn(env, 0);
351     fprintf(stderr, "do_rt_sigreturn: not implemented\n");
352     return -TARGET_ENOSYS;
353 }
354 
355 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
356 #define SPARC_MC_TSTATE 0
357 #define SPARC_MC_PC 1
358 #define SPARC_MC_NPC 2
359 #define SPARC_MC_Y 3
360 #define SPARC_MC_G1 4
361 #define SPARC_MC_G2 5
362 #define SPARC_MC_G3 6
363 #define SPARC_MC_G4 7
364 #define SPARC_MC_G5 8
365 #define SPARC_MC_G6 9
366 #define SPARC_MC_G7 10
367 #define SPARC_MC_O0 11
368 #define SPARC_MC_O1 12
369 #define SPARC_MC_O2 13
370 #define SPARC_MC_O3 14
371 #define SPARC_MC_O4 15
372 #define SPARC_MC_O5 16
373 #define SPARC_MC_O6 17
374 #define SPARC_MC_O7 18
375 #define SPARC_MC_NGREG 19
376 
377 typedef abi_ulong target_mc_greg_t;
378 typedef target_mc_greg_t target_mc_gregset_t[SPARC_MC_NGREG];
379 
380 struct target_mc_fq {
381     abi_ulong *mcfq_addr;
382     uint32_t mcfq_insn;
383 };
384 
385 struct target_mc_fpu {
386     union {
387         uint32_t sregs[32];
388         uint64_t dregs[32];
389         //uint128_t qregs[16];
390     } mcfpu_fregs;
391     abi_ulong mcfpu_fsr;
392     abi_ulong mcfpu_fprs;
393     abi_ulong mcfpu_gsr;
394     struct target_mc_fq *mcfpu_fq;
395     unsigned char mcfpu_qcnt;
396     unsigned char mcfpu_qentsz;
397     unsigned char mcfpu_enab;
398 };
399 typedef struct target_mc_fpu target_mc_fpu_t;
400 
401 typedef struct {
402     target_mc_gregset_t mc_gregs;
403     target_mc_greg_t mc_fp;
404     target_mc_greg_t mc_i7;
405     target_mc_fpu_t mc_fpregs;
406 } target_mcontext_t;
407 
408 struct target_ucontext {
409     struct target_ucontext *tuc_link;
410     abi_ulong tuc_flags;
411     target_sigset_t tuc_sigmask;
412     target_mcontext_t tuc_mcontext;
413 };
414 
415 /* A V9 register window */
416 struct target_reg_window {
417     abi_ulong locals[8];
418     abi_ulong ins[8];
419 };
420 
421 #define TARGET_STACK_BIAS 2047
422 
423 /* {set, get}context() needed for 64-bit SparcLinux userland. */
424 void sparc64_set_context(CPUSPARCState *env)
425 {
426     abi_ulong ucp_addr;
427     struct target_ucontext *ucp;
428     target_mc_gregset_t *grp;
429     abi_ulong pc, npc, tstate;
430     abi_ulong fp, i7, w_addr;
431     unsigned int i;
432 
433     ucp_addr = env->regwptr[UREG_I0];
434     if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) {
435         goto do_sigsegv;
436     }
437     grp  = &ucp->tuc_mcontext.mc_gregs;
438     __get_user(pc, &((*grp)[SPARC_MC_PC]));
439     __get_user(npc, &((*grp)[SPARC_MC_NPC]));
440     if ((pc | npc) & 3) {
441         goto do_sigsegv;
442     }
443     if (env->regwptr[UREG_I1]) {
444         target_sigset_t target_set;
445         sigset_t set;
446 
447         if (TARGET_NSIG_WORDS == 1) {
448             __get_user(target_set.sig[0], &ucp->tuc_sigmask.sig[0]);
449         } else {
450             abi_ulong *src, *dst;
451             src = ucp->tuc_sigmask.sig;
452             dst = target_set.sig;
453             for (i = 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) {
454                 __get_user(*dst, src);
455             }
456         }
457         target_to_host_sigset_internal(&set, &target_set);
458         set_sigmask(&set);
459     }
460     env->pc = pc;
461     env->npc = npc;
462     __get_user(env->y, &((*grp)[SPARC_MC_Y]));
463     __get_user(tstate, &((*grp)[SPARC_MC_TSTATE]));
464     env->asi = (tstate >> 24) & 0xff;
465     cpu_put_ccr(env, tstate >> 32);
466     cpu_put_cwp64(env, tstate & 0x1f);
467     __get_user(env->gregs[1], (&(*grp)[SPARC_MC_G1]));
468     __get_user(env->gregs[2], (&(*grp)[SPARC_MC_G2]));
469     __get_user(env->gregs[3], (&(*grp)[SPARC_MC_G3]));
470     __get_user(env->gregs[4], (&(*grp)[SPARC_MC_G4]));
471     __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5]));
472     __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6]));
473     __get_user(env->gregs[7], (&(*grp)[SPARC_MC_G7]));
474     __get_user(env->regwptr[UREG_I0], (&(*grp)[SPARC_MC_O0]));
475     __get_user(env->regwptr[UREG_I1], (&(*grp)[SPARC_MC_O1]));
476     __get_user(env->regwptr[UREG_I2], (&(*grp)[SPARC_MC_O2]));
477     __get_user(env->regwptr[UREG_I3], (&(*grp)[SPARC_MC_O3]));
478     __get_user(env->regwptr[UREG_I4], (&(*grp)[SPARC_MC_O4]));
479     __get_user(env->regwptr[UREG_I5], (&(*grp)[SPARC_MC_O5]));
480     __get_user(env->regwptr[UREG_I6], (&(*grp)[SPARC_MC_O6]));
481     __get_user(env->regwptr[UREG_I7], (&(*grp)[SPARC_MC_O7]));
482 
483     __get_user(fp, &(ucp->tuc_mcontext.mc_fp));
484     __get_user(i7, &(ucp->tuc_mcontext.mc_i7));
485 
486     w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
487     if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
488                  abi_ulong) != 0) {
489         goto do_sigsegv;
490     }
491     if (put_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]),
492                  abi_ulong) != 0) {
493         goto do_sigsegv;
494     }
495     /* FIXME this does not match how the kernel handles the FPU in
496      * its sparc64_set_context implementation. In particular the FPU
497      * is only restored if fenab is non-zero in:
498      *   __get_user(fenab, &(ucp->tuc_mcontext.mc_fpregs.mcfpu_enab));
499      */
500     __get_user(env->fprs, &(ucp->tuc_mcontext.mc_fpregs.mcfpu_fprs));
501     {
502         uint32_t *src = ucp->tuc_mcontext.mc_fpregs.mcfpu_fregs.sregs;
503         for (i = 0; i < 64; i++, src++) {
504             if (i & 1) {
505                 __get_user(env->fpr[i/2].l.lower, src);
506             } else {
507                 __get_user(env->fpr[i/2].l.upper, src);
508             }
509         }
510     }
511     __get_user(env->fsr,
512                &(ucp->tuc_mcontext.mc_fpregs.mcfpu_fsr));
513     __get_user(env->gsr,
514                &(ucp->tuc_mcontext.mc_fpregs.mcfpu_gsr));
515     unlock_user_struct(ucp, ucp_addr, 0);
516     return;
517 do_sigsegv:
518     unlock_user_struct(ucp, ucp_addr, 0);
519     force_sig(TARGET_SIGSEGV);
520 }
521 
522 void sparc64_get_context(CPUSPARCState *env)
523 {
524     abi_ulong ucp_addr;
525     struct target_ucontext *ucp;
526     target_mc_gregset_t *grp;
527     target_mcontext_t *mcp;
528     abi_ulong fp, i7, w_addr;
529     int err;
530     unsigned int i;
531     target_sigset_t target_set;
532     sigset_t set;
533 
534     ucp_addr = env->regwptr[UREG_I0];
535     if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) {
536         goto do_sigsegv;
537     }
538 
539     mcp = &ucp->tuc_mcontext;
540     grp = &mcp->mc_gregs;
541 
542     /* Skip over the trap instruction, first. */
543     env->pc = env->npc;
544     env->npc += 4;
545 
546     /* If we're only reading the signal mask then do_sigprocmask()
547      * is guaranteed not to fail, which is important because we don't
548      * have any way to signal a failure or restart this operation since
549      * this is not a normal syscall.
550      */
551     err = do_sigprocmask(0, NULL, &set);
552     assert(err == 0);
553     host_to_target_sigset_internal(&target_set, &set);
554     if (TARGET_NSIG_WORDS == 1) {
555         __put_user(target_set.sig[0],
556                    (abi_ulong *)&ucp->tuc_sigmask);
557     } else {
558         abi_ulong *src, *dst;
559         src = target_set.sig;
560         dst = ucp->tuc_sigmask.sig;
561         for (i = 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) {
562             __put_user(*src, dst);
563         }
564         if (err)
565             goto do_sigsegv;
566     }
567 
568     /* XXX: tstate must be saved properly */
569     //    __put_user(env->tstate, &((*grp)[SPARC_MC_TSTATE]));
570     __put_user(env->pc, &((*grp)[SPARC_MC_PC]));
571     __put_user(env->npc, &((*grp)[SPARC_MC_NPC]));
572     __put_user(env->y, &((*grp)[SPARC_MC_Y]));
573     __put_user(env->gregs[1], &((*grp)[SPARC_MC_G1]));
574     __put_user(env->gregs[2], &((*grp)[SPARC_MC_G2]));
575     __put_user(env->gregs[3], &((*grp)[SPARC_MC_G3]));
576     __put_user(env->gregs[4], &((*grp)[SPARC_MC_G4]));
577     __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5]));
578     __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6]));
579     __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7]));
580     __put_user(env->regwptr[UREG_I0], &((*grp)[SPARC_MC_O0]));
581     __put_user(env->regwptr[UREG_I1], &((*grp)[SPARC_MC_O1]));
582     __put_user(env->regwptr[UREG_I2], &((*grp)[SPARC_MC_O2]));
583     __put_user(env->regwptr[UREG_I3], &((*grp)[SPARC_MC_O3]));
584     __put_user(env->regwptr[UREG_I4], &((*grp)[SPARC_MC_O4]));
585     __put_user(env->regwptr[UREG_I5], &((*grp)[SPARC_MC_O5]));
586     __put_user(env->regwptr[UREG_I6], &((*grp)[SPARC_MC_O6]));
587     __put_user(env->regwptr[UREG_I7], &((*grp)[SPARC_MC_O7]));
588 
589     w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
590     fp = i7 = 0;
591     if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
592                  abi_ulong) != 0) {
593         goto do_sigsegv;
594     }
595     if (get_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]),
596                  abi_ulong) != 0) {
597         goto do_sigsegv;
598     }
599     __put_user(fp, &(mcp->mc_fp));
600     __put_user(i7, &(mcp->mc_i7));
601 
602     {
603         uint32_t *dst = ucp->tuc_mcontext.mc_fpregs.mcfpu_fregs.sregs;
604         for (i = 0; i < 64; i++, dst++) {
605             if (i & 1) {
606                 __put_user(env->fpr[i/2].l.lower, dst);
607             } else {
608                 __put_user(env->fpr[i/2].l.upper, dst);
609             }
610         }
611     }
612     __put_user(env->fsr, &(mcp->mc_fpregs.mcfpu_fsr));
613     __put_user(env->gsr, &(mcp->mc_fpregs.mcfpu_gsr));
614     __put_user(env->fprs, &(mcp->mc_fpregs.mcfpu_fprs));
615 
616     if (err)
617         goto do_sigsegv;
618     unlock_user_struct(ucp, ucp_addr, 1);
619     return;
620 do_sigsegv:
621     unlock_user_struct(ucp, ucp_addr, 1);
622     force_sig(TARGET_SIGSEGV);
623 }
624 #endif
625