]> Git Repo - qemu.git/blobdiff - target-ppc/translate.c
KVM: Get all cpuid values from function 2 (Amit Shah)
[qemu.git] / target-ppc / translate.c
index aa85ba74c778e6d133ea8044f21d56854bd75ca3..e829498d6efc374ec20e696bd124fa43a1604f57 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
  */
 #include <stdarg.h>
 #include <stdlib.h>
 //#define DO_SINGLE_STEP
 //#define PPC_DEBUG_DISAS
 //#define DO_PPC_STATISTICS
-//#define OPTIMIZE_FPRF_UPDATE
 
+#ifdef PPC_DEBUG_DISAS
+#  define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
+#else
+#  define LOG_DISAS(...) do { } while (0)
+#endif
 /*****************************************************************************/
 /* Code translation helpers                                                  */
 
@@ -162,11 +166,6 @@ void ppc_translate_init(void)
     done_init = 1;
 }
 
-#if defined(OPTIMIZE_FPRF_UPDATE)
-static uint16_t *gen_fprf_buf[OPC_BUF_SIZE];
-static uint16_t **gen_fprf_ptr;
-#endif
-
 /* internal defines */
 typedef struct DisasContext {
     struct TranslationBlock *tb;
@@ -206,7 +205,7 @@ struct opc_handler_t {
 static always_inline void gen_reset_fpstatus (void)
 {
 #ifdef CONFIG_SOFTFLOAT
-    gen_op_reset_fpstatus();
+    gen_helper_reset_fpstatus();
 #endif
 }
 
@@ -216,9 +215,6 @@ static always_inline void gen_compute_fprf (TCGv_i64 arg, int set_fprf, int set_
 
     if (set_fprf != 0) {
         /* This case might be optimized later */
-#if defined(OPTIMIZE_FPRF_UPDATE)
-        *gen_fprf_ptr++ = gen_opc_ptr;
-#endif
         tcg_gen_movi_i32(t0, 1);
         gen_helper_compute_fprf(t0, arg, t0);
         if (unlikely(set_rc)) {
@@ -230,24 +226,11 @@ static always_inline void gen_compute_fprf (TCGv_i64 arg, int set_fprf, int set_
         tcg_gen_movi_i32(t0, 0);
         gen_helper_compute_fprf(t0, arg, t0);
         tcg_gen_mov_i32(cpu_crf[1], t0);
-        if (set_fprf)
-            gen_helper_float_check_status();
     }
 
     tcg_temp_free_i32(t0);
 }
 
-static always_inline void gen_optimize_fprf (void)
-{
-#if defined(OPTIMIZE_FPRF_UPDATE)
-    uint16_t **ptr;
-
-    for (ptr = gen_fprf_buf; ptr != (gen_fprf_ptr - 1); ptr++)
-        *ptr = INDEX_op_nop1;
-    gen_fprf_ptr = gen_fprf_buf;
-#endif
-}
-
 static always_inline void gen_set_access_type (DisasContext *ctx, int access_type)
 {
     if (ctx->access_type != access_type) {
@@ -266,49 +249,55 @@ static always_inline void gen_update_nip (DisasContext *ctx, target_ulong nip)
         tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
 }
 
-#define GEN_EXCP(ctx, excp, error)                                            \
-do {                                                                          \
-    TCGv_i32 t0 = tcg_const_i32(excp);                                        \
-    TCGv_i32 t1 = tcg_const_i32(error);                                       \
-    if ((ctx)->exception == POWERPC_EXCP_NONE) {                              \
-        gen_update_nip(ctx, (ctx)->nip);                                      \
-    }                                                                         \
-    gen_helper_raise_exception_err(t0, t1);                                   \
-    tcg_temp_free_i32(t0);                                                    \
-    tcg_temp_free_i32(t1);                                                    \
-    ctx->exception = (excp);                                                  \
-} while (0)
-
-#define GEN_EXCP_INVAL(ctx)                                                   \
-GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM,                                         \
-         POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
-
-#define GEN_EXCP_PRIVOPC(ctx)                                                 \
-GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM,                                         \
-         POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
-
-#define GEN_EXCP_PRIVREG(ctx)                                                 \
-GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM,                                         \
-         POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
+static always_inline void gen_exception_err (DisasContext *ctx, uint32_t excp, uint32_t error)
+{
+    TCGv_i32 t0, t1;
+    if (ctx->exception == POWERPC_EXCP_NONE) {
+        gen_update_nip(ctx, ctx->nip);
+    }
+    t0 = tcg_const_i32(excp);
+    t1 = tcg_const_i32(error);
+    gen_helper_raise_exception_err(t0, t1);
+    tcg_temp_free_i32(t0);
+    tcg_temp_free_i32(t1);
+    ctx->exception = (excp);
+}
 
-#define GEN_EXCP_NO_FP(ctx)                                                   \
-GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
+static always_inline void gen_exception (DisasContext *ctx, uint32_t excp)
+{
+    TCGv_i32 t0;
+    if (ctx->exception == POWERPC_EXCP_NONE) {
+        gen_update_nip(ctx, ctx->nip);
+    }
+    t0 = tcg_const_i32(excp);
+    gen_helper_raise_exception(t0);
+    tcg_temp_free_i32(t0);
+    ctx->exception = (excp);
+}
 
-#define GEN_EXCP_NO_AP(ctx)                                                   \
-GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
+static always_inline void gen_debug_exception (DisasContext *ctx)
+{
+    TCGv_i32 t0;
+    gen_update_nip(ctx, ctx->nip);
+    t0 = tcg_const_i32(EXCP_DEBUG);
+    gen_helper_raise_exception(t0);
+    tcg_temp_free_i32(t0);
+}
 
-#define GEN_EXCP_NO_VR(ctx)                                                   \
-GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
+static always_inline void gen_inval_exception (DisasContext *ctx, uint32_t error)
+{
+    gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
+}
 
 /* Stop translation */
-static always_inline void GEN_STOP (DisasContext *ctx)
+static always_inline void gen_stop_exception (DisasContext *ctx)
 {
     gen_update_nip(ctx, ctx->nip);
     ctx->exception = POWERPC_EXCP_STOP;
 }
 
 /* No need to update nip here, as execution flow will change */
-static always_inline void GEN_SYNC (DisasContext *ctx)
+static always_inline void gen_sync_exception (DisasContext *ctx)
 {
     ctx->exception = POWERPC_EXCP_SYNC;
 }
@@ -386,10 +375,16 @@ EXTRACT_HELPER(IMM, 12, 8);
 EXTRACT_SHELPER(SIMM, 0, 16);
 /* 16 bits unsigned immediate value */
 EXTRACT_HELPER(UIMM, 0, 16);
+/* 5 bits signed immediate value */
+EXTRACT_HELPER(SIMM5, 16, 5);
+/* 5 bits signed immediate value */
+EXTRACT_HELPER(UIMM5, 16, 5);
 /* Bit count */
 EXTRACT_HELPER(NB, 11, 5);
 /* Shift count */
 EXTRACT_HELPER(SH, 11, 5);
+/* Vector shift count */
+EXTRACT_HELPER(VSH, 6, 4);
 /* Mask start */
 EXTRACT_HELPER(MB, 6, 5);
 /* Mask end */
@@ -691,7 +686,7 @@ GEN_OPCODE_MARK(start);
 /* Invalid instruction */
 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
 {
-    GEN_EXCP_INVAL(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
 }
 
 static opc_handler_t invalid_handler = {
@@ -2085,9 +2080,11 @@ GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B)
 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)                        \
 {                                                                             \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
+    /* NIP cannot be restored if the memory exception comes from an helper */ \
+    gen_update_nip(ctx, ctx->nip - 4);                                        \
     gen_reset_fpstatus();                                                     \
     gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],      \
                      cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);     \
@@ -2106,9 +2103,11 @@ _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)                             \
 {                                                                             \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
+    /* NIP cannot be restored if the memory exception comes from an helper */ \
+    gen_update_nip(ctx, ctx->nip - 4);                                        \
     gen_reset_fpstatus();                                                     \
     gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],      \
                      cpu_fpr[rB(ctx->opcode)]);                               \
@@ -2126,9 +2125,11 @@ _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)                             \
 {                                                                             \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
+    /* NIP cannot be restored if the memory exception comes from an helper */ \
+    gen_update_nip(ctx, ctx->nip - 4);                                        \
     gen_reset_fpstatus();                                                     \
     gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],      \
                        cpu_fpr[rC(ctx->opcode)]);                             \
