--- nono/m88xx0/m88100ops.cpp 2026/04/29 17:04:38 1.1.1.3 +++ nono/m88xx0/m88100ops.cpp 2026/04/29 17:04:44 1.1.1.5 @@ -5,6 +5,8 @@ // #include "m88100acc.h" +#include +#include // 命令のフィールド取り出し #define FLD_D m88100opf_D(opX) @@ -29,21 +31,58 @@ #define rD (r[FLD_D]) #define rS1 (r[FLD_S1]) #define rS2 (r[FLD_S2]) +// ダブルワードの2ワード目 +#define FLD_D2 ((FLD_D + 1) & 0x1f) +#define rD2 (r[FLD_D2]) + +// FP フィールド +#define FP_T1 m88100opf_FP_T1(opX) +#define FP_T2 m88100opf_FP_T2(opX) +#define FP_TD m88100opf_FP_TD(opX) + +// XXX: 暫定 +#include "fp.h" +#define FP_GET(v, t, n) \ +do { \ + if (t == 0) { \ + v = u2f(r[n]); \ + } else if (t == 1) { \ + if (n == 31) { \ + FPException(M88K_FPEXCEP_FUNIMP); \ + return; \ + } \ + v = u2d(((uint64)r[n] << 32) | r[n + 1]); \ + } else { \ + FPException(M88K_FPEXCEP_FROP); \ + return; \ + } \ +} while (0) +#define FP_SET(t, n, v) \ +do { \ + if (t == 0) { \ + r[n] = f2u(v); \ + } else if (t == 1) { \ + if (n == 31) { \ + FPException(M88K_FPEXCEP_FUNIMP); \ + return; \ + } \ + uint64 tmp = d2u(v); \ + r[n] = tmp >> 32; \ + r[n + 1] = (uint32)tmp; \ + } else { \ + FPException(M88K_FPEXCEP_FROP); \ + return; \ + } \ +} while (0) // ブランチ命令入り口 inline void -m88kcpu::EnterBranch() -{ -} - -// ブランチ本体 -inline void -m88kcpu::DoBranch(uint32 toaddr) +m88kcpu::EnterBranch(uint32 toaddr) { // ブランチヒストリに登録しつつ、 // ブランチヒストリからブランチ状況を取得 - auto e = brhist.AddEntry(xip, toaddr, opX); + auto e = brhist.AddEntry(xip | (IsSuper() ? 1 : 0), toaddr, opX); fip = toaddr; // STOP 検出。 @@ -97,10 +136,12 @@ m88kcpu::ExitBranch() } // 遅延ブランチ出口 +// 速度を稼ぐため、ビット反転だけでこれを区別しているので、 +// 同じ op 中で複数回呼び出さないこと。 inline void m88kcpu::ExitDelayBranch() { - opF = OpSetDelay(opF); + opF ^= DELAYSLOT; } // ロードストアユニットの usr の処理。 @@ -279,10 +320,12 @@ OP_DEF(xmem_bu_imm) addr = rS1 + IMM16; LDST_ALIGN(1); + AddCycle(4); // Table.7-3 + lastaddr = addr; tmp = cmmu[1].xmem_8(addr, rD); if ((int64)tmp < 0) { - XmemDataException(addr, rD, DM_BU | DM_LOCK); + XmemDataException(addr, DM_BU | DM_LOCK); return; } if (FLD_D == 0) @@ -299,10 +342,12 @@ OP_DEF(xmem_w_imm) addr = rS1 + IMM16; LDST_ALIGN(4); + AddCycle(4); // Table.7-3 + lastaddr = addr; tmp = cmmu[1].xmem_32(addr, rD); if ((int64)tmp < 0) { - XmemDataException(addr, rD, DM_W | DM_LOCK); + XmemDataException(addr, DM_W | DM_LOCK); return; } if (FLD_D == 0) @@ -314,66 +359,72 @@ OP_DEF(xmem_w_imm) OP_DEF(ld_hu_imm) { uint32 addr; - uint64 tmp; + uint64 data; addr = rS1 + IMM16; LDST_ALIGN(2); + AddCycle(3); // Table.7-3 + lastaddr = addr; - tmp = cmmu[1].load_16(addr); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_HU); + data = cmmu[1].load_16(addr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_HU); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data; } // 000011_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_bu_imm) { uint32 addr; - uint64 tmp; + uint64 data; addr = rS1 + IMM16; LDST_ALIGN(1); + AddCycle(3); // Table.7-3 + lastaddr = addr; - tmp = cmmu[1].load_8(addr); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_BU); + data = cmmu[1].load_8(addr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_BU); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data; } // 000100_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_d_imm) { uint32 addr; - uint64 tmp, tmp2; + uint64 data1, data2; addr = rS1 + IMM16; LDST_ALIGN(8); + AddCycle(4); // Table.7-3 + lastaddr = addr; - tmp = cmmu[1].load_32(addr); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_D1); + data1 = cmmu[1].load_32(addr); + if ((int64)data1 < 0) { + ReadDataException64(addr, DM_D1); return; } addr += 4; - tmp2 = cmmu[1].load_32(addr); - if ((int64)tmp2 < 0) { - ReadDataException(addr, DM_D2); + data2 = cmmu[1].load_32(addr); + if ((int64)data2 < 0) { + ReadDataException64(addr, DM_D2); return; } - rD = tmp; - r[(FLD_D + 1) & 0x1f] = tmp2; + rD = data1; + rD2 = data2; r[0] = 0; } @@ -381,78 +432,89 @@ OP_DEF(ld_d_imm) OP_DEF(ld_w_imm) { uint32 addr; - uint64 tmp; + uint64 data; addr = rS1 + IMM16; LDST_ALIGN(4); + AddCycle(3); // Table.7-3 + lastaddr = addr; - tmp = cmmu[1].load_32(addr); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_W); + data = cmmu[1].load_32(addr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_W); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data; } // 000110_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_h_imm) { uint32 addr; - uint64 tmp; + uint64 data; addr = rS1 + IMM16; LDST_ALIGN(2); + AddCycle(3); // Table.7-3 + lastaddr = addr; - tmp = cmmu[1].load_16(addr); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_H); + data = cmmu[1].load_16(addr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_H); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int16)tmp; + rD = (uint32)(int32)(int16)data; } // 000111_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_b_imm) { uint32 addr; - uint64 tmp; + uint64 data; addr = rS1 + IMM16; LDST_ALIGN(1); + AddCycle(3); // Table.7-3 + lastaddr = addr; - tmp = cmmu[1].load_8(addr); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_B); + data = cmmu[1].load_8(addr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_B); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int8)tmp; + rD = (uint32)(int32)(int8)data; } // 001000_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(st_d_imm) { uint32 addr; + uint64 rv; addr = rS1 + IMM16; LDST_ALIGN(8); + AddCycle(1 + 4); // Table.7-3 + lastaddr = addr; - if ((int64)cmmu[1].store_32(addr, rD) < 0) { - WriteDataException(addr, rD, DM_D1); + rv = cmmu[1].store_32(addr, rD); + if ((int64)rv < 0) { + WriteDataException64(addr, DM_D1); return; } addr += 4; - if ((int64)cmmu[1].store_32(addr, r[(FLD_D + 1) & 0x1f]) < 0) { - WriteDataException(addr, r[(FLD_D + 1) & 0x1f], DM_D2); + rv = cmmu[1].store_32(addr, rD2); + if ((int64)rv < 0) { + WriteDataException64(addr, DM_D2); return; } } @@ -461,13 +523,17 @@ OP_DEF(st_d_imm) OP_DEF(st_w_imm) { uint32 addr; + uint64 rv; addr = rS1 + IMM16; LDST_ALIGN(4); + AddCycle(3); // Table.7-3 + lastaddr = addr; - if ((int64)cmmu[1].store_32(addr, rD) < 0) { - WriteDataException(addr, rD, DM_W); + rv = cmmu[1].store_32(addr, rD); + if ((int64)rv < 0) { + WriteDataException32(addr, DM_W); return; } } @@ -476,13 +542,17 @@ OP_DEF(st_w_imm) OP_DEF(st_h_imm) { uint32 addr; + uint64 rv; addr = rS1 + IMM16; LDST_ALIGN(2); + AddCycle(3); // Table.7-3 + lastaddr = addr; - if ((int64)cmmu[1].store_16(addr, rD) < 0) { - WriteDataException(addr, rD, DM_H); + rv = cmmu[1].store_16(addr, rD & 0xffff); + if ((int64)rv < 0) { + WriteDataException32(addr, DM_H); return; } } @@ -491,13 +561,17 @@ OP_DEF(st_h_imm) OP_DEF(st_b_imm) { uint32 addr; + uint64 rv; addr = rS1 + IMM16; LDST_ALIGN(1); + AddCycle(3); // Table.7-3 + lastaddr = addr; - if ((int64)cmmu[1].store_8(addr, rD) < 0) { - WriteDataException(addr, rD, DM_B); + rv = cmmu[1].store_8(addr, rD & 0xff); + if ((int64)rv < 0) { + WriteDataException32(addr, DM_B); return; } } @@ -621,6 +695,9 @@ OP_DEF(divu_imm) fpu_unimpl(); return; } + + AddCycle(38); // Table.7-6 (ただしざっくり) + if (IMM16 == 0) { Exception(M88K_EXCEP_INT_DIV); return; @@ -637,6 +714,9 @@ OP_DEF(mul_imm) fpu_unimpl(); return; } + + AddCycle(4); // Table.7-6 (ただしざっくり) + if (FLD_D == 0) return; rD = rS1 * IMM16; @@ -677,6 +757,9 @@ OP_DEF(div_imm) fpu_unimpl(); return; } + + AddCycle(38); // Table.7-6 (ただしざっくり) + if ((int32)rS1 < 0 || IMM16 == 0) { Exception(M88K_EXCEP_INT_DIV); return; @@ -758,7 +841,7 @@ OP_DEF(stcr) } cr[FLD_CR] = rS1; if (FLD_CR == 1) { - SetPSR(psr); + SetPSR(); } } @@ -809,7 +892,7 @@ OP_DEF(xcr) rD = cr[FLD_CR]; cr[FLD_CR] = tmp; if (FLD_CR == 1) { - SetPSR(psr); + SetPSR(); } r[0] = 0; } @@ -849,78 +932,185 @@ OP_DEF(fxcr) // 100001_DDDDDSSSSS_00000n_nnnnnsssss OP_DEF(fmul) { - OP_FUNC(unimpl); + // 暫定 + double s1; + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s1, FP_T1, FLD_S1); + FP_GET(s2, FP_T2, FLD_S2); + FP_SET(FP_TD, FLD_D, s1 * s2); } // 100001_DDDDD00000_001000_000nnsssss OP_DEF(flt) { - OP_FUNC(unimpl); + // 暫定 + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_SET(FP_TD, FLD_D, (double)rS2); } + // 100001_DDDDDSSSSS_00101n_nnnnnsssss OP_DEF(fadd) { - OP_FUNC(unimpl); + // 暫定 + double s1; + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s1, FP_T1, FLD_S1); + FP_GET(s2, FP_T2, FLD_S2); + FP_SET(FP_TD, FLD_D, s1 + s2); } // 100001_DDDDDSSSSS_00110n_nnnnnsssss OP_DEF(fsub) { - OP_FUNC(unimpl); + // 暫定 + double s1; + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s1, FP_T1, FLD_S1); + FP_GET(s2, FP_T2, FLD_S2); + FP_SET(FP_TD, FLD_D, s1 - s2); } // 100001_DDDDDSSSSS_00111n_nnnnnsssss OP_DEF(fcmp) { - OP_FUNC(unimpl); + // 暫定 + double s1; + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s1, FP_T1, FLD_S1); + FP_GET(s2, FP_T2, FLD_S2); + rD = acc_fcmp(s1, s2); } // 100001_DDDDD00000_010010_0nn00sssss OP_DEF(int) { - OP_FUNC(unimpl); + // 暫定 + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s2, FP_T2, FLD_S2); + + int mode = (fpcr >> 14) & 3; + switch (mode) { + case 0: + std::fesetround(FE_TONEAREST); + rD = (uint32)(int32)std::nearbyint(s2); + break; + case 1: + rD = (uint32)(int32)std::trunc(s2); + break; + case 2: + rD = (uint32)(int32)std::floor(s2); + break; + case 3: + rD = (uint32)(int32)std::ceil(s2); + break; + } } // 100001_DDDDD00000_010100_0nn00sssss OP_DEF(nint) { - OP_FUNC(unimpl); + // 暫定 + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s2, FP_T2, FLD_S2); + std::fesetround(FE_TONEAREST); + rD = (uint32)(int32)std::nearbyint(s2); } // 100001_DDDDD00000_010110_0nn00sssss OP_DEF(trnc) { - OP_FUNC(unimpl); + // 暫定 + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s2, FP_T2, FLD_S2); +printf("trunc(%f) => %f\n", s2, std::trunc(s2)); + rD = (uint32)(int32)std::trunc(s2); } // 100001_DDDDDSSSSS_01110n_nnnnnsssss OP_DEF(fdiv) { - OP_FUNC(unimpl); + // 暫定 + double s1; + double s2; + + if (FLD_D == 0) { + FPException(M88K_FPEXCEP_FUNIMP); + return; + } + + FP_GET(s1, FP_T1, FLD_S1); + FP_GET(s2, FP_T2, FLD_S2); + FP_SET(FP_TD, FLD_D, s1 / s2); } // 110000_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(br) { - EnterBranch(); - DoBranch(xip + D26); + AddCycle(1); // Table.7-5 + EnterBranch(xip + D26); ExitBranch(); } // 110001_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(br_n) { - EnterBranch(); - DoBranch(xip + D26); + AddCycle(0); // Table.7-5 + EnterBranch(xip + D26); ExitDelayBranch(); } // 110010_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(bsr) { - EnterBranch(); - DoBranch(xip + D26); + AddCycle(1); // Table.7-5 + EnterBranch(xip + D26); r[1] = nip; ExitBranch(); } @@ -928,8 +1118,8 @@ OP_DEF(bsr) // 110011_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(bsr_n) { - EnterBranch(); - DoBranch(xip + D26); + AddCycle(0); // Table.7-5 + EnterBranch(xip + D26); r[1] = nip + 4; ExitDelayBranch(); } @@ -938,8 +1128,8 @@ OP_DEF(bsr_n) OP_DEF(bb0) { if ((rS1 & (1 << B5)) == 0) { - EnterBranch(); - DoBranch(xip + D16); + AddCycle(1); // Table.7-5 + EnterBranch(xip + D16); ExitBranch(); } } @@ -948,8 +1138,7 @@ OP_DEF(bb0) OP_DEF(bb0_n) { if ((rS1 & (1 << B5)) == 0) { - EnterBranch(); - DoBranch(xip + D16); + EnterBranch(xip + D16); ExitDelayBranch(); } } @@ -958,8 +1147,8 @@ OP_DEF(bb0_n) OP_DEF(bb1) { if ((rS1 & (1 << B5)) != 0) { - EnterBranch(); - DoBranch(xip + D16); + AddCycle(1); // Table.7-5 + EnterBranch(xip + D16); ExitBranch(); } } @@ -968,8 +1157,7 @@ OP_DEF(bb1) OP_DEF(bb1_n) { if ((rS1 & (1 << B5)) != 0) { - EnterBranch(); - DoBranch(xip + D16); + EnterBranch(xip + D16); ExitDelayBranch(); } } @@ -978,8 +1166,8 @@ OP_DEF(bb1_n) OP_DEF(bcnd) { if (acc_cnd(rS1) & M5) { - EnterBranch(); - DoBranch(xip + D16); + AddCycle(1); // Table.7-5 + EnterBranch(xip + D16); ExitBranch(); } } @@ -988,8 +1176,7 @@ OP_DEF(bcnd) OP_DEF(bcnd_n) { if (acc_cnd(rS1) & M5) { - EnterBranch(); - DoBranch(xip + D16); + EnterBranch(xip + D16); ExitDelayBranch(); } } @@ -1107,6 +1294,8 @@ OP_DEF(xmem_bu) LDST_USR_SCALE_ALIGN(1); + AddCycle(4); // Table.7-3 + lastaddr = addr; // 例外安全のために都度 S/U ビットを制御 @@ -1114,7 +1303,7 @@ OP_DEF(xmem_bu) tmp = cmmu[1].xmem_8(addr, rD); if (__predict_false(usr)) cmmu[1].SetSuper(true); if ((int64)tmp < 0) { - XmemDataException(addr, rD, DM_BU | DM_LOCK | usr); + XmemDataException(addr, DM_BU | DM_LOCK | usr); return; } if (FLD_D == 0) @@ -1131,6 +1320,8 @@ OP_DEF(xmem_w) LDST_USR_SCALE_ALIGN(4); + AddCycle(4); // Table.7-3 + lastaddr = addr; // 例外安全のために都度 S/U ビットを制御 @@ -1138,7 +1329,7 @@ OP_DEF(xmem_w) tmp = cmmu[1].xmem_32(addr, rD); if (__predict_false(usr)) cmmu[1].SetSuper(true); if ((int64)tmp < 0) { - XmemDataException(addr, rD, DM_W | DM_LOCK | usr); + XmemDataException(addr, DM_W | DM_LOCK | usr); return; } @@ -1150,186 +1341,200 @@ OP_DEF(xmem_w) // 111101_DDDDDSSSSS_000010_xU000sssss OP_DEF(ld_hu) { - uint64 tmp; + uint64 data; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(2); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].load_16(addr); + data = cmmu[1].load_16(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_HU | usr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_HU | usr); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data; } // 111101_DDDDDSSSSS_000011_xU000sssss OP_DEF(ld_bu) { - uint64 tmp; + uint64 data; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(1); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].load_8(addr); + data = cmmu[1].load_8(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_BU | usr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_BU | usr); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data; } // 111101_DDDDDSSSSS_000100_xU000sssss OP_DEF(ld_d) { - uint64 tmp, tmp2; + uint64 data1, data2; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(8); + AddCycle(4); // Table.7-3 + lastaddr = addr; // 例外安全のために都度 S/U ビットを制御 if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].load_32(addr); + data1 = cmmu[1].load_32(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_D1 | usr); + if ((int64)data1 < 0) { + ReadDataException64(addr, DM_D1 | usr); return; } addr += 4; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp2 = cmmu[1].load_32(addr); + data2 = cmmu[1].load_32(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_D2 | usr); + if ((int64)data2 < 0) { + ReadDataException64(addr, DM_D2 | usr); return; } - rD = tmp; - r[(FLD_D + 1) & 0x1f] = tmp2; + rD = data1; + rD2 = data2; r[0] = 0; } // 111101_DDDDDSSSSS_000101_xU000sssss OP_DEF(ld_w) { - uint64 tmp; + uint64 data; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(4); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].load_32(addr); + data = cmmu[1].load_32(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_W | usr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_W | usr); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data; } // 111101_DDDDDSSSSS_000110_xU000sssss OP_DEF(ld_h) { - uint64 tmp; + uint64 data; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(2); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].load_16(addr); + data = cmmu[1].load_16(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_H | usr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_H | usr); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int16)tmp; + rD = (uint32)(int32)(int16)data; } // 111101_DDDDDSSSSS_000111_xU000sssss OP_DEF(ld_b) { - uint64 tmp; + uint64 data; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(1); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].load_8(addr); + data = cmmu[1].load_8(addr); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - ReadDataException(addr, DM_B | usr); + if ((int64)data < 0) { + ReadDataException32(addr, DM_B | usr); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int8)tmp; + rD = (uint32)(int32)(int8)data; } // 111101_DDDDDSSSSS_001000_xU000sssss OP_DEF(st_d) { - uint64 tmp2; + uint64 rv; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(8); + AddCycle(1 + 4); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp2 = cmmu[1].store_32(addr, rD); + rv = cmmu[1].store_32(addr, rD); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp2 < 0) { - WriteDataException(addr, rD, DM_D1 | usr); + if ((int64)rv < 0) { + WriteDataException64(addr, DM_D1 | usr); return; } addr += 4; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp2 = cmmu[1].store_32(addr, r[(FLD_D + 1) & 0x1f]); + rv = cmmu[1].store_32(addr, rD2); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp2 < 0) { - WriteDataException(addr, r[(FLD_D + 1) & 0x1f], DM_D2 | usr); + if ((int64)rv < 0) { + WriteDataException64(addr, DM_D2 | usr); return; } } @@ -1337,20 +1542,22 @@ OP_DEF(st_d) // 111101_DDDDDSSSSS_001001_xU000sssss OP_DEF(st_w) { - uint64 tmp2; + uint64 rv; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(4); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp2 = cmmu[1].store_32(addr, rD); + rv = cmmu[1].store_32(addr, rD); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp2 < 0) { - WriteDataException(addr, rD, DM_W | usr); + if ((int64)rv < 0) { + WriteDataException32(addr, DM_W | usr); return; } } @@ -1358,20 +1565,22 @@ OP_DEF(st_w) // 111101_DDDDDSSSSS_001010_xU000sssss OP_DEF(st_h) { - uint64 tmp2; + uint64 rv; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(2); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp2 = cmmu[1].store_16(addr, rD); + rv = cmmu[1].store_16(addr, rD & 0xffff); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp2 < 0) { - WriteDataException(addr, rD, DM_H | usr); + if ((int64)rv < 0) { + WriteDataException32(addr, DM_H | usr); return; } } @@ -1379,20 +1588,22 @@ OP_DEF(st_h) // 111101_DDDDDSSSSS_001011_xU000sssss OP_DEF(st_b) { - uint64 tmp2; + uint64 rv; uint32 addr; uint32 usr; LDST_USR_SCALE_ALIGN(1); + AddCycle(3); // Table.7-3 + lastaddr = addr; if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp2 = cmmu[1].store_8(addr, rD); + rv = cmmu[1].store_8(addr, rD & 0xff); if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp2 < 0) { - WriteDataException(addr, rD, DM_B | usr); + if ((int64)rv < 0) { + WriteDataException32(addr, DM_B | usr); return; } } @@ -1507,7 +1718,7 @@ OP_DEF(addu) res += GetCY(); } if (IsCO) { - SetCY((res >> 32) & 1); + SetCY(res >> 32); } if (FLD_D == 0) return; @@ -1528,7 +1739,7 @@ OP_DEF(subu) res += 1; } if (IsCO) { - SetCY((res >> 32) & 1); + SetCY(res >> 32); } if (FLD_D == 0) return; @@ -1542,6 +1753,9 @@ OP_DEF(divu) fpu_unimpl(); return; } + + AddCycle(38); // Table.7-6 (ただしざっくり) + if (rS2 == 0) { Exception(M88K_EXCEP_INT_DIV); return; @@ -1558,6 +1772,9 @@ OP_DEF(mul) fpu_unimpl(); return; } + + AddCycle(4); // Table.7-6 (ただしざっくり) + if (FLD_D == 0) return; rD = rS1 * rS2; @@ -1573,7 +1790,7 @@ OP_DEF(add) // XXX: オーバーフローが起きたときにキャリーが更新されるかどうか // ドキュメントされてない気がする if (IsCO) { - SetCY((res >> 32) & 1); + SetCY(res >> 32); } if (isovf_add(rS1, rS2, res)) { Exception(M88K_EXCEP_INT_OVF); @@ -1600,7 +1817,7 @@ OP_DEF(sub) // XXX: オーバーフローが起きたときにキャリーが更新されるかどうか // ドキュメントされてない気がする if (IsCO) { - SetCY((res >> 32) & 1); + SetCY(res >> 32); } if (isovf_sub(rS1, rS2, res)) { Exception(M88K_EXCEP_INT_OVF); @@ -1618,6 +1835,9 @@ OP_DEF(div) fpu_unimpl(); return; } + + AddCycle(38); // Table.7-6 (ただしざっくり) + if ((int32)rS1 < 0 || (int32)rS2 <= 0) { Exception(M88K_EXCEP_INT_DIV); return; @@ -1709,24 +1929,24 @@ OP_DEF(rot_2) // 111101_zzzzzzzzzz_110000_00000sssss OP_DEF(jmp) { - EnterBranch(); - DoBranch(rS2); + AddCycle(1); // Table.7-5 + EnterBranch(rS2); ExitBranch(); } // 111101_zzzzzzzzzz_110001_00000sssss OP_DEF(jmp_n) { - EnterBranch(); - DoBranch(rS2); + AddCycle(0); // Table.7-5 + EnterBranch(rS2); ExitDelayBranch(); } // 111101_zzzzzzzzzz_110010_00000sssss OP_DEF(jsr) { - EnterBranch(); - DoBranch(rS2); + AddCycle(1); // Table.7-5 + EnterBranch(rS2); r[1] = nip; ExitBranch(); } @@ -1734,8 +1954,8 @@ OP_DEF(jsr) // 111101_zzzzzzzzzz_110011_00000sssss OP_DEF(jsr_n) { - EnterBranch(); - DoBranch(rS2); + AddCycle(0); // Table.7-5 + EnterBranch(rS2); r[1] = nip + 4; ExitDelayBranch(); } @@ -1786,6 +2006,8 @@ OP_DEF(ff0) // 111101_zzzzzzzzzz_111111_0000000000 OP_DEF(rte) { + AddCycle(2); // Table.7-5 + SetPSR(epsr); // LUNA88K の ROM1.2 は sxip, snip, sfip を制御してくる。 @@ -1798,19 +2020,19 @@ OP_DEF(rte) // (実際はクロックが消費されるかも?) // sfip が VALID なので、そこから実行を再開する。 if (snip & SIP_V) { - DoBranch(snip & SIP_MASK); - fetch(); + EnterBranch(snip & SIP_MASK); + ExitBranch(); fip = sfip & SIP_MASK; } else { - DoBranch(sfip & SIP_MASK); - fetch(); + EnterBranch(sfip & SIP_MASK); + ExitBranch(); } // ディレイスロットにいた命令かどうかをやんわり復元する。 // 88110 ではこの情報が E?IP に保持されているが // 88100 にはない。 if (nip + 4 != fip) { - opF = OpSetDelay(opF); + ExitDelayBranch(); } }