hw/arm/virt: Disable pl011 clock migration if needed
[qemu/ar7.git] / include / exec / gen-icount.h
blob298e01eef4979c17065414b5c6c18943d41f8f5d
1 #ifndef GEN_ICOUNT_H
2 #define GEN_ICOUNT_H
4 #include "qemu/timer.h"
6 /* Helpers for instruction counting code generation. */
8 static TCGOp *icount_start_insn;
10 static inline void gen_io_start(void)
12 TCGv_i32 tmp = tcg_const_i32(1);
13 tcg_gen_st_i32(tmp, cpu_env,
14 offsetof(ArchCPU, parent_obj.can_do_io) -
15 offsetof(ArchCPU, env));
16 tcg_temp_free_i32(tmp);
20 * cpu->can_do_io is cleared automatically at the beginning of
21 * each translation block. The cost is minimal and only paid
22 * for -icount, plus it would be very easy to forget doing it
23 * in the translator. Therefore, backends only need to call
24 * gen_io_start.
26 static inline void gen_io_end(void)
28 TCGv_i32 tmp = tcg_const_i32(0);
29 tcg_gen_st_i32(tmp, cpu_env,
30 offsetof(ArchCPU, parent_obj.can_do_io) -
31 offsetof(ArchCPU, env));
32 tcg_temp_free_i32(tmp);
35 static inline void gen_tb_start(const TranslationBlock *tb)
37 TCGv_i32 count;
39 tcg_ctx->exitreq_label = gen_new_label();
40 if (tb_cflags(tb) & CF_USE_ICOUNT) {
41 count = tcg_temp_local_new_i32();
42 } else {
43 count = tcg_temp_new_i32();
46 tcg_gen_ld_i32(count, cpu_env,
47 offsetof(ArchCPU, neg.icount_decr.u32) -
48 offsetof(ArchCPU, env));
50 if (tb_cflags(tb) & CF_USE_ICOUNT) {
52 * We emit a sub with a dummy immediate argument. Keep the insn index
53 * of the sub so that we later (when we know the actual insn count)
54 * can update the argument with the actual insn count.
56 tcg_gen_sub_i32(count, count, tcg_constant_i32(0));
57 icount_start_insn = tcg_last_op();
60 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
62 if (tb_cflags(tb) & CF_USE_ICOUNT) {
63 tcg_gen_st16_i32(count, cpu_env,
64 offsetof(ArchCPU, neg.icount_decr.u16.low) -
65 offsetof(ArchCPU, env));
66 gen_io_end();
69 tcg_temp_free_i32(count);
72 static inline void gen_tb_end(const TranslationBlock *tb, int num_insns)
74 if (tb_cflags(tb) & CF_USE_ICOUNT) {
76 * Update the num_insn immediate parameter now that we know
77 * the actual insn count.
79 tcg_set_insn_param(icount_start_insn, 2,
80 tcgv_i32_arg(tcg_constant_i32(num_insns)));
83 gen_set_label(tcg_ctx->exitreq_label);
84 tcg_gen_exit_tb(tb, TB_EXIT_REQUESTED);
87 #endif