1 | /* Helpers for instruction counting code generation. */
|
---|
2 |
|
---|
3 | static TCGArg *icount_arg;
|
---|
4 | static int icount_label;
|
---|
5 |
|
---|
6 | #ifndef VBOX
|
---|
7 | static inline void gen_icount_start(void)
|
---|
8 | #else /* VBOX */
|
---|
9 | DECLINLINE(void) gen_icount_start(void)
|
---|
10 | #endif /* VBOX */
|
---|
11 | {
|
---|
12 | TCGv count;
|
---|
13 |
|
---|
14 | if (!use_icount)
|
---|
15 | return;
|
---|
16 |
|
---|
17 | icount_label = gen_new_label();
|
---|
18 | /* FIXME: This generates lousy code. We can't use tcg_new_temp because
|
---|
19 | count needs to live over the conditional branch. To workaround this
|
---|
20 | we allow the target to supply a convenient register temporary. */
|
---|
21 | #ifndef ICOUNT_TEMP
|
---|
22 | count = tcg_temp_local_new(TCG_TYPE_I32);
|
---|
23 | #else
|
---|
24 | count = ICOUNT_TEMP;
|
---|
25 | #endif
|
---|
26 | tcg_gen_ld_i32(count, cpu_env, offsetof(CPUState, icount_decr.u32));
|
---|
27 | /* This is a horrid hack to allow fixing up the value later. */
|
---|
28 | icount_arg = gen_opparam_ptr + 1;
|
---|
29 | tcg_gen_subi_i32(count, count, 0xdeadbeef);
|
---|
30 |
|
---|
31 | tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, icount_label);
|
---|
32 | tcg_gen_st16_i32(count, cpu_env, offsetof(CPUState, icount_decr.u16.low));
|
---|
33 | #ifndef ICOUNT_TEMP
|
---|
34 | tcg_temp_free(count);
|
---|
35 | #endif
|
---|
36 | }
|
---|
37 |
|
---|
38 | static void gen_icount_end(TranslationBlock *tb, int num_insns)
|
---|
39 | {
|
---|
40 | if (use_icount) {
|
---|
41 | *icount_arg = num_insns;
|
---|
42 | gen_set_label(icount_label);
|
---|
43 | tcg_gen_exit_tb((long)tb + 2);
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | #ifndef VBOX
|
---|
48 | inline static void gen_io_start(void)
|
---|
49 | #else
|
---|
50 | DECLINLINE(void) gen_io_start(void)
|
---|
51 | #endif
|
---|
52 | {
|
---|
53 | TCGv tmp = tcg_const_i32(1);
|
---|
54 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
|
---|
55 | tcg_temp_free(tmp);
|
---|
56 | }
|
---|
57 |
|
---|
58 | #ifndef VBOX
|
---|
59 | static inline void gen_io_end(void)
|
---|
60 | #else /* VBOX */
|
---|
61 | DECLINLINE(void) gen_io_end(void)
|
---|
62 | #endif /* VBOX */
|
---|
63 | {
|
---|
64 | TCGv tmp = tcg_const_i32(0);
|
---|
65 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
|
---|
66 | tcg_temp_free(tmp);
|
---|
67 | }
|
---|
68 |
|
---|