@@ -2146,9 +2147,11 @@ _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)                        \
 {                                                                             \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
+    /* NIP cannot be restored if the memory exception comes from an helper */ \
+    gen_update_nip(ctx, ctx->nip - 4);                                        \
     gen_reset_fpstatus();                                                     \
     gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);   \
     gen_compute_fprf(cpu_fpr[rD(ctx->opcode)],                                \
@@ -2159,9 +2162,11 @@ GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)                        \
 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)                        \
 {                                                                             \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
+    /* NIP cannot be restored if the memory exception comes from an helper */ \
+    gen_update_nip(ctx, ctx->nip - 4);                                        \
     gen_reset_fpstatus();                                                     \
     gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);   \
     gen_compute_fprf(cpu_fpr[rD(ctx->opcode)],                                \
@@ -2188,9 +2193,11 @@ GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
 GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES)
 {
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
     gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
     gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);
@@ -2206,9 +2213,11 @@ GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
 {
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
     gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
     gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
@@ -2217,9 +2226,11 @@ GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
 {
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
     gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
     gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);
@@ -2265,26 +2276,34 @@ GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
 /* fcmpo */
 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
 {
+    TCGv_i32 crf;
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
-    gen_helper_fcmpo(cpu_crf[crfD(ctx->opcode)],
-                     cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
+    crf = tcg_const_i32(crfD(ctx->opcode));
+    gen_helper_fcmpo(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf);
+    tcg_temp_free_i32(crf);
     gen_helper_float_check_status();
 }
 
 /* fcmpu */
 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
 {
+    TCGv_i32 crf;
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
-    gen_helper_fcmpu(cpu_crf[crfD(ctx->opcode)],
-                     cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
+    crf = tcg_const_i32(crfD(ctx->opcode));
+    gen_helper_fcmpu(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf);
+    tcg_temp_free_i32(crf);
     gen_helper_float_check_status();
 }
 
@@ -2298,7 +2317,7 @@ GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
 {
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
     tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
@@ -2319,10 +2338,9 @@ GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
     int bfa;
 
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
-    gen_optimize_fprf();
     bfa = 4 * (7 - crfS(ctx->opcode));
     tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa);
     tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
@@ -2333,10 +2351,9 @@ GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
 {
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
-    gen_optimize_fprf();
     gen_reset_fpstatus();
     tcg_gen_extu_i32_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
     gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
@@ -2348,14 +2365,19 @@ GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
     uint8_t crb;
 
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
-    crb = 32 - (crbD(ctx->opcode) >> 2);
-    gen_optimize_fprf();
+    crb = 31 - crbD(ctx->opcode);
     gen_reset_fpstatus();
-    if (likely(crb != 30 && crb != 29))
-        tcg_gen_andi_i32(cpu_fpscr, cpu_fpscr, ~(1 << crb));
+    if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
+        TCGv_i32 t0;
+        /* NIP cannot be restored if the memory exception comes from an helper */
+        gen_update_nip(ctx, ctx->nip - 4);
+        t0 = tcg_const_i32(crb);
+        gen_helper_fpscr_clrbit(t0);
+        tcg_temp_free_i32(t0);
+    }
     if (unlikely(Rc(ctx->opcode) != 0)) {
         tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
     }
@@ -2367,15 +2389,17 @@ GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
     uint8_t crb;
 
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
-    crb = 32 - (crbD(ctx->opcode) >> 2);
-    gen_optimize_fprf();
+    crb = 31 - crbD(ctx->opcode);
     gen_reset_fpstatus();
     /* XXX: we pretend we can only do IEEE floating-point computations */
     if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
-        TCGv_i32 t0 = tcg_const_i32(crb);
+        TCGv_i32 t0;
+        /* NIP cannot be restored if the memory exception comes from an helper */
+        gen_update_nip(ctx, ctx->nip - 4);
+        t0 = tcg_const_i32(crb);
         gen_helper_fpscr_setbit(t0);
         tcg_temp_free_i32(t0);
     }
@@ -2392,10 +2416,11 @@ GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
     TCGv_i32 t0;
 
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
-    gen_optimize_fprf();
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
     t0 = tcg_const_i32(FM(ctx->opcode));
     gen_helper_store_fpscr(cpu_fpr[rB(ctx->opcode)], t0);
@@ -2415,12 +2440,13 @@ GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
     TCGv_i32 t1;
 
     if (unlikely(!ctx->fpu_enabled)) {
-        GEN_EXCP_NO_FP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_FPU);
         return;
     }
     bf = crbD(ctx->opcode) >> 2;
     sh = 7 - bf;
-    gen_optimize_fprf();
+    /* NIP cannot be restored if the memory exception comes from an helper */
+    gen_update_nip(ctx, ctx->nip - 4);
     gen_reset_fpstatus();
     t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh));
     t1 = tcg_const_i32(1 << sh);
@@ -2700,7 +2726,7 @@ GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type)                       \
     TCGv EA;                                                                  \
     if (unlikely(rA(ctx->opcode) == 0 ||                                      \
                  rA(ctx->opcode) == rD(ctx->opcode))) {                       \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -2720,7 +2746,7 @@ GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type)                     \
     TCGv EA;                                                                  \
     if (unlikely(rA(ctx->opcode) == 0 ||                                      \
                  rA(ctx->opcode) == rD(ctx->opcode))) {                       \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -2771,7 +2797,7 @@ GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
     if (Rc(ctx->opcode)) {
         if (unlikely(rA(ctx->opcode) == 0 ||
                      rA(ctx->opcode) == rD(ctx->opcode))) {
-            GEN_EXCP_INVAL(ctx);
+            gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
             return;
         }
     }
@@ -2793,25 +2819,25 @@ GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     int ra, rd;
     TCGv EA;
 
     /* Restore CPU state */
     if (unlikely(ctx->mem_idx == 0)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     ra = rA(ctx->opcode);
     rd = rD(ctx->opcode);
     if (unlikely((rd & 1) || rd == ra)) {
-        GEN_EXCP_INVAL(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         return;
     }
     if (unlikely(ctx->le_mode)) {
         /* Little-endian mode is not handled */
-        GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
+        gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
         return;
     }
     gen_set_access_type(ctx, ACCESS_INT);
@@ -2842,7 +2868,7 @@ GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type)                       \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(rA(ctx->opcode) == 0)) {                                     \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -2861,7 +2887,7 @@ GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type)                     \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(rA(ctx->opcode) == 0)) {                                     \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -2906,20 +2932,20 @@ GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B)
     rs = rS(ctx->opcode);
     if ((ctx->opcode & 0x3) == 0x2) {
 #if defined(CONFIG_USER_ONLY)
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
         /* stq */
         if (unlikely(ctx->mem_idx == 0)) {
-            GEN_EXCP_PRIVOPC(ctx);
+            gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
             return;
         }
         if (unlikely(rs & 1)) {
-            GEN_EXCP_INVAL(ctx);
+            gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
             return;
         }
         if (unlikely(ctx->le_mode)) {
             /* Little-endian mode is not handled */
-            GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
+            gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
             return;
         }
         gen_set_access_type(ctx, ACCESS_INT);
@@ -2934,7 +2960,7 @@ GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B)
         /* std / stdu */
         if (Rc(ctx->opcode)) {
             if (unlikely(rA(ctx->opcode) == 0)) {
-                GEN_EXCP_INVAL(ctx);
+                gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
                 return;
             }
         }
