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 int icount_start_insn_idx;
   9static TCGLabel *exitreq_label;
  10
  11static inline void gen_tb_start(TranslationBlock *tb)
  12{
  13    TCGv_i32 count, imm;
  14
  15    exitreq_label = gen_new_label();
  16    if (tb->cflags & CF_USE_ICOUNT) {
  17        count = tcg_temp_local_new_i32();
  18    } else {
  19        count = tcg_temp_new_i32();
  20    }
  21
  22    tcg_gen_ld_i32(count, tcg_ctx.tcg_env,
  23                   -ENV_OFFSET + offsetof(CPUState, icount_decr.u32));
  24
  25    if (tb->cflags & 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        icount_start_insn_idx = tcg_op_buf_count();
  31        tcg_gen_movi_i32(imm, 0xdeadbeef);
  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, exitreq_label);
  38
  39    if (tb->cflags & CF_USE_ICOUNT) {
  40        tcg_gen_st16_i32(count, tcg_ctx.tcg_env,
  41                         -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low));
  42    }
  43
  44    tcg_temp_free_i32(count);
  45}
  46
  47static inline void gen_tb_end(TranslationBlock *tb, int num_insns)
  48{
  49    if (tb->cflags & CF_USE_ICOUNT) {
  50        /* Update the num_insn immediate parameter now that we know
  51         * the actual insn count.  */
  52        tcg_set_insn_param(icount_start_insn_idx, 1, num_insns);
  53    }
  54
  55    gen_set_label(exitreq_label);
  56    tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_REQUESTED);
  57
  58    /* Terminate the linked list.  */
  59    tcg_ctx.gen_op_buf[tcg_ctx.gen_op_buf[0].prev].next = 0;
  60}
  61
  62static inline void gen_io_start(void)
  63{
  64    TCGv_i32 tmp = tcg_const_i32(1);
  65    tcg_gen_st_i32(tmp, tcg_ctx.tcg_env,
  66                   -ENV_OFFSET + offsetof(CPUState, can_do_io));
  67    tcg_temp_free_i32(tmp);
  68}
  69
  70static inline void gen_io_end(void)
  71{
  72    TCGv_i32 tmp = tcg_const_i32(0);
  73    tcg_gen_st_i32(tmp, tcg_ctx.tcg_env,
  74                   -ENV_OFFSET + offsetof(CPUState, can_do_io));
  75    tcg_temp_free_i32(tmp);
  76}
  77
  78#endif
  79