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