@@ -3096,8 +3122,7 @@ GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING)
     if (unlikely(((start + nr) > 32  &&
                   start <= ra && (start + nr - 32) > ra) ||
                  ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
-        GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
-                 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
         return;
     }
     gen_set_access_type(ctx, ACCESS_INT);
@@ -3183,7 +3208,7 @@ GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO)
 /* isync */
 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM)
 {
-    GEN_STOP(ctx);
+    gen_stop_exception(ctx);
 }
 
 /* lwarx */
@@ -3268,7 +3293,7 @@ GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT)
     tcg_gen_st_i32(t0, cpu_env, offsetof(CPUState, halted));
     tcg_temp_free_i32(t0);
     /* Stop translation, as the CPU is supposed to sleep from now */
-    GEN_EXCP(ctx, EXCP_HLT, 1);
+    gen_exception_err(ctx, EXCP_HLT, 1);
 }
 
 /***                         Floating-point load                           ***/
@@ -3277,7 +3302,7 @@ GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type)                          \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3292,11 +3317,11 @@ GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type)                       \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     if (unlikely(rA(ctx->opcode) == 0)) {                                     \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3312,11 +3337,11 @@ GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type)                      \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     if (unlikely(rA(ctx->opcode) == 0)) {                                     \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3332,7 +3357,7 @@ GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type)                      \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3370,7 +3395,7 @@ GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type)                          \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3385,11 +3410,11 @@ GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type)                       \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     if (unlikely(rA(ctx->opcode) == 0)) {                                     \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3405,11 +3430,11 @@ GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type)                      \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     if (unlikely(rA(ctx->opcode) == 0)) {                                     \
-        GEN_EXCP_INVAL(ctx);                                                  \
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3425,7 +3450,7 @@ GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type)                      \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->fpu_enabled)) {                                        \
-        GEN_EXCP_NO_FP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
@@ -3491,12 +3516,11 @@ static always_inline void gen_goto_tb (DisasContext *ctx, int n,
                 ctx->exception == POWERPC_EXCP_BRANCH) {
                 target_ulong tmp = ctx->nip;
                 ctx->nip = dest;
-                GEN_EXCP(ctx, POWERPC_EXCP_TRACE, 0);
+                gen_exception(ctx, POWERPC_EXCP_TRACE);
                 ctx->nip = tmp;
             }
             if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
-                gen_update_nip(ctx, dest);
-                gen_helper_raise_debug();
+                gen_debug_exception(ctx);
             }
         }
         tcg_gen_exit_tb(0);
@@ -3560,7 +3584,7 @@ static always_inline void gen_bcond (DisasContext *ctx, int type)
         /* Decrement and test CTR */
         TCGv temp = tcg_temp_new();
         if (unlikely(type == BCOND_CTR)) {
-            GEN_EXCP_INVAL(ctx);
+            gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
             return;
         }
         tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
@@ -3694,15 +3718,15 @@ GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     /* Restore CPU state */
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_rfi();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
@@ -3710,30 +3734,30 @@ GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     /* Restore CPU state */
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_rfid();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     /* Restore CPU state */
     if (unlikely(ctx->mem_idx <= 1)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_hrfid();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 #endif
@@ -3749,7 +3773,7 @@ GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
     uint32_t lev;
 
     lev = (ctx->opcode >> 5) & 0x7F;
-    GEN_EXCP(ctx, POWERPC_SYSCALL, lev);
+    gen_exception_err(ctx, POWERPC_SYSCALL, lev);
 }
 
 /***                                Trap                                   ***/
@@ -3828,10 +3852,10 @@ GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
@@ -3873,25 +3897,20 @@ static always_inline void gen_op_mfspr (DisasContext *ctx)
              * allowing userland application to read the PVR
              */
             if (sprn != SPR_PVR) {
-                if (loglevel != 0) {
-                    fprintf(logfile, "Trying to read privileged spr %d %03x at "
+                qemu_log("Trying to read privileged spr %d %03x at "
                             ADDRX "\n", sprn, sprn, ctx->nip);
-                }
                 printf("Trying to read privileged spr %d %03x at " ADDRX "\n",
                        sprn, sprn, ctx->nip);
             }
-            GEN_EXCP_PRIVREG(ctx);
+            gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         }
     } else {
         /* Not defined */
-        if (loglevel != 0) {
-            fprintf(logfile, "Trying to read invalid spr %d %03x at "
+        qemu_log("Trying to read invalid spr %d %03x at "
                     ADDRX "\n", sprn, sprn, ctx->nip);
-        }
         printf("Trying to read invalid spr %d %03x at " ADDRX "\n",
                sprn, sprn, ctx->nip);
-        GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
-                 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
     }
 }
 
@@ -3931,10 +3950,10 @@ GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     if (ctx->opcode & 0x00010000) {
@@ -3953,7 +3972,7 @@ GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
         gen_helper_store_msr(cpu_gpr[rS(ctx->opcode)]);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
-        ctx->exception = POWERPC_EXCP_STOP;
+        gen_stop_exception(ctx);
     }
 #endif
 }
@@ -3962,10 +3981,10 @@ GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     if (ctx->opcode & 0x00010000) {
@@ -3996,7 +4015,7 @@ GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
             gen_helper_store_msr(cpu_gpr[rS(ctx->opcode)]);
         /* Must stop the translation as machine state (may have) changed */
         /* Note that mtmsr is not always defined as context-synchronizing */
-        ctx->exception = POWERPC_EXCP_STOP;
+        gen_stop_exception(ctx);
     }
 #endif
 }
@@ -4020,24 +4039,19 @@ GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
             (*write_cb)(ctx, sprn, rS(ctx->opcode));
         } else {
             /* Privilege exception */
-            if (loglevel != 0) {
-                fprintf(logfile, "Trying to write privileged spr %d %03x at "
+            qemu_log("Trying to write privileged spr %d %03x at "
                         ADDRX "\n", sprn, sprn, ctx->nip);
-            }
             printf("Trying to write privileged spr %d %03x at " ADDRX "\n",
                    sprn, sprn, ctx->nip);
-            GEN_EXCP_PRIVREG(ctx);
+            gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         }
     } else {
         /* Not defined */
-        if (loglevel != 0) {
-            fprintf(logfile, "Trying to write invalid spr %d %03x at "
+        qemu_log("Trying to write invalid spr %d %03x at "
                     ADDRX "\n", sprn, sprn, ctx->nip);
-        }
         printf("Trying to write invalid spr %d %03x at " ADDRX "\n",
                sprn, sprn, ctx->nip);
-        GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
-                 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
     }
 }
 
