xref: /openbmc/qemu/linux-user/sparc/signal.c (revision 4a4ff4c5)
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 = get_sp_from_cpustate(env);
127 
128     /*
129      * If we are on the alternate signal stack and would overflow it, don't.
130      * Return an always-bogus address instead so we will die with SIGSEGV.
131          */
132     if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize))) {
133             return -1;
134     }
135 
136     /* This is the X/Open sanctioned signal stack switching.  */
137     sp = target_sigsp(sp, sa) - framesize;
138 
139     /* Always align the stack frame.  This handles two cases.  First,
140      * sigaltstack need not be mindful of platform specific stack
141      * alignment.  Second, if we took this signal because the stack
142      * is not aligned properly, we'd like to take the signal cleanly
143      * and report that.
144      */
145     sp &= ~15UL;
146 
147     return sp;
148 }
149 
150 static int
151 setup___siginfo(__siginfo_t *si, CPUSPARCState *env, abi_ulong mask)
152 {
153     int err = 0, i;
154 
155     __put_user(env->psr, &si->si_regs.psr);
156     __put_user(env->pc, &si->si_regs.pc);
157     __put_user(env->npc, &si->si_regs.npc);
158     __put_user(env->y, &si->si_regs.y);
159     for (i=0; i < 8; i++) {
160         __put_user(env->gregs[i], &si->si_regs.u_regs[i]);
161     }
162     for (i=0; i < 8; i++) {
163         __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
164     }
165     __put_user(mask, &si->si_mask);
166     return err;
167 }
168 
169 #if 0
170 static int
171 setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
172                  CPUSPARCState *env, unsigned long mask)
173 {
174     int err = 0;
175 
176     __put_user(mask, &sc->sigc_mask);
177     __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
178     __put_user(env->pc, &sc->sigc_pc);
179     __put_user(env->npc, &sc->sigc_npc);
180     __put_user(env->psr, &sc->sigc_psr);
181     __put_user(env->gregs[1], &sc->sigc_g1);
182     __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
183 
184     return err;
185 }
186 #endif
187 #define NF_ALIGNEDSZ  (((sizeof(struct target_signal_frame) + 7) & (~7)))
188 
189 void setup_frame(int sig, struct target_sigaction *ka,
190                  target_sigset_t *set, CPUSPARCState *env)
191 {
192     abi_ulong sf_addr;
193     struct target_signal_frame *sf;
194     int sigframe_size, err, i;
195 
196     /* 1. Make sure everything is clean */
197     //synchronize_user_stack();
198 
199     sigframe_size = NF_ALIGNEDSZ;
200     sf_addr = get_sigframe(ka, env, sigframe_size);
201     trace_user_setup_frame(env, sf_addr);
202 
203     sf = lock_user(VERIFY_WRITE, sf_addr,
204                    sizeof(struct target_signal_frame), 0);
205     if (!sf) {
206         goto sigsegv;
207     }
208 #if 0
209     if (invalid_frame_pointer(sf, sigframe_size))
210         goto sigill_and_return;
211 #endif
212     /* 2. Save the current process state */
213     err = setup___siginfo(&sf->info, env, set->sig[0]);
214     __put_user(0, &sf->extra_size);
215 
216     //save_fpu_state(regs, &sf->fpu_state);
217     //__put_user(&sf->fpu_state, &sf->fpu_save);
218 
219     __put_user(set->sig[0], &sf->info.si_mask);
220     for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) {
221         __put_user(set->sig[i + 1], &sf->extramask[i]);
222     }
223 
224     for (i = 0; i < 8; i++) {
225         __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]);
226     }
227     for (i = 0; i < 8; i++) {
228         __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]);
229     }
230     if (err)
231         goto sigsegv;
232 
233     /* 3. signal handler back-trampoline and parameters */
234     env->regwptr[UREG_FP] = sf_addr;
235     env->regwptr[UREG_I0] = sig;
236     env->regwptr[UREG_I1] = sf_addr +
237             offsetof(struct target_signal_frame, info);
238     env->regwptr[UREG_I2] = sf_addr +
239             offsetof(struct target_signal_frame, info);
240 
241     /* 4. signal handler */
242     env->pc = ka->_sa_handler;
243     env->npc = (env->pc + 4);
244     /* 5. return to kernel instructions */
245     if (ka->ka_restorer) {
246         env->regwptr[UREG_I7] = ka->ka_restorer;
247     } else {
248         uint32_t val32;
249 
250         env->regwptr[UREG_I7] = sf_addr +
251                 offsetof(struct target_signal_frame, insns) - 2 * 4;
252 
253         /* mov __NR_sigreturn, %g1 */
254         val32 = 0x821020d8;
255         __put_user(val32, &sf->insns[0]);
256 
257         /* t 0x10 */
258         val32 = 0x91d02010;
259         __put_user(val32, &sf->insns[1]);
260         if (err)
261             goto sigsegv;
262 
263         /* Flush instruction space. */
264         // flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
265         // tb_flush(env);
266     }
267     unlock_user(sf, sf_addr, sizeof(struct target_signal_frame));
268     return;
269 #if 0
270 sigill_and_return:
271     force_sig(TARGET_SIGILL);
272 #endif
273 sigsegv:
274     unlock_user(sf, sf_addr, sizeof(struct target_signal_frame));
275     force_sigsegv(sig);
276 }
277 
278 void setup_rt_frame(int sig, struct target_sigaction *ka,
279                     target_siginfo_t *info,
280                     target_sigset_t *set, CPUSPARCState *env)
281 {
282     fprintf(stderr, "setup_rt_frame: not implemented\n");
283 }
284 
285 long do_sigreturn(CPUSPARCState *env)
286 {
287     abi_ulong sf_addr;
288     struct target_signal_frame *sf;
289     uint32_t up_psr, pc, npc;
290     target_sigset_t set;
291     sigset_t host_set;
292     int err=0, i;
293 
294     sf_addr = env->regwptr[UREG_FP];
295     trace_user_do_sigreturn(env, sf_addr);
296     if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) {
297         goto segv_and_exit;
298     }
299 
300     /* 1. Make sure we are not getting garbage from the user */
301 
302     if (sf_addr & 3)
303         goto segv_and_exit;
304 
305     __get_user(pc,  &sf->info.si_regs.pc);
306     __get_user(npc, &sf->info.si_regs.npc);
307 
308     if ((pc | npc) & 3) {
309         goto segv_and_exit;
310     }
311 
312     /* 2. Restore the state */
313     __get_user(up_psr, &sf->info.si_regs.psr);
314 
315     /* User can only change condition codes and FPU enabling in %psr. */
316     env->psr = (up_psr & (PSR_ICC /* | PSR_EF */))
317             | (env->psr & ~(PSR_ICC /* | PSR_EF */));
318 
319     env->pc = pc;
320     env->npc = npc;
321     __get_user(env->y, &sf->info.si_regs.y);
322     for (i=0; i < 8; i++) {
323         __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]);
324     }
325     for (i=0; i < 8; i++) {
326         __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
327     }
328 
329     /* FIXME: implement FPU save/restore:
330          * __get_user(fpu_save, &sf->fpu_save);
331          * if (fpu_save)
332          *        err |= restore_fpu_state(env, fpu_save);
333          */
334 
335     /* This is pretty much atomic, no amount locking would prevent
336          * the races which exist anyways.
337          */
338     __get_user(set.sig[0], &sf->info.si_mask);
339     for(i = 1; i < TARGET_NSIG_WORDS; i++) {
340         __get_user(set.sig[i], &sf->extramask[i - 1]);
341     }
342 
343     target_to_host_sigset_internal(&host_set, &set);
344     set_sigmask(&host_set);
345 
346     if (err) {
347         goto segv_and_exit;
348     }
349     unlock_user_struct(sf, sf_addr, 0);
350     return -TARGET_QEMU_ESIGRETURN;
351 
352 segv_and_exit:
353     unlock_user_struct(sf, sf_addr, 0);
354     force_sig(TARGET_SIGSEGV);
355     return -TARGET_QEMU_ESIGRETURN;
356 }
357 
358 long do_rt_sigreturn(CPUSPARCState *env)
359 {
360     trace_user_do_rt_sigreturn(env, 0);
361     fprintf(stderr, "do_rt_sigreturn: not implemented\n");
362     return -TARGET_ENOSYS;
363 }
364 
365 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
366 #define SPARC_MC_TSTATE 0
367 #define SPARC_MC_PC 1
368 #define SPARC_MC_NPC 2
369 #define SPARC_MC_Y 3
370 #define SPARC_MC_G1 4
371 #define SPARC_MC_G2 5
372 #define SPARC_MC_G3 6
373 #define SPARC_MC_G4 7
374 #define SPARC_MC_G5 8
375 #define SPARC_MC_G6 9
376 #define SPARC_MC_G7 10
377 #define SPARC_MC_O0 11
378 #define SPARC_MC_O1 12
379 #define SPARC_MC_O2 13
380 #define SPARC_MC_O3 14
381 #define SPARC_MC_O4 15
382 #define SPARC_MC_O5 16
383 #define SPARC_MC_O6 17
384 #define SPARC_MC_O7 18
385 #define SPARC_MC_NGREG 19
386 
387 typedef abi_ulong target_mc_greg_t;
388 typedef target_mc_greg_t target_mc_gregset_t[SPARC_MC_NGREG];
389 
390 struct target_mc_fq {
391     abi_ulong *mcfq_addr;
392     uint32_t mcfq_insn;
393 };
394 
395 struct target_mc_fpu {
396     union {
397         uint32_t sregs[32];
398         uint64_t dregs[32];
399         //uint128_t qregs[16];
400     } mcfpu_fregs;
401     abi_ulong mcfpu_fsr;
402     abi_ulong mcfpu_fprs;
403     abi_ulong mcfpu_gsr;
404     struct target_mc_fq *mcfpu_fq;
405     unsigned char mcfpu_qcnt;
406     unsigned char mcfpu_qentsz;
407     unsigned char mcfpu_enab;
408 };
409 typedef struct target_mc_fpu target_mc_fpu_t;
410 
411 typedef struct {
412     target_mc_gregset_t mc_gregs;
413     target_mc_greg_t mc_fp;
414     target_mc_greg_t mc_i7;
415     target_mc_fpu_t mc_fpregs;
416 } target_mcontext_t;
417 
418 struct target_ucontext {
419     struct target_ucontext *tuc_link;
420     abi_ulong tuc_flags;
421     target_sigset_t tuc_sigmask;
422     target_mcontext_t tuc_mcontext;
423 };
424 
425 /* A V9 register window */
426 struct target_reg_window {
427     abi_ulong locals[8];
428     abi_ulong ins[8];
429 };
430 
431 #define TARGET_STACK_BIAS 2047
432 
433 /* {set, get}context() needed for 64-bit SparcLinux userland. */
434 void sparc64_set_context(CPUSPARCState *env)
435 {
436     abi_ulong ucp_addr;
437     struct target_ucontext *ucp;
438     target_mc_gregset_t *grp;
439     abi_ulong pc, npc, tstate;
440     abi_ulong fp, i7, w_addr;
441     unsigned int i;
442 
443     ucp_addr = env->regwptr[UREG_I0];
444     if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) {
445         goto do_sigsegv;
446     }
447     grp  = &ucp->tuc_mcontext.mc_gregs;
448     __get_user(pc, &((*grp)[SPARC_MC_PC]));
449     __get_user(npc, &((*grp)[SPARC_MC_NPC]));
450     if ((pc | npc) & 3) {
451         goto do_sigsegv;
452     }
453     if (env->regwptr[UREG_I1]) {
454         target_sigset_t target_set;
455         sigset_t set;
456 
457         if (TARGET_NSIG_WORDS == 1) {
458             __get_user(target_set.sig[0], &ucp->tuc_sigmask.sig[0]);
459         } else {
460             abi_ulong *src, *dst;
461             src = ucp->tuc_sigmask.sig;
462             dst = target_set.sig;
463             for (i = 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) {
464                 __get_user(*dst, src);
465             }
466         }
467         target_to_host_sigset_internal(&set, &target_set);
468         set_sigmask(&set);
469     }
470     env->pc = pc;
471     env->npc = npc;
472     __get_user(env->y, &((*grp)[SPARC_MC_Y]));
473     __get_user(tstate, &((*grp)[SPARC_MC_TSTATE]));
474     env->asi = (tstate >> 24) & 0xff;
475     cpu_put_ccr(env, tstate >> 32);
476     cpu_put_cwp64(env, tstate & 0x1f);
477     __get_user(env->gregs[1], (&(*grp)[SPARC_MC_G1]));
478     __get_user(env->gregs[2], (&(*grp)[SPARC_MC_G2]));
479     __get_user(env->gregs[3], (&(*grp)[SPARC_MC_G3]));
480     __get_user(env->gregs[4], (&(*grp)[SPARC_MC_G4]));
481     __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5]));
482     __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6]));
483     __get_user(env->gregs[7], (&(*grp)[SPARC_MC_G7]));
484     __get_user(env->regwptr[UREG_I0], (&(*grp)[SPARC_MC_O0]));
485     __get_user(env->regwptr[UREG_I1], (&(*grp)[SPARC_MC_O1]));
486     __get_user(env->regwptr[UREG_I2], (&(*grp)[SPARC_MC_O2]));
487     __get_user(env->regwptr[UREG_I3], (&(*grp)[SPARC_MC_O3]));
488     __get_user(env->regwptr[UREG_I4], (&(*grp)[SPARC_MC_O4]));
489     __get_user(env->regwptr[UREG_I5], (&(*grp)[SPARC_MC_O5]));
490     __get_user(env->regwptr[UREG_I6], (&(*grp)[SPARC_MC_O6]));
491     __get_user(env->regwptr[UREG_I7], (&(*grp)[SPARC_MC_O7]));
492 
493     __get_user(fp, &(ucp->tuc_mcontext.mc_fp));
494     __get_user(i7, &(ucp->tuc_mcontext.mc_i7));
495 
496     w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
497     if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
498                  abi_ulong) != 0) {
499         goto do_sigsegv;
500     }
501     if (put_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]),
502                  abi_ulong) != 0) {
503         goto do_sigsegv;
504     }
505     /* FIXME this does not match how the kernel handles the FPU in
506      * its sparc64_set_context implementation. In particular the FPU
507      * is only restored if fenab is non-zero in:
508      *   __get_user(fenab, &(ucp->tuc_mcontext.mc_fpregs.mcfpu_enab));
509      */
510     __get_user(env->fprs, &(ucp->tuc_mcontext.mc_fpregs.mcfpu_fprs));
511     {
512         uint32_t *src = ucp->tuc_mcontext.mc_fpregs.mcfpu_fregs.sregs;
513         for (i = 0; i < 64; i++, src++) {
514             if (i & 1) {
515                 __get_user(env->fpr[i/2].l.lower, src);
516             } else {
517                 __get_user(env->fpr[i/2].l.upper, src);
518             }
519         }
520     }
521     __get_user(env->fsr,
522                &(ucp->tuc_mcontext.mc_fpregs.mcfpu_fsr));
523     __get_user(env->gsr,
524                &(ucp->tuc_mcontext.mc_fpregs.mcfpu_gsr));
525     unlock_user_struct(ucp, ucp_addr, 0);
526     return;
527 do_sigsegv:
528     unlock_user_struct(ucp, ucp_addr, 0);
529     force_sig(TARGET_SIGSEGV);
530 }
531 
532 void sparc64_get_context(CPUSPARCState *env)
533 {
534     abi_ulong ucp_addr;
535     struct target_ucontext *ucp;
536     target_mc_gregset_t *grp;
537     target_mcontext_t *mcp;
538     abi_ulong fp, i7, w_addr;
539     int err;
540     unsigned int i;
541     target_sigset_t target_set;
542     sigset_t set;
543 
544     ucp_addr = env->regwptr[UREG_I0];
545     if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) {
546         goto do_sigsegv;
547     }
548 
549     mcp = &ucp->tuc_mcontext;
550     grp = &mcp->mc_gregs;
551 
552     /* Skip over the trap instruction, first. */
553     env->pc = env->npc;
554     env->npc += 4;
555 
556     /* If we're only reading the signal mask then do_sigprocmask()
557      * is guaranteed not to fail, which is important because we don't
558      * have any way to signal a failure or restart this operation since
559      * this is not a normal syscall.
560      */
561     err = do_sigprocmask(0, NULL, &set);
562     assert(err == 0);
563     host_to_target_sigset_internal(&target_set, &set);
564     if (TARGET_NSIG_WORDS == 1) {
565         __put_user(target_set.sig[0],
566                    (abi_ulong *)&ucp->tuc_sigmask);
567     } else {
568         abi_ulong *src, *dst;
569         src = target_set.sig;
570         dst = ucp->tuc_sigmask.sig;
571         for (i = 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) {
572             __put_user(*src, dst);
573         }
574         if (err)
575             goto do_sigsegv;
576     }
577 
578     /* XXX: tstate must be saved properly */
579     //    __put_user(env->tstate, &((*grp)[SPARC_MC_TSTATE]));
580     __put_user(env->pc, &((*grp)[SPARC_MC_PC]));
581     __put_user(env->npc, &((*grp)[SPARC_MC_NPC]));
582     __put_user(env->y, &((*grp)[SPARC_MC_Y]));
583     __put_user(env->gregs[1], &((*grp)[SPARC_MC_G1]));
584     __put_user(env->gregs[2], &((*grp)[SPARC_MC_G2]));
585     __put_user(env->gregs[3], &((*grp)[SPARC_MC_G3]));
586     __put_user(env->gregs[4], &((*grp)[SPARC_MC_G4]));
587     __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5]));
588     __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6]));
589     __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7]));
590     __put_user(env->regwptr[UREG_I0], &((*grp)[SPARC_MC_O0]));
591     __put_user(env->regwptr[UREG_I1], &((*grp)[SPARC_MC_O1]));
592     __put_user(env->regwptr[UREG_I2], &((*grp)[SPARC_MC_O2]));
593     __put_user(env->regwptr[UREG_I3], &((*grp)[SPARC_MC_O3]));
594     __put_user(env->regwptr[UREG_I4], &((*grp)[SPARC_MC_O4]));
595     __put_user(env->regwptr[UREG_I5], &((*grp)[SPARC_MC_O5]));
596     __put_user(env->regwptr[UREG_I6], &((*grp)[SPARC_MC_O6]));
597     __put_user(env->regwptr[UREG_I7], &((*grp)[SPARC_MC_O7]));
598 
599     w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
600     fp = i7 = 0;
601     if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
602                  abi_ulong) != 0) {
603         goto do_sigsegv;
604     }
605     if (get_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]),
606                  abi_ulong) != 0) {
607         goto do_sigsegv;
608     }
609     __put_user(fp, &(mcp->mc_fp));
610     __put_user(i7, &(mcp->mc_i7));
611 
612     {
613         uint32_t *dst = ucp->tuc_mcontext.mc_fpregs.mcfpu_fregs.sregs;
614         for (i = 0; i < 64; i++, dst++) {
615             if (i & 1) {
616                 __put_user(env->fpr[i/2].l.lower, dst);
617             } else {
618                 __put_user(env->fpr[i/2].l.upper, dst);
619             }
620         }
621     }
622     __put_user(env->fsr, &(mcp->mc_fpregs.mcfpu_fsr));
623     __put_user(env->gsr, &(mcp->mc_fpregs.mcfpu_gsr));
624     __put_user(env->fprs, &(mcp->mc_fpregs.mcfpu_fprs));
625 
626     if (err)
627         goto do_sigsegv;
628     unlock_user_struct(ucp, ucp_addr, 1);
629     return;
630 do_sigsegv:
631     unlock_user_struct(ucp, ucp_addr, 1);
632     force_sig(TARGET_SIGSEGV);
633 }
634 #endif
635