gen-icount.h 1.7 KB
Newer Older
P
Paolo Bonzini 已提交
1 2 3
#ifndef GEN_ICOUNT_H
#define GEN_ICOUNT_H 1

4
#include "qemu/timer.h"
B
Blue Swirl 已提交
5

T
ths 已提交
6
/* Helpers for instruction counting code generation.  */
P
pbrook 已提交
7 8 9

static TCGArg *icount_arg;
static int icount_label;
10
static int exitreq_label;
P
pbrook 已提交
11

12
static inline void gen_tb_start(void)
P
pbrook 已提交
13
{
P
pbrook 已提交
14
    TCGv_i32 count;
15 16 17
    TCGv_i32 flag;

    exitreq_label = gen_new_label();
18
    flag = tcg_temp_new_i32();
19 20 21 22
    tcg_gen_ld_i32(flag, cpu_env,
                   offsetof(CPUState, tcg_exit_req) - ENV_OFFSET);
    tcg_gen_brcondi_i32(TCG_COND_NE, flag, 0, exitreq_label);
    tcg_temp_free_i32(flag);
P
pbrook 已提交
23 24 25 26 27

    if (!use_icount)
        return;

    icount_label = gen_new_label();
P
pbrook 已提交
28
    count = tcg_temp_local_new_i32();
29
    tcg_gen_ld_i32(count, cpu_env, offsetof(CPUArchState, icount_decr.u32));
P
pbrook 已提交
30
    /* This is a horrid hack to allow fixing up the value later.  */
31
    icount_arg = tcg_ctx.gen_opparam_ptr + 1;
P
pbrook 已提交
32 33 34
    tcg_gen_subi_i32(count, count, 0xdeadbeef);

    tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, icount_label);
35
    tcg_gen_st16_i32(count, cpu_env, offsetof(CPUArchState, icount_decr.u16.low));
P
pbrook 已提交
36
    tcg_temp_free_i32(count);
P
pbrook 已提交
37 38
}

39
static void gen_tb_end(TranslationBlock *tb, int num_insns)
P
pbrook 已提交
40
{
41 42 43
    gen_set_label(exitreq_label);
    tcg_gen_exit_tb((tcg_target_long)tb + TB_EXIT_REQUESTED);

P
pbrook 已提交
44 45 46
    if (use_icount) {
        *icount_arg = num_insns;
        gen_set_label(icount_label);
47
        tcg_gen_exit_tb((tcg_target_long)tb + TB_EXIT_ICOUNT_EXPIRED);
P
pbrook 已提交
48 49 50
    }
}

51
static inline void gen_io_start(void)
P
pbrook 已提交
52
{
P
pbrook 已提交
53
    TCGv_i32 tmp = tcg_const_i32(1);
54
    tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUArchState, can_do_io));
P
pbrook 已提交
55
    tcg_temp_free_i32(tmp);
P
pbrook 已提交
56 57 58 59
}

static inline void gen_io_end(void)
{
P
pbrook 已提交
60
    TCGv_i32 tmp = tcg_const_i32(0);
61
    tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUArchState, can_do_io));
P
pbrook 已提交
62
    tcg_temp_free_i32(tmp);
P
pbrook 已提交
63
}
P
Paolo Bonzini 已提交
64 65

#endif