@@ -4058,11 +4072,11 @@ GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE)
 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv EA, val;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     EA = tcg_temp_new();
@@ -4135,6 +4149,33 @@ GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT)
     tcg_temp_free(t0);
 }
 
+/* dst / dstt */
+GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC)
+{
+    if (rA(ctx->opcode) == 0) {
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
+    } else {
+        /* interpreted as no-op */
+    }
+}
+
+/* dstst /dststt */
+GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC)
+{
+    if (rA(ctx->opcode) == 0) {
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
+    } else {
+        /* interpreted as no-op */
+    }
+
+}
+
+/* dss / dssall */
+GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC)
+{
+    /* interpreted as no-op */
+}
+
 /* icbi */
 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI)
 {
@@ -4164,11 +4205,11 @@ GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_const_tl(SR(ctx->opcode));
@@ -4181,11 +4222,11 @@ GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_temp_new();
@@ -4200,11 +4241,11 @@ GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_const_tl(SR(ctx->opcode));
@@ -4217,11 +4258,11 @@ GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_temp_new();
@@ -4238,11 +4279,11 @@ GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_const_tl(SR(ctx->opcode));
@@ -4256,11 +4297,11 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
              PPC_SEGMENT_64B)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_temp_new();
@@ -4275,11 +4316,11 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_const_tl(SR(ctx->opcode));
@@ -4293,11 +4334,11 @@ GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
              PPC_SEGMENT_64B)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     t0 = tcg_temp_new();
@@ -4315,10 +4356,10 @@ GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_tlbia();
@@ -4329,10 +4370,10 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -4351,16 +4392,16 @@ GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* This has no effect: it should ensure that all previous
      * tlbie have completed
      */
-    GEN_STOP(ctx);
+    gen_stop_exception(ctx);
 #endif
 }
 
@@ -4369,10 +4410,10 @@ GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_slbia();
@@ -4383,10 +4424,10 @@ GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_slbie(cpu_gpr[rB(ctx->opcode)]);
@@ -5067,24 +5108,24 @@ GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
 {
     /* XXX: TODO */
-    GEN_EXCP_INVAL(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
 }
 
 /* esa */
 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
 {
     /* XXX: TODO */
-    GEN_EXCP_INVAL(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
 }
 
 /* mfrom */
 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
@@ -5096,10 +5137,10 @@ GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_6xx_tlbd(cpu_gpr[rB(ctx->opcode)]);
@@ -5110,10 +5151,10 @@ GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_6xx_tlbi(cpu_gpr[rB(ctx->opcode)]);
@@ -5125,10 +5166,10 @@ GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_74xx_tlbd(cpu_gpr[rB(ctx->opcode)]);
@@ -5139,10 +5180,10 @@ GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB)
 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_74xx_tlbi(cpu_gpr[rB(ctx->opcode)]);
@@ -5161,10 +5202,10 @@ GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
 {
     /* Cache line invalidate: privileged and treated as no-op */
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
 #endif
@@ -5179,13 +5220,13 @@ GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     int ra = rA(ctx->opcode);
     int rd = rD(ctx->opcode);
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     t0 = tcg_temp_new();
@@ -5202,11 +5243,11 @@ GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     t0 = tcg_temp_new();
@@ -5219,14 +5260,14 @@ GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_helper_rfsvc();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
@@ -5372,18 +5413,18 @@ GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI)
 {
     /* XXX: TODO */
-    GEN_EXCP_INVAL(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
 }
 
 /* XXX: not implemented on 440 ? */
 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     t0 = tcg_temp_new();
@@ -5612,11 +5653,11 @@ GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv dcrn;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     /* NIP cannot be restored if the memory exception comes from an helper */
@@ -5631,11 +5672,11 @@ GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR)
 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     TCGv dcrn;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     /* NIP cannot be restored if the memory exception comes from an helper */
@@ -5651,10 +5692,10 @@ GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR)
 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     /* NIP cannot be restored if the memory exception comes from an helper */
@@ -5669,10 +5710,10 @@ GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX)
 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVREG(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVREG(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
         return;
     }
     /* NIP cannot be restored if the memory exception comes from an helper */
@@ -5704,10 +5745,10 @@ GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* interpreted as no-op */
@@ -5718,11 +5759,11 @@ GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv EA, val;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     gen_set_access_type(ctx, ACCESS_CACHE);
@@ -5749,10 +5790,10 @@ GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* interpreted as no-op */
@@ -5763,10 +5804,10 @@ GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* interpreted as no-op */
@@ -5777,30 +5818,30 @@ GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* Restore CPU state */
     gen_helper_40x_rfci();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* Restore CPU state */
     gen_helper_rfci();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
@@ -5809,15 +5850,15 @@ GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* Restore CPU state */
     gen_helper_rfdi();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
@@ -5825,15 +5866,15 @@ GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI)
 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     /* Restore CPU state */
     gen_helper_rfmci();
-    GEN_SYNC(ctx);
+    gen_sync_exception(ctx);
 #endif
 }
 
@@ -5842,10 +5883,10 @@ GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     switch (rB(ctx->opcode)) {
@@ -5856,7 +5897,7 @@ GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
         gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
         break;
     default:
-        GEN_EXCP_INVAL(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         break;
     }
 #endif
@@ -5866,11 +5907,11 @@ GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     t0 = tcg_temp_new();
@@ -5893,10 +5934,10 @@ GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     switch (rB(ctx->opcode)) {
@@ -5907,7 +5948,7 @@ GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
         gen_helper_4xx_tlbwe_lo(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
         break;
     default:
-        GEN_EXCP_INVAL(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         break;
     }
 #endif
@@ -5918,10 +5959,10 @@ GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     switch (rB(ctx->opcode)) {
@@ -5935,7 +5976,7 @@ GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
         }
         break;
     default:
-        GEN_EXCP_INVAL(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         break;
     }
 #endif
@@ -5945,11 +5986,11 @@ GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     t0 = tcg_temp_new();
@@ -5972,10 +6013,10 @@ GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     switch (rB(ctx->opcode)) {
@@ -5989,7 +6030,7 @@ GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
         }
         break;
     default:
-        GEN_EXCP_INVAL(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         break;
     }
 #endif
@@ -5999,11 +6040,11 @@ GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     TCGv t0;
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     t0 = tcg_temp_new();
@@ -6014,7 +6055,7 @@ GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
     /* Stop translation to have a chance to raise an exception
      * if we just set msr_ee to 1
      */
-    GEN_STOP(ctx);
+    gen_stop_exception(ctx);
 #endif
 }
 
@@ -6022,18 +6063,18 @@ GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE)
 {
 #if defined(CONFIG_USER_ONLY)
-    GEN_EXCP_PRIVOPC(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
 #else
     if (unlikely(!ctx->mem_idx)) {
-        GEN_EXCP_PRIVOPC(ctx);
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
         return;
     }
     if (ctx->opcode & 0x00010000) {
         tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
         /* Stop translation to have a chance to raise an exception */
-        GEN_STOP(ctx);
+        gen_stop_exception(ctx);
     } else {
-        tcg_gen_andi_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
+        tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
     }
 #endif
 }
@@ -6049,7 +6090,7 @@ GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
 }
 
 /* mbar replaces eieio on 440 */
-GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
+GEN_HANDLER(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, PPC_BOOKE)
 {
     /* interpreted as no-op */
 }
@@ -6072,12 +6113,19 @@ GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
 /***                      Altivec vector extension                         ***/
 /* Altivec registers moves */
 
+static always_inline TCGv_ptr gen_avr_ptr(int reg)
+{
+    TCGv_ptr r = tcg_temp_new_ptr();
+    tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
+    return r;
+}
+
 #define GEN_VR_LDX(name, opc2, opc3)                                          \
 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)                  \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->altivec_enabled)) {                                    \
-        GEN_EXCP_NO_VR(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_VPU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -6101,7 +6149,7 @@ GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)              \
 {                                                                             \
     TCGv EA;                                                                  \
     if (unlikely(!ctx->altivec_enabled)) {                                    \
-        GEN_EXCP_NO_VR(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_VPU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -6120,14 +6168,419 @@ GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)              \
     tcg_temp_free(EA);                                                        \
 }
 
+#define GEN_VR_LVE(name, opc2, opc3)                                    \
+    GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)   \
+    {                                                                   \
+        TCGv EA;                                                        \
+        TCGv_ptr rs;                                                    \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        gen_set_access_type(ctx, ACCESS_INT);                           \
+        EA = tcg_temp_new();                                            \
+        gen_addr_reg_index(ctx, EA);                                    \
+        rs = gen_avr_ptr(rS(ctx->opcode));                              \
+        gen_helper_lve##name (rs, EA);                                  \
+        tcg_temp_free(EA);                                              \
+        tcg_temp_free_ptr(rs);                                          \
+    }
+
+#define GEN_VR_STVE(name, opc2, opc3)                                   \
+    GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)  \
+    {                                                                   \
+        TCGv EA;                                                        \
+        TCGv_ptr rs;                                                    \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        gen_set_access_type(ctx, ACCESS_INT);                           \
+        EA = tcg_temp_new();                                            \
+        gen_addr_reg_index(ctx, EA);                                    \
+        rs = gen_avr_ptr(rS(ctx->opcode));                              \
+        gen_helper_stve##name (rs, EA);                                 \
+        tcg_temp_free(EA);                                              \
+        tcg_temp_free_ptr(rs);                                          \
+    }
+
 GEN_VR_LDX(lvx, 0x07, 0x03);
 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
 GEN_VR_LDX(lvxl, 0x07, 0x0B);
 
