]>
Commit | Line | Data |
---|---|---|
cb9c377f | 1 | #ifndef GEN_ICOUNT_H |
175de524 | 2 | #define GEN_ICOUNT_H |
cb9c377f | 3 | |
1de7afc9 | 4 | #include "qemu/timer.h" |
29e922b6 | 5 | |
bf20dc07 | 6 | /* Helpers for instruction counting code generation. */ |
dd5d6fe9 | 7 | |
25caa94c | 8 | static int icount_start_insn_idx; |
42a268c2 | 9 | static TCGLabel *exitreq_label; |
dd5d6fe9 | 10 | |
cd42d5b2 | 11 | static inline void gen_tb_start(TranslationBlock *tb) |
dd5d6fe9 | 12 | { |
1aab16c2 | 13 | TCGv_i32 count, imm; |
378df4b2 PM |
14 | |
15 | exitreq_label = gen_new_label(); | |
1aab16c2 PB |
16 | if (tb->cflags & CF_USE_ICOUNT) { |
17 | count = tcg_temp_local_new_i32(); | |
18 | } else { | |
19 | count = tcg_temp_new_i32(); | |
c45cb8bb | 20 | } |
dd5d6fe9 | 21 | |
28ecfd7a AF |
22 | tcg_gen_ld_i32(count, cpu_env, |
23 | -ENV_OFFSET + offsetof(CPUState, icount_decr.u32)); | |
c45cb8bb | 24 | |
1aab16c2 PB |
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); | |
c45cb8bb | 38 | |
1aab16c2 PB |
39 | if (tb->cflags & CF_USE_ICOUNT) { |
40 | tcg_gen_st16_i32(count, cpu_env, | |
41 | -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low)); | |
42 | } | |
dd5d6fe9 | 43 | |
a7812ae4 | 44 | tcg_temp_free_i32(count); |
dd5d6fe9 PB |
45 | } |
46 | ||
806f352d | 47 | static void gen_tb_end(TranslationBlock *tb, int num_insns) |
dd5d6fe9 | 48 | { |
cd42d5b2 | 49 | if (tb->cflags & CF_USE_ICOUNT) { |
25caa94c EI |
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); | |
dd5d6fe9 | 53 | } |
0a7df5da | 54 | |
1aab16c2 PB |
55 | gen_set_label(exitreq_label); |
56 | tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_REQUESTED); | |
57 | ||
c45cb8bb | 58 | /* Terminate the linked list. */ |
dcb8e758 | 59 | tcg_ctx.gen_op_buf[tcg_ctx.gen_op_buf[0].prev].next = 0; |
dd5d6fe9 PB |
60 | } |
61 | ||
86178a57 | 62 | static inline void gen_io_start(void) |
dd5d6fe9 | 63 | { |
a7812ae4 | 64 | TCGv_i32 tmp = tcg_const_i32(1); |
99df7dce | 65 | tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io)); |
a7812ae4 | 66 | tcg_temp_free_i32(tmp); |
dd5d6fe9 PB |
67 | } |
68 | ||
69 | static inline void gen_io_end(void) | |
70 | { | |
a7812ae4 | 71 | TCGv_i32 tmp = tcg_const_i32(0); |
99df7dce | 72 | tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io)); |
a7812ae4 | 73 | tcg_temp_free_i32(tmp); |
dd5d6fe9 | 74 | } |
cb9c377f PB |
75 | |
76 | #endif |