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
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(TranslationBlock *tb)
39 tcg_ctx->exitreq_label = gen_new_label();
40 if (tb_cflags(tb) & CF_USE_ICOUNT) {
41 count = tcg_temp_local_new_i32();
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) {
51 imm = tcg_temp_new_i32();
52 /* We emit a movi with a dummy immediate argument. Keep the insn index
53 * of the movi so that we later (when we know the actual insn count)
54 * can update the immediate argument with the actual insn count. */
55 tcg_gen_movi_i32(imm, 0xdeadbeef);
56 icount_start_insn = tcg_last_op();
58 tcg_gen_sub_i32(count, count, imm);
59 tcg_temp_free_i32(imm);
62 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
64 if (tb_cflags(tb) & CF_USE_ICOUNT) {
65 tcg_gen_st16_i32(count, cpu_env,
66 offsetof(ArchCPU, neg.icount_decr.u16.low) -
67 offsetof(ArchCPU, env));
71 tcg_temp_free_i32(count);
74 static inline void gen_tb_end(TranslationBlock *tb, int num_insns)
76 if (tb_cflags(tb) & CF_USE_ICOUNT) {
77 /* Update the num_insn immediate parameter now that we know
78 * the actual insn count. */
79 tcg_set_insn_param(icount_start_insn, 1, num_insns);
82 gen_set_label(tcg_ctx->exitreq_label);
83 tcg_gen_exit_tb(tb, TB_EXIT_REQUESTED);