blob: 3268f720a595073ae98c03db88e9eb60de3d76d6 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/* Helpers for instruction counting code generation. */
2
3static TCGArg *icount_arg;
4static int icount_label;
5
6static inline void gen_icount_start(void)
7{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07008 TCGv_i32 count;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08009
10 if (!use_icount)
11 return;
12
13 icount_label = gen_new_label();
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070014 count = tcg_temp_local_new_i32();
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080015 tcg_gen_ld_i32(count, cpu_env, offsetof(CPUState, icount_decr.u32));
16 /* This is a horrid hack to allow fixing up the value later. */
17 icount_arg = gen_opparam_ptr + 1;
18 tcg_gen_subi_i32(count, count, 0xdeadbeef);
19
20 tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, icount_label);
21 tcg_gen_st16_i32(count, cpu_env, offsetof(CPUState, icount_decr.u16.low));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070022 tcg_temp_free_i32(count);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080023}
24
25static void gen_icount_end(TranslationBlock *tb, int num_insns)
26{
27 if (use_icount) {
28 *icount_arg = num_insns;
29 gen_set_label(icount_label);
30 tcg_gen_exit_tb((long)tb + 2);
31 }
32}
33
David 'Digit' Turner92518662010-05-10 23:26:01 -070034static inline void gen_io_start(void)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080035{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070036 TCGv_i32 tmp = tcg_const_i32(1);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080037 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070038 tcg_temp_free_i32(tmp);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080039}
40
41static inline void gen_io_end(void)
42{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070043 TCGv_i32 tmp = tcg_const_i32(0);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080044 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070045 tcg_temp_free_i32(tmp);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080046}