qemu/include/exec/gen-icount.h
<<
>>
Prefs
   1#ifndef GEN_ICOUNT_H
   2#define GEN_ICOUNT_H
   3
   4#include "qemu/timer.h"
   5
   6/* Helpers for instruction counting code generation.  */
   7
   8static TCGOp *icount_start_insn;
   9
  10static inline void gen_tb_start(TranslationBlock *tb)
  11{
  12    TCGv_i32 count, imm;
  13
  14    tcg_ctx->exitreq_label = gen_new_label();
  15    if (tb_cflags(tb) & CF_USE_ICOUNT) {
  16        count = tcg_temp_local_new_i32();
  17    } else {
  18        count = tcg_temp_new_i32();
  19    }
  20
  21    tcg_gen_ld_i32(count, cpu_env,
  22                   offsetof(ArchCPU, neg.icount_decr.u32) -
  23                   offsetof(ArchCPU, env));
  24
  25    if (tb_cflags(tb) & CF_USE_ICOUNT) {
  26        imm = tcg_temp_new_i32();
  27        /* We emit a movi with a dummy immediate argument. Keep the insn index
  28         * of the movi so that we later (when we know the actual insn count)
  29         * can update the immediate argument with the actual insn count.  */
  30        tcg_gen_movi_i32(imm, 0xdeadbeef);
  31        icount_start_insn = tcg_last_op();
  32
  33        tcg_gen_sub_i32(count, count, imm);
  34        tcg_temp_free_i32(imm);
  35    }
  36
  37    tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
  38
  39    if (tb_cflags(tb) & CF_USE_ICOUNT) {
  40        tcg_gen_st16_i32(count, cpu_env,
  41                         offsetof(ArchCPU, neg.icount_decr.u16.low) -
  42                         offsetof(ArchCPU, env));
  43    }
  44
  45    tcg_temp_free_i32(count);
  46}
  47
  48static inline void gen_tb_end(TranslationBlock *tb, int num_insns)
  49{
  50    if (tb_cflags(tb) & CF_USE_ICOUNT) {
  51        /* Update the num_insn immediate parameter now that we know
  52         * the actual insn count.  */
  53        tcg_set_insn_param(icount_start_insn, 1, num_insns);
  54    }
  55
  56    gen_set_label(tcg_ctx->exitreq_label);
  57    tcg_gen_exit_tb(tb, TB_EXIT_REQUESTED);
  58}
  59
  60static inline void gen_io_start(void)
  61{
  62    TCGv_i32 tmp = tcg_const_i32(1);
  63    tcg_gen_st_i32(tmp, cpu_env,
  64                   offsetof(ArchCPU, parent_obj.can_do_io) -
  65                   offsetof(ArchCPU, env));
  66    tcg_temp_free_i32(tmp);
  67}
  68
  69static inline void gen_io_end(void)
  70{
  71    TCGv_i32 tmp = tcg_const_i32(0);
  72    tcg_gen_st_i32(tmp, cpu_env,
  73                   offsetof(ArchCPU, parent_obj.can_do_io) -
  74                   offsetof(ArchCPU, env));
  75    tcg_temp_free_i32(tmp);
  76}
  77
  78#endif
  79