]> Git Repo - qemu.git/blobdiff - target-mips/translate.c
Restart interrupts after an exception.
[qemu.git] / target-mips / translate.c
index 9ed30a7996a6ed88b3e9dda68935fc8bdf22b6d4..b0cc3e71740a6d3f67731588884fcd91dc07f76c 100644 (file)
@@ -305,7 +305,7 @@ enum {
 };
 
 /* MFMC0 opcodes */
-#define MASK_MFMC0(op)     MASK_CP0(op) | (op & ((0x0C << 11) | (1 << 5)))
+#define MASK_MFMC0(op)     MASK_CP0(op) | (op & 0xFFFF)
 
 enum {
     OPC_DI       = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
@@ -358,7 +358,44 @@ enum {
 #define MASK_CP1_FUNC(op)       MASK_CP1(op) | (op & 0x3F)
 
 #define MASK_CP2(op)       MASK_OP_MAJOR(op) | (op & (0x1F << 21))
-#define MASK_CP3(op)       MASK_OP_MAJOR(op) | (op & (0x1F << 21))
+
+enum {
+    OPC_MFC2    = (0x00 << 21) | OPC_CP2,
+    OPC_DMFC2   = (0x01 << 21) | OPC_CP2,
+    OPC_CFC2    = (0x02 << 21) | OPC_CP2,
+    OPC_MFHC2   = (0x03 << 21) | OPC_CP2,
+    OPC_MTC2    = (0x04 << 21) | OPC_CP2,
+    OPC_DMTC2   = (0x05 << 21) | OPC_CP2,
+    OPC_CTC2    = (0x06 << 21) | OPC_CP2,
+    OPC_MTHC2   = (0x07 << 21) | OPC_CP2,
+    OPC_BC2     = (0x08 << 21) | OPC_CP2,
+};
+
+#define MASK_CP3(op)       MASK_OP_MAJOR(op) | (op & 0x3F)
+
+enum {
+    OPC_LWXC1   = 0x00 | OPC_CP3,
+    OPC_LDXC1   = 0x01 | OPC_CP3,
+    OPC_LUXC1   = 0x05 | OPC_CP3,
+    OPC_SWXC1   = 0x08 | OPC_CP3,
+    OPC_SDXC1   = 0x09 | OPC_CP3,
+    OPC_SUXC1   = 0x0D | OPC_CP3,
+    OPC_PREFX   = 0x0F | OPC_CP3,
+    OPC_ALNV_PS = 0x1E | OPC_CP3,
+    OPC_MADD_S  = 0x20 | OPC_CP3,
+    OPC_MADD_D  = 0x21 | OPC_CP3,
+    OPC_MADD_PS = 0x26 | OPC_CP3,
+    OPC_MSUB_S  = 0x28 | OPC_CP3,
+    OPC_MSUB_D  = 0x29 | OPC_CP3,
+    OPC_MSUB_PS = 0x2E | OPC_CP3,
+    OPC_NMADD_S = 0x30 | OPC_CP3,
+    OPC_NMADD_D = 0x32 | OPC_CP3,
+    OPC_NMADD_PS= 0x36 | OPC_CP3,
+    OPC_NMSUB_S = 0x38 | OPC_CP3,
+    OPC_NMSUB_D = 0x39 | OPC_CP3,
+    OPC_NMSUB_PS= 0x3E | OPC_CP3,
+};
+
 
 const unsigned char *regnames[] =
     { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
@@ -677,6 +714,7 @@ static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
         opn = "sd";
         break;
     case OPC_SCD:
+        save_cpu_state(ctx, 1);
         GEN_LOAD_REG_TN(T1, rt);
         op_ldst(scd);
         opn = "scd";
@@ -775,6 +813,7 @@ static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
         opn = "ll";
         break;
     case OPC_SC:
+        save_cpu_state(ctx, 1);
         GEN_LOAD_REG_TN(T1, rt);
         op_ldst(sc);
         GEN_STORE_TN_REG(rt, T0);
@@ -849,18 +888,43 @@ static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
         MIPS_DEBUG("NOP");
         return;
     }
-    if (opc == OPC_ADDI || opc == OPC_ADDIU ||
-        opc == OPC_DADDI || opc == OPC_DADDIU ||
-        opc == OPC_SLTI || opc == OPC_SLTIU)
+    uimm = (uint16_t)imm;
+    switch (opc) {
+    case OPC_ADDI:
+    case OPC_ADDIU:
+#ifdef TARGET_MIPS64
+    case OPC_DADDI:
+    case OPC_DADDIU:
+#endif
+    case OPC_SLTI:
+    case OPC_SLTIU:
         uimm = (int32_t)imm; /* Sign extend to 32 bits */
-    else
-        uimm = (uint16_t)imm;
-    if (opc != OPC_LUI) {
+        /* Fall through. */
+    case OPC_ANDI:
+    case OPC_ORI:
+    case OPC_XORI:
         GEN_LOAD_REG_TN(T0, rs);
         GEN_LOAD_IMM_TN(T1, uimm);
-    } else {
-        uimm = uimm << 16;
+        break;
+    case OPC_LUI:
+        uimm <<= 16;
         GEN_LOAD_IMM_TN(T0, uimm);
+        break;
+    case OPC_SLL:
+    case OPC_SRA:
+    case OPC_SRL:
+#ifdef TARGET_MIPS64
+    case OPC_DSLL:
+    case OPC_DSRA:
+    case OPC_DSRL:
+    case OPC_DSLL32:
+    case OPC_DSRA32:
+    case OPC_DSRL32:
+#endif
+        uimm &= 0x1f;
+        GEN_LOAD_REG_TN(T0, rs);
+        GEN_LOAD_IMM_TN(T1, uimm);
+        break;
     }
     switch (opc) {
     case OPC_ADDI:
@@ -915,13 +979,20 @@ static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
         opn = "sra";
         break;
     case OPC_SRL:
-       if ((ctx->opcode >> 21) & 1) {
-            gen_op_rotr();
-            opn = "rotr";
-       } else {
+        switch ((ctx->opcode >> 21) & 0x1f) {
+        case 0:
             gen_op_srl();
             opn = "srl";
-       }
+            break;
+        case 1:
+            gen_op_rotr();
+            opn = "rotr";
+            break;
+        default:
+            MIPS_INVAL("invalid srl flag");
+            generate_exception(ctx, EXCP_RI);
+            break;
+        }
         break;
 #ifdef TARGET_MIPS64
     case OPC_DSLL:
@@ -933,13 +1004,20 @@ static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
         opn = "dsra";
         break;
     case OPC_DSRL:
-       if ((ctx->opcode >> 21) & 1) {
-            gen_op_drotr();
-            opn = "drotr";
-       } else {
+        switch ((ctx->opcode >> 21) & 0x1f) {
+        case 0:
             gen_op_dsrl();
             opn = "dsrl";
-       }
+            break;
+        case 1:
+            gen_op_drotr();
+            opn = "drotr";
+            break;
+        default:
+            MIPS_INVAL("invalid dsrl flag");
+            generate_exception(ctx, EXCP_RI);
+            break;
+        }
         break;
     case OPC_DSLL32:
         gen_op_dsll32();
@@ -950,13 +1028,20 @@ static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
         opn = "dsra32";
         break;
     case OPC_DSRL32:
-       if ((ctx->opcode >> 21) & 1) {
-            gen_op_drotr32();
-            opn = "drotr32";
-       } else {
+        switch ((ctx->opcode >> 21) & 0x1f) {
+        case 0:
             gen_op_dsrl32();
             opn = "dsrl32";
-       }
+            break;
+        case 1:
+            gen_op_drotr32();
+            opn = "drotr32";
+            break;
+        default:
+            MIPS_INVAL("invalid dsrl32 flag");
+            generate_exception(ctx, EXCP_RI);
+            break;
+        }
         break;
 #endif
     default:
@@ -1068,13 +1153,20 @@ static void gen_arith (DisasContext *ctx, uint32_t opc,
         opn = "srav";
         break;
     case OPC_SRLV:
-       if ((ctx->opcode >> 6) & 1) {
-            gen_op_rotrv();
-            opn = "rotrv";
-       } else {
+        switch ((ctx->opcode >> 6) & 0x1f) {
+        case 0:
             gen_op_srlv();
             opn = "srlv";
-       }
+            break;
+        case 1:
+            gen_op_rotrv();
+            opn = "rotrv";
+            break;
+        default:
+            MIPS_INVAL("invalid srlv flag");
+            generate_exception(ctx, EXCP_RI);
+            break;
+        }
         break;
 #ifdef TARGET_MIPS64
     case OPC_DSLLV:
@@ -1086,13 +1178,20 @@ static void gen_arith (DisasContext *ctx, uint32_t opc,
         opn = "dsrav";
         break;
     case OPC_DSRLV:
-       if ((ctx->opcode >> 6) & 1) {
-            gen_op_drotrv();
-            opn = "drotrv";
-       } else {
+        switch ((ctx->opcode >> 6) & 0x1f) {
+        case 0:
             gen_op_dsrlv();
             opn = "dsrlv";
-       }
+            break;
+        case 1:
+            gen_op_drotrv();
+            opn = "drotrv";
+            break;
+        default:
+            MIPS_INVAL("invalid dsrlv flag");
+            generate_exception(ctx, EXCP_RI);
+            break;
+        }
         break;
 #endif
     default:
@@ -1426,7 +1525,7 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
         /* Jump to register */
         if (offset != 0 && offset != 16) {
             /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
-              others are reserved. */
+               others are reserved. */
             generate_exception(ctx, EXCP_RI);
             return;
         }
@@ -1470,14 +1569,14 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
         case OPC_BLTZALL: /* 0 < 0 likely */
             gen_op_set_T0(ctx->pc + 8);
             gen_op_store_T0_gpr(31);
-            gen_goto_tb(ctx, 0, ctx->pc + 4);
+            gen_goto_tb(ctx, 0, ctx->pc + 8);
             return;
         case OPC_BNEL:    /* rx != rx likely */
         case OPC_BGTZL:   /* 0 > 0 likely */
         case OPC_BLTZL:   /* 0 < 0 likely */
             /* Skip the instruction in the delay slot */
             MIPS_DEBUG("bnever and skip");
-            gen_goto_tb(ctx, 0, ctx->pc + 4);
+            gen_goto_tb(ctx, 0, ctx->pc + 8);
             return;
         case OPC_J:
             ctx->hflags |= MIPS_HFLAG_B;
@@ -1580,6 +1679,10 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
         likely:
             ctx->hflags |= MIPS_HFLAG_BL;
             break;
+        default:
+            MIPS_INVAL("conditional branch/jump");
+            generate_exception(ctx, EXCP_RI);
+            return;
         }
         gen_op_set_bcond();
     }
@@ -1590,7 +1693,6 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
         gen_op_set_T0(ctx->pc + 8);
         gen_op_store_T0_gpr(blink);
     }
-    return;
 }
 
 /* special3 bitfield operations */
@@ -1659,21 +1761,21 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 0:
         switch (sel) {
         case 0:
-           gen_op_mfc0_index();
+            gen_op_mfc0_index();
             rn = "Index";
             break;
         case 1:
-//         gen_op_mfc0_mvpcontrol(); /* MT ASE */
+//            gen_op_mfc0_mvpcontrol(); /* MT ASE */
             rn = "MVPControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_mfc0_mvpconf0(); /* MT ASE */
+//            gen_op_mfc0_mvpconf0(); /* MT ASE */
             rn = "MVPConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_mfc0_mvpconf1(); /* MT ASE */
+//            gen_op_mfc0_mvpconf1(); /* MT ASE */
             rn = "MVPConf1";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -1683,35 +1785,35 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
         case 0:
             gen_op_mfc0_random();
             rn = "Random";
-           break;
+            break;
         case 1:
-//         gen_op_mfc0_vpecontrol(); /* MT ASE */
+//            gen_op_mfc0_vpecontrol(); /* MT ASE */
             rn = "VPEControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_mfc0_vpeconf0(); /* MT ASE */
+//            gen_op_mfc0_vpeconf0(); /* MT ASE */
             rn = "VPEConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_mfc0_vpeconf1(); /* MT ASE */
+//            gen_op_mfc0_vpeconf1(); /* MT ASE */
             rn = "VPEConf1";
-//         break;
+//            break;
         case 4:
-//         gen_op_mfc0_YQMask(); /* MT ASE */
+//            gen_op_mfc0_YQMask(); /* MT ASE */
             rn = "YQMask";
-//         break;
+//            break;
         case 5:
-//         gen_op_mfc0_vpeschedule(); /* MT ASE */
+//            gen_op_mfc0_vpeschedule(); /* MT ASE */
             rn = "VPESchedule";
-//         break;
+//            break;
         case 6:
-//         gen_op_mfc0_vpeschefback(); /* MT ASE */
+//            gen_op_mfc0_vpeschefback(); /* MT ASE */
             rn = "VPEScheFBack";
-//         break;
+//            break;
         case 7:
-//         gen_op_mfc0_vpeopt(); /* MT ASE */
+//            gen_op_mfc0_vpeopt(); /* MT ASE */
             rn = "VPEOpt";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -1719,37 +1821,37 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 2:
         switch (sel) {
         case 0:
-           gen_op_mfc0_entrylo0();
-           rn = "EntryLo0";
-           break;
+            gen_op_mfc0_entrylo0();
+            rn = "EntryLo0";
+            break;
         case 1:
-//         gen_op_mfc0_tcstatus(); /* MT ASE */
-           rn = "TCStatus";
-//         break;
+//            gen_op_mfc0_tcstatus(); /* MT ASE */
+            rn = "TCStatus";
+//            break;
         case 2:
-//         gen_op_mfc0_tcbind(); /* MT ASE */
-           rn = "TCBind";
-//         break;
+//            gen_op_mfc0_tcbind(); /* MT ASE */
+            rn = "TCBind";
+//            break;
         case 3:
-//         gen_op_mfc0_tcrestart(); /* MT ASE */
-           rn = "TCRestart";
-//         break;
+//            gen_op_mfc0_tcrestart(); /* MT ASE */
+            rn = "TCRestart";
+//            break;
         case 4:
-//         gen_op_mfc0_tchalt(); /* MT ASE */
-           rn = "TCHalt";
-//         break;
+//            gen_op_mfc0_tchalt(); /* MT ASE */
+            rn = "TCHalt";
+//            break;
         case 5:
-//         gen_op_mfc0_tccontext(); /* MT ASE */
-           rn = "TCContext";
-//         break;
+//            gen_op_mfc0_tccontext(); /* MT ASE */
+            rn = "TCContext";
+//            break;
         case 6:
-//         gen_op_mfc0_tcschedule(); /* MT ASE */
-           rn = "TCSchedule";
-//         break;
+//            gen_op_mfc0_tcschedule(); /* MT ASE */
+            rn = "TCSchedule";
+//            break;
         case 7:
-//         gen_op_mfc0_tcschefback(); /* MT ASE */
-           rn = "TCScheFBack";
-//         break;
+//            gen_op_mfc0_tcschefback(); /* MT ASE */
+            rn = "TCScheFBack";
+//            break;
         default:
             goto die;
         }
@@ -1757,87 +1859,87 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 3:
         switch (sel) {
         case 0:
-           gen_op_mfc0_entrylo1();
-           rn = "EntryLo1";
-           break;
+            gen_op_mfc0_entrylo1();
+            rn = "EntryLo1";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 4:
         switch (sel) {
         case 0:
-           gen_op_mfc0_context();
-           rn = "Context";
-           break;
+            gen_op_mfc0_context();
+            rn = "Context";
+            break;
         case 1:
-//         gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
-           rn = "ContextConfig";
-//         break;
+//            gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
+            rn = "ContextConfig";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 5:
         switch (sel) {
         case 0:
-           gen_op_mfc0_pagemask();
-           rn = "PageMask";
-           break;
+            gen_op_mfc0_pagemask();
+            rn = "PageMask";
+            break;
         case 1:
-           gen_op_mfc0_pagegrain();
-           rn = "PageGrain";
-           break;
+            gen_op_mfc0_pagegrain();
+            rn = "PageGrain";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 6:
         switch (sel) {
         case 0:
-           gen_op_mfc0_wired();
-           rn = "Wired";
-           break;
+            gen_op_mfc0_wired();
+            rn = "Wired";
+            break;
         case 1:
-//         gen_op_mfc0_srsconf0(); /* shadow registers */
-           rn = "SRSConf0";
-//         break;
+//            gen_op_mfc0_srsconf0(); /* shadow registers */
+            rn = "SRSConf0";
+//            break;
         case 2:
-//         gen_op_mfc0_srsconf1(); /* shadow registers */
-           rn = "SRSConf1";
-//         break;
+//            gen_op_mfc0_srsconf1(); /* shadow registers */
+            rn = "SRSConf1";
+//            break;
         case 3:
-//         gen_op_mfc0_srsconf2(); /* shadow registers */
-           rn = "SRSConf2";
-//         break;
+//            gen_op_mfc0_srsconf2(); /* shadow registers */
+            rn = "SRSConf2";
+//            break;
         case 4:
-//         gen_op_mfc0_srsconf3(); /* shadow registers */
-           rn = "SRSConf3";
-//         break;
+//            gen_op_mfc0_srsconf3(); /* shadow registers */
+            rn = "SRSConf3";
+//            break;
         case 5:
-//         gen_op_mfc0_srsconf4(); /* shadow registers */
-           rn = "SRSConf4";
-//         break;
+//            gen_op_mfc0_srsconf4(); /* shadow registers */
+            rn = "SRSConf4";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 7:
         switch (sel) {
         case 0:
-           gen_op_mfc0_hwrena();
-           rn = "HWREna";
-           break;
+            gen_op_mfc0_hwrena();
+            rn = "HWREna";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 8:
         switch (sel) {
         case 0:
-           gen_op_mfc0_badvaddr();
-           rn = "BadVaddr";
-           break;
+            gen_op_mfc0_badvaddr();
+            rn = "BadVaddr";
+            break;
         default:
             goto die;
        }
@@ -1845,53 +1947,53 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 9:
         switch (sel) {
         case 0:
-           gen_op_mfc0_count();
-           rn = "Count";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mfc0_count();
+            rn = "Count";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
+        }
         break;
     case 10:
         switch (sel) {
         case 0:
-           gen_op_mfc0_entryhi();
-           rn = "EntryHi";
-           break;
+            gen_op_mfc0_entryhi();
+            rn = "EntryHi";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 11:
         switch (sel) {
         case 0:
-           gen_op_mfc0_compare();
-           rn = "Compare";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mfc0_compare();
+            rn = "Compare";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
+        }
         break;
     case 12:
         switch (sel) {
         case 0:
-           gen_op_mfc0_status();
-           rn = "Status";
-           break;
+            gen_op_mfc0_status();
+            rn = "Status";
+            break;
         case 1:
-           gen_op_mfc0_intctl();
-           rn = "IntCtl";
-           break;
+            gen_op_mfc0_intctl();
+            rn = "IntCtl";
+            break;
         case 2:
-           gen_op_mfc0_srsctl();
-           rn = "SRSCtl";
-           break;
+            gen_op_mfc0_srsctl();
+            rn = "SRSCtl";
+            break;
         case 3:
-//         gen_op_mfc0_srsmap(); /* shadow registers */
-           rn = "SRSMap";
-//         break;
+//            gen_op_mfc0_srsmap(); /* shadow registers */
+            rn = "SRSMap";
+//            break;
         default:
             goto die;
        }
@@ -1899,9 +2001,9 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 13:
         switch (sel) {
         case 0:
-           gen_op_mfc0_cause();
-           rn = "Cause";
-           break;
+            gen_op_mfc0_cause();
+            rn = "Cause";
+            break;
         default:
             goto die;
        }
@@ -1909,23 +2011,23 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 14:
         switch (sel) {
         case 0:
-           gen_op_mfc0_epc();
-           rn = "EPC";
-           break;
+            gen_op_mfc0_epc();
+            rn = "EPC";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 15:
         switch (sel) {
         case 0:
-           gen_op_mfc0_prid();
-           rn = "PRid";
-           break;
+            gen_op_mfc0_prid();
+            rn = "PRid";
+            break;
         case 1:
-           gen_op_mfc0_ebase();
-           rn = "EBase";
-           break;
+            gen_op_mfc0_ebase();
+            rn = "EBase";
+            break;
         default:
             goto die;
        }
@@ -1965,9 +2067,9 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 17:
         switch (sel) {
         case 0:
-           gen_op_mfc0_lladdr();
-           rn = "LLAddr";
-           break;
+            gen_op_mfc0_lladdr();
+            rn = "LLAddr";
+            break;
         default:
             goto die;
         }
@@ -1975,37 +2077,37 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 18:
         switch (sel) {
         case 0:
-           gen_op_mfc0_watchlo0();
-           rn = "WatchLo";
-           break;
+            gen_op_mfc0_watchlo0();
+            rn = "WatchLo";
+            break;
         case 1:
-//         gen_op_mfc0_watchlo1();
-           rn = "WatchLo1";
-//         break;
+//            gen_op_mfc0_watchlo1();
+            rn = "WatchLo1";
+//            break;
         case 2:
-//         gen_op_mfc0_watchlo2();
-           rn = "WatchLo2";
-//         break;
+//            gen_op_mfc0_watchlo2();
+            rn = "WatchLo2";
+//            break;
         case 3:
-//         gen_op_mfc0_watchlo3();
-           rn = "WatchLo3";
-//         break;
+//            gen_op_mfc0_watchlo3();
+            rn = "WatchLo3";
+//            break;
         case 4:
-//         gen_op_mfc0_watchlo4();
-           rn = "WatchLo4";
-//         break;
+//            gen_op_mfc0_watchlo4();
+            rn = "WatchLo4";
+//            break;
         case 5:
-//         gen_op_mfc0_watchlo5();
-           rn = "WatchLo5";
-//         break;
+//            gen_op_mfc0_watchlo5();
+            rn = "WatchLo5";
+//            break;
         case 6:
-//         gen_op_mfc0_watchlo6();
-           rn = "WatchLo6";
-//         break;
+//            gen_op_mfc0_watchlo6();
+            rn = "WatchLo6";
+//            break;
         case 7:
-//         gen_op_mfc0_watchlo7();
-           rn = "WatchLo7";
-//         break;
+//            gen_op_mfc0_watchlo7();
+            rn = "WatchLo7";
+//            break;
         default:
             goto die;
         }
@@ -2013,37 +2115,37 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 19:
         switch (sel) {
         case 0:
-           gen_op_mfc0_watchhi0();
-           rn = "WatchHi";
-           break;
+            gen_op_mfc0_watchhi0();
+            rn = "WatchHi";
+            break;
         case 1:
-//         gen_op_mfc0_watchhi1();
-           rn = "WatchHi1";
-//         break;
+//            gen_op_mfc0_watchhi1();
+            rn = "WatchHi1";
+//            break;
         case 2:
-//         gen_op_mfc0_watchhi2();
-           rn = "WatchHi2";
-//         break;
+//            gen_op_mfc0_watchhi2();
+            rn = "WatchHi2";
+//            break;
         case 3:
-//         gen_op_mfc0_watchhi3();
-           rn = "WatchHi3";
-//         break;
+//            gen_op_mfc0_watchhi3();
+            rn = "WatchHi3";
+//            break;
         case 4:
-//         gen_op_mfc0_watchhi4();
-           rn = "WatchHi4";
-//         break;
+//            gen_op_mfc0_watchhi4();
+            rn = "WatchHi4";
+//            break;
         case 5:
-//         gen_op_mfc0_watchhi5();
-           rn = "WatchHi5";
-//         break;
+//            gen_op_mfc0_watchhi5();
+            rn = "WatchHi5";
+//            break;
         case 6:
-//         gen_op_mfc0_watchhi6();
-           rn = "WatchHi6";
-//         break;
+//            gen_op_mfc0_watchhi6();
+            rn = "WatchHi6";
+//            break;
         case 7:
-//         gen_op_mfc0_watchhi7();
-           rn = "WatchHi7";
-//         break;
+//            gen_op_mfc0_watchhi7();
+            rn = "WatchHi7";
+//            break;
         default:
             goto die;
         }
@@ -2051,10 +2153,10 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 20:
         switch (sel) {
         case 0:
-           /* 64 bit MMU only */
-           gen_op_mfc0_xcontext();
-           rn = "XContext";
-           break;
+            /* 64 bit MMU only */
+            gen_op_mfc0_xcontext();
+            rn = "XContext";
+            break;
         default:
             goto die;
         }
@@ -2063,39 +2165,39 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
        /* Officially reserved, but sel 0 is used for R1x000 framemask */
         switch (sel) {
         case 0:
-           gen_op_mfc0_framemask();
-           rn = "Framemask";
-           break;
+            gen_op_mfc0_framemask();
+            rn = "Framemask";
+            break;
         default:
             goto die;
         }
         break;
     case 22:
-       /* ignored */
-       rn = "'Diagnostic"; /* implementation dependent */
-       break;
+        /* ignored */
+        rn = "'Diagnostic"; /* implementation dependent */
+        break;
     case 23:
         switch (sel) {
         case 0:
-           gen_op_mfc0_debug(); /* EJTAG support */
-           rn = "Debug";
-           break;
+            gen_op_mfc0_debug(); /* EJTAG support */
+            rn = "Debug";
+            break;
         case 1:
-//         gen_op_mfc0_tracecontrol(); /* PDtrace support */
-           rn = "TraceControl";
-//         break;
+//            gen_op_mfc0_tracecontrol(); /* PDtrace support */
+            rn = "TraceControl";
+//            break;
         case 2:
-//         gen_op_mfc0_tracecontrol2(); /* PDtrace support */
-           rn = "TraceControl2";
-//         break;
+//            gen_op_mfc0_tracecontrol2(); /* PDtrace support */
+            rn = "TraceControl2";
+//            break;
         case 3:
-//         gen_op_mfc0_usertracedata(); /* PDtrace support */
-           rn = "UserTraceData";
-//         break;
+//            gen_op_mfc0_usertracedata(); /* PDtrace support */
+            rn = "UserTraceData";
+//            break;
         case 4:
-//         gen_op_mfc0_debug(); /* PDtrace support */
-           rn = "TraceBPC";
-//         break;
+//            gen_op_mfc0_debug(); /* PDtrace support */
+            rn = "TraceBPC";
+//            break;
         default:
             goto die;
         }
@@ -2103,9 +2205,9 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 24:
         switch (sel) {
         case 0:
-           gen_op_mfc0_depc(); /* EJTAG support */
-           rn = "DEPC";
-           break;
+            gen_op_mfc0_depc(); /* EJTAG support */
+            rn = "DEPC";
+            break;
         default:
             goto die;
         }
@@ -2113,37 +2215,37 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 25:
         switch (sel) {
         case 0:
-           gen_op_mfc0_performance0();
-           rn = "Performance0";
+            gen_op_mfc0_performance0();
+            rn = "Performance0";
             break;
         case 1:
-//         gen_op_mfc0_performance1();
-           rn = "Performance1";
-//         break;
+//            gen_op_mfc0_performance1();
+            rn = "Performance1";
+//            break;
         case 2:
-//         gen_op_mfc0_performance2();
-           rn = "Performance2";
-//         break;
+//            gen_op_mfc0_performance2();
+            rn = "Performance2";
+//            break;
         case 3:
-//         gen_op_mfc0_performance3();
-           rn = "Performance3";
-//         break;
+//            gen_op_mfc0_performance3();
+            rn = "Performance3";
+//            break;
         case 4:
-//         gen_op_mfc0_performance4();
-           rn = "Performance4";
-//         break;
+//            gen_op_mfc0_performance4();
+            rn = "Performance4";
+//            break;
         case 5:
-//         gen_op_mfc0_performance5();
-           rn = "Performance5";
-//         break;
+//            gen_op_mfc0_performance5();
+            rn = "Performance5";
+//            break;
         case 6:
-//         gen_op_mfc0_performance6();
-           rn = "Performance6";
-//         break;
+//            gen_op_mfc0_performance6();
+            rn = "Performance6";
+//            break;
         case 7:
-//         gen_op_mfc0_performance7();
-           rn = "Performance7";
-//         break;
+//            gen_op_mfc0_performance7();
+            rn = "Performance7";
+//            break;
         default:
             goto die;
         }
@@ -2155,8 +2257,8 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
         switch (sel) {
         /* ignored */
         case 0 ... 3:
-           rn = "CacheErr";
-           break;
+            rn = "CacheErr";
+            break;
         default:
             goto die;
         }
@@ -2204,9 +2306,9 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 30:
         switch (sel) {
         case 0:
-           gen_op_mfc0_errorepc();
-           rn = "ErrorEPC";
-           break;
+            gen_op_mfc0_errorepc();
+            rn = "ErrorEPC";
+            break;
         default:
             goto die;
         }
@@ -2214,9 +2316,9 @@ static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
     case 31:
         switch (sel) {
         case 0:
-           gen_op_mfc0_desave(); /* EJTAG support */
-           rn = "DESAVE";
-           break;
+            gen_op_mfc0_desave(); /* EJTAG support */
+            rn = "DESAVE";
+            break;
         default:
             goto die;
         }
@@ -2254,17 +2356,17 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
             rn = "Index";
             break;
         case 1:
-//         gen_op_mtc0_mvpcontrol(); /* MT ASE */
+//            gen_op_mtc0_mvpcontrol(); /* MT ASE */
             rn = "MVPControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_mtc0_mvpconf0(); /* MT ASE */
+//            gen_op_mtc0_mvpconf0(); /* MT ASE */
             rn = "MVPConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_mtc0_mvpconf1(); /* MT ASE */
+//            gen_op_mtc0_mvpconf1(); /* MT ASE */
             rn = "MVPConf1";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -2272,37 +2374,37 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 1:
         switch (sel) {
         case 0:
-           /* ignored */
+            /* ignored */
             rn = "Random";
-           break;
+            break;
         case 1:
-//         gen_op_mtc0_vpecontrol(); /* MT ASE */
+//            gen_op_mtc0_vpecontrol(); /* MT ASE */
             rn = "VPEControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_mtc0_vpeconf0(); /* MT ASE */
+//            gen_op_mtc0_vpeconf0(); /* MT ASE */
             rn = "VPEConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_mtc0_vpeconf1(); /* MT ASE */
+//            gen_op_mtc0_vpeconf1(); /* MT ASE */
             rn = "VPEConf1";
-//         break;
+//            break;
         case 4:
-//         gen_op_mtc0_YQMask(); /* MT ASE */
+//            gen_op_mtc0_YQMask(); /* MT ASE */
             rn = "YQMask";
-//         break;
+//            break;
         case 5:
-//         gen_op_mtc0_vpeschedule(); /* MT ASE */
+//            gen_op_mtc0_vpeschedule(); /* MT ASE */
             rn = "VPESchedule";
-//         break;
+//            break;
         case 6:
-//         gen_op_mtc0_vpeschefback(); /* MT ASE */
+//            gen_op_mtc0_vpeschefback(); /* MT ASE */
             rn = "VPEScheFBack";
-//         break;
+//            break;
         case 7:
-//         gen_op_mtc0_vpeopt(); /* MT ASE */
+//            gen_op_mtc0_vpeopt(); /* MT ASE */
             rn = "VPEOpt";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -2310,37 +2412,37 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 2:
         switch (sel) {
         case 0:
-           gen_op_mtc0_entrylo0();
-           rn = "EntryLo0";
-           break;
+            gen_op_mtc0_entrylo0();
+            rn = "EntryLo0";
+            break;
         case 1:
-//         gen_op_mtc0_tcstatus(); /* MT ASE */
-           rn = "TCStatus";
-//         break;
+//            gen_op_mtc0_tcstatus(); /* MT ASE */
+            rn = "TCStatus";
+//            break;
         case 2:
-//         gen_op_mtc0_tcbind(); /* MT ASE */
-           rn = "TCBind";
-//         break;
+//            gen_op_mtc0_tcbind(); /* MT ASE */
+            rn = "TCBind";
+//            break;
         case 3:
-//         gen_op_mtc0_tcrestart(); /* MT ASE */
-           rn = "TCRestart";
-//         break;
+//            gen_op_mtc0_tcrestart(); /* MT ASE */
+            rn = "TCRestart";
+//            break;
         case 4:
-//         gen_op_mtc0_tchalt(); /* MT ASE */
-           rn = "TCHalt";
-//         break;
+//            gen_op_mtc0_tchalt(); /* MT ASE */
+            rn = "TCHalt";
+//            break;
         case 5:
-//         gen_op_mtc0_tccontext(); /* MT ASE */
-           rn = "TCContext";
-//         break;
+//            gen_op_mtc0_tccontext(); /* MT ASE */
+            rn = "TCContext";
+//            break;
         case 6:
-//         gen_op_mtc0_tcschedule(); /* MT ASE */
-           rn = "TCSchedule";
-//         break;
+//            gen_op_mtc0_tcschedule(); /* MT ASE */
+            rn = "TCSchedule";
+//            break;
         case 7:
-//         gen_op_mtc0_tcschefback(); /* MT ASE */
-           rn = "TCScheFBack";
-//         break;
+//            gen_op_mtc0_tcschefback(); /* MT ASE */
+            rn = "TCScheFBack";
+//            break;
         default:
             goto die;
         }
@@ -2348,80 +2450,80 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 3:
         switch (sel) {
         case 0:
-           gen_op_mtc0_entrylo1();
-           rn = "EntryLo1";
-           break;
+            gen_op_mtc0_entrylo1();
+            rn = "EntryLo1";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 4:
         switch (sel) {
         case 0:
-           gen_op_mtc0_context();
-           rn = "Context";
-           break;
+            gen_op_mtc0_context();
+            rn = "Context";
+            break;
         case 1:
-//         gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
-           rn = "ContextConfig";
-//         break;
+//            gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
+            rn = "ContextConfig";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 5:
         switch (sel) {
         case 0:
-           gen_op_mtc0_pagemask();
-           rn = "PageMask";
-           break;
+            gen_op_mtc0_pagemask();
+            rn = "PageMask";
+            break;
         case 1:
-           gen_op_mtc0_pagegrain();
-           rn = "PageGrain";
-           break;
+            gen_op_mtc0_pagegrain();
+            rn = "PageGrain";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 6:
         switch (sel) {
         case 0:
-           gen_op_mtc0_wired();
-           rn = "Wired";
-           break;
+            gen_op_mtc0_wired();
+            rn = "Wired";
+            break;
         case 1:
-//         gen_op_mtc0_srsconf0(); /* shadow registers */
-           rn = "SRSConf0";
-//         break;
+//            gen_op_mtc0_srsconf0(); /* shadow registers */
+            rn = "SRSConf0";
+//            break;
         case 2:
-//         gen_op_mtc0_srsconf1(); /* shadow registers */
-           rn = "SRSConf1";
-//         break;
+//            gen_op_mtc0_srsconf1(); /* shadow registers */
+            rn = "SRSConf1";
+//            break;
         case 3:
-//         gen_op_mtc0_srsconf2(); /* shadow registers */
-           rn = "SRSConf2";
-//         break;
+//            gen_op_mtc0_srsconf2(); /* shadow registers */
+            rn = "SRSConf2";
+//            break;
         case 4:
-//         gen_op_mtc0_srsconf3(); /* shadow registers */
-           rn = "SRSConf3";
-//         break;
+//            gen_op_mtc0_srsconf3(); /* shadow registers */
+            rn = "SRSConf3";
+//            break;
         case 5:
-//         gen_op_mtc0_srsconf4(); /* shadow registers */
-           rn = "SRSConf4";
-//         break;
+//            gen_op_mtc0_srsconf4(); /* shadow registers */
+            rn = "SRSConf4";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 7:
         switch (sel) {
         case 0:
-           gen_op_mtc0_hwrena();
-           rn = "HWREna";
-           break;
+            gen_op_mtc0_hwrena();
+            rn = "HWREna";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 8:
         /* ignored */
@@ -2430,104 +2532,106 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 9:
         switch (sel) {
         case 0:
-           gen_op_mtc0_count();
-           rn = "Count";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mtc0_count();
+            rn = "Count";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 10:
         switch (sel) {
         case 0:
-           gen_op_mtc0_entryhi();
-           rn = "EntryHi";
-           break;
+            gen_op_mtc0_entryhi();
+            rn = "EntryHi";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 11:
         switch (sel) {
         case 0:
-           gen_op_mtc0_compare();
-           rn = "Compare";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mtc0_compare();
+            rn = "Compare";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 12:
         switch (sel) {
         case 0:
-           gen_op_mtc0_status();
-           rn = "Status";
-           break;
+            gen_op_mtc0_status();
+            rn = "Status";
+            break;
         case 1:
-           gen_op_mtc0_intctl();
-           rn = "IntCtl";
-           break;
+            gen_op_mtc0_intctl();
+            rn = "IntCtl";
+            break;
         case 2:
-           gen_op_mtc0_srsctl();
-           rn = "SRSCtl";
-           break;
+            gen_op_mtc0_srsctl();
+            rn = "SRSCtl";
+            break;
         case 3:
-//         gen_op_mtc0_srsmap(); /* shadow registers */
-           rn = "SRSMap";
-//         break;
+//            gen_op_mtc0_srsmap(); /* shadow registers */
+            rn = "SRSMap";
+//            break;
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 13:
         switch (sel) {
         case 0:
-           gen_op_mtc0_cause();
-           rn = "Cause";
-           break;
+            gen_op_mtc0_cause();
+            rn = "Cause";
+            break;
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 14:
         switch (sel) {
         case 0:
-           gen_op_mtc0_epc();
-           rn = "EPC";
-           break;
+            gen_op_mtc0_epc();
+            rn = "EPC";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 15:
         switch (sel) {
         case 0:
-           /* ignored */
-           rn = "PRid";
-           break;
+            /* ignored */
+            rn = "PRid";
+            break;
         case 1:
-           gen_op_mtc0_ebase();
-           rn = "EBase";
-           break;
+            gen_op_mtc0_ebase();
+            rn = "EBase";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 16:
         switch (sel) {
         case 0:
             gen_op_mtc0_config0();
             rn = "Config";
+            /* Stop translation as we may have switched the execution mode */
+            ctx->bstate = BS_STOP;
             break;
         case 1:
             /* ignored, read only */
@@ -2536,6 +2640,8 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
         case 2:
             gen_op_mtc0_config2();
             rn = "Config2";
+            /* Stop translation as we may have switched the execution mode */
+            ctx->bstate = BS_STOP;
             break;
         case 3:
             /* ignored, read only */
@@ -2555,15 +2661,13 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
             rn = "Invalid config selector";
             goto die;
         }
-        /* Stop translation as we may have switched the execution mode */
-        ctx->bstate = BS_STOP;
         break;
     case 17:
         switch (sel) {
         case 0:
-           /* ignored */
-           rn = "LLAddr";
-           break;
+            /* ignored */
+            rn = "LLAddr";
+            break;
         default:
             goto die;
         }
@@ -2571,37 +2675,37 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 18:
         switch (sel) {
         case 0:
-           gen_op_mtc0_watchlo0();
-           rn = "WatchLo";
-           break;
+            gen_op_mtc0_watchlo0();
+            rn = "WatchLo";
+            break;
         case 1:
-//         gen_op_mtc0_watchlo1();
-           rn = "WatchLo1";
-//         break;
+//            gen_op_mtc0_watchlo1();
+            rn = "WatchLo1";
+//            break;
         case 2:
-//         gen_op_mtc0_watchlo2();
-           rn = "WatchLo2";
-//         break;
+//            gen_op_mtc0_watchlo2();
+            rn = "WatchLo2";
+//            break;
         case 3:
-//         gen_op_mtc0_watchlo3();
-           rn = "WatchLo3";
-//         break;
+//            gen_op_mtc0_watchlo3();
+            rn = "WatchLo3";
+//            break;
         case 4:
-//         gen_op_mtc0_watchlo4();
-           rn = "WatchLo4";
-//         break;
+//            gen_op_mtc0_watchlo4();
+            rn = "WatchLo4";
+//            break;
         case 5:
-//         gen_op_mtc0_watchlo5();
-           rn = "WatchLo5";
-//         break;
+//            gen_op_mtc0_watchlo5();
+            rn = "WatchLo5";
+//            break;
         case 6:
-//         gen_op_mtc0_watchlo6();
-           rn = "WatchLo6";
-//         break;
+//            gen_op_mtc0_watchlo6();
+            rn = "WatchLo6";
+//            break;
         case 7:
-//         gen_op_mtc0_watchlo7();
-           rn = "WatchLo7";
-//         break;
+//            gen_op_mtc0_watchlo7();
+            rn = "WatchLo7";
+//            break;
         default:
             goto die;
         }
@@ -2609,37 +2713,37 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 19:
         switch (sel) {
         case 0:
-           gen_op_mtc0_watchhi0();
-           rn = "WatchHi";
-           break;
+            gen_op_mtc0_watchhi0();
+            rn = "WatchHi";
+            break;
         case 1:
-//         gen_op_mtc0_watchhi1();
-           rn = "WatchHi1";
-//         break;
+//            gen_op_mtc0_watchhi1();
+            rn = "WatchHi1";
+//            break;
         case 2:
-//         gen_op_mtc0_watchhi2();
-           rn = "WatchHi2";
-//         break;
+//            gen_op_mtc0_watchhi2();
+            rn = "WatchHi2";
+//            break;
         case 3:
-//         gen_op_mtc0_watchhi3();
-           rn = "WatchHi3";
-//         break;
+//            gen_op_mtc0_watchhi3();
+            rn = "WatchHi3";
+//            break;
         case 4:
-//         gen_op_mtc0_watchhi4();
-           rn = "WatchHi4";
-//         break;
+//            gen_op_mtc0_watchhi4();
+            rn = "WatchHi4";
+//            break;
         case 5:
-//         gen_op_mtc0_watchhi5();
-           rn = "WatchHi5";
-//         break;
+//            gen_op_mtc0_watchhi5();
+            rn = "WatchHi5";
+//            break;
         case 6:
-//         gen_op_mtc0_watchhi6();
-           rn = "WatchHi6";
-//         break;
+//            gen_op_mtc0_watchhi6();
+            rn = "WatchHi6";
+//            break;
         case 7:
-//         gen_op_mtc0_watchhi7();
-           rn = "WatchHi7";
-//         break;
+//            gen_op_mtc0_watchhi7();
+            rn = "WatchHi7";
+//            break;
         default:
             goto die;
         }
@@ -2647,10 +2751,10 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 20:
         switch (sel) {
         case 0:
-           /* 64 bit MMU only */
-           gen_op_mtc0_xcontext();
-           rn = "XContext";
-           break;
+            /* 64 bit MMU only */
+            /* Nothing writable in lower 32 bits */
+            rn = "XContext";
+            break;
         default:
             goto die;
         }
@@ -2659,9 +2763,9 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
        /* Officially reserved, but sel 0 is used for R1x000 framemask */
         switch (sel) {
         case 0:
-           gen_op_mtc0_framemask();
-           rn = "Framemask";
-           break;
+            gen_op_mtc0_framemask();
+            rn = "Framemask";
+            break;
         default:
             goto die;
         }
@@ -2669,41 +2773,41 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 22:
         /* ignored */
         rn = "Diagnostic"; /* implementation dependent */
-       break;
+        break;
     case 23:
         switch (sel) {
         case 0:
-           gen_op_mtc0_debug(); /* EJTAG support */
-           rn = "Debug";
-           break;
+            gen_op_mtc0_debug(); /* EJTAG support */
+            rn = "Debug";
+            break;
         case 1:
-//         gen_op_mtc0_tracecontrol(); /* PDtrace support */
-           rn = "TraceControl";
-//         break;
+//            gen_op_mtc0_tracecontrol(); /* PDtrace support */
+            rn = "TraceControl";
+//            break;
         case 2:
-//         gen_op_mtc0_tracecontrol2(); /* PDtrace support */
-           rn = "TraceControl2";
-//         break;
+//            gen_op_mtc0_tracecontrol2(); /* PDtrace support */
+            rn = "TraceControl2";
+//            break;
         case 3:
-//         gen_op_mtc0_usertracedata(); /* PDtrace support */
-           rn = "UserTraceData";
-//         break;
+//            gen_op_mtc0_usertracedata(); /* PDtrace support */
+            rn = "UserTraceData";
+//            break;
         case 4:
-//         gen_op_mtc0_debug(); /* PDtrace support */
-           rn = "TraceBPC";
-//         break;
+//            gen_op_mtc0_debug(); /* PDtrace support */
+            rn = "TraceBPC";
+//            break;
         default:
             goto die;
         }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 24:
         switch (sel) {
         case 0:
-           gen_op_mtc0_depc(); /* EJTAG support */
-           rn = "DEPC";
-           break;
+            gen_op_mtc0_depc(); /* EJTAG support */
+            rn = "DEPC";
+            break;
         default:
             goto die;
         }
@@ -2711,51 +2815,51 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 25:
         switch (sel) {
         case 0:
-           gen_op_mtc0_performance0();
-           rn = "Performance0";
-           break;
+            gen_op_mtc0_performance0();
+            rn = "Performance0";
+            break;
         case 1:
-//         gen_op_mtc0_performance1();
-           rn = "Performance1";
-//         break;
+//            gen_op_mtc0_performance1();
+            rn = "Performance1";
+//            break;
         case 2:
-//         gen_op_mtc0_performance2();
-           rn = "Performance2";
-//         break;
+//            gen_op_mtc0_performance2();
+            rn = "Performance2";
+//            break;
         case 3:
-//         gen_op_mtc0_performance3();
-           rn = "Performance3";
-//         break;
+//            gen_op_mtc0_performance3();
+            rn = "Performance3";
+//            break;
         case 4:
-//         gen_op_mtc0_performance4();
-           rn = "Performance4";
-//         break;
+//            gen_op_mtc0_performance4();
+            rn = "Performance4";
+//            break;
         case 5:
-//         gen_op_mtc0_performance5();
-           rn = "Performance5";
-//         break;
+//            gen_op_mtc0_performance5();
+            rn = "Performance5";
+//            break;
         case 6:
-//         gen_op_mtc0_performance6();
-           rn = "Performance6";
-//         break;
+//            gen_op_mtc0_performance6();
+            rn = "Performance6";
+//            break;
         case 7:
-//         gen_op_mtc0_performance7();
-           rn = "Performance7";
-//         break;
+//            gen_op_mtc0_performance7();
+            rn = "Performance7";
+//            break;
         default:
             goto die;
         }
        break;
     case 26:
-       /* ignored */
+        /* ignored */
         rn = "ECC";
-       break;
+        break;
     case 27:
         switch (sel) {
         case 0 ... 3:
-           /* ignored */
-           rn = "CacheErr";
-           break;
+            /* ignored */
+            rn = "CacheErr";
+            break;
         default:
             goto die;
         }
@@ -2773,7 +2877,7 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
         case 3:
         case 5:
         case 7:
-           gen_op_mtc0_datalo();
+            gen_op_mtc0_datalo();
             rn = "DataLo";
             break;
         default:
@@ -2793,7 +2897,7 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
         case 3:
         case 5:
         case 7:
-           gen_op_mtc0_datahi();
+            gen_op_mtc0_datahi();
             rn = "DataHi";
             break;
         default:
@@ -2804,9 +2908,9 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 30:
         switch (sel) {
         case 0:
-           gen_op_mtc0_errorepc();
-           rn = "ErrorEPC";
-           break;
+            gen_op_mtc0_errorepc();
+            rn = "ErrorEPC";
+            break;
         default:
             goto die;
         }
@@ -2814,14 +2918,14 @@ static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
     case 31:
         switch (sel) {
         case 0:
-           gen_op_mtc0_desave(); /* EJTAG support */
-           rn = "DESAVE";
-           break;
+            gen_op_mtc0_desave(); /* EJTAG support */
+            rn = "DESAVE";
+            break;
         default:
             goto die;
         }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     default:
        goto die;
@@ -2844,6 +2948,7 @@ die:
     generate_exception(ctx, EXCP_RI);
 }
 
+#ifdef TARGET_MIPS64
 static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
 {
     const char *rn = "invalid";
@@ -2852,21 +2957,21 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 0:
         switch (sel) {
         case 0:
-           gen_op_mfc0_index();
+            gen_op_mfc0_index();
             rn = "Index";
             break;
         case 1:
-//         gen_op_dmfc0_mvpcontrol(); /* MT ASE */
+//            gen_op_dmfc0_mvpcontrol(); /* MT ASE */
             rn = "MVPControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_dmfc0_mvpconf0(); /* MT ASE */
+//            gen_op_dmfc0_mvpconf0(); /* MT ASE */
             rn = "MVPConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_dmfc0_mvpconf1(); /* MT ASE */
+//            gen_op_dmfc0_mvpconf1(); /* MT ASE */
             rn = "MVPConf1";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -2876,35 +2981,35 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
         case 0:
             gen_op_mfc0_random();
             rn = "Random";
-           break;
+            break;
         case 1:
-//         gen_op_dmfc0_vpecontrol(); /* MT ASE */
+//            gen_op_dmfc0_vpecontrol(); /* MT ASE */
             rn = "VPEControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_dmfc0_vpeconf0(); /* MT ASE */
+//            gen_op_dmfc0_vpeconf0(); /* MT ASE */
             rn = "VPEConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_dmfc0_vpeconf1(); /* MT ASE */
+//            gen_op_dmfc0_vpeconf1(); /* MT ASE */
             rn = "VPEConf1";
-//         break;
+//            break;
         case 4:
-//         gen_op_dmfc0_YQMask(); /* MT ASE */
+//            gen_op_dmfc0_YQMask(); /* MT ASE */
             rn = "YQMask";
-//         break;
+//            break;
         case 5:
-//         gen_op_dmfc0_vpeschedule(); /* MT ASE */
+//            gen_op_dmfc0_vpeschedule(); /* MT ASE */
             rn = "VPESchedule";
-//         break;
+//            break;
         case 6:
-//         gen_op_dmfc0_vpeschefback(); /* MT ASE */
+//            gen_op_dmfc0_vpeschefback(); /* MT ASE */
             rn = "VPEScheFBack";
-//         break;
+//            break;
         case 7:
-//         gen_op_dmfc0_vpeopt(); /* MT ASE */
+//            gen_op_dmfc0_vpeopt(); /* MT ASE */
             rn = "VPEOpt";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -2912,37 +3017,37 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 2:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_entrylo0();
-           rn = "EntryLo0";
-           break;
+            gen_op_dmfc0_entrylo0();
+            rn = "EntryLo0";
+            break;
         case 1:
-//         gen_op_dmfc0_tcstatus(); /* MT ASE */
-           rn = "TCStatus";
-//         break;
+//            gen_op_dmfc0_tcstatus(); /* MT ASE */
+            rn = "TCStatus";
+//            break;
         case 2:
-//         gen_op_dmfc0_tcbind(); /* MT ASE */
-           rn = "TCBind";
-//         break;
+//            gen_op_dmfc0_tcbind(); /* MT ASE */
+            rn = "TCBind";
+//            break;
         case 3:
-//         gen_op_dmfc0_tcrestart(); /* MT ASE */
-           rn = "TCRestart";
-//         break;
+//            gen_op_dmfc0_tcrestart(); /* MT ASE */
+            rn = "TCRestart";
+//            break;
         case 4:
-//         gen_op_dmfc0_tchalt(); /* MT ASE */
-           rn = "TCHalt";
-//         break;
+//            gen_op_dmfc0_tchalt(); /* MT ASE */
+            rn = "TCHalt";
+//            break;
         case 5:
-//         gen_op_dmfc0_tccontext(); /* MT ASE */
-           rn = "TCContext";
-//         break;
+//            gen_op_dmfc0_tccontext(); /* MT ASE */
+            rn = "TCContext";
+//            break;
         case 6:
-//         gen_op_dmfc0_tcschedule(); /* MT ASE */
-           rn = "TCSchedule";
-//         break;
+//            gen_op_dmfc0_tcschedule(); /* MT ASE */
+            rn = "TCSchedule";
+//            break;
         case 7:
-//         gen_op_dmfc0_tcschefback(); /* MT ASE */
-           rn = "TCScheFBack";
-//         break;
+//            gen_op_dmfc0_tcschefback(); /* MT ASE */
+            rn = "TCScheFBack";
+//            break;
         default:
             goto die;
         }
@@ -2950,195 +3055,195 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 3:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_entrylo1();
-           rn = "EntryLo1";
-           break;
+            gen_op_dmfc0_entrylo1();
+            rn = "EntryLo1";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 4:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_context();
-           rn = "Context";
-           break;
+            gen_op_dmfc0_context();
+            rn = "Context";
+            break;
         case 1:
-//         gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
-           rn = "ContextConfig";
-//         break;
+//            gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
+            rn = "ContextConfig";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 5:
         switch (sel) {
         case 0:
-           gen_op_mfc0_pagemask();
-           rn = "PageMask";
-           break;
+            gen_op_mfc0_pagemask();
+            rn = "PageMask";
+            break;
         case 1:
-           gen_op_mfc0_pagegrain();
-           rn = "PageGrain";
-           break;
+            gen_op_mfc0_pagegrain();
+            rn = "PageGrain";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 6:
         switch (sel) {
         case 0:
-           gen_op_mfc0_wired();
-           rn = "Wired";
-           break;
+            gen_op_mfc0_wired();
+            rn = "Wired";
+            break;
         case 1:
-//         gen_op_dmfc0_srsconf0(); /* shadow registers */
-           rn = "SRSConf0";
-//         break;
+//            gen_op_dmfc0_srsconf0(); /* shadow registers */
+            rn = "SRSConf0";
+//            break;
         case 2:
-//         gen_op_dmfc0_srsconf1(); /* shadow registers */
-           rn = "SRSConf1";
-//         break;
+//            gen_op_dmfc0_srsconf1(); /* shadow registers */
+            rn = "SRSConf1";
+//            break;
         case 3:
-//         gen_op_dmfc0_srsconf2(); /* shadow registers */
-           rn = "SRSConf2";
-//         break;
+//            gen_op_dmfc0_srsconf2(); /* shadow registers */
+            rn = "SRSConf2";
+//            break;
         case 4:
-//         gen_op_dmfc0_srsconf3(); /* shadow registers */
-           rn = "SRSConf3";
-//         break;
+//            gen_op_dmfc0_srsconf3(); /* shadow registers */
+            rn = "SRSConf3";
+//            break;
         case 5:
-//         gen_op_dmfc0_srsconf4(); /* shadow registers */
-           rn = "SRSConf4";
-//         break;
+//            gen_op_dmfc0_srsconf4(); /* shadow registers */
+            rn = "SRSConf4";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 7:
         switch (sel) {
         case 0:
-           gen_op_mfc0_hwrena();
-           rn = "HWREna";
-           break;
+            gen_op_mfc0_hwrena();
+            rn = "HWREna";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 8:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_badvaddr();
-           rn = "BadVaddr";
-           break;
+            gen_op_dmfc0_badvaddr();
+            rn = "BadVaddr";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 9:
         switch (sel) {
         case 0:
-           gen_op_mfc0_count();
-           rn = "Count";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mfc0_count();
+            rn = "Count";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
+        }
         break;
     case 10:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_entryhi();
-           rn = "EntryHi";
-           break;
+            gen_op_dmfc0_entryhi();
+            rn = "EntryHi";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 11:
         switch (sel) {
         case 0:
-           gen_op_mfc0_compare();
-           rn = "Compare";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mfc0_compare();
+            rn = "Compare";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
+        }
         break;
     case 12:
         switch (sel) {
         case 0:
-           gen_op_mfc0_status();
-           rn = "Status";
-           break;
+            gen_op_mfc0_status();
+            rn = "Status";
+            break;
         case 1:
-           gen_op_mfc0_intctl();
-           rn = "IntCtl";
-           break;
+            gen_op_mfc0_intctl();
+            rn = "IntCtl";
+            break;
         case 2:
-           gen_op_mfc0_srsctl();
-           rn = "SRSCtl";
-           break;
+            gen_op_mfc0_srsctl();
+            rn = "SRSCtl";
+            break;
         case 3:
-           gen_op_mfc0_srsmap(); /* shadow registers */
-           rn = "SRSMap";
-           break;
+            gen_op_mfc0_srsmap(); /* shadow registers */
+            rn = "SRSMap";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 13:
         switch (sel) {
         case 0:
-           gen_op_mfc0_cause();
-           rn = "Cause";
-           break;
+            gen_op_mfc0_cause();
+            rn = "Cause";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 14:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_epc();
-           rn = "EPC";
-           break;
+            gen_op_dmfc0_epc();
+            rn = "EPC";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 15:
         switch (sel) {
         case 0:
-           gen_op_mfc0_prid();
-           rn = "PRid";
-           break;
+            gen_op_mfc0_prid();
+            rn = "PRid";
+            break;
         case 1:
-           gen_op_mfc0_ebase();
-           rn = "EBase";
-           break;
+            gen_op_mfc0_ebase();
+            rn = "EBase";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 16:
         switch (sel) {
         case 0:
-           gen_op_mfc0_config0();
+            gen_op_mfc0_config0();
             rn = "Config";
             break;
         case 1:
-           gen_op_mfc0_config1();
+            gen_op_mfc0_config1();
             rn = "Config1";
             break;
         case 2:
-           gen_op_mfc0_config2();
+            gen_op_mfc0_config2();
             rn = "Config2";
             break;
         case 3:
-           gen_op_mfc0_config3();
+            gen_op_mfc0_config3();
             rn = "Config3";
             break;
        /* 6,7 are implementation dependent */
@@ -3149,9 +3254,9 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 17:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_lladdr();
-           rn = "LLAddr";
-           break;
+            gen_op_dmfc0_lladdr();
+            rn = "LLAddr";
+            break;
         default:
             goto die;
         }
@@ -3159,37 +3264,37 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 18:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_watchlo0();
-           rn = "WatchLo";
-           break;
+            gen_op_dmfc0_watchlo0();
+            rn = "WatchLo";
+            break;
         case 1:
-//         gen_op_dmfc0_watchlo1();
-           rn = "WatchLo1";
-//         break;
+//            gen_op_dmfc0_watchlo1();
+            rn = "WatchLo1";
+//            break;
         case 2:
-//         gen_op_dmfc0_watchlo2();
-           rn = "WatchLo2";
-//         break;
+//            gen_op_dmfc0_watchlo2();
+            rn = "WatchLo2";
+//            break;
         case 3:
-//         gen_op_dmfc0_watchlo3();
-           rn = "WatchLo3";
-//         break;
+//            gen_op_dmfc0_watchlo3();
+            rn = "WatchLo3";
+//            break;
         case 4:
-//         gen_op_dmfc0_watchlo4();
-           rn = "WatchLo4";
-//         break;
+//            gen_op_dmfc0_watchlo4();
+            rn = "WatchLo4";
+//            break;
         case 5:
-//         gen_op_dmfc0_watchlo5();
-           rn = "WatchLo5";
-//         break;
+//            gen_op_dmfc0_watchlo5();
+            rn = "WatchLo5";
+//            break;
         case 6:
-//         gen_op_dmfc0_watchlo6();
-           rn = "WatchLo6";
-//         break;
+//            gen_op_dmfc0_watchlo6();
+            rn = "WatchLo6";
+//            break;
         case 7:
-//         gen_op_dmfc0_watchlo7();
-           rn = "WatchLo7";
-//         break;
+//            gen_op_dmfc0_watchlo7();
+            rn = "WatchLo7";
+//            break;
         default:
             goto die;
         }
@@ -3197,37 +3302,37 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 19:
         switch (sel) {
         case 0:
-           gen_op_mfc0_watchhi0();
-           rn = "WatchHi";
-           break;
+            gen_op_mfc0_watchhi0();
+            rn = "WatchHi";
+            break;
         case 1:
-//         gen_op_mfc0_watchhi1();
-           rn = "WatchHi1";
-//         break;
+//            gen_op_mfc0_watchhi1();
+            rn = "WatchHi1";
+//            break;
         case 2:
-//         gen_op_mfc0_watchhi2();
-           rn = "WatchHi2";
-//         break;
+//            gen_op_mfc0_watchhi2();
+            rn = "WatchHi2";
+//            break;
         case 3:
-//         gen_op_mfc0_watchhi3();
-           rn = "WatchHi3";
-//         break;
+//            gen_op_mfc0_watchhi3();
+            rn = "WatchHi3";
+//            break;
         case 4:
-//         gen_op_mfc0_watchhi4();
-           rn = "WatchHi4";
-//         break;
+//            gen_op_mfc0_watchhi4();
+            rn = "WatchHi4";
+//            break;
         case 5:
-//         gen_op_mfc0_watchhi5();
-           rn = "WatchHi5";
-//         break;
+//            gen_op_mfc0_watchhi5();
+            rn = "WatchHi5";
+//            break;
         case 6:
-//         gen_op_mfc0_watchhi6();
-           rn = "WatchHi6";
-//         break;
+//            gen_op_mfc0_watchhi6();
+            rn = "WatchHi6";
+//            break;
         case 7:
-//         gen_op_mfc0_watchhi7();
-           rn = "WatchHi7";
-//         break;
+//            gen_op_mfc0_watchhi7();
+            rn = "WatchHi7";
+//            break;
         default:
             goto die;
         }
@@ -3235,10 +3340,10 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 20:
         switch (sel) {
         case 0:
-           /* 64 bit MMU only */
-           gen_op_dmfc0_xcontext();
-           rn = "XContext";
-           break;
+            /* 64 bit MMU only */
+            gen_op_dmfc0_xcontext();
+            rn = "XContext";
+            break;
         default:
             goto die;
         }
@@ -3247,39 +3352,39 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
        /* Officially reserved, but sel 0 is used for R1x000 framemask */
         switch (sel) {
         case 0:
-           gen_op_mfc0_framemask();
-           rn = "Framemask";
-           break;
+            gen_op_mfc0_framemask();
+            rn = "Framemask";
+            break;
         default:
             goto die;
         }
         break;
     case 22:
-       /* ignored */
-       rn = "'Diagnostic"; /* implementation dependent */
-       break;
+        /* ignored */
+        rn = "'Diagnostic"; /* implementation dependent */
+        break;
     case 23:
         switch (sel) {
         case 0:
-           gen_op_mfc0_debug(); /* EJTAG support */
-           rn = "Debug";
-           break;
+            gen_op_mfc0_debug(); /* EJTAG support */
+            rn = "Debug";
+            break;
         case 1:
-//         gen_op_dmfc0_tracecontrol(); /* PDtrace support */
-           rn = "TraceControl";
-//         break;
+//            gen_op_dmfc0_tracecontrol(); /* PDtrace support */
+            rn = "TraceControl";
+//            break;
         case 2:
-//         gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
-           rn = "TraceControl2";
-//         break;
+//            gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
+            rn = "TraceControl2";
+//            break;
         case 3:
-//         gen_op_dmfc0_usertracedata(); /* PDtrace support */
-           rn = "UserTraceData";
-//         break;
+//            gen_op_dmfc0_usertracedata(); /* PDtrace support */
+            rn = "UserTraceData";
+//            break;
         case 4:
-//         gen_op_dmfc0_debug(); /* PDtrace support */
-           rn = "TraceBPC";
-//         break;
+//            gen_op_dmfc0_debug(); /* PDtrace support */
+            rn = "TraceBPC";
+//            break;
         default:
             goto die;
         }
@@ -3287,9 +3392,9 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 24:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_depc(); /* EJTAG support */
-           rn = "DEPC";
-           break;
+            gen_op_dmfc0_depc(); /* EJTAG support */
+            rn = "DEPC";
+            break;
         default:
             goto die;
         }
@@ -3297,37 +3402,37 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 25:
         switch (sel) {
         case 0:
-           gen_op_mfc0_performance0();
-           rn = "Performance0";
+            gen_op_mfc0_performance0();
+            rn = "Performance0";
             break;
         case 1:
-//         gen_op_dmfc0_performance1();
-           rn = "Performance1";
-//         break;
+//            gen_op_dmfc0_performance1();
+            rn = "Performance1";
+//            break;
         case 2:
-//         gen_op_dmfc0_performance2();
-           rn = "Performance2";
-//         break;
+//            gen_op_dmfc0_performance2();
+            rn = "Performance2";
+//            break;
         case 3:
-//         gen_op_dmfc0_performance3();
-           rn = "Performance3";
-//         break;
+//            gen_op_dmfc0_performance3();
+            rn = "Performance3";
+//            break;
         case 4:
-//         gen_op_dmfc0_performance4();
-           rn = "Performance4";
-//         break;
+//            gen_op_dmfc0_performance4();
+            rn = "Performance4";
+//            break;
         case 5:
-//         gen_op_dmfc0_performance5();
-           rn = "Performance5";
-//         break;
+//            gen_op_dmfc0_performance5();
+            rn = "Performance5";
+//            break;
         case 6:
-//         gen_op_dmfc0_performance6();
-           rn = "Performance6";
-//         break;
+//            gen_op_dmfc0_performance6();
+            rn = "Performance6";
+//            break;
         case 7:
-//         gen_op_dmfc0_performance7();
-           rn = "Performance7";
-//         break;
+//            gen_op_dmfc0_performance7();
+            rn = "Performance7";
+//            break;
         default:
             goto die;
         }
@@ -3339,8 +3444,8 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
         switch (sel) {
         /* ignored */
         case 0 ... 3:
-           rn = "CacheErr";
-           break;
+            rn = "CacheErr";
+            break;
         default:
             goto die;
         }
@@ -3388,9 +3493,9 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 30:
         switch (sel) {
         case 0:
-           gen_op_dmfc0_errorepc();
-           rn = "ErrorEPC";
-           break;
+            gen_op_dmfc0_errorepc();
+            rn = "ErrorEPC";
+            break;
         default:
             goto die;
         }
@@ -3398,15 +3503,15 @@ static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
     case 31:
         switch (sel) {
         case 0:
-           gen_op_mfc0_desave(); /* EJTAG support */
-           rn = "DESAVE";
-           break;
+            gen_op_mfc0_desave(); /* EJTAG support */
+            rn = "DESAVE";
+            break;
         default:
             goto die;
         }
         break;
     default:
-       goto die;
+        goto die;
     }
 #if defined MIPS_DEBUG_DISAS
     if (loglevel & CPU_LOG_TB_IN_ASM) {
@@ -3438,17 +3543,17 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
             rn = "Index";
             break;
         case 1:
-//         gen_op_dmtc0_mvpcontrol(); /* MT ASE */
+//            gen_op_dmtc0_mvpcontrol(); /* MT ASE */
             rn = "MVPControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_dmtc0_mvpconf0(); /* MT ASE */
+//            gen_op_dmtc0_mvpconf0(); /* MT ASE */
             rn = "MVPConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_dmtc0_mvpconf1(); /* MT ASE */
+//            gen_op_dmtc0_mvpconf1(); /* MT ASE */
             rn = "MVPConf1";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -3456,37 +3561,37 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 1:
         switch (sel) {
         case 0:
-           /* ignored */
+            /* ignored */
             rn = "Random";
-           break;
+            break;
         case 1:
-//         gen_op_dmtc0_vpecontrol(); /* MT ASE */
+//            gen_op_dmtc0_vpecontrol(); /* MT ASE */
             rn = "VPEControl";
-//         break;
+//            break;
         case 2:
-//         gen_op_dmtc0_vpeconf0(); /* MT ASE */
+//            gen_op_dmtc0_vpeconf0(); /* MT ASE */
             rn = "VPEConf0";
-//         break;
+//            break;
         case 3:
-//         gen_op_dmtc0_vpeconf1(); /* MT ASE */
+//            gen_op_dmtc0_vpeconf1(); /* MT ASE */
             rn = "VPEConf1";
-//         break;
+//            break;
         case 4:
-//         gen_op_dmtc0_YQMask(); /* MT ASE */
+//            gen_op_dmtc0_YQMask(); /* MT ASE */
             rn = "YQMask";
-//         break;
+//            break;
         case 5:
-//         gen_op_dmtc0_vpeschedule(); /* MT ASE */
+//            gen_op_dmtc0_vpeschedule(); /* MT ASE */
             rn = "VPESchedule";
-//         break;
+//            break;
         case 6:
-//         gen_op_dmtc0_vpeschefback(); /* MT ASE */
+//            gen_op_dmtc0_vpeschefback(); /* MT ASE */
             rn = "VPEScheFBack";
-//         break;
+//            break;
         case 7:
-//         gen_op_dmtc0_vpeopt(); /* MT ASE */
+//            gen_op_dmtc0_vpeopt(); /* MT ASE */
             rn = "VPEOpt";
-//         break;
+//            break;
         default:
             goto die;
         }
@@ -3494,37 +3599,37 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 2:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_entrylo0();
-           rn = "EntryLo0";
-           break;
+            gen_op_dmtc0_entrylo0();
+            rn = "EntryLo0";
+            break;
         case 1:
-//         gen_op_dmtc0_tcstatus(); /* MT ASE */
-           rn = "TCStatus";
-//         break;
+//            gen_op_dmtc0_tcstatus(); /* MT ASE */
+            rn = "TCStatus";
+//            break;
         case 2:
-//         gen_op_dmtc0_tcbind(); /* MT ASE */
-           rn = "TCBind";
-//         break;
+//            gen_op_dmtc0_tcbind(); /* MT ASE */
+            rn = "TCBind";
+//            break;
         case 3:
-//         gen_op_dmtc0_tcrestart(); /* MT ASE */
-           rn = "TCRestart";
-//         break;
+//            gen_op_dmtc0_tcrestart(); /* MT ASE */
+            rn = "TCRestart";
+//            break;
         case 4:
-//         gen_op_dmtc0_tchalt(); /* MT ASE */
-           rn = "TCHalt";
-//         break;
+//            gen_op_dmtc0_tchalt(); /* MT ASE */
+            rn = "TCHalt";
+//            break;
         case 5:
-//         gen_op_dmtc0_tccontext(); /* MT ASE */
-           rn = "TCContext";
-//         break;
+//            gen_op_dmtc0_tccontext(); /* MT ASE */
+            rn = "TCContext";
+//            break;
         case 6:
-//         gen_op_dmtc0_tcschedule(); /* MT ASE */
-           rn = "TCSchedule";
-//         break;
+//            gen_op_dmtc0_tcschedule(); /* MT ASE */
+            rn = "TCSchedule";
+//            break;
         case 7:
-//         gen_op_dmtc0_tcschefback(); /* MT ASE */
-           rn = "TCScheFBack";
-//         break;
+//            gen_op_dmtc0_tcschefback(); /* MT ASE */
+            rn = "TCScheFBack";
+//            break;
         default:
             goto die;
         }
@@ -3532,80 +3637,80 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 3:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_entrylo1();
-           rn = "EntryLo1";
-           break;
+            gen_op_dmtc0_entrylo1();
+            rn = "EntryLo1";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 4:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_context();
-           rn = "Context";
-           break;
+            gen_op_dmtc0_context();
+            rn = "Context";
+            break;
         case 1:
-//         gen_op_dmtc0_contextconfig(); /* SmartMIPS ASE */
-           rn = "ContextConfig";
-//         break;
+//           gen_op_dmtc0_contextconfig(); /* SmartMIPS ASE */
+            rn = "ContextConfig";
+//           break;
         default:
             goto die;
-       }
+        }
         break;
     case 5:
         switch (sel) {
         case 0:
-           gen_op_mtc0_pagemask();
-           rn = "PageMask";
-           break;
+            gen_op_mtc0_pagemask();
+            rn = "PageMask";
+            break;
         case 1:
-           gen_op_mtc0_pagegrain();
-           rn = "PageGrain";
-           break;
+            gen_op_mtc0_pagegrain();
+            rn = "PageGrain";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 6:
         switch (sel) {
         case 0:
-           gen_op_mtc0_wired();
-           rn = "Wired";
-           break;
+            gen_op_mtc0_wired();
+            rn = "Wired";
+            break;
         case 1:
-//         gen_op_dmtc0_srsconf0(); /* shadow registers */
-           rn = "SRSConf0";
-//         break;
+//            gen_op_dmtc0_srsconf0(); /* shadow registers */
+            rn = "SRSConf0";
+//            break;
         case 2:
-//         gen_op_dmtc0_srsconf1(); /* shadow registers */
-           rn = "SRSConf1";
-//         break;
+//            gen_op_dmtc0_srsconf1(); /* shadow registers */
+            rn = "SRSConf1";
+//            break;
         case 3:
-//         gen_op_dmtc0_srsconf2(); /* shadow registers */
-           rn = "SRSConf2";
-//         break;
+//            gen_op_dmtc0_srsconf2(); /* shadow registers */
+            rn = "SRSConf2";
+//            break;
         case 4:
-//         gen_op_dmtc0_srsconf3(); /* shadow registers */
-           rn = "SRSConf3";
-//         break;
+//            gen_op_dmtc0_srsconf3(); /* shadow registers */
+            rn = "SRSConf3";
+//            break;
         case 5:
-//         gen_op_dmtc0_srsconf4(); /* shadow registers */
-           rn = "SRSConf4";
-//         break;
+//            gen_op_dmtc0_srsconf4(); /* shadow registers */
+            rn = "SRSConf4";
+//            break;
         default:
             goto die;
-       }
+        }
         break;
     case 7:
         switch (sel) {
         case 0:
-           gen_op_mtc0_hwrena();
-           rn = "HWREna";
-           break;
+            gen_op_mtc0_hwrena();
+            rn = "HWREna";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 8:
         /* ignored */
@@ -3614,115 +3719,119 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 9:
         switch (sel) {
         case 0:
-           gen_op_mtc0_count();
-           rn = "Count";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mtc0_count();
+            rn = "Count";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 10:
         switch (sel) {
         case 0:
-           gen_op_mtc0_entryhi();
-           rn = "EntryHi";
-           break;
+            gen_op_mtc0_entryhi();
+            rn = "EntryHi";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 11:
         switch (sel) {
         case 0:
-           gen_op_mtc0_compare();
-           rn = "Compare";
-           break;
-       /* 6,7 are implementation dependent */
+            gen_op_mtc0_compare();
+            rn = "Compare";
+            break;
+        /* 6,7 are implementation dependent */
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 12:
         switch (sel) {
         case 0:
-           gen_op_mtc0_status();
-           rn = "Status";
-           break;
+            gen_op_mtc0_status();
+            rn = "Status";
+            break;
         case 1:
-           gen_op_mtc0_intctl();
-           rn = "IntCtl";
-           break;
+            gen_op_mtc0_intctl();
+            rn = "IntCtl";
+            break;
         case 2:
-           gen_op_mtc0_srsctl();
-           rn = "SRSCtl";
-           break;
+            gen_op_mtc0_srsctl();
+            rn = "SRSCtl";
+            break;
         case 3:
-         gen_op_mtc0_srsmap(); /* shadow registers */
-           rn = "SRSMap";
-         break;
+            gen_op_mtc0_srsmap(); /* shadow registers */
+            rn = "SRSMap";
+            break;
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 13:
         switch (sel) {
         case 0:
-           gen_op_mtc0_cause();
-           rn = "Cause";
-           break;
+            gen_op_mtc0_cause();
+            rn = "Cause";
+            break;
         default:
             goto die;
-       }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        }
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 14:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_epc();
-           rn = "EPC";
-           break;
+            gen_op_dmtc0_epc();
+            rn = "EPC";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 15:
         switch (sel) {
         case 0:
-           /* ignored */
-           rn = "PRid";
-           break;
+            /* ignored */
+            rn = "PRid";
+            break;
         case 1:
-           gen_op_mtc0_ebase();
-           rn = "EBase";
-           break;
+            gen_op_mtc0_ebase();
+            rn = "EBase";
+            break;
         default:
             goto die;
-       }
+        }
         break;
     case 16:
         switch (sel) {
         case 0:
             gen_op_mtc0_config0();
             rn = "Config";
+            /* Stop translation as we may have switched the execution mode */
+            ctx->bstate = BS_STOP;
             break;
         case 1:
-           /* ignored */
+            /* ignored */
             rn = "Config1";
             break;
         case 2:
             gen_op_mtc0_config2();
             rn = "Config2";
+            /* Stop translation as we may have switched the execution mode */
+            ctx->bstate = BS_STOP;
             break;
         case 3:
-           /* ignored */
+            /* ignored */
             rn = "Config3";
             break;
         /* 6,7 are implementation dependent */
@@ -3730,15 +3839,13 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
             rn = "Invalid config selector";
             goto die;
         }
-        /* Stop translation as we may have switched the execution mode */
-        ctx->bstate = BS_STOP;
         break;
     case 17:
         switch (sel) {
         case 0:
-           /* ignored */
-           rn = "LLAddr";
-           break;
+            /* ignored */
+            rn = "LLAddr";
+            break;
         default:
             goto die;
         }
@@ -3746,37 +3853,37 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 18:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_watchlo0();
-           rn = "WatchLo";
-           break;
+            gen_op_dmtc0_watchlo0();
+            rn = "WatchLo";
+            break;
         case 1:
-//         gen_op_dmtc0_watchlo1();
-           rn = "WatchLo1";
-//         break;
+//            gen_op_dmtc0_watchlo1();
+            rn = "WatchLo1";
+//            break;
         case 2:
-//         gen_op_dmtc0_watchlo2();
-           rn = "WatchLo2";
-//         break;
+//            gen_op_dmtc0_watchlo2();
+            rn = "WatchLo2";
+//            break;
         case 3:
-//         gen_op_dmtc0_watchlo3();
-           rn = "WatchLo3";
-//         break;
+//            gen_op_dmtc0_watchlo3();
+            rn = "WatchLo3";
+//            break;
         case 4:
-//         gen_op_dmtc0_watchlo4();
-           rn = "WatchLo4";
-//         break;
+//            gen_op_dmtc0_watchlo4();
+            rn = "WatchLo4";
+//            break;
         case 5:
-//         gen_op_dmtc0_watchlo5();
-           rn = "WatchLo5";
-//         break;
+//            gen_op_dmtc0_watchlo5();
+            rn = "WatchLo5";
+//            break;
         case 6:
-//         gen_op_dmtc0_watchlo6();
-           rn = "WatchLo6";
-//         break;
+//            gen_op_dmtc0_watchlo6();
+            rn = "WatchLo6";
+//            break;
         case 7:
-//         gen_op_dmtc0_watchlo7();
-           rn = "WatchLo7";
-//         break;
+//            gen_op_dmtc0_watchlo7();
+            rn = "WatchLo7";
+//            break;
         default:
             goto die;
         }
@@ -3784,37 +3891,37 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 19:
         switch (sel) {
         case 0:
-           gen_op_mtc0_watchhi0();
-           rn = "WatchHi";
-           break;
+            gen_op_mtc0_watchhi0();
+            rn = "WatchHi";
+            break;
         case 1:
-//         gen_op_dmtc0_watchhi1();
-           rn = "WatchHi1";
-//         break;
+//            gen_op_dmtc0_watchhi1();
+            rn = "WatchHi1";
+//            break;
         case 2:
-//         gen_op_dmtc0_watchhi2();
-           rn = "WatchHi2";
-//         break;
+//            gen_op_dmtc0_watchhi2();
+            rn = "WatchHi2";
+//            break;
         case 3:
-//         gen_op_dmtc0_watchhi3();
-           rn = "WatchHi3";
-//         break;
+//            gen_op_dmtc0_watchhi3();
+            rn = "WatchHi3";
+//            break;
         case 4:
-//         gen_op_dmtc0_watchhi4();
-           rn = "WatchHi4";
-//         break;
+//            gen_op_dmtc0_watchhi4();
+            rn = "WatchHi4";
+//            break;
         case 5:
-//         gen_op_dmtc0_watchhi5();
-           rn = "WatchHi5";
-//         break;
+//            gen_op_dmtc0_watchhi5();
+            rn = "WatchHi5";
+//            break;
         case 6:
-//         gen_op_dmtc0_watchhi6();
-           rn = "WatchHi6";
-//         break;
+//            gen_op_dmtc0_watchhi6();
+            rn = "WatchHi6";
+//            break;
         case 7:
-//         gen_op_dmtc0_watchhi7();
-           rn = "WatchHi7";
-//         break;
+//            gen_op_dmtc0_watchhi7();
+            rn = "WatchHi7";
+//            break;
         default:
             goto die;
         }
@@ -3822,10 +3929,10 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 20:
         switch (sel) {
         case 0:
-           /* 64 bit MMU only */
-           gen_op_dmtc0_xcontext();
-           rn = "XContext";
-           break;
+            /* 64 bit MMU only */
+            gen_op_dmtc0_xcontext();
+            rn = "XContext";
+            break;
         default:
             goto die;
         }
@@ -3834,9 +3941,9 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
        /* Officially reserved, but sel 0 is used for R1x000 framemask */
         switch (sel) {
         case 0:
-           gen_op_mtc0_framemask();
-           rn = "Framemask";
-           break;
+            gen_op_mtc0_framemask();
+            rn = "Framemask";
+            break;
         default:
             goto die;
         }
@@ -3844,41 +3951,41 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 22:
         /* ignored */
         rn = "Diagnostic"; /* implementation dependent */
-       break;
+        break;
     case 23:
         switch (sel) {
         case 0:
-           gen_op_mtc0_debug(); /* EJTAG support */
-           rn = "Debug";
-           break;
+            gen_op_mtc0_debug(); /* EJTAG support */
+            rn = "Debug";
+            break;
         case 1:
-//         gen_op_dmtc0_tracecontrol(); /* PDtrace support */
-           rn = "TraceControl";
-//         break;
+//            gen_op_dmtc0_tracecontrol(); /* PDtrace support */
+            rn = "TraceControl";
+//            break;
         case 2:
-//         gen_op_dmtc0_tracecontrol2(); /* PDtrace support */
-           rn = "TraceControl2";
-//         break;
+//            gen_op_dmtc0_tracecontrol2(); /* PDtrace support */
+            rn = "TraceControl2";
+//            break;
         case 3:
-//         gen_op_dmtc0_usertracedata(); /* PDtrace support */
-           rn = "UserTraceData";
-//         break;
+//            gen_op_dmtc0_usertracedata(); /* PDtrace support */
+            rn = "UserTraceData";
+//            break;
         case 4:
-//         gen_op_dmtc0_debug(); /* PDtrace support */
-           rn = "TraceBPC";
-//         break;
+//            gen_op_dmtc0_debug(); /* PDtrace support */
+            rn = "TraceBPC";
+//            break;
         default:
             goto die;
         }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     case 24:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_depc(); /* EJTAG support */
-           rn = "DEPC";
-           break;
+            gen_op_dmtc0_depc(); /* EJTAG support */
+            rn = "DEPC";
+            break;
         default:
             goto die;
         }
@@ -3886,55 +3993,55 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 25:
         switch (sel) {
         case 0:
-           gen_op_mtc0_performance0();
-           rn = "Performance0";
-           break;
+            gen_op_mtc0_performance0();
+            rn = "Performance0";
+            break;
         case 1:
-//         gen_op_dmtc0_performance1();
-           rn = "Performance1";
-//         break;
+//            gen_op_dmtc0_performance1();
+            rn = "Performance1";
+//            break;
         case 2:
-//         gen_op_dmtc0_performance2();
-           rn = "Performance2";
-//         break;
+//            gen_op_dmtc0_performance2();
+            rn = "Performance2";
+//            break;
         case 3:
-//         gen_op_dmtc0_performance3();
-           rn = "Performance3";
-//         break;
+//            gen_op_dmtc0_performance3();
+            rn = "Performance3";
+//            break;
         case 4:
-//         gen_op_dmtc0_performance4();
-           rn = "Performance4";
-//         break;
+//            gen_op_dmtc0_performance4();
+            rn = "Performance4";
+//            break;
         case 5:
-//         gen_op_dmtc0_performance5();
-           rn = "Performance5";
-//         break;
+//            gen_op_dmtc0_performance5();
+            rn = "Performance5";
+//            break;
         case 6:
-//         gen_op_dmtc0_performance6();
-           rn = "Performance6";
-//         break;
+//            gen_op_dmtc0_performance6();
+            rn = "Performance6";
+//            break;
         case 7:
-//         gen_op_dmtc0_performance7();
-           rn = "Performance7";
-//         break;
+//            gen_op_dmtc0_performance7();
+            rn = "Performance7";
+//            break;
         default:
             goto die;
         }
-       break;
+        break;
     case 26:
-       /* ignored */
+        /* ignored */
         rn = "ECC";
-       break;
+        break;
     case 27:
         switch (sel) {
         case 0 ... 3:
-           /* ignored */
-           rn = "CacheErr";
-           break;
+            /* ignored */
+            rn = "CacheErr";
+            break;
         default:
             goto die;
         }
-       break;
+        break;
     case 28:
         switch (sel) {
         case 0:
@@ -3948,7 +4055,7 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
         case 3:
         case 5:
         case 7:
-           gen_op_mtc0_datalo();
+            gen_op_mtc0_datalo();
             rn = "DataLo";
             break;
         default:
@@ -3968,20 +4075,20 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
         case 3:
         case 5:
         case 7:
-           gen_op_mtc0_datahi();
+            gen_op_mtc0_datahi();
             rn = "DataHi";
             break;
         default:
             rn = "invalid sel";
             goto die;
         }
-       break;
+        break;
     case 30:
         switch (sel) {
         case 0:
-           gen_op_dmtc0_errorepc();
-           rn = "ErrorEPC";
-           break;
+            gen_op_dmtc0_errorepc();
+            rn = "ErrorEPC";
+            break;
         default:
             goto die;
         }
@@ -3989,17 +4096,17 @@ static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
     case 31:
         switch (sel) {
         case 0:
-           gen_op_mtc0_desave(); /* EJTAG support */
-           rn = "DESAVE";
-           break;
+            gen_op_mtc0_desave(); /* EJTAG support */
+            rn = "DESAVE";
+            break;
         default:
             goto die;
         }
-       /* Stop translation as we may have switched the execution mode */
-       ctx->bstate = BS_STOP;
+        /* Stop translation as we may have switched the execution mode */
+        ctx->bstate = BS_STOP;
         break;
     default:
-       goto die;
+        goto die;
     }
 #if defined MIPS_DEBUG_DISAS
     if (loglevel & CPU_LOG_TB_IN_ASM) {
@@ -4018,6 +4125,7 @@ die:
 #endif
     generate_exception(ctx, EXCP_RI);
 }
+#endif /* TARGET_MIPS64 */
 
 static void gen_cp0 (DisasContext *ctx, uint32_t opc, int rt, int rd)
 {
@@ -4034,15 +4142,11 @@ static void gen_cp0 (DisasContext *ctx, uint32_t opc, int rt, int rd)
         opn = "mfc0";
         break;
     case OPC_MTC0:
-        /* If we get an exception, we want to restart at next instruction */
-        /* XXX: breaks for mtc in delay slot */
-        ctx->pc += 4;
-        save_cpu_state(ctx, 1);
-        ctx->pc -= 4;
         GEN_LOAD_REG_TN(T0, rt);
         gen_mtc0(ctx, rd, ctx->opcode & 0x7);
         opn = "mtc0";
         break;
+#ifdef TARGET_MIPS64
     case OPC_DMFC0:
         if (rt == 0) {
             /* Treat as NOP */
@@ -4053,15 +4157,11 @@ static void gen_cp0 (DisasContext *ctx, uint32_t opc, int rt, int rd)
         opn = "dmfc0";
         break;
     case OPC_DMTC0:
-        /* If we get an exception, we want to restart at next instruction */
-        /* XXX: breaks for dmtc in delay slot */
-        ctx->pc += 4;
-        save_cpu_state(ctx, 1);
-        ctx->pc -= 4;
         GEN_LOAD_REG_TN(T0, rt);
         gen_dmtc0(ctx, rd, ctx->opcode & 0x7);
         opn = "dmtc0";
         break;
+#endif
 #if defined(MIPS_USES_R4K_TLB)
     case OPC_TLBWI:
         gen_op_tlbwi();
@@ -4566,6 +4666,7 @@ static void decode_opc (CPUState *env, DisasContext *ctx)
 
     /* make sure instructions are on a word boundary */
     if (ctx->pc & 0x3) {
+        env->CP0_BadVAddr = ctx->pc;
         generate_exception(ctx, EXCP_AdEL);
         return;
     }
@@ -4614,20 +4715,29 @@ static void decode_opc (CPUState *env, DisasContext *ctx)
         case OPC_MTLO:          /* Move to HI/LO */
             gen_HILO(ctx, op1, rs);
             break;
-        case OPC_PMON:          /* Pmon entry point */
+        case OPC_PMON:          /* Pmon entry point, also R4010 selsl */
+#ifdef MIPS_STRICT_STANDARD
+            MIPS_INVAL("PMON / selsl");
+            generate_exception(ctx, EXCP_RI);
+#else
             gen_op_pmon(sa);
+#endif
             break;
         case OPC_SYSCALL:
             generate_exception(ctx, EXCP_SYSCALL);
-            ctx->bstate = BS_EXCP;
             break;
         case OPC_BREAK:
             generate_exception(ctx, EXCP_BREAK);
             break;
-        case OPC_SPIM:        /* SPIM ? */
+        case OPC_SPIM:
+#ifdef MIPS_STRICT_STANDARD
+            MIPS_INVAL("SPIM");
+            generate_exception(ctx, EXCP_RI);
+#else
            /* Implemented as RI exception for now. */
             MIPS_INVAL("spim (unofficial)");
             generate_exception(ctx, EXCP_RI);
+#endif
             break;
         case OPC_SYNC:
             /* Treat as a noop. */
@@ -4703,83 +4813,86 @@ static void decode_opc (CPUState *env, DisasContext *ctx)
         }
         break;
     case OPC_SPECIAL3:
-        op1 = MASK_SPECIAL3(ctx->opcode);
-        switch (op1) {
-        case OPC_EXT:
-        case OPC_INS:
-            gen_bitops(ctx, op1, rt, rs, sa, rd);
+         op1 = MASK_SPECIAL3(ctx->opcode);
+         switch (op1) {
+         case OPC_EXT:
+         case OPC_INS:
+             gen_bitops(ctx, op1, rt, rs, sa, rd);
+             break;
+         case OPC_BSHFL:
+             op2 = MASK_BSHFL(ctx->opcode);
+             switch (op2) {
+             case OPC_WSBH:
+                 GEN_LOAD_REG_TN(T1, rt);
+                 gen_op_wsbh();
+                 break;
+             case OPC_SEB:
+                 GEN_LOAD_REG_TN(T1, rt);
+                 gen_op_seb();
+                 break;
+             case OPC_SEH:
+                 GEN_LOAD_REG_TN(T1, rt);
+                 gen_op_seh();
+                 break;
+             default:            /* Invalid */
+                 MIPS_INVAL("bshfl");
+                 generate_exception(ctx, EXCP_RI);
+                 break;
+            }
+            GEN_STORE_TN_REG(rd, T0);
             break;
-        case OPC_BSHFL:
-            op2 = MASK_BSHFL(ctx->opcode);
-            switch (op2) {
-            case OPC_WSBH:
-                GEN_LOAD_REG_TN(T1, rt);
-                gen_op_wsbh();
+        case OPC_RDHWR:
+            switch (rd) {
+            case 0:
+                save_cpu_state(ctx, 1);
+                gen_op_rdhwr_cpunum();
                 break;
-            case OPC_SEB:
-                GEN_LOAD_REG_TN(T1, rt);
-                gen_op_seb();
+            case 1:
+                save_cpu_state(ctx, 1);
+                gen_op_rdhwr_synci_step();
                 break;
-            case OPC_SEH:
-                GEN_LOAD_REG_TN(T1, rt);
-                gen_op_seh();
+            case 2:
+                save_cpu_state(ctx, 1);
+                gen_op_rdhwr_cc();
                 break;
-             default:            /* Invalid */
-                MIPS_INVAL("bshfl");
-                generate_exception(ctx, EXCP_RI);
+            case 3:
+                save_cpu_state(ctx, 1);
+                gen_op_rdhwr_ccres();
                 break;
-           }
-           GEN_STORE_TN_REG(rd, T0);
-           break;
-       case OPC_RDHWR:
-           switch (rd) {
-           case 0:
-               gen_op_rdhwr_cpunum();
-               break;
-           case 1:
-               gen_op_rdhwr_synci_step();
-               break;
-           case 2:
-               gen_op_rdhwr_cc();
-               break;
-           case 3:
-               gen_op_rdhwr_ccres();
-               break;
+            case 29:
 #if defined (CONFIG_USER_ONLY)
-           case 29:
-               gen_op_tls_value ();
-               GEN_STORE_TN_REG(rt, T0);
-               break;
+                gen_op_tls_value ();
+                break;
 #endif
-           default:            /* Invalid */
-               MIPS_INVAL("rdhwr");
-               generate_exception(ctx, EXCP_RI);
-               break;
-           }
-           GEN_STORE_TN_REG(rt, T0);
-           break;
+            default:            /* Invalid */
+                MIPS_INVAL("rdhwr");
+                generate_exception(ctx, EXCP_RI);
+                break;
+            }
+            GEN_STORE_TN_REG(rt, T0);
+            break;
 #ifdef TARGET_MIPS64
-       case OPC_DEXTM ... OPC_DEXT:
-       case OPC_DINSM ... OPC_DINS:
-           gen_bitops(ctx, op1, rt, rs, sa, rd);
-            break;
-       case OPC_DBSHFL:
-           op2 = MASK_DBSHFL(ctx->opcode);
-           switch (op2) {
-           case OPC_DSBH:
-               GEN_LOAD_REG_TN(T1, rt);
-               gen_op_dsbh();
-               break;
-           case OPC_DSHD:
-               GEN_LOAD_REG_TN(T1, rt);
-               gen_op_dshd();
-               break;
+        case OPC_DEXTM ... OPC_DEXT:
+        case OPC_DINSM ... OPC_DINS:
+            gen_bitops(ctx, op1, rt, rs, sa, rd);
+            break;
+        case OPC_DBSHFL:
+            op2 = MASK_DBSHFL(ctx->opcode);
+            switch (op2) {
+            case OPC_DSBH:
+                GEN_LOAD_REG_TN(T1, rt);
+                gen_op_dsbh();
+                break;
+            case OPC_DSHD:
+                GEN_LOAD_REG_TN(T1, rt);
+                gen_op_dshd();
+                break;
             default:            /* Invalid */
                 MIPS_INVAL("dbshfl");
                 generate_exception(ctx, EXCP_RI);
                 break;
-           }
-           GEN_STORE_TN_REG(rd, T0);
+            }
+            GEN_STORE_TN_REG(rd, T0);
 #endif
         default:            /* Invalid */
             MIPS_INVAL("special3");
@@ -4808,6 +4921,7 @@ static void decode_opc (CPUState *env, DisasContext *ctx)
         }
         break;
     case OPC_CP0:
+        save_cpu_state(ctx, 1);
         gen_op_cp0_enabled();
         op1 = MASK_CP0(ctx->opcode);
         switch (op1) {
@@ -4945,6 +5059,9 @@ static void decode_opc (CPUState *env, DisasContext *ctx)
             gen_op_cp1_enabled();
             op1 = MASK_CP3(ctx->opcode);
             switch (op1) {
+            case OPC_PREFX:
+                /* treat as noop */
+                break;
             /* Not implemented */
             default:
                 generate_exception (ctx, EXCP_RI);
@@ -4984,7 +5101,7 @@ static void decode_opc (CPUState *env, DisasContext *ctx)
         break;
     }
     if (ctx->hflags & MIPS_HFLAG_BMASK) {
-        int hflags = ctx->hflags;
+        int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
         /* Branches completion */
         ctx->hflags &= ~MIPS_HFLAG_BMASK;
         ctx->bstate = BS_BRANCH;
@@ -5117,15 +5234,26 @@ gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
     if (env->singlestep_enabled) {
         save_cpu_state(ctxp, ctx.bstate == BS_NONE);
         gen_op_debug();
-        goto done_generating;
-    }
-    else if (ctx.bstate != BS_BRANCH && ctx.bstate != BS_EXCP) {
-        save_cpu_state(ctxp, 0);
-        gen_goto_tb(&ctx, 0, ctx.pc);
+    } else {
+       switch (ctx.bstate) {
+        case BS_EXCP:
+            gen_op_interrupt_restart();
+            break;
+        case BS_STOP:
+            gen_op_interrupt_restart();
+            /* Fall through. */
+        case BS_NONE:
+            save_cpu_state(ctxp, 0);
+            gen_goto_tb(&ctx, 0, ctx.pc);
+            break;
+        case BS_BRANCH:
+        default:
+            break;
+       }
+        gen_op_reset_T0();
+        /* Generate the return instruction. */
+        gen_op_exit_tb();
     }
-    gen_op_reset_T0();
-    /* Generate the return instruction */
-    gen_op_exit_tb();
 done_generating:
     *gen_opc_ptr = INDEX_op_end;
     if (search_pc) {
@@ -5305,7 +5433,11 @@ void cpu_reset (CPUMIPSState *env)
     /* SMP not implemented */
     env->CP0_EBase = 0x80000000;
     env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
+    /* vectored interrupts not implemented, timer on int 7,
+       no performance counters. */
+    env->CP0_IntCtl = 0xe0000000;
     env->CP0_WatchLo = 0;
+    env->CP0_WatchHi = 0;
     /* Count register increments in debug mode, EJTAG version 1 */
     env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
 #endif
@@ -5314,9 +5446,6 @@ void cpu_reset (CPUMIPSState *env)
     env->hflags |= MIPS_HFLAG_UM;
     env->user_mode_only = 1;
 #endif
-    /* XXX some guesswork here, values are CPU specific */
-    env->SYNCI_Step = 16;
-    env->CCRes = 2;
 }
 
 #include "translate_init.c"
This page took 0.191689 seconds and 4 git commands to generate.