diff mbox

[for-2.10,3/3] target/mips: Fix RDHWR CC with icount

Message ID 248e7141b59e3cce8768f8210ade7f19108c92fa.1501667615.git-series.james.hogan@imgtec.com
State New
Headers show

Commit Message

James Hogan Aug. 2, 2017, 9:59 a.m. UTC
RDHWR CC reads the CPU timer like MFC0 CP0_Count, so with icount enabled
it must set can_do_io while it calls the helper to avoid the "Bad icount
read" error. It should also break out of the translation loop to ensure
that timer interrupts are immediately handled.

Fixes: 2e70f6efa8b9 ("Add instruction counter.")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Yongbok Kim <yongbok.kim@imgtec.com>
---
I've based this on MFC0 Count, but this instruction is also available to
usermode (e.g. CONFIG_USER_ONLY), which I presume is still fine.
---
 target/mips/translate.c | 11 +++++++++++
 1 file changed, 11 insertions(+), 0 deletions(-)

Comments

Richard Henderson Aug. 2, 2017, 3:01 p.m. UTC | #1
On 08/02/2017 02:59 AM, James Hogan wrote:
> RDHWR CC reads the CPU timer like MFC0 CP0_Count, so with icount enabled
> it must set can_do_io while it calls the helper to avoid the "Bad icount
> read" error. It should also break out of the translation loop to ensure
> that timer interrupts are immediately handled.
> 
> Fixes: 2e70f6efa8b9 ("Add instruction counter.")
> Signed-off-by: James Hogan<james.hogan@imgtec.com>
> Cc: Aurelien Jarno<aurelien@aurel32.net>
> Cc: Yongbok Kim<yongbok.kim@imgtec.com>
> ---
> I've based this on MFC0 Count, but this instruction is also available to
> usermode (e.g. CONFIG_USER_ONLY), which I presume is still fine.
> ---
>   target/mips/translate.c | 11 +++++++++++
>   1 file changed, 11 insertions(+), 0 deletions(-)

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~
diff mbox

Patch

diff --git a/target/mips/translate.c b/target/mips/translate.c
index 6e724ac71dcd..f29092f6d4ac 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -10759,8 +10759,19 @@  static void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel)
         gen_store_gpr(t0, rt);
         break;
     case 2:
+        if (ctx->tb->cflags & CF_USE_ICOUNT) {
+            gen_io_start();
+        }
         gen_helper_rdhwr_cc(t0, cpu_env);
+        if (ctx->tb->cflags & CF_USE_ICOUNT) {
+            gen_io_end();
+        }
         gen_store_gpr(t0, rt);
+        /* Break the TB to be able to take timer interrupts immediately
+           after reading count. BS_STOP isn't sufficient, we need to ensure
+           we break completely out of translated code.  */
+        gen_save_pc(ctx->pc + 4);
+        ctx->bstate = BS_EXCP;
         break;
     case 3:
         gen_helper_rdhwr_ccres(t0, cpu_env);