blob: 430cb446d0e381c68560af14e5e224fcf76a4d93 [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();
Andreas Färber9349b4f2012-03-14 01:38:32 +010017 tcg_gen_ld_i32(count, cpu_env, offsetof(CPUArchState, icount_decr.u32));
pbrookdd5d6fe2008-06-29 10:43:16 +000018 /* 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ärber9349b4f2012-03-14 01:38:32 +010023 tcg_gen_st16_i32(count, cpu_env, offsetof(CPUArchState, 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);
Stefan Weil4b4a72e2011-04-02 13:36:31 +020032 tcg_gen_exit_tb((tcg_target_long)tb + 2);
pbrookdd5d6fe2008-06-29 10:43:16 +000033 }
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);
Andreas Färber9349b4f2012-03-14 01:38:32 +010039 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUArchState, 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);
Andreas Färber9349b4f2012-03-14 01:38:32 +010046 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUArchState, can_do_io));
pbrooka7812ae2008-11-17 14:43:54 +000047 tcg_temp_free_i32(tmp);
pbrookdd5d6fe2008-06-29 10:43:16 +000048}