cpu-exec-common.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * emulator main execution loop
  3. *
  4. * Copyright (c) 2003-2005 Fabrice Bellard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "exec/log.h"
  21. #include "system/tcg.h"
  22. #include "qemu/plugin.h"
  23. #include "internal-common.h"
  24. bool tcg_allowed;
  25. bool tcg_cflags_has(CPUState *cpu, uint32_t flags)
  26. {
  27. return cpu->tcg_cflags & flags;
  28. }
  29. void tcg_cflags_set(CPUState *cpu, uint32_t flags)
  30. {
  31. cpu->tcg_cflags |= flags;
  32. }
  33. uint32_t curr_cflags(CPUState *cpu)
  34. {
  35. uint32_t cflags = cpu->tcg_cflags;
  36. /*
  37. * Record gdb single-step. We should be exiting the TB by raising
  38. * EXCP_DEBUG, but to simplify other tests, disable chaining too.
  39. *
  40. * For singlestep and -d nochain, suppress goto_tb so that
  41. * we can log -d cpu,exec after every TB.
  42. */
  43. if (unlikely(cpu->singlestep_enabled)) {
  44. cflags |= CF_NO_GOTO_TB | CF_NO_GOTO_PTR | CF_SINGLE_STEP | 1;
  45. } else if (qatomic_read(&one_insn_per_tb)) {
  46. cflags |= CF_NO_GOTO_TB | 1;
  47. } else if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
  48. cflags |= CF_NO_GOTO_TB;
  49. }
  50. return cflags;
  51. }
  52. /* exit the current TB, but without causing any exception to be raised */
  53. void cpu_loop_exit_noexc(CPUState *cpu)
  54. {
  55. cpu->exception_index = -1;
  56. cpu_loop_exit(cpu);
  57. }
  58. void cpu_loop_exit(CPUState *cpu)
  59. {
  60. /* Undo the setting in cpu_tb_exec. */
  61. cpu->neg.can_do_io = true;
  62. /* Undo any setting in generated code. */
  63. qemu_plugin_disable_mem_helpers(cpu);
  64. siglongjmp(cpu->jmp_env, 1);
  65. }
  66. void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)
  67. {
  68. if (pc) {
  69. cpu_restore_state(cpu, pc);
  70. }
  71. cpu_loop_exit(cpu);
  72. }
  73. void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)
  74. {
  75. /* Prevent looping if already executing in a serial context. */
  76. g_assert(!cpu_in_serial_context(cpu));
  77. cpu->exception_index = EXCP_ATOMIC;
  78. cpu_loop_exit_restore(cpu, pc);
  79. }