signal.c 18 KB

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