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
20 #include "qemu/osdep.h"
21 #include "exec/log.h"
22 #include "system/tcg.h"
23 #include "qemu/plugin.h"
24 #include "internal-common.h"
25
26 bool tcg_allowed;
27
tcg_cflags_has(CPUState * cpu,uint32_t flags)28 bool tcg_cflags_has(CPUState *cpu, uint32_t flags)
29 {
30 return cpu->tcg_cflags & flags;
31 }
32
tcg_cflags_set(CPUState * cpu,uint32_t flags)33 void tcg_cflags_set(CPUState *cpu, uint32_t flags)
34 {
35 cpu->tcg_cflags |= flags;
36 }
37
curr_cflags(CPUState * cpu)38 uint32_t curr_cflags(CPUState *cpu)
39 {
40 uint32_t cflags = cpu->tcg_cflags;
41
42 /*
43 * Record gdb single-step. We should be exiting the TB by raising
44 * EXCP_DEBUG, but to simplify other tests, disable chaining too.
45 *
46 * For singlestep and -d nochain, suppress goto_tb so that
47 * we can log -d cpu,exec after every TB.
48 */
49 if (unlikely(cpu->singlestep_enabled)) {
50 cflags |= CF_NO_GOTO_TB | CF_NO_GOTO_PTR | CF_SINGLE_STEP | 1;
51 } else if (qatomic_read(&one_insn_per_tb)) {
52 cflags |= CF_NO_GOTO_TB | 1;
53 } else if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
54 cflags |= CF_NO_GOTO_TB;
55 }
56
57 return cflags;
58 }
59
60 /* exit the current TB, but without causing any exception to be raised */
cpu_loop_exit_noexc(CPUState * cpu)61 void cpu_loop_exit_noexc(CPUState *cpu)
62 {
63 cpu->exception_index = -1;
64 cpu_loop_exit(cpu);
65 }
66
cpu_loop_exit(CPUState * cpu)67 void cpu_loop_exit(CPUState *cpu)
68 {
69 /* Undo the setting in cpu_tb_exec. */
70 cpu->neg.can_do_io = true;
71 /* Undo any setting in generated code. */
72 qemu_plugin_disable_mem_helpers(cpu);
73 siglongjmp(cpu->jmp_env, 1);
74 }
75
cpu_loop_exit_restore(CPUState * cpu,uintptr_t pc)76 void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)
77 {
78 if (pc) {
79 cpu_restore_state(cpu, pc);
80 }
81 cpu_loop_exit(cpu);
82 }
83
cpu_loop_exit_atomic(CPUState * cpu,uintptr_t pc)84 void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)
85 {
86 /* Prevent looping if already executing in a serial context. */
87 g_assert(!cpu_in_serial_context(cpu));
88 cpu->exception_index = EXCP_ATOMIC;
89 cpu_loop_exit_restore(cpu, pc);
90 }
91