cpu_loop.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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(CPUM68KState *env)
  24. {
  25. CPUState *cs = env_cpu(env);
  26. int trapnr;
  27. unsigned int n;
  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_HALT_INSN:
  36. /* Semihosing syscall. */
  37. env->pc += 4;
  38. do_m68k_semihosting(env, env->dregs[0]);
  39. break;
  40. case EXCP_ILLEGAL:
  41. case EXCP_LINEA:
  42. case EXCP_LINEF:
  43. info.si_signo = TARGET_SIGILL;
  44. info.si_errno = 0;
  45. info.si_code = TARGET_ILL_ILLOPN;
  46. info._sifields._sigfault._addr = env->pc;
  47. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  48. break;
  49. case EXCP_CHK:
  50. info.si_signo = TARGET_SIGFPE;
  51. info.si_errno = 0;
  52. info.si_code = TARGET_FPE_INTOVF;
  53. info._sifields._sigfault._addr = env->pc;
  54. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  55. break;
  56. case EXCP_DIV0:
  57. info.si_signo = TARGET_SIGFPE;
  58. info.si_errno = 0;
  59. info.si_code = TARGET_FPE_INTDIV;
  60. info._sifields._sigfault._addr = env->pc;
  61. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  62. break;
  63. case EXCP_TRAP0:
  64. {
  65. abi_long ret;
  66. n = env->dregs[0];
  67. env->pc += 2;
  68. ret = do_syscall(env,
  69. n,
  70. env->dregs[1],
  71. env->dregs[2],
  72. env->dregs[3],
  73. env->dregs[4],
  74. env->dregs[5],
  75. env->aregs[0],
  76. 0, 0);
  77. if (ret == -TARGET_ERESTARTSYS) {
  78. env->pc -= 2;
  79. } else if (ret != -TARGET_QEMU_ESIGRETURN) {
  80. env->dregs[0] = ret;
  81. }
  82. }
  83. break;
  84. case EXCP_INTERRUPT:
  85. /* just indicate that signals should be handled asap */
  86. break;
  87. case EXCP_ACCESS:
  88. {
  89. info.si_signo = TARGET_SIGSEGV;
  90. info.si_errno = 0;
  91. /* XXX: check env->error_code */
  92. info.si_code = TARGET_SEGV_MAPERR;
  93. info._sifields._sigfault._addr = env->mmu.ar;
  94. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  95. }
  96. break;
  97. case EXCP_DEBUG:
  98. info.si_signo = TARGET_SIGTRAP;
  99. info.si_errno = 0;
  100. info.si_code = TARGET_TRAP_BRKPT;
  101. queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
  102. break;
  103. case EXCP_ATOMIC:
  104. cpu_exec_step_atomic(cs);
  105. break;
  106. default:
  107. EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr);
  108. abort();
  109. }
  110. process_pending_signals(env);
  111. }
  112. }
  113. void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
  114. {
  115. CPUState *cpu = env_cpu(env);
  116. TaskState *ts = cpu->opaque;
  117. struct image_info *info = ts->info;
  118. env->pc = regs->pc;
  119. env->dregs[0] = regs->d0;
  120. env->dregs[1] = regs->d1;
  121. env->dregs[2] = regs->d2;
  122. env->dregs[3] = regs->d3;
  123. env->dregs[4] = regs->d4;
  124. env->dregs[5] = regs->d5;
  125. env->dregs[6] = regs->d6;
  126. env->dregs[7] = regs->d7;
  127. env->aregs[0] = regs->a0;
  128. env->aregs[1] = regs->a1;
  129. env->aregs[2] = regs->a2;
  130. env->aregs[3] = regs->a3;
  131. env->aregs[4] = regs->a4;
  132. env->aregs[5] = regs->a5;
  133. env->aregs[6] = regs->a6;
  134. env->aregs[7] = regs->usp;
  135. env->sr = regs->sr;
  136. ts->stack_base = info->start_stack;
  137. ts->heap_base = info->brk;
  138. /* This will be filled in on the first SYS_HEAPINFO call. */
  139. ts->heap_limit = 0;
  140. }