+GEN_VR_LVE(bx, 0x07, 0x00);
+GEN_VR_LVE(hx, 0x07, 0x01);
+GEN_VR_LVE(wx, 0x07, 0x02);
+
 GEN_VR_STX(svx, 0x07, 0x07);
 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
 GEN_VR_STX(svxl, 0x07, 0x0F);
 
+GEN_VR_STVE(bx, 0x07, 0x04);
+GEN_VR_STVE(hx, 0x07, 0x05);
+GEN_VR_STVE(wx, 0x07, 0x06);
+
+GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC)
+{
+    TCGv_ptr rd;
+    TCGv EA;
+    if (unlikely(!ctx->altivec_enabled)) {
+        gen_exception(ctx, POWERPC_EXCP_VPU);
+        return;
+    }
+    EA = tcg_temp_new();
+    gen_addr_reg_index(ctx, EA);
+    rd = gen_avr_ptr(rD(ctx->opcode));
+    gen_helper_lvsl(rd, EA);
+    tcg_temp_free(EA);
+    tcg_temp_free_ptr(rd);
+}
+
+GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC)
+{
+    TCGv_ptr rd;
+    TCGv EA;
+    if (unlikely(!ctx->altivec_enabled)) {
+        gen_exception(ctx, POWERPC_EXCP_VPU);
+        return;
+    }
+    EA = tcg_temp_new();
+    gen_addr_reg_index(ctx, EA);
+    rd = gen_avr_ptr(rD(ctx->opcode));
+    gen_helper_lvsr(rd, EA);
+    tcg_temp_free(EA);
+    tcg_temp_free_ptr(rd);
+}
+
+GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC)
+{
+    TCGv_i32 t;
+    if (unlikely(!ctx->altivec_enabled)) {
+        gen_exception(ctx, POWERPC_EXCP_VPU);
+        return;
+    }
+    tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
+    t = tcg_temp_new_i32();
+    tcg_gen_ld_i32(t, cpu_env, offsetof(CPUState, vscr));
+    tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
+    tcg_temp_free_i32(t);
+}
+
+GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC)
+{
+    TCGv_ptr p;
+    if (unlikely(!ctx->altivec_enabled)) {
+        gen_exception(ctx, POWERPC_EXCP_VPU);
+        return;
+    }
+    p = gen_avr_ptr(rD(ctx->opcode));
+    gen_helper_mtvscr(p);
+    tcg_temp_free_ptr(p);
+}
+
+/* Logical operations */
+#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3)                        \
+GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)            \
+{                                                                       \
+    if (unlikely(!ctx->altivec_enabled)) {                              \
+        gen_exception(ctx, POWERPC_EXCP_VPU);                           \
+        return;                                                         \
+    }                                                                   \
+    tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
+    tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
+}
+
+GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
+GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
+GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
+GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
+GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
+
+#define GEN_VXFORM(name, opc2, opc3)                                    \
+GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)            \
+{                                                                       \
+    TCGv_ptr ra, rb, rd;                                                \
+    if (unlikely(!ctx->altivec_enabled)) {                              \
+        gen_exception(ctx, POWERPC_EXCP_VPU);                           \
+        return;                                                         \
+    }                                                                   \
+    ra = gen_avr_ptr(rA(ctx->opcode));                                  \
+    rb = gen_avr_ptr(rB(ctx->opcode));                                  \
+    rd = gen_avr_ptr(rD(ctx->opcode));                                  \
+    gen_helper_##name (rd, ra, rb);                                     \
+    tcg_temp_free_ptr(ra);                                              \
+    tcg_temp_free_ptr(rb);                                              \
+    tcg_temp_free_ptr(rd);                                              \
+}
+
+GEN_VXFORM(vaddubm, 0, 0);
+GEN_VXFORM(vadduhm, 0, 1);
+GEN_VXFORM(vadduwm, 0, 2);
+GEN_VXFORM(vsububm, 0, 16);
+GEN_VXFORM(vsubuhm, 0, 17);
+GEN_VXFORM(vsubuwm, 0, 18);
+GEN_VXFORM(vmaxub, 1, 0);
+GEN_VXFORM(vmaxuh, 1, 1);
+GEN_VXFORM(vmaxuw, 1, 2);
+GEN_VXFORM(vmaxsb, 1, 4);
+GEN_VXFORM(vmaxsh, 1, 5);
+GEN_VXFORM(vmaxsw, 1, 6);
+GEN_VXFORM(vminub, 1, 8);
+GEN_VXFORM(vminuh, 1, 9);
+GEN_VXFORM(vminuw, 1, 10);
+GEN_VXFORM(vminsb, 1, 12);
+GEN_VXFORM(vminsh, 1, 13);
+GEN_VXFORM(vminsw, 1, 14);
+GEN_VXFORM(vavgub, 1, 16);
+GEN_VXFORM(vavguh, 1, 17);
+GEN_VXFORM(vavguw, 1, 18);
+GEN_VXFORM(vavgsb, 1, 20);
+GEN_VXFORM(vavgsh, 1, 21);
+GEN_VXFORM(vavgsw, 1, 22);
+GEN_VXFORM(vmrghb, 6, 0);
+GEN_VXFORM(vmrghh, 6, 1);
+GEN_VXFORM(vmrghw, 6, 2);
+GEN_VXFORM(vmrglb, 6, 4);
+GEN_VXFORM(vmrglh, 6, 5);
+GEN_VXFORM(vmrglw, 6, 6);
+GEN_VXFORM(vmuloub, 4, 0);
+GEN_VXFORM(vmulouh, 4, 1);
+GEN_VXFORM(vmulosb, 4, 4);
+GEN_VXFORM(vmulosh, 4, 5);
+GEN_VXFORM(vmuleub, 4, 8);
+GEN_VXFORM(vmuleuh, 4, 9);
+GEN_VXFORM(vmulesb, 4, 12);
+GEN_VXFORM(vmulesh, 4, 13);
+GEN_VXFORM(vslb, 2, 4);
+GEN_VXFORM(vslh, 2, 5);
+GEN_VXFORM(vslw, 2, 6);
+GEN_VXFORM(vsrb, 2, 8);
+GEN_VXFORM(vsrh, 2, 9);
+GEN_VXFORM(vsrw, 2, 10);
+GEN_VXFORM(vsrab, 2, 12);
+GEN_VXFORM(vsrah, 2, 13);
+GEN_VXFORM(vsraw, 2, 14);
+GEN_VXFORM(vslo, 6, 16);
+GEN_VXFORM(vsro, 6, 17);
+GEN_VXFORM(vaddcuw, 0, 6);
+GEN_VXFORM(vsubcuw, 0, 22);
+GEN_VXFORM(vaddubs, 0, 8);
+GEN_VXFORM(vadduhs, 0, 9);
+GEN_VXFORM(vadduws, 0, 10);
+GEN_VXFORM(vaddsbs, 0, 12);
+GEN_VXFORM(vaddshs, 0, 13);
+GEN_VXFORM(vaddsws, 0, 14);
+GEN_VXFORM(vsububs, 0, 24);
+GEN_VXFORM(vsubuhs, 0, 25);
+GEN_VXFORM(vsubuws, 0, 26);
+GEN_VXFORM(vsubsbs, 0, 28);
+GEN_VXFORM(vsubshs, 0, 29);
+GEN_VXFORM(vsubsws, 0, 30);
+GEN_VXFORM(vrlb, 2, 0);
+GEN_VXFORM(vrlh, 2, 1);
+GEN_VXFORM(vrlw, 2, 2);
+GEN_VXFORM(vsl, 2, 7);
+GEN_VXFORM(vsr, 2, 11);
+GEN_VXFORM(vpkuhum, 7, 0);
+GEN_VXFORM(vpkuwum, 7, 1);
+GEN_VXFORM(vpkuhus, 7, 2);
+GEN_VXFORM(vpkuwus, 7, 3);
+GEN_VXFORM(vpkshus, 7, 4);
+GEN_VXFORM(vpkswus, 7, 5);
+GEN_VXFORM(vpkshss, 7, 6);
+GEN_VXFORM(vpkswss, 7, 7);
+GEN_VXFORM(vpkpx, 7, 12);
+GEN_VXFORM(vsum4ubs, 4, 24);
+GEN_VXFORM(vsum4sbs, 4, 28);
+GEN_VXFORM(vsum4shs, 4, 25);
+GEN_VXFORM(vsum2sws, 4, 26);
+GEN_VXFORM(vsumsws, 4, 30);
+
+#define GEN_VXRFORM1(opname, name, str, opc2, opc3)                     \
+    GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC)   \
+    {                                                                   \
+        TCGv_ptr ra, rb, rd;                                            \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        ra = gen_avr_ptr(rA(ctx->opcode));                              \
+        rb = gen_avr_ptr(rB(ctx->opcode));                              \
+        rd = gen_avr_ptr(rD(ctx->opcode));                              \
+        gen_helper_##opname (rd, ra, rb);                               \
+        tcg_temp_free_ptr(ra);                                          \
+        tcg_temp_free_ptr(rb);                                          \
+        tcg_temp_free_ptr(rd);                                          \
+    }
+
+#define GEN_VXRFORM(name, opc2, opc3)                                \
+    GEN_VXRFORM1(name, name, #name, opc2, opc3)                      \
+    GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
+
+GEN_VXRFORM(vcmpequb, 3, 0)
+GEN_VXRFORM(vcmpequh, 3, 1)
+GEN_VXRFORM(vcmpequw, 3, 2)
+GEN_VXRFORM(vcmpgtsb, 3, 12)
+GEN_VXRFORM(vcmpgtsh, 3, 13)
+GEN_VXRFORM(vcmpgtsw, 3, 14)
+GEN_VXRFORM(vcmpgtub, 3, 8)
+GEN_VXRFORM(vcmpgtuh, 3, 9)
+GEN_VXRFORM(vcmpgtuw, 3, 10)
+
+#define GEN_VXFORM_SIMM(name, opc2, opc3)                               \
+    GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)        \
+    {                                                                   \
+        TCGv_ptr rd;                                                    \
+        TCGv_i32 simm;                                                  \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        simm = tcg_const_i32(SIMM5(ctx->opcode));                       \
+        rd = gen_avr_ptr(rD(ctx->opcode));                              \
+        gen_helper_##name (rd, simm);                                   \
+        tcg_temp_free_i32(simm);                                        \
+        tcg_temp_free_ptr(rd);                                          \
+    }
+
+GEN_VXFORM_SIMM(vspltisb, 6, 12);
+GEN_VXFORM_SIMM(vspltish, 6, 13);
+GEN_VXFORM_SIMM(vspltisw, 6, 14);
+
+#define GEN_VXFORM_NOA(name, opc2, opc3)                                \
+    GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)        \
+    {                                                                   \
+        TCGv_ptr rb, rd;                                                \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        rb = gen_avr_ptr(rB(ctx->opcode));                              \
+        rd = gen_avr_ptr(rD(ctx->opcode));                              \
+        gen_helper_##name (rd, rb);                                     \
+        tcg_temp_free_ptr(rb);                                          \
+        tcg_temp_free_ptr(rd);                                         \
+    }
+
+GEN_VXFORM_NOA(vupkhsb, 7, 8);
+GEN_VXFORM_NOA(vupkhsh, 7, 9);
+GEN_VXFORM_NOA(vupklsb, 7, 10);
+GEN_VXFORM_NOA(vupklsh, 7, 11);
+GEN_VXFORM_NOA(vupkhpx, 7, 13);
+GEN_VXFORM_NOA(vupklpx, 7, 15);
+GEN_VXFORM_NOA(vlogefp, 5, 7);
+GEN_VXFORM_NOA(vrfim, 5, 8);
+GEN_VXFORM_NOA(vrfin, 5, 9);
+GEN_VXFORM_NOA(vrfip, 5, 10);
+GEN_VXFORM_NOA(vrfiz, 5, 11);
+
+#define GEN_VXFORM_SIMM(name, opc2, opc3)                               \
+    GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)        \
+    {                                                                   \
+        TCGv_ptr rd;                                                    \
+        TCGv_i32 simm;                                                  \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        simm = tcg_const_i32(SIMM5(ctx->opcode));                       \
+        rd = gen_avr_ptr(rD(ctx->opcode));                              \
+        gen_helper_##name (rd, simm);                                   \
+        tcg_temp_free_i32(simm);                                        \
+        tcg_temp_free_ptr(rd);                                          \
+    }
+
+#define GEN_VXFORM_UIMM(name, opc2, opc3)                               \
+    GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)        \
+    {                                                                   \
+        TCGv_ptr rb, rd;                                                \
+        TCGv_i32 uimm;                                                  \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        uimm = tcg_const_i32(UIMM5(ctx->opcode));                       \
+        rb = gen_avr_ptr(rB(ctx->opcode));                              \
+        rd = gen_avr_ptr(rD(ctx->opcode));                              \
+        gen_helper_##name (rd, rb, uimm);                               \
+        tcg_temp_free_i32(uimm);                                        \
+        tcg_temp_free_ptr(rb);                                          \
+        tcg_temp_free_ptr(rd);                                          \
+    }
+
+GEN_VXFORM_UIMM(vspltb, 6, 8);
+GEN_VXFORM_UIMM(vsplth, 6, 9);
+GEN_VXFORM_UIMM(vspltw, 6, 10);
+GEN_VXFORM_UIMM(vcfux, 5, 12);
+GEN_VXFORM_UIMM(vcfsx, 5, 13);
+
+GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC)
+{
+    TCGv_ptr ra, rb, rd;
+    TCGv_i32 sh;
+    if (unlikely(!ctx->altivec_enabled)) {
+        gen_exception(ctx, POWERPC_EXCP_VPU);
+        return;
+    }
+    ra = gen_avr_ptr(rA(ctx->opcode));
+    rb = gen_avr_ptr(rB(ctx->opcode));
+    rd = gen_avr_ptr(rD(ctx->opcode));
+    sh = tcg_const_i32(VSH(ctx->opcode));
+    gen_helper_vsldoi (rd, ra, rb, sh);
+    tcg_temp_free_ptr(ra);
+    tcg_temp_free_ptr(rb);
+    tcg_temp_free_ptr(rd);
+    tcg_temp_free_i32(sh);
+}
+
+#define GEN_VAFORM_PAIRED(name0, name1, opc2)                           \
+    GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) \
+    {                                                                   \
+        TCGv_ptr ra, rb, rc, rd;                                        \
+        if (unlikely(!ctx->altivec_enabled)) {                          \
+            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
+            return;                                                     \
+        }                                                               \
+        ra = gen_avr_ptr(rA(ctx->opcode));                              \
+        rb = gen_avr_ptr(rB(ctx->opcode));                              \
+        rc = gen_avr_ptr(rC(ctx->opcode));                              \
+        rd = gen_avr_ptr(rD(ctx->opcode));                              \
+        if (Rc(ctx->opcode)) {                                          \
+            gen_helper_##name1 (rd, ra, rb, rc);                        \
+        } else {                                                        \
+            gen_helper_##name0 (rd, ra, rb, rc);                        \
+        }                                                               \
+        tcg_temp_free_ptr(ra);                                          \
+        tcg_temp_free_ptr(rb);                                          \
+        tcg_temp_free_ptr(rc);                                          \
+        tcg_temp_free_ptr(rd);                                          \
+    }
+
+GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
+
+GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC)
+{
+    TCGv_ptr ra, rb, rc, rd;
+    if (unlikely(!ctx->altivec_enabled)) {
+        gen_exception(ctx, POWERPC_EXCP_VPU);
+        return;
+    }
+    ra = gen_avr_ptr(rA(ctx->opcode));
+    rb = gen_avr_ptr(rB(ctx->opcode));
+    rc = gen_avr_ptr(rC(ctx->opcode));
+    rd = gen_avr_ptr(rD(ctx->opcode));
+    gen_helper_vmladduhm(rd, ra, rb, rc);
+    tcg_temp_free_ptr(ra);
+    tcg_temp_free_ptr(rb);
+    tcg_temp_free_ptr(rc);
+    tcg_temp_free_ptr(rd);
+}
+
+GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
+GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
+GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
+GEN_VAFORM_PAIRED(vsel, vperm, 21)
+
 /***                           SPE extension                               ***/
 /* Register moves */
 
