David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame^] | 1 | #include "qemu-timer.h" |
| 2 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 3 | /* Helpers for instruction counting code generation. */ |
| 4 | |
| 5 | static TCGArg *icount_arg; |
| 6 | static int icount_label; |
| 7 | |
| 8 | static inline void gen_icount_start(void) |
| 9 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 10 | TCGv_i32 count; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 11 | |
| 12 | if (!use_icount) |
| 13 | return; |
| 14 | |
| 15 | icount_label = gen_new_label(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 16 | count = tcg_temp_local_new_i32(); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 17 | 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)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 24 | tcg_temp_free_i32(count); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | static 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 | |
David 'Digit' Turner | 9251866 | 2010-05-10 23:26:01 -0700 | [diff] [blame] | 36 | static inline void gen_io_start(void) |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 37 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 38 | TCGv_i32 tmp = tcg_const_i32(1); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 39 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 40 | tcg_temp_free_i32(tmp); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline void gen_io_end(void) |
| 44 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 45 | TCGv_i32 tmp = tcg_const_i32(0); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 46 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 47 | tcg_temp_free_i32(tmp); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 48 | } |