diff mbox

[RFCv2,1/1] SPARC64: add icount support

Message ID 20180614105323.22524-2-mark.cave-ayland@ilande.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Mark Cave-Ayland June 14, 2018, 10:53 a.m. UTC
This patch adds gen_io_start()/gen_io_end() to various instructions as required
in order to boot my OpenBIOS test images on qemu-system-sparc64 with icount
enabled.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 target/sparc/translate.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

Comments

Richard Henderson June 14, 2018, 9:02 p.m. UTC | #1
On 06/14/2018 12:53 AM, Mark Cave-Ayland wrote:
> +                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
> +                            gen_io_start();
> +                        }

Need to use tb_cflags(dc->base.tb) for the atomic_read therein.


> +                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
> +                                        gen_io_end();
> +                                        /* End TB to handle timer interrupt */
> +                                        save_state(dc);
> +                                        gen_op_next_insn();
> +                                        tcg_gen_exit_tb(NULL, 0);
> +                                        dc->base.is_jmp = DISAS_NORETURN;
> +                                    }

Exiting the TB should not be dependent on icount.

I would encourage you to introduce e.g. DISAS_EXIT, and code to handle that in
sparc_tr_tb_stop, to avoid replicating this pattern so many times.


r~
Mark Cave-Ayland June 14, 2018, 10:09 p.m. UTC | #2
On 14/06/18 22:02, Richard Henderson wrote:

> On 06/14/2018 12:53 AM, Mark Cave-Ayland wrote:
>> +                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
>> +                            gen_io_start();
>> +                        }
> 
> Need to use tb_cflags(dc->base.tb) for the atomic_read therein.
> 
> 
>> +                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
>> +                                        gen_io_end();
>> +                                        /* End TB to handle timer interrupt */
>> +                                        save_state(dc);
>> +                                        gen_op_next_insn();
>> +                                        tcg_gen_exit_tb(NULL, 0);
>> +                                        dc->base.is_jmp = DISAS_NORETURN;
>> +                                    }
> 
> Exiting the TB should not be dependent on icount.
> 
> I would encourage you to introduce e.g. DISAS_EXIT, and code to handle that in
> sparc_tr_tb_stop, to avoid replicating this pattern so many times.

Okay thanks for the feedback. I've made the changes and will post a v3 
shortly.

I still see the "WARNING: Time of Day clock error" messages on the 
console when booting Milax with icount enabled, although I'm inclined to 
merge this if you're happy with the patch as it is a definite improvement.


ATB,

Mark.
Richard Henderson June 14, 2018, 10:34 p.m. UTC | #3
On 06/14/2018 12:09 PM, Mark Cave-Ayland wrote:
> I still see the "WARNING: Time of Day clock error" messages on the console when
> booting Milax with icount enabled, although I'm inclined to merge this if
> you're happy with the patch as it is a definite improvement.

Yeah, let's fix whatever that is separately.


r~
diff mbox

Patch

diff --git a/target/sparc/translate.c b/target/sparc/translate.c
index f3d430c1b2..56101387a8 100644
--- a/target/sparc/translate.c
+++ b/target/sparc/translate.c
@@ -3400,11 +3400,17 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                         r_const = tcg_const_i32(dc->mem_idx);
                         tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                        offsetof(CPUSPARCState, tick));
+                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                            gen_io_start();
+                        }
                         gen_helper_tick_get_count(cpu_dst, cpu_env, r_tickptr,
                                                   r_const);
                         tcg_temp_free_ptr(r_tickptr);
                         tcg_temp_free_i32(r_const);
                         gen_store_gpr(dc, rd, cpu_dst);
+                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                            gen_io_end();
+                        }
                     }
                     break;
                 case 0x5: /* V9 rdpc */
@@ -3447,11 +3453,17 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                         r_const = tcg_const_i32(dc->mem_idx);
                         tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                        offsetof(CPUSPARCState, stick));
+                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                            gen_io_start();
+                        }
                         gen_helper_tick_get_count(cpu_dst, cpu_env, r_tickptr,
                                                   r_const);
                         tcg_temp_free_ptr(r_tickptr);
                         tcg_temp_free_i32(r_const);
                         gen_store_gpr(dc, rd, cpu_dst);
+                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                            gen_io_end();
+                        }
                     }
                     break;
                 case 0x19: /* System tick compare */
@@ -3576,10 +3588,16 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                         r_const = tcg_const_i32(dc->mem_idx);
                         tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                        offsetof(CPUSPARCState, tick));
+                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                            gen_io_start();
+                        }
                         gen_helper_tick_get_count(cpu_tmp0, cpu_env,
                                                   r_tickptr, r_const);
                         tcg_temp_free_ptr(r_tickptr);
                         tcg_temp_free_i32(r_const);
+                        if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                            gen_io_end();
+                        }
                     }
                     break;
                 case 5: // tba
