All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: qemu-ppc@nongnu.org
Cc: qemu-devel@nongnu.org, david@gibson.dropbear.id.au,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [Qemu-devel] [PATCHv2 12/31] ppc: Don't update NIP in lswi/lswx/stswi/stswx
Date: Wed, 27 Jul 2016 16:56:30 +1000	[thread overview]
Message-ID: <1469602609-31349-12-git-send-email-benh@kernel.crashing.org> (raw)
In-Reply-To: <1469602609-31349-1-git-send-email-benh@kernel.crashing.org>

Instead, pass GETPC() result to the corresponding helpers. This
requires a bit of fiddling to get the PC (hopefully) right in
the case where we generate a program check, though the hacks there
are temporary, a subsequent patch will clean this all up by always
having the nip already set to the right instruction when taking
the fault.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 target-ppc/excp_helper.c |  8 ++++++++
 target-ppc/mem_helper.c  | 26 ++++++++++++++++----------
 target-ppc/translate.c   | 18 ++++++++----------
 3 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c
index 02d9e79..eb00473 100644
--- a/target-ppc/excp_helper.c
+++ b/target-ppc/excp_helper.c
@@ -285,6 +285,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
             LOG_EXCP("Invalid instruction at " TARGET_FMT_lx "\n", env->nip);
             msr |= 0x00080000;
             env->spr[SPR_BOOKE_ESR] = ESR_PIL;
+            /* Some invalids will have the PC in the right place already */
+            if (env->error_code & POWERPC_EXCP_INVAL_LSWX) {
+                goto store_next;
+            }
             break;
         case POWERPC_EXCP_PRIV:
             msr |= 0x00040000;
@@ -306,6 +310,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
         srr1 = SPR_HSRR1;
         new_msr |= (target_ulong)MSR_HVB;
         new_msr |= env->msr & ((target_ulong)1 << MSR_RI);
+        /* Some invalids will have the PC in the right place already */
+        if (env->error_code == (POWERPC_EXCP_INVAL|POWERPC_EXCP_INVAL_LSWX)) {
+                goto store_next;
+        }
         goto store_current;
     case POWERPC_EXCP_FPU:       /* Floating-point unavailable exception     */
         goto store_current;
diff --git a/target-ppc/mem_helper.c b/target-ppc/mem_helper.c
index e4ed377..de96c91 100644
--- a/target-ppc/mem_helper.c
+++ b/target-ppc/mem_helper.c
@@ -77,23 +77,30 @@ void helper_stmw(CPUPPCState *env, target_ulong addr, uint32_t reg)
     }
 }
 
-void helper_lsw(CPUPPCState *env, target_ulong addr, uint32_t nb, uint32_t reg)
+static void do_lsw(CPUPPCState *env, target_ulong addr, uint32_t nb,
+                   uint32_t reg, uintptr_t raddr)
 {
     int sh;
 
     for (; nb > 3; nb -= 4) {
-        env->gpr[reg] = cpu_ldl_data(env, addr);
+        env->gpr[reg] = cpu_ldl_data_ra(env, addr, raddr);
         reg = (reg + 1) % 32;
         addr = addr_add(env, addr, 4);
     }
     if (unlikely(nb > 0)) {
         env->gpr[reg] = 0;
         for (sh = 24; nb > 0; nb--, sh -= 8) {
-            env->gpr[reg] |= cpu_ldub_data(env, addr) << sh;
+            env->gpr[reg] |= cpu_ldub_data_ra(env, addr, raddr) << sh;
             addr = addr_add(env, addr, 1);
         }
     }
 }
+
+void helper_lsw(CPUPPCState *env, target_ulong addr, uint32_t nb, uint32_t reg)
+{
+    do_lsw(env, addr, nb, reg, GETPC());
+}
+
 /* PPC32 specification says we must generate an exception if
  * rA is in the range of registers to be loaded.
  * In an other hand, IBM says this is valid, but rA won't be loaded.
@@ -106,12 +113,11 @@ void helper_lswx(CPUPPCState *env, target_ulong addr, uint32_t reg,
         int num_used_regs = (xer_bc + 3) / 4;
         if (unlikely((ra != 0 && lsw_reg_in_range(reg, num_used_regs, ra)) ||
                      lsw_reg_in_range(reg, num_used_regs, rb))) {
-            env->nip += 4;     /* Compensate the "nip - 4" from gen_lswx() */
-            helper_raise_exception_err(env, POWERPC_EXCP_PROGRAM,
-                                       POWERPC_EXCP_INVAL |
-                                       POWERPC_EXCP_INVAL_LSWX);
+            raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
+                                   POWERPC_EXCP_INVAL |
+                                   POWERPC_EXCP_INVAL_LSWX, GETPC());
         } else {
-            helper_lsw(env, addr, xer_bc, reg);
+            do_lsw(env, addr, xer_bc, reg, GETPC());
         }
     }
 }
