blob: 8879da633525f3ecfe78b64092f7b3cec6397067 [file] [log] [blame]
Blue Swirl29e922b2010-03-29 19:24:00 +00001#include "qemu-timer.h"
2
thsbf20dc02008-06-30 17:22:19 +00003/* Helpers for instruction counting code generation. */
pbrookdd5d6fe2008-06-29 10:43:16 +00004
5static TCGArg *icount_arg;
6static int icount_label;
7
8static inline void gen_icount_start(void)
9{
pbrooka7812ae2008-11-17 14:43:54 +000010 TCGv_i32 count;
pbrookdd5d6fe2008-06-29 10:43:16 +000011
12 if (!use_icount)
13 return;
14
15 icount_label = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +000016 count = tcg_temp_local_new_i32();
pbrookdd5d6fe2008-06-29 10:43:16 +000017 tcg_gen_ld_i32(count, cpu_env, offsetof(CPUState, icount_decr.u32));
18 /* This is a horrid hack to allow fixing up the value later. */
19 icount_arg = gen_opparam_ptr + 1;
20 tcg_gen_subi_i32(count, count, 0xdeadbeef);
21
22 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, icount_label);
23 tcg_gen_st16_i32(count, cpu_env, offsetof(CPUState, icount_decr.u16.low));
pbrooka7812ae2008-11-17 14:43:54 +000024 tcg_temp_free_i32(count);
pbrookdd5d6fe2008-06-29 10:43:16 +000025}
26
27static void gen_icount_end(TranslationBlock *tb, int num_insns)
28{
29 if (use_icount) {
30 *icount_arg = num_insns;
31 gen_set_label(icount_label);
32 tcg_gen_exit_tb((long)tb + 2);
33 }
34}
35
Juan Quintela86178a52009-09-23 01:19:00 +020036static inline void gen_io_start(void)
pbrookdd5d6fe2008-06-29 10:43:16 +000037{
pbrooka7812ae2008-11-17 14:43:54 +000038 TCGv_i32 tmp = tcg_const_i32(1);
pbrookdd5d6fe2008-06-29 10:43:16 +000039 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
pbrooka7812ae2008-11-17 14:43:54 +000040 tcg_temp_free_i32(tmp);
pbrookdd5d6fe2008-06-29 10:43:16 +000041}
42
43static inline void gen_io_end(void)
44{
pbrooka7812ae2008-11-17 14:43:54 +000045 TCGv_i32 tmp = tcg_const_i32(0);
pbrookdd5d6fe2008-06-29 10:43:16 +000046 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
pbrooka7812ae2008-11-17 14:43:54 +000047 tcg_temp_free_i32(tmp);
pbrookdd5d6fe2008-06-29 10:43:16 +000048}