Blue Swirl | 29e922b | 2010-03-29 19:24:00 +0000 | [diff] [blame] | 1 | #include "qemu-timer.h" |
| 2 | |
ths | bf20dc0 | 2008-06-30 17:22:19 +0000 | [diff] [blame] | 3 | /* Helpers for instruction counting code generation. */ |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 4 | |
| 5 | static TCGArg *icount_arg; |
| 6 | static int icount_label; |
| 7 | |
| 8 | static inline void gen_icount_start(void) |
| 9 | { |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 10 | TCGv_i32 count; |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 11 | |
| 12 | if (!use_icount) |
| 13 | return; |
| 14 | |
| 15 | icount_label = gen_new_label(); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 16 | count = tcg_temp_local_new_i32(); |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 17 | tcg_gen_ld_i32(count, cpu_env, offsetof(CPUArchState, icount_decr.u32)); |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 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); |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 23 | tcg_gen_st16_i32(count, cpu_env, offsetof(CPUArchState, icount_decr.u16.low)); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 24 | tcg_temp_free_i32(count); |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [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); |
Stefan Weil | 4b4a72e | 2011-04-02 13:36:31 +0200 | [diff] [blame] | 32 | tcg_gen_exit_tb((tcg_target_long)tb + 2); |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
Juan Quintela | 86178a5 | 2009-09-23 01:19:00 +0200 | [diff] [blame] | 36 | static inline void gen_io_start(void) |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 37 | { |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 38 | TCGv_i32 tmp = tcg_const_i32(1); |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 39 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUArchState, can_do_io)); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 40 | tcg_temp_free_i32(tmp); |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline void gen_io_end(void) |
| 44 | { |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 45 | TCGv_i32 tmp = tcg_const_i32(0); |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 46 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUArchState, can_do_io)); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 47 | tcg_temp_free_i32(tmp); |
pbrook | dd5d6fe | 2008-06-29 10:43:16 +0000 | [diff] [blame] | 48 | } |