@@ -122,13 +128,13 @@ void helper_stsw(CPUPPCState *env, target_ulong addr, uint32_t nb,
     int sh;
 
     for (; nb > 3; nb -= 4) {
-        cpu_stl_data(env, addr, env->gpr[reg]);
+        cpu_stl_data_ra(env, addr, env->gpr[reg], GETPC());
         reg = (reg + 1) % 32;
         addr = addr_add(env, addr, 4);
     }
     if (unlikely(nb > 0)) {
         for (sh = 24; nb > 0; nb--, sh -= 8) {
-            cpu_stb_data(env, addr, (env->gpr[reg] >> sh) & 0xFF);
+            cpu_stb_data_ra(env, addr, (env->gpr[reg] >> sh) & 0xFF, GETPC());
             addr = addr_add(env, addr, 1);
         }
     }
diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index ba14bda..c32e2be 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -2915,12 +2915,16 @@ static void gen_lswi(DisasContext *ctx)
         nb = 32;
     nr = (nb + 3) / 4;
     if (unlikely(lsw_reg_in_range(start, nr, ra))) {
+        /* The handler expects the PC to point to *this* instruction,
+         * so setting ctx->exception here prevents it from being
+         * improperly updated again by gen_inval_exception
+         */
+        gen_update_nip(ctx, ctx->nip - 4);
+        ctx->exception = POWERPC_EXCP_HV_EMU;
         gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
         return;
     }
     gen_set_access_type(ctx, ACCESS_INT);
-    /* NIP cannot be restored if the memory exception comes from an helper */
-    gen_update_nip(ctx, ctx->nip - 4);
     t0 = tcg_temp_new();
     gen_addr_register(ctx, t0);
     t1 = tcg_const_i32(nb);
@@ -2937,8 +2941,6 @@ static void gen_lswx(DisasContext *ctx)
     TCGv t0;
     TCGv_i32 t1, t2, t3;
     gen_set_access_type(ctx, ACCESS_INT);
-    /* NIP cannot be restored if the memory exception comes from an helper */
-    gen_update_nip(ctx, ctx->nip - 4);
     t0 = tcg_temp_new();
     gen_addr_reg_index(ctx, t0);
     t1 = tcg_const_i32(rD(ctx->opcode));
@@ -2958,8 +2960,6 @@ static void gen_stswi(DisasContext *ctx)
     TCGv_i32 t1, t2;
     int nb = NB(ctx->opcode);
     gen_set_access_type(ctx, ACCESS_INT);
-    /* NIP cannot be restored if the memory exception comes from an helper */
-    gen_update_nip(ctx, ctx->nip - 4);
     t0 = tcg_temp_new();
     gen_addr_register(ctx, t0);
     if (nb == 0)
@@ -2978,8 +2978,6 @@ static void gen_stswx(DisasContext *ctx)
     TCGv t0;
     TCGv_i32 t1, t2;
     gen_set_access_type(ctx, ACCESS_INT);
-    /* NIP cannot be restored if the memory exception comes from an helper */
-    gen_update_nip(ctx, ctx->nip - 4);
     t0 = tcg_temp_new();
     gen_addr_reg_index(ctx, t0);
     t1 = tcg_temp_new_i32();
@@ -4081,7 +4079,7 @@ static void gen_dcbz(DisasContext *ctx)
 static void gen_dst(DisasContext *ctx)
 {
     if (rA(ctx->opcode) == 0) {
-        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
     } else {
         /* interpreted as no-op */
     }
@@ -4091,7 +4089,7 @@ static void gen_dst(DisasContext *ctx)
 static void gen_dstst(DisasContext *ctx)
 {
     if (rA(ctx->opcode) == 0) {
-        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
     } else {
         /* interpreted as no-op */
     }
-- 
2.7.4

  parent reply	other threads:[~2016-07-27  7:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-27  6:56 [Qemu-devel] [PATCHv2 01/31] ppc: Provide basic raise_exception_* functions Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 02/31] ppc: Move classic fp ops out of translate.c Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 03/31] ppc: Move embedded spe " Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 04/31] ppc: Move DFP " Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 05/31] ppc: Move VMX " Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 06/31] ppc: Move VSX " Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 07/31] ppc: Rename fload_invalid_op_excp to float_invalid_op_excp Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 08/31] ppc: Make float_invalid_op_excp() pass the return address Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 09/31] ppc: Make float_check_status() " Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 10/31] ppc: Don't update the NIP in floating point generated code Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 11/31] ppc: FP exceptions are always precise Benjamin Herrenschmidt
2016-07-27  7:21   ` David Gibson
2016-07-27  9:44     ` Benjamin Herrenschmidt
2016-07-28  0:32       ` David Gibson
2016-07-27  6:56 ` Benjamin Herrenschmidt [this message]
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 13/31] ppc: Don't update NIP in lmw/stmw/icbi Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 14/31] ppc: Make tlb_fill() use new exception helper Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 15/31] ppc: Rework NIP updates vs. exception generation Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 16/31] ppc: Fix source NIP on SLB related interrupts Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 17/31] ppc: Don't update NIP in DCR access routines Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 18/31] ppc: Don't update NIP in facility unavailable interrupts Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 19/31] ppc: Don't update NIP BookE 2.06 tlbwe Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 20/31] ppc: Don't update NIP on conditional trap instructions Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 21/31] ppc: Don't update NIP if not taking alignment exceptions Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 22/31] ppc: Don't update NIP in dcbz and lscbx Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 23/31] ppc: Make alignment exceptions suck less Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 24/31] ppc: Handle unconditional (always/never) traps at translation time Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 25/31] ppc: Speed up dcbz Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 26/31] ppc: Fix CFAR updates Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 27/31] ppc: Avoid double translation for lvx/lvxl/stvx/stvxl Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 28/31] ppc: Don't set access_type on all load/stores on hash64 Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 29/31] ppc: Use a helper to generate "LE unsupported" alignment interrupts Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 30/31] ppc: load/store multiple and string insns don't do LE Benjamin Herrenschmidt
2016-07-27  6:56 ` [Qemu-devel] [PATCHv2 31/31] ppc: Speed up load/store multiple Benjamin Herrenschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469602609-31349-12-git-send-email-benh@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.