@@ -6163,7 +6616,7 @@ GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type)                   \
 /* Handler for undefined SPE opcodes */
 static always_inline void gen_speundef (DisasContext *ctx)
 {
-    GEN_EXCP_INVAL(ctx);
+    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
 }
 
 /* SPE logic */
@@ -6172,7 +6625,7 @@ static always_inline void gen_speundef (DisasContext *ctx)
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],                \
@@ -6183,7 +6636,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],                \
@@ -6208,7 +6661,7 @@ GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
@@ -6229,7 +6682,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],               \
@@ -6249,7 +6702,7 @@ GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
@@ -6270,7 +6723,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);               \
@@ -6308,13 +6761,13 @@ GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
     TCGv_i32 t1 = tcg_temp_local_new_i32();                                   \
     TCGv_i32 t2 = tcg_temp_local_new_i32();                                   \
-    TCGv_i64 t3 = tcg_temp_local_new(TCG_TYPE_I64);                           \
+    TCGv_i64 t3 = tcg_temp_local_new_i64();                                   \
     tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]);                      \
     tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]);                      \
     tcg_op(t0, t0, t2);                                                       \
@@ -6334,7 +6787,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],                \
@@ -6412,7 +6865,7 @@ GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
 static always_inline void gen_evmergehi (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -6441,7 +6894,7 @@ GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
@@ -6451,7 +6904,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
     tcg_op(t0, t0, rA(ctx->opcode));                                          \
     tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32);                       \
     tcg_gen_trunc_i64_i32(t1, t2);                                            \
