1#ifndef GEN_ICOUNT_H
2#define GEN_ICOUNT_H
3
4#include "exec/exec-all.h"
5#include "qemu/timer.h"
6
7
8
9static TCGOp *icount_start_insn;
10
11static inline void gen_io_start(void)
12{
13 TCGv_i32 tmp = tcg_const_i32(1);
14 tcg_gen_st_i32(tmp, cpu_env,
15 offsetof(ArchCPU, parent_obj.can_do_io) -
16 offsetof(ArchCPU, env));
17 tcg_temp_free_i32(tmp);
18}
19
20static inline void gen_tb_start(const TranslationBlock *tb)
21{
22 TCGv_i32 count;
23
24 if (tb_cflags(tb) & CF_USE_ICOUNT) {
25 count = tcg_temp_local_new_i32();
26 } else {
27 count = tcg_temp_new_i32();
28 }
29
30 tcg_gen_ld_i32(count, cpu_env,
31 offsetof(ArchCPU, neg.icount_decr.u32) -
32 offsetof(ArchCPU, env));
33
34 if (tb_cflags(tb) & CF_USE_ICOUNT) {
35
36
37
38
39
40 tcg_gen_sub_i32(count, count, tcg_constant_i32(0));
41 icount_start_insn = tcg_last_op();
42 }
43
44
45
46
47
48
49
50
51 if (tb_cflags(tb) & CF_NOIRQ) {
52 tcg_ctx->exitreq_label = NULL;
53 } else {
54 tcg_ctx->exitreq_label = gen_new_label();
55 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
56 }
57
58 if (tb_cflags(tb) & CF_USE_ICOUNT) {
59 tcg_gen_st16_i32(count, cpu_env,
60 offsetof(ArchCPU, neg.icount_decr.u16.low) -
61 offsetof(ArchCPU, env));
62
63
64
65
66
67
68
69 tcg_gen_st_i32(tcg_constant_i32(0), cpu_env,
70 offsetof(ArchCPU, parent_obj.can_do_io) -
71 offsetof(ArchCPU, env));
72 }
73
74 tcg_temp_free_i32(count);
75}
76
77static inline void gen_tb_end(const TranslationBlock *tb, int num_insns)
78{
79 if (tb_cflags(tb) & CF_USE_ICOUNT) {
80
81
82
83
84 tcg_set_insn_param(icount_start_insn, 2,
85 tcgv_i32_arg(tcg_constant_i32(num_insns)));
86 }
87
88 if (tcg_ctx->exitreq_label) {
89 gen_set_label(tcg_ctx->exitreq_label);
90 tcg_gen_exit_tb(tb, TB_EXIT_REQUESTED);
91 }
92}
93
94#endif
95