cpu_loop.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(CPUSH4State *env)
  24. {
  25. CPUState *cs = env_cpu(env);
  26. int trapnr, ret;
  27. target_siginfo_t info;
  28. while (1) {
  29. bool arch_interrupt = true;
  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 0x160:
  36. env->pc += 2;
  37. ret = do_syscall(env,
  38. env->gregs[3],
  39. env->gregs[4],
  40. env->gregs[5],
  41. env->gregs[6],
  42. env->gregs[7],
  43. env->gregs[0],
  44. env->gregs[1],
  45. 0, 0);
  46. if (ret == -TARGET_ERESTARTSYS) {
  47. env->pc -= 2;
  48. } else if (ret != -TARGET_QEMU_ESIGRETURN) {
  49. env->gregs[0] = ret;
  50. }
  51. break;
  52. case EXCP_INTERRUPT:
  53. /* just indicate that signals should be handled asap */
  54. break;
  55. case EXCP_DEBUG:
  56. info.si_signo = TARGET_SIGTRAP;
  57. info.si_errno = 0;
  58. info.si_code = TARGET_TRAP_BRKPT;
  59. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  60. break;
  61. case 0xa0:
  62. case 0xc0:
  63. info.si_signo = TARGET_SIGSEGV;
  64. info.si_errno = 0;
  65. info.si_code = TARGET_SEGV_MAPERR;
  66. info._sifields._sigfault._addr = env->tea;
  67. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  68. break;
  69. case EXCP_ATOMIC:
  70. cpu_exec_step_atomic(cs);
  71. arch_interrupt = false;
  72. break;
  73. default:
  74. fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
  75. cpu_dump_state(cs, stderr, 0);
  76. exit(EXIT_FAILURE);
  77. }
  78. process_pending_signals (env);
  79. /* Most of the traps imply an exception or interrupt, which
  80. implies an REI instruction has been executed. Which means
  81. that LDST (aka LOK_ADDR) should be cleared. But there are
  82. a few exceptions for traps internal to QEMU. */
  83. if (arch_interrupt) {
  84. env->lock_addr = -1;
  85. }
  86. }
  87. }
  88. void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
  89. {
  90. int i;
  91. for(i = 0; i < 16; i++) {
  92. env->gregs[i] = regs->regs[i];
  93. }
  94. env->pc = regs->pc;
  95. }