]> git.proxmox.com Git - mirror_qemu.git/blame - include/exec/gen-icount.h
icount: Add align option to icount
[mirror_qemu.git] / include / exec / gen-icount.h
CommitLineData
cb9c377f
PB
1#ifndef GEN_ICOUNT_H
2#define GEN_ICOUNT_H 1
3
1de7afc9 4#include "qemu/timer.h"
29e922b6 5
bf20dc07 6/* Helpers for instruction counting code generation. */
dd5d6fe9
PB
7
8static TCGArg *icount_arg;
9static int icount_label;
378df4b2 10static int exitreq_label;
dd5d6fe9 11
806f352d 12static inline void gen_tb_start(void)
dd5d6fe9 13{
a7812ae4 14 TCGv_i32 count;
378df4b2
PM
15 TCGv_i32 flag;
16
17 exitreq_label = gen_new_label();
a4960ef3 18 flag = tcg_temp_new_i32();
378df4b2
PM
19 tcg_gen_ld_i32(flag, cpu_env,
20 offsetof(CPUState, tcg_exit_req) - ENV_OFFSET);
21 tcg_gen_brcondi_i32(TCG_COND_NE, flag, 0, exitreq_label);
22 tcg_temp_free_i32(flag);
dd5d6fe9
PB
23
24 if (!use_icount)
25 return;
26
27 icount_label = gen_new_label();
a7812ae4 28 count = tcg_temp_local_new_i32();
28ecfd7a
AF
29 tcg_gen_ld_i32(count, cpu_env,
30 -ENV_OFFSET + offsetof(CPUState, icount_decr.u32));
dd5d6fe9 31 /* This is a horrid hack to allow fixing up the value later. */
c4afe5c4 32 icount_arg = tcg_ctx.gen_opparam_ptr + 1;
dd5d6fe9
PB
33 tcg_gen_subi_i32(count, count, 0xdeadbeef);
34
35 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, icount_label);
28ecfd7a
AF
36 tcg_gen_st16_i32(count, cpu_env,
37 -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low));
a7812ae4 38 tcg_temp_free_i32(count);
dd5d6fe9
PB
39}
40
806f352d 41static void gen_tb_end(TranslationBlock *tb, int num_insns)
dd5d6fe9 42{
378df4b2 43 gen_set_label(exitreq_label);
8cfd0495 44 tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_REQUESTED);
378df4b2 45
dd5d6fe9
PB
46 if (use_icount) {
47 *icount_arg = num_insns;
48 gen_set_label(icount_label);
8cfd0495 49 tcg_gen_exit_tb((uintptr_t)tb + TB_EXIT_ICOUNT_EXPIRED);
dd5d6fe9
PB
50 }
51}
52
86178a57 53static inline void gen_io_start(void)
dd5d6fe9 54{
a7812ae4 55 TCGv_i32 tmp = tcg_const_i32(1);
99df7dce 56 tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io));
a7812ae4 57 tcg_temp_free_i32(tmp);
dd5d6fe9
PB
58}
59
60static inline void gen_io_end(void)
61{
a7812ae4 62 TCGv_i32 tmp = tcg_const_i32(0);
99df7dce 63 tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io));
a7812ae4 64 tcg_temp_free_i32(tmp);
dd5d6fe9 65}
cb9c377f
PB
66
67#endif