cpu_loop.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * qemu user cpu loop
  3. *
  4. * Copyright (c) 2003-2008 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 "user-internals.h"
  22. #include "user/cpu_loop.h"
  23. #include "signal-common.h"
  24. void cpu_loop(CPUOpenRISCState *env)
  25. {
  26. CPUState *cs = env_cpu(env);
  27. int trapnr;
  28. abi_long ret;
  29. for (;;) {
  30. cpu_exec_start(cs);
  31. trapnr = cpu_exec(cs);
  32. cpu_exec_end(cs);
  33. process_queued_cpu_work(cs);
  34. switch (trapnr) {
  35. case EXCP_SYSCALL:
  36. env->pc += 4; /* 0xc00; */
  37. ret = do_syscall(env,
  38. cpu_get_gpr(env, 11), /* return value */
  39. cpu_get_gpr(env, 3), /* r3 - r7 are params */
  40. cpu_get_gpr(env, 4),
  41. cpu_get_gpr(env, 5),
  42. cpu_get_gpr(env, 6),
  43. cpu_get_gpr(env, 7),
  44. cpu_get_gpr(env, 8), 0, 0);
  45. if (ret == -QEMU_ERESTARTSYS) {
  46. env->pc -= 4;
  47. } else if (ret != -QEMU_ESIGRETURN) {
  48. cpu_set_gpr(env, 11, ret);
  49. }
  50. break;
  51. case EXCP_ALIGN:
  52. force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, env->eear);
  53. break;
  54. case EXCP_ILLEGAL:
  55. force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
  56. break;
  57. case EXCP_INTERRUPT:
  58. /* We processed the pending cpu work above. */
  59. break;
  60. case EXCP_DEBUG:
  61. force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
  62. break;
  63. case EXCP_ATOMIC:
  64. cpu_exec_step_atomic(cs);
  65. break;
  66. case EXCP_RANGE:
  67. /* Requires SR.OVE set, which linux-user won't do. */
  68. cpu_abort(cs, "Unexpected RANGE exception");
  69. case EXCP_FPE:
  70. /*
  71. * Requires FPSCR.FPEE set. Writes to FPSCR from usermode not
  72. * yet enabled in kernel ABI, so linux-user does not either.
  73. */
  74. cpu_abort(cs, "Unexpected FPE exception");
  75. default:
  76. g_assert_not_reached();
  77. }
  78. process_pending_signals(env);
  79. }
  80. }
  81. void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
  82. {
  83. int i;
  84. for (i = 0; i < 32; i++) {
  85. cpu_set_gpr(env, i, regs->gpr[i]);
  86. }
  87. env->pc = regs->pc;
  88. cpu_set_sr(env, regs->sr);
  89. }