-    tcg_temp_free_i64(t2);                                                        \
+    tcg_temp_free_i64(t2);                                                    \
     tcg_op(t1, t1, rA(ctx->opcode));                                          \
     tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);                 \
     tcg_temp_free_i32(t0);                                                    \
@@ -6462,7 +6915,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],                \
@@ -6480,7 +6933,7 @@ GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     int l1 = gen_new_label();                                                 \
@@ -6520,7 +6973,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     int l1 = gen_new_label();                                                 \
@@ -6563,7 +7016,7 @@ static always_inline void gen_brinc (DisasContext *ctx)
 static always_inline void gen_evmergelo (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -6582,7 +7035,7 @@ static always_inline void gen_evmergelo (DisasContext *ctx)
 static always_inline void gen_evmergehilo (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -6601,7 +7054,7 @@ static always_inline void gen_evmergehilo (DisasContext *ctx)
 static always_inline void gen_evmergelohi (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7052,7 +7505,7 @@ GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)                      \
 {                                                                             \
     TCGv t0;                                                                  \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     gen_set_access_type(ctx, ACCESS_INT);                                     \
@@ -7214,7 +7667,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
     TCGv_i32 t0, t1;                                                          \
     TCGv_i64 t2;                                                              \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     t0 = tcg_temp_new_i32();                                                  \
@@ -7235,7 +7688,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],     \
@@ -7246,7 +7699,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     TCGv_i32 t0, t1;                                                          \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     t0 = tcg_temp_new_i32();                                                  \
@@ -7261,7 +7714,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     gen_helper_##name(cpu_crf[crfD(ctx->opcode)],                             \
@@ -7302,7 +7755,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     gen_helper_##name(cpu_gpr[rD(ctx->opcode)],                               \
@@ -7313,7 +7766,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     TCGv_i64 t0, t1;                                                          \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     t0 = tcg_temp_new_i64();                                                  \
@@ -7329,7 +7782,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     gen_helper_##name(cpu_crf[crfD(ctx->opcode)],                             \
@@ -7340,7 +7793,7 @@ static always_inline void gen_##name (DisasContext *ctx)                      \
 {                                                                             \
     TCGv_i64 t0, t1;                                                          \
     if (unlikely(!ctx->spe_enabled)) {                                        \
-        GEN_EXCP_NO_AP(ctx);                                                  \
+        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
         return;                                                               \
     }                                                                         \
     t0 = tcg_temp_new_i64();                                                  \
@@ -7362,7 +7815,7 @@ GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
 static always_inline void gen_evfsabs (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7375,7 +7828,7 @@ static always_inline void gen_evfsabs (DisasContext *ctx)
 static always_inline void gen_evfsnabs (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7388,7 +7841,7 @@ static always_inline void gen_evfsnabs (DisasContext *ctx)
 static always_inline void gen_evfsneg (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7444,7 +7897,7 @@ GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
 static always_inline void gen_efsabs (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
     tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
@@ -7452,7 +7905,7 @@ static always_inline void gen_efsabs (DisasContext *ctx)
 static always_inline void gen_efsnabs (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
     tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
@@ -7460,7 +7913,7 @@ static always_inline void gen_efsnabs (DisasContext *ctx)
 static always_inline void gen_efsneg (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
     tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
@@ -7512,7 +7965,7 @@ GEN_SPEFPUOP_ARITH2_64_64(efddiv);
 static always_inline void gen_efdabs (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7524,7 +7977,7 @@ static always_inline void gen_efdabs (DisasContext *ctx)
 static always_inline void gen_efdnabs (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7536,7 +7989,7 @@ static always_inline void gen_efdnabs (DisasContext *ctx)
 static always_inline void gen_efdneg (DisasContext *ctx)
 {
     if (unlikely(!ctx->spe_enabled)) {
-        GEN_EXCP_NO_AP(ctx);
+        gen_exception(ctx, POWERPC_EXCP_APU);
         return;
     }
 #if defined(TARGET_PPC64)
@@ -7651,6 +8104,7 @@ void cpu_dump_state (CPUState *env, FILE *f,
         if ((i & (RFPL - 1)) == (RFPL - 1))
             cpu_fprintf(f, "\n");
     }
+    cpu_fprintf(f, "FPSCR %08x\n", env->fpscr);
 #if !defined(CONFIG_USER_ONLY)
     cpu_fprintf(f, "SRR0 " ADDRX " SRR1 " ADDRX " SDR1 " ADDRX "\n",
                 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
@@ -7723,9 +8177,6 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
 
     pc_start = tb->pc;
     gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
-#if defined(OPTIMIZE_FPRF_UPDATE)
-    gen_fprf_ptr = gen_fprf_buf;
-#endif
     ctx.nip = pc_start;
     ctx.tb = tb;
     ctx.exception = POWERPC_EXCP_NONE;
@@ -7768,8 +8219,7 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
         if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
             TAILQ_FOREACH(bp, &env->breakpoints, entry) {
                 if (bp->pc == ctx.nip) {
-                    gen_update_nip(&ctx, ctx.nip);
-                    gen_helper_raise_debug();
+                    gen_debug_exception(ctxp);
                     break;
                 }
             }
@@ -7785,13 +8235,9 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
                 gen_opc_icount[lj] = num_insns;
             }
         }
-#if defined PPC_DEBUG_DISAS
-        if (loglevel & CPU_LOG_TB_IN_ASM) {
-            fprintf(logfile, "----------------\n");
-            fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
-                    ctx.nip, ctx.mem_idx, (int)msr_ir);
-        }
-#endif
+        LOG_DISAS("----------------\n");
+        LOG_DISAS("nip=" ADDRX " super=%d ir=%d\n",
+                  ctx.nip, ctx.mem_idx, (int)msr_ir);
         if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
             gen_io_start();
         if (unlikely(ctx.le_mode)) {
@@ -7799,13 +8245,9 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
         } else {
             ctx.opcode = ldl_code(ctx.nip);
         }
-#if defined PPC_DEBUG_DISAS
-        if (loglevel & CPU_LOG_TB_IN_ASM) {
-            fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
+        LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
                     ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
                     opc3(ctx.opcode), little_endian ? "little" : "big");
-        }
-#endif
         ctx.nip += 4;
         table = env->opcodes;
         num_insns++;
@@ -7820,11 +8262,11 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
         }
         /* Is opcode *REALLY* valid ? */
         if (unlikely(handler->handler == &gen_invalid)) {
-            if (loglevel != 0) {
-                fprintf(logfile, "invalid/unsupported opcode: "
-                        "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
-                        opc1(ctx.opcode), opc2(ctx.opcode),
-                        opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
+            if (qemu_log_enabled()) {
+                qemu_log("invalid/unsupported opcode: "
+                          "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
+                          opc1(ctx.opcode), opc2(ctx.opcode),
+                          opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
             } else {
                 printf("invalid/unsupported opcode: "
                        "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
@@ -7833,12 +8275,12 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
             }
         } else {
             if (unlikely((ctx.opcode & handler->inval) != 0)) {
-                if (loglevel != 0) {
-                    fprintf(logfile, "invalid bits: %08x for opcode: "
-                            "%02x - %02x - %02x (%08x) " ADDRX "\n",
-                            ctx.opcode & handler->inval, opc1(ctx.opcode),
-                            opc2(ctx.opcode), opc3(ctx.opcode),
-                            ctx.opcode, ctx.nip - 4);
+                if (qemu_log_enabled()) {
+                    qemu_log("invalid bits: %08x for opcode: "
+                              "%02x - %02x - %02x (%08x) " ADDRX "\n",
+                              ctx.opcode & handler->inval, opc1(ctx.opcode),
+                              opc2(ctx.opcode), opc3(ctx.opcode),
+                              ctx.opcode, ctx.nip - 4);
                 } else {
                     printf("invalid bits: %08x for opcode: "
                            "%02x - %02x - %02x (%08x) " ADDRX "\n",
@@ -7846,7 +8288,7 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
                            opc2(ctx.opcode), opc3(ctx.opcode),
                            ctx.opcode, ctx.nip - 4);
                 }
-                GEN_EXCP_INVAL(ctxp);
+                gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
                 break;
             }
         }
@@ -7860,7 +8302,7 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
                      ctx.exception != POWERPC_SYSCALL &&
                      ctx.exception != POWERPC_EXCP_TRAP &&
                      ctx.exception != POWERPC_EXCP_BRANCH)) {
-            GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
+            gen_exception(ctxp, POWERPC_EXCP_TRACE);
         } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
                             (env->singlestep_enabled) ||
                             num_insns >= max_insns)) {
@@ -7879,8 +8321,7 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
         gen_goto_tb(&ctx, 0, ctx.nip);
     } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
         if (unlikely(env->singlestep_enabled)) {
-            gen_update_nip(&ctx, ctx.nip);
-            gen_helper_raise_debug();
+            gen_debug_exception(ctxp);
         }
         /* Generate the return instruction */
         tcg_gen_exit_tb(0);
@@ -7897,17 +8338,15 @@ static always_inline void gen_intermediate_code_internal (CPUState *env,
         tb->icount = num_insns;
     }
 #if defined(DEBUG_DISAS)
-    if (loglevel & CPU_LOG_TB_CPU) {
-        fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
-        cpu_dump_state(env, logfile, fprintf, 0);
-    }
-    if (loglevel & CPU_LOG_TB_IN_ASM) {
+    qemu_log_mask(CPU_LOG_TB_CPU, "---------------- excp: %04x\n", ctx.exception);
+    log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
+    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         int flags;
         flags = env->bfd_mach;
         flags |= ctx.le_mode << 16;
-        fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
-        target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
-        fprintf(logfile, "\n");
+        qemu_log("IN: %s\n", lookup_symbol(pc_start));
+        log_target_disas(pc_start, ctx.nip - pc_start, flags);
+        qemu_log("\n");
     }
 #endif
 }
This page took 0.119164 seconds and 4 git commands to generate.