cpu_loop.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "user-internals.h"
  23. #include "cpu_loop-common.h"
  24. #include "signal-common.h"
  25. void cpu_loop(CPUOpenRISCState *env)
  26. {
  27. CPUState *cs = env_cpu(env);
  28. int trapnr;
  29. abi_long ret;
  30. target_siginfo_t info;
  31. for (;;) {
  32. cpu_exec_start(cs);
  33. trapnr = cpu_exec(cs);
  34. cpu_exec_end(cs);
  35. process_queued_cpu_work(cs);
  36. switch (trapnr) {
  37. case EXCP_SYSCALL:
  38. env->pc += 4; /* 0xc00; */
  39. ret = do_syscall(env,
  40. cpu_get_gpr(env, 11), /* return value */
  41. cpu_get_gpr(env, 3), /* r3 - r7 are params */
  42. cpu_get_gpr(env, 4),
  43. cpu_get_gpr(env, 5),
  44. cpu_get_gpr(env, 6),
  45. cpu_get_gpr(env, 7),
  46. cpu_get_gpr(env, 8), 0, 0);
  47. if (ret == -TARGET_ERESTARTSYS) {
  48. env->pc -= 4;
  49. } else if (ret != -TARGET_QEMU_ESIGRETURN) {
  50. cpu_set_gpr(env, 11, ret);
  51. }
  52. break;
  53. case EXCP_DPF:
  54. case EXCP_IPF:
  55. case EXCP_RANGE:
  56. info.si_signo = TARGET_SIGSEGV;
  57. info.si_errno = 0;
  58. info.si_code = TARGET_SEGV_MAPERR;
  59. info._sifields._sigfault._addr = env->pc;
  60. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  61. break;
  62. case EXCP_ALIGN:
  63. info.si_signo = TARGET_SIGBUS;
  64. info.si_errno = 0;
  65. info.si_code = TARGET_BUS_ADRALN;
  66. info._sifields._sigfault._addr = env->pc;
  67. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  68. break;
  69. case EXCP_ILLEGAL:
  70. info.si_signo = TARGET_SIGILL;
  71. info.si_errno = 0;
  72. info.si_code = TARGET_ILL_ILLOPC;
  73. info._sifields._sigfault._addr = env->pc;
  74. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  75. break;
  76. case EXCP_FPE:
  77. info.si_signo = TARGET_SIGFPE;
  78. info.si_errno = 0;
  79. info.si_code = 0;
  80. info._sifields._sigfault._addr = env->pc;
  81. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  82. break;
  83. case EXCP_INTERRUPT:
  84. /* We processed the pending cpu work above. */
  85. break;
  86. case EXCP_DEBUG:
  87. info.si_signo = TARGET_SIGTRAP;
  88. info.si_errno = 0;
  89. info.si_code = TARGET_TRAP_BRKPT;
  90. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  91. break;
  92. case EXCP_ATOMIC:
  93. cpu_exec_step_atomic(cs);
  94. break;
  95. default:
  96. g_assert_not_reached();
  97. }
  98. process_pending_signals(env);
  99. }
  100. }
  101. void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
  102. {
  103. int i;
  104. for (i = 0; i < 32; i++) {
  105. cpu_set_gpr(env, i, regs->gpr[i]);
  106. }
  107. env->pc = regs->pc;
  108. cpu_set_sr(env, regs->sr);
  109. }