kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT
[qemu/ar7.git] / include / exec / gen-icount.h
blobda53395de6b3e4a49786efb0198c9204cb43b670
1 #ifndef GEN_ICOUNT_H
2 #define GEN_ICOUNT_H 1
4 #include "qemu/timer.h"
6 /* Helpers for instruction counting code generation. */
8 static TCGArg *icount_arg;
9 static int icount_label;
10 static int exitreq_label;
12 static inline void gen_tb_start(void)
14 TCGv_i32 count;
15 TCGv_i32 flag;
17 exitreq_label = gen_new_label();
18 flag = tcg_temp_new_i32();
19 tcg_gen_ld_i32(flag, cpu_env,
20 offsetof(CPUState, tcg_exit_req) - ENV_OFFSET);
21 tcg_gen_brcondi_i32(TCG_COND_NE, flag, 0, exitreq_label);
22 tcg_temp_free_i32(flag);
24 if (!use_icount)
25 return;
27 icount_label = gen_new_label();
28 count = tcg_temp_local_new_i32();
29 tcg_gen_ld_i32(count, cpu_env,
30 -ENV_OFFSET + offsetof(CPUState, icount_decr.u32));
31 /* This is a horrid hack to allow fixing up the value later. */
32 icount_arg = tcg_ctx.gen_opparam_ptr + 1;
33 tcg_gen_subi_i32(count, count, 0xdeadbeef);
35 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, icount_label);
36 tcg_gen_st16_i32(count, cpu_env,
37 -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low));
38 tcg_temp_free_i32(count);
41 static void gen_tb_end(TranslationBlock *tb, int num_insns)
43 gen_set_label(exitreq_label);
44 tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_REQUESTED);
46 if (use_icount) {
47 *icount_arg = num_insns;
48 gen_set_label(icount_label);
49 tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_ICOUNT_EXPIRED);
53 static inline void gen_io_start(void)
55 TCGv_i32 tmp = tcg_const_i32(1);
56 tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io));
57 tcg_temp_free_i32(tmp);
60 static inline void gen_io_end(void)
62 TCGv_i32 tmp = tcg_const_i32(0);
63 tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io));
64 tcg_temp_free_i32(tmp);
67 #endif