@@ -4385,9 +4403,20 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                     r_tickptr = tcg_temp_new_ptr();
                                     tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                    offsetof(CPUSPARCState, tick));
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_start();
+                                    }
                                     gen_helper_tick_set_limit(r_tickptr,
                                                               cpu_tick_cmpr);
                                     tcg_temp_free_ptr(r_tickptr);
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_end();
+                                        /* End TB to handle timer interrupt */
+                                        save_state(dc);
+                                        gen_op_next_insn();
+                                        tcg_gen_exit_tb(NULL, 0);
+                                        dc->base.is_jmp = DISAS_NORETURN;
+                                    }
                                 }
                                 break;
                             case 0x18: /* System tick */
@@ -4403,9 +4432,20 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                     r_tickptr = tcg_temp_new_ptr();
                                     tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                    offsetof(CPUSPARCState, stick));
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_start();
+                                    }
                                     gen_helper_tick_set_count(r_tickptr,
                                                               cpu_tmp0);
                                     tcg_temp_free_ptr(r_tickptr);
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_end();
+                                        /* End TB to handle timer interrupt */
+                                        save_state(dc);
+                                        gen_op_next_insn();
+                                        tcg_gen_exit_tb(NULL, 0);
+                                        dc->base.is_jmp = DISAS_NORETURN;
+                                    }
                                 }
                                 break;
                             case 0x19: /* System tick compare */
@@ -4421,9 +4461,20 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                     r_tickptr = tcg_temp_new_ptr();
                                     tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                    offsetof(CPUSPARCState, stick));
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_start();
+                                    }
                                     gen_helper_tick_set_limit(r_tickptr,
                                                               cpu_stick_cmpr);
                                     tcg_temp_free_ptr(r_tickptr);
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_end();
+                                        /* End TB to handle timer interrupt */
+                                        save_state(dc);
+                                        gen_op_next_insn();
+                                        tcg_gen_exit_tb(NULL, 0);
+                                        dc->base.is_jmp = DISAS_NORETURN;
+                                    }
                                 }
                                 break;
 
@@ -4531,9 +4582,20 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                     r_tickptr = tcg_temp_new_ptr();
                                     tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                    offsetof(CPUSPARCState, tick));
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_start();
+                                    }
                                     gen_helper_tick_set_count(r_tickptr,
                                                               cpu_tmp0);
                                     tcg_temp_free_ptr(r_tickptr);
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_end();
+                                        /* End TB to handle timer interrupt */
+                                        save_state(dc);
+                                        gen_op_next_insn();
+                                        tcg_gen_exit_tb(NULL, 0);
+                                        dc->base.is_jmp = DISAS_NORETURN;
+                                    }
                                 }
                                 break;
                             case 5: // tba
@@ -4541,7 +4603,13 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                 break;
                             case 6: // pstate
                                 save_state(dc);
+                                if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                    gen_io_start();
+                                }
                                 gen_helper_wrpstate(cpu_env, cpu_tmp0);
+                                if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                    gen_io_end();
+                                }
                                 dc->npc = DYNAMIC_PC;
                                 break;
                             case 7: // tl
@@ -4551,7 +4619,13 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                 dc->npc = DYNAMIC_PC;
                                 break;
                             case 8: // pil
+                                if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                    gen_io_start();
+                                }
                                 gen_helper_wrpil(cpu_env, cpu_tmp0);
+                                if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                    gen_io_end();
+                                }
                                 break;
                             case 9: // cwp
                                 gen_helper_wrcwp(cpu_env, cpu_tmp0);
@@ -4642,9 +4716,20 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                     r_tickptr = tcg_temp_new_ptr();
                                     tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                    offsetof(CPUSPARCState, hstick));
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_start();
+                                    }
                                     gen_helper_tick_set_limit(r_tickptr,
                                                               cpu_hstick_cmpr);
                                     tcg_temp_free_ptr(r_tickptr);
+                                    if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                        gen_io_end();
+                                        /* End TB to handle timer interrupt */
+                                        save_state(dc);
+                                        gen_op_next_insn();
+                                        tcg_gen_exit_tb(NULL, 0);
+                                        dc->base.is_jmp = DISAS_NORETURN;
+                                    }
                                 }
                                 break;
                             case 6: // hver readonly
@@ -5265,14 +5350,26 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                                 goto priv_insn;
                             dc->npc = DYNAMIC_PC;
                             dc->pc = DYNAMIC_PC;
+                            if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                gen_io_start();
+                            }
                             gen_helper_done(cpu_env);
+                            if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                gen_io_end();
+                            }
                             goto jmp_insn;
                         case 1:
                             if (!supervisor(dc))
                                 goto priv_insn;
                             dc->npc = DYNAMIC_PC;
                             dc->pc = DYNAMIC_PC;
+                            if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                gen_io_start();
+                            }
                             gen_helper_retry(cpu_env);
+                            if (dc->base.tb->cflags & CF_USE_ICOUNT) {
+                                gen_io_end();
+                            }
                             goto jmp_insn;
                         default:
                             goto illegal_insn;