cpu_loop.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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-common.h"
  21. #include "qemu.h"
  22. #include "cpu_loop-common.h"
  23. void cpu_loop(CPUOpenRISCState *env)
  24. {
  25. CPUState *cs = env_cpu(env);
  26. int trapnr;
  27. abi_long ret;
  28. target_siginfo_t info;
  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 == -TARGET_ERESTARTSYS) {
  46. env->pc -= 4;
  47. } else if (ret != -TARGET_QEMU_ESIGRETURN) {
  48. cpu_set_gpr(env, 11, ret);
  49. }
  50. break;
  51. case EXCP_DPF:
  52. case EXCP_IPF:
  53. case EXCP_RANGE:
  54. info.si_signo = TARGET_SIGSEGV;
  55. info.si_errno = 0;
  56. info.si_code = TARGET_SEGV_MAPERR;
  57. info._sifields._sigfault._addr = env->pc;
  58. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  59. break;
  60. case EXCP_ALIGN:
  61. info.si_signo = TARGET_SIGBUS;
  62. info.si_errno = 0;
  63. info.si_code = TARGET_BUS_ADRALN;
  64. info._sifields._sigfault._addr = env->pc;
  65. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  66. break;
  67. case EXCP_ILLEGAL:
  68. info.si_signo = TARGET_SIGILL;
  69. info.si_errno = 0;
  70. info.si_code = TARGET_ILL_ILLOPC;
  71. info._sifields._sigfault._addr = env->pc;
  72. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  73. break;
  74. case EXCP_FPE:
  75. info.si_signo = TARGET_SIGFPE;
  76. info.si_errno = 0;
  77. info.si_code = 0;
  78. info._sifields._sigfault._addr = env->pc;
  79. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  80. break;
  81. case EXCP_INTERRUPT:
  82. /* We processed the pending cpu work above. */
  83. break;
  84. case EXCP_DEBUG:
  85. info.si_signo = TARGET_SIGTRAP;
  86. info.si_errno = 0;
  87. info.si_code = TARGET_TRAP_BRKPT;
  88. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  89. break;
  90. case EXCP_ATOMIC:
  91. cpu_exec_step_atomic(cs);
  92. break;
  93. default:
  94. g_assert_not_reached();
  95. }
  96. process_pending_signals(env);
  97. }
  98. }
  99. void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
  100. {
  101. int i;
  102. for (i = 0; i < 32; i++) {
  103. cpu_set_gpr(env, i, regs->gpr[i]);
  104. }
  105. env->pc = regs->pc;
  106. cpu_set_sr(env, regs->sr);
  107. }