--- nono/m88xx0/m88100ops.cpp 2026/04/29 17:05:07 1.1.1.12 +++ nono/m88xx0/m88100ops.cpp 2026/04/29 17:05:47 1.1.1.16 @@ -10,75 +10,86 @@ #include // 命令のフィールド取り出し -#define FLD_D m88100opf_D(opX) -#define FLD_S1 m88100opf_S1(opX) -#define FLD_S2 m88100opf_S2(opX) -#define FLD_CR m88100opf_CR(opX) -#define B5 m88100opf_B5(opX) -#define M5 m88100opf_M5(opX) -#define W5 m88100opf_W5(opX) -#define O5 m88100opf_O5(opX) -#define IMM16 m88100opf_IMM16(opX) -#define VEC9 m88100opf_VEC9(opX) +#define FLD_D m88100opf_D(reg.opX) +#define FLD_S1 m88100opf_S1(reg.opX) +#define FLD_S2 m88100opf_S2(reg.opX) +#define FLD_CR m88100opf_CR(reg.opX) +#define B5 m88100opf_B5(reg.opX) +#define M5 m88100opf_M5(reg.opX) +#define W5 m88100opf_W5(reg.opX) +#define O5 m88100opf_O5(reg.opX) +#define IMM16 m88100opf_IMM16(reg.opX) +#define VEC9 m88100opf_VEC9(reg.opX) +#define IsCO ((reg.opX & 0x100)) +#define IsCI ((reg.opX & 0x200)) // 符号拡張・シフト済みのディスプレースメント // XXX: (負数の右シフト)GCC only -#define D16 (((int32)(int16)opX) << 2) -#define D26 (((int32)(opX << 6) >> 4)) -#define IsCO ((opX >> 8) & 1) -#define IsCI ((opX >> 9) & 1) +#define D16 (((int32)(int16)reg.opX) << 2) +#define D26 (((int32)(reg.opX << 6) >> 4)) // レジスタアクセス -#define rD (r[FLD_D]) -#define rS1 (r[FLD_S1]) -#define rS2 (r[FLD_S2]) +#define rD (reg.r[FLD_D]) +#define rS1 (reg.r[FLD_S1]) +#define rS2 (reg.r[FLD_S2]) // ダブルワードの2ワード目 #define FLD_D2 ((FLD_D + 1) & 0x1f) -#define rD2 (r[FLD_D2]) +#define rD2 (reg.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) +#define FP_T1 m88100opf_FP_T1(reg.opX) +#define FP_T2 m88100opf_FP_T2(reg.opX) +#define FP_TD m88100opf_FP_TD(reg.opX) // XXX t(サイズ)が原因で Reserved Operand になった時の S1, S2 はどうなる? #define FP_GET(v, t, n) \ do { \ if (t == 0) { \ - v = u2f(r[n]); \ + v = u2f(reg.r[n]); \ } else if (t == 1) { \ - v = u2d(((uint64)r[n] << 32) | r[(n + 1) & 31]); \ + uint64 tmp = (uint64)reg.r[n] << 32; \ + if (__predict_true(n != 31)) \ + tmp |= reg.r[n + 1]; \ + v = u2d(tmp); \ } else { \ FPPreciseException(FPECR_FROP); \ return; \ } \ } while (0) +// n==0 は事前に弾いてある。 #define FP_SET(t, n, v) \ do { \ if (t == 0) { \ - r[n] = f2u(v); \ + reg.r[n] = f2u(v); \ } else if (t == 1) { \ uint64 tmp = d2u(v); \ - r[n] = tmp >> 32; \ + reg.r[n] = tmp >> 32; \ if (__predict_true(n != 31)) \ - r[n + 1] = (uint32)tmp; \ + reg.r[n + 1] = (uint32)tmp; \ } else { \ FPPreciseException(FPECR_FROP); \ return; \ } \ } while (0) -// ブランチ命令入り口 -inline void -m88kcpu::EnterBranch(uint32 toaddr) +#define CHECK_FPU do { \ + if (IsFPUEnable() == false) { \ + FPPreciseException(FPECR_FUNIMP); \ + return; \ + } \ +} while (0) + +// ブランチ命令 +void +MPU88xx0Device::DoBranch(uint32 toaddr, bool next_exec) { // ジャンプ先アドレスの下位2bitはマスクされる toaddr &= ~3; // ブランチヒストリに登録しつつ、 // ブランチヒストリからブランチ状況を取得 - auto e = brhist.AddEntry(xip | (IsSuper() ? 1 : 0), toaddr, opX); - fip = toaddr; + auto e = brhist.AddEntry(reg.xip | (IsSuper() ? 1 : 0), toaddr, reg.opX); + reg.fip = toaddr; // STOP 検出。 // m88k には STOP 状態 (何もせず割り込みだけ待つ状態。m68k の STOP 命令 @@ -109,9 +120,9 @@ m88kcpu::EnterBranch(uint32 toaddr) // e.count == 2 のときだけ STOP の検証をすれば良い。 // d はブランチ間の命令数 - uint32 d = (xip - toaddr) / sizeof(uint32); + uint32 d = (reg.xip - toaddr) / sizeof(uint32); // 遅延ブランチなら 1 命令余分に実行するはずなので 1 足す - if ((opX & (1 << 26)) != 0) { + if (next_exec) { d++; } // ブランチ間の命令がすべて NOP なら STOP ということにする。 @@ -129,37 +140,12 @@ m88kcpu::EnterBranch(uint32 toaddr) } // STOP ではなかったら、あとは放置していい } -} - -// 通常(即時)ブランチ出口 -inline void -m88kcpu::ExitBranch() -{ - // re-fetch branched instruction - fetch(); -} - -// 遅延ブランチ出口 -// 速度を稼ぐため、ビット反転だけでこれを区別しているので、 -// 同じ op 中で複数回呼び出さないこと。 -inline void -m88kcpu::ExitDelayBranch() -{ - opF ^= DELAYSLOT; -} -// ロードストアユニットの usr の処理。 -// 正常なら true を返す (ので呼び出し側は実行継続)、 -// 例外が起きたら処理して false を返すので呼び出し側は即リターンすること。 -inline bool -m88kcpu::ldst_usr(uint32& usr) -{ - usr = (opX & (1 << 8)) ? DM_USR : 0; - if (IsUser() && usr) { - Exception(M88K_EXCEP_PRIV); - return false; + if (next_exec == false) { + // 通常(即時)ブランチ出口 + // re-fetch branched instruction + fetch(); } - return true; } // MEMO: ロードストアでの usr の処理で、CMMU に対して @@ -173,43 +159,39 @@ m88kcpu::ldst_usr(uint32& usr) // ロードストアユニットの scale の処理。addr を返す。 inline uint32 -m88kcpu::ldst_scale(uint32 size) +MPU88xx0Device::ldst_scale(uint32 size) { - if ((opX & (1 << 9)) != 0) { + if ((reg.opX & (1U << 9)) != 0) { return rS1 + rS2 * size; } else { return rS1 + rS2; } } -// ロードストアユニットの align の処理。 -// 正常なら true を返す (ので呼び出し側は実行継続)、 -// 例外が起きたら処理して false を返すので呼び出し側は即リターンすること。 -inline bool -m88kcpu::ldst_align(uint32 size, uint32& addr) -{ - if ((addr & (size - 1)) != 0) { - if (IsMXM()) { - addr &= ~(size - 1); - } else { - Exception(M88K_EXCEP_MISALIGNED); - return false; - } - } - return true; -} - -// ロードストアユニットの usr と scale の処理 (呼び出し用マクロ) +// ロードストアユニットの usr と scale の処理。 +// 正常な場合は usr と addr を更新する。 +// 例外の場合は例外を処理してこのマクロが展開してある関数から return する。 #define LDST_USR_SCALE(size) do { \ - if (ldst_usr(usr) == false) \ + usr = (reg.opX & (1U << 8)) ? DM_USR : 0; \ + if (IsUser() && usr) { \ + Exception(EXCPRI_PRIV); \ return; \ + } \ addr = ldst_scale(size); \ } while (0) -// ロードストアユニットの align の処理 (呼び出し用マクロ) +// ロードストアユニットの align の処理。 +// 正常な場合は addr を更新する可能性がある。 +// 例外の場合は例外を処理してこのマクロが展開されてる関数から return する。 #define LDST_ALIGN(size) do { \ - if (ldst_align(size, addr) == false) \ - return; \ + if ((addr & (size - 1)) != 0) { \ + if (IsMXM()) { \ + addr &= ~(size - 1); \ + } else { \ + InternalException(EXCVEC_MISALIGNED); \ + return; \ + } \ + } \ } while (0) // ロードストアユニットのまとめたもの @@ -218,6 +200,18 @@ m88kcpu::ldst_align(uint32 size, uint32& LDST_ALIGN(size); \ } while (0) +// .usr 開始。 +#define ENTER_USR() do { \ + if (__predict_false(usr)) \ + cmmu[1]->SetSuper(false); \ +} while (0) + +// .usr 終了。 +#define LEAVE_USR() do { \ + if (__predict_false(usr)) \ + cmmu[1]->SetSuper(true); \ +} while (0) + // 幅規制付き算術左シフト static inline uint32 ASL(uint32 a, int n) @@ -235,7 +229,7 @@ ASR(uint32 a, int n) { if (n <= 0) return a; - if (n >= 32) + if (n >= 31) return (int32)a < 0 ? -1 : 0; // XXX: 負数の右シフト return (int32)a >> n; @@ -266,10 +260,10 @@ isovf_sub(uint32 s1, uint32 s2, uint32 r } // bcnd のやつ -static inline int +static inline uint acc_cnd(uint32 r) { - int rv; + uint rv; if ((r & 0x80000000) != 0) { if (r == 0x80000000) { rv = 0x8; @@ -292,9 +286,9 @@ acc_bf(int w, int ofs) { uint32 m; if (w == 0) { - m = 0xFFFFFFFFU; + m = 0xffffffffU; } else { - m = ~(0xFFFFFFFFU << w); + m = ~(0xffffffffU << w); } return m << ofs; } @@ -315,7 +309,7 @@ static int rm_to_round[4] = { OP_DEF(xmem_bu_imm) { uint32 addr; - uint64 tmp; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(1); @@ -323,21 +317,21 @@ OP_DEF(xmem_bu_imm) AddCycle(4); // Table.7-3 lastaddr = addr; - tmp = cmmu[1].xmem_8(addr, rD & 0xff); - if ((int64)tmp < 0) { - XmemDataException(addr, DM_BU | DM_LOCK); + data = cmmu[1]->xmem_1(addr, rD & 0xff); + if (__predict_false(data.IsBusErr())) { + XmemDataException(addr, DM_BU); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data.Data(); } // 000001_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(xmem_w_imm) { uint32 addr; - uint64 tmp; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(4); @@ -345,21 +339,21 @@ OP_DEF(xmem_w_imm) AddCycle(4); // Table.7-3 lastaddr = addr; - tmp = cmmu[1].xmem_32(addr, rD); - if ((int64)tmp < 0) { - XmemDataException(addr, DM_W | DM_LOCK); + data = cmmu[1]->xmem_4(addr, rD); + if (__predict_false(data.IsBusErr())) { + XmemDataException(addr, DM_W); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data.Data(); } // 000010_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_hu_imm) { uint32 addr; - uint64 data; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(2); @@ -367,21 +361,21 @@ OP_DEF(ld_hu_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - data = cmmu[1].load_16(addr); - if ((int64)data < 0) { + data = cmmu[1]->load_2(addr); + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_HU); return; } if (FLD_D == 0) return; - rD = data; + rD = data.Data(); } // 000011_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_bu_imm) { uint32 addr; - uint64 data; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(1); @@ -389,21 +383,21 @@ OP_DEF(ld_bu_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - data = cmmu[1].load_8(addr); - if ((int64)data < 0) { + data = cmmu[1]->load_1(addr); + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_BU); return; } if (FLD_D == 0) return; - rD = data; + rD = data.Data(); } // 000100_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_d_imm) { - uint32 addr; - uint64 data1, data2; + uint32 addr; // ReadDataException64() に渡すのは常に先頭アドレス。 + busdata data; addr = rS1 + IMM16; LDST_ALIGN(8); @@ -411,28 +405,32 @@ OP_DEF(ld_d_imm) AddCycle(4); // Table.7-3 lastaddr = addr; - data1 = cmmu[1].load_32(addr); - if ((int64)data1 < 0) { + + data = cmmu[1]->load_4(addr); + if (__predict_false(data.IsBusErr())) { ReadDataException64(addr, DM_D1); return; } - addr += 4; - data2 = cmmu[1].load_32(addr); - if ((int64)data2 < 0) { + if (__predict_true(FLD_D != 0)) { + rD = data.Data(); + } + + data = cmmu[1]->load_4(addr + 4); + if (__predict_false(data.IsBusErr())) { ReadDataException64(addr, DM_D2); return; } - rD = data1; - rD2 = data2; - r[0] = 0; + if (__predict_true(FLD_D2 != 0)) { + rD2 = data.Data(); + } } // 000101_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_w_imm) { uint32 addr; - uint64 data; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(4); @@ -440,21 +438,21 @@ OP_DEF(ld_w_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - data = cmmu[1].load_32(addr); - if ((int64)data < 0) { + data = cmmu[1]->load_4(addr); + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_W); return; } if (FLD_D == 0) return; - rD = data; + rD = data.Data(); } // 000110_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_h_imm) { uint32 addr; - uint64 data; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(2); @@ -462,21 +460,21 @@ OP_DEF(ld_h_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - data = cmmu[1].load_16(addr); - if ((int64)data < 0) { + data = cmmu[1]->load_2(addr); + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_H); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int16)data; + rD = (uint32)(int32)(int16)data.Data(); } // 000111_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(ld_b_imm) { uint32 addr; - uint64 data; + busdata data; addr = rS1 + IMM16; LDST_ALIGN(1); @@ -484,21 +482,21 @@ OP_DEF(ld_b_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - data = cmmu[1].load_8(addr); - if ((int64)data < 0) { + data = cmmu[1]->load_1(addr); + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_B); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int8)data; + rD = (uint32)(int32)(int8)data.Data(); } // 001000_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(st_d_imm) { - uint32 addr; - uint64 rv; + uint32 addr; // WriteDataException64() に渡すのは常に先頭アドレス。 + busdata r; addr = rS1 + IMM16; LDST_ALIGN(8); @@ -506,14 +504,15 @@ OP_DEF(st_d_imm) AddCycle(1 + 4); // Table.7-3 lastaddr = addr; - rv = cmmu[1].store_32(addr, rD); - if ((int64)rv < 0) { + + r = cmmu[1]->store_4(addr, rD); + if (__predict_false(r.IsBusErr())) { WriteDataException64(addr, DM_D1); return; } - addr += 4; - rv = cmmu[1].store_32(addr, rD2); - if ((int64)rv < 0) { + + r = cmmu[1]->store_4(addr + 4, rD2); + if (__predict_false(r.IsBusErr())) { WriteDataException64(addr, DM_D2); return; } @@ -523,7 +522,7 @@ OP_DEF(st_d_imm) OP_DEF(st_w_imm) { uint32 addr; - uint64 rv; + busdata r; addr = rS1 + IMM16; LDST_ALIGN(4); @@ -531,8 +530,8 @@ OP_DEF(st_w_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - rv = cmmu[1].store_32(addr, rD); - if ((int64)rv < 0) { + r = cmmu[1]->store_4(addr, rD); + if (__predict_false(r.IsBusErr())) { WriteDataException32(addr, DM_W); return; } @@ -542,7 +541,7 @@ OP_DEF(st_w_imm) OP_DEF(st_h_imm) { uint32 addr; - uint64 rv; + busdata r; addr = rS1 + IMM16; LDST_ALIGN(2); @@ -550,8 +549,8 @@ OP_DEF(st_h_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - rv = cmmu[1].store_16(addr, rD & 0xffff); - if ((int64)rv < 0) { + r = cmmu[1]->store_2(addr, rD & 0xffff); + if (__predict_false(r.IsBusErr())) { WriteDataException32(addr, DM_H); return; } @@ -561,7 +560,7 @@ OP_DEF(st_h_imm) OP_DEF(st_b_imm) { uint32 addr; - uint64 rv; + busdata r; addr = rS1 + IMM16; LDST_ALIGN(1); @@ -569,8 +568,8 @@ OP_DEF(st_b_imm) AddCycle(3); // Table.7-3 lastaddr = addr; - rv = cmmu[1].store_8(addr, rD & 0xff); - if ((int64)rv < 0) { + r = cmmu[1]->store_1(addr, rD & 0xff); + if (__predict_false(r.IsBusErr())) { WriteDataException32(addr, DM_B); return; } @@ -691,15 +690,12 @@ OP_DEF(subu_imm) // 011010_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(divu_imm) { - if (!IsFPUEnable()) { - fpu_unimpl(); - return; - } + CHECK_FPU; AddCycle(38); // Table.7-6 (ただしざっくり) if (IMM16 == 0) { - Exception(M88K_EXCEP_INT_DIV); + InternalException(EXCVEC_INT_DIV); return; } if (FLD_D == 0) @@ -710,10 +706,7 @@ OP_DEF(divu_imm) // 011011_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(mul_imm) { - if (!IsFPUEnable()) { - fpu_unimpl(); - return; - } + CHECK_FPU; AddCycle(4); // Table.7-6 (ただしざっくり) @@ -728,7 +721,7 @@ OP_DEF(add_imm) uint32 imm = IMM16; uint32 res = rS1 + imm; if (isovf_add(rS1, imm, res)) { - Exception(M88K_EXCEP_INT_OVF); + InternalException(EXCVEC_INT_OVF); return; } if (FLD_D == 0) @@ -742,7 +735,7 @@ OP_DEF(sub_imm) uint32 imm = IMM16; uint32 res = rS1 - imm; if (isovf_sub(rS1, imm, res)) { - Exception(M88K_EXCEP_INT_OVF); + InternalException(EXCVEC_INT_OVF); return; } if (FLD_D == 0) @@ -753,15 +746,12 @@ OP_DEF(sub_imm) // 011110_DDDDDSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(div_imm) { - if (!IsFPUEnable()) { - fpu_unimpl(); - return; - } + CHECK_FPU; AddCycle(38); // Table.7-6 (ただしざっくり) if ((int32)rS1 < 0 || IMM16 == 0) { - Exception(M88K_EXCEP_INT_DIV); + InternalException(EXCVEC_INT_DIV); return; } if (FLD_D == 0) @@ -780,20 +770,20 @@ OP_DEF(cmp_imm) // 100000_DDDDDzzzzz_01000n_nnnnnzzzzz OP_DEF(ldcr) { - if (IsUser()) { - Exception(M88K_EXCEP_PRIV); + if (__predict_false(IsUser())) { + Exception(EXCPRI_PRIV); return; } - if (FLD_CR > countof(cr)) { + if (FLD_CR > countof(reg.cr)) { // 制御レジスタ番号が範囲外の時は // 88100 では undocumented、 // 88110 では Unimplemented Opcode 例外。 - Exception(M88K_EXCEP_UNIMPL_OP); + Exception(EXCPRI_UNIMPL_OP); return; } if (FLD_D == 0) return; - rD = cr[FLD_CR]; + rD = reg.cr[FLD_CR]; } // 100000_DDDDDzzzzz_01001n_nnnnnzzzzz @@ -812,7 +802,7 @@ OP_DEF(fldcr) if (n >= 62) { n = n - 62 + 9; } else { - if (IsUser()) { + if (__predict_false(IsUser())) { FPPreciseException(FPECR_FPRV); return; } @@ -825,25 +815,30 @@ OP_DEF(fldcr) return; // XXX 内部がバグってなければ読み出す時にマスクする必要はないが、一応 - rD = fcr[n] & fcr_mask[n]; + rD = reg.fcr[n] & reg.fcr_mask[n]; } // 100000_zzzzzSSSSS_10000n_nnnnnsssss OP_DEF(stcr) { - if (IsUser()) { - Exception(M88K_EXCEP_PRIV); + if (__predict_false(IsUser())) { + Exception(EXCPRI_PRIV); return; } - if (FLD_CR > countof(cr)) { + + uint n = FLD_CR; + if (n > countof(reg.cr)) { // 制御レジスタ番号が範囲外の時は // 88100 では undocumented、 // 88110 では Unimplemented Opcode 例外。 - Exception(M88K_EXCEP_UNIMPL_OP); + Exception(EXCPRI_UNIMPL_OP); return; } - cr[FLD_CR] = rS1; - if (FLD_CR == 1) { + // PID, SXIP は Read Only。 + if (__predict_true(n != 0 && n != 4)) { + reg.cr[n] = rS1; + } + if (n == 1) { SetPSR(); } } @@ -864,7 +859,7 @@ OP_DEF(fstcr) if (n >= 62) { n = n - 62 + 9; } else { - if (IsUser()) { + if (__predict_false(IsUser())) { FPPreciseException(FPECR_FPRV); return; } @@ -874,11 +869,11 @@ OP_DEF(fstcr) } } - fcr[n] = rS1 & fcr_mask[n]; + reg.fcr[n] = rS1 & reg.fcr_mask[n]; // FPCR が変更されたら、ホストの丸めモードも更新 if (n == 10) { - uint32 rm = (fpcr >> 14) & 3; + uint32 rm = (reg.fpcr >> 14) & 3; std::fesetround(rm_to_round[rm]); } } @@ -888,24 +883,29 @@ OP_DEF(xcr) { uint32 tmp; - if (IsUser()) { - Exception(M88K_EXCEP_PRIV); + if (__predict_false(IsUser())) { + Exception(EXCPRI_PRIV); return; } - if (FLD_CR > countof(cr)) { + + uint n = FLD_CR; + if (n > countof(reg.cr)) { // 制御レジスタ番号が範囲外の時は // 88100 では undocumented、 // 88110 では Unimplemented Opcode 例外。 - Exception(M88K_EXCEP_UNIMPL_OP); + Exception(EXCPRI_UNIMPL_OP); return; } tmp = rS1; - rD = cr[FLD_CR]; - cr[FLD_CR] = tmp; - if (FLD_CR == 1) { + rD = reg.cr[n]; + // PID, SXIP は Read Only。 + if (__predict_true(n != 0 && n != 4)) { + reg.cr[n] = tmp; + } + reg.r[0] = 0; + if (n == 1) { SetPSR(); } - r[0] = 0; } // 100000_DDDDDSSSSS_11001n_nnnnnsssss @@ -921,7 +921,7 @@ OP_DEF(fxcr) // FCR9..61 read0 FPRV FUNIMP FPRV // FCR62,63 xchg xchg xchg xchg - if (IsUser() && n < 62) { + if (__predict_false(IsUser()) && n < 62) { FPPreciseException(FPECR_FPRV); return; } @@ -930,8 +930,8 @@ OP_DEF(fxcr) goto exchange; } else if (__predict_false(n < 9)) { // FCR1..8 は読み込み専用レジスタなので、読み出す側のみ - rD = fcr[n] & fcr_mask[n]; - r[0] = 0; + rD = reg.fcr[n] & reg.fcr_mask[n]; + reg.r[0] = 0; return; } else if (__predict_false(n < 62)) { // FCR9..61 は未実装レジスタなので、0 が読み出せるのみ @@ -943,19 +943,19 @@ OP_DEF(fxcr) exchange: uint32 tmp = rS1; - rD = fcr[n] & fcr_mask[n]; - fcr[n] = tmp & fcr_mask[n]; + rD = reg.fcr[n] & reg.fcr_mask[n]; + reg.fcr[n] = tmp & reg.fcr_mask[n]; - r[0] = 0; + reg.r[0] = 0; } // 100001_DDDDDSSSSS_00000n_nnnnnsssss OP_DEF(fmul) { - // 暫定 double s1; double s2; + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -969,7 +969,7 @@ OP_DEF(fmul) // 100001_DDDDD00000_001000_000nnsssss OP_DEF(flt) { - // 暫定 + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -982,10 +982,10 @@ OP_DEF(flt) // 100001_DDDDDSSSSS_00101n_nnnnnsssss OP_DEF(fadd) { - // 暫定 double s1; double s2; + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -999,10 +999,10 @@ OP_DEF(fadd) // 100001_DDDDDSSSSS_00110n_nnnnnsssss OP_DEF(fsub) { - // 暫定 double s1; double s2; + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -1019,6 +1019,7 @@ OP_DEF(fcmp) double s1; double s2; + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -1044,10 +1045,10 @@ OP_DEF(fcmp) uint32 res = 0; if (s2 >= 0) { - if (s1 <= 0 || s2 <= s1) res |= 0x0800; // ob + if (s1 <= 0 || s1 >= s2) res |= 0x0800; // ob if (0 < s1 && s1 < s2) res |= 0x0400; // in if (0 <= s1 && s1 <= s2) res |= 0x0200; // ib - if (s1 < 0 || s2 < s1) res |= 0x0100; // ou + if (s1 < 0 || s1 > s2) res |= 0x0100; // ou } if (s1 >= s2) res |= 0x0080; // ge if (s1 < s2) res |= 0x0040; // lt @@ -1069,12 +1070,13 @@ OP_DEF(fcmp) // int, nint, trnc 命令の共通部 void -m88kcpu::ops_int(int rndmode) +MPU88xx0Device::ops_int(int rndmode) { double src; double res; int exponent; + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -1126,10 +1128,10 @@ OP_DEF(trnc) // 100001_DDDDDSSSSS_01110n_nnnnnsssss OP_DEF(fdiv) { - // 暫定 double s1; double s2; + CHECK_FPU; if (FLD_D == 0) { FPPreciseException(FPECR_FUNIMP); return; @@ -1144,71 +1146,63 @@ OP_DEF(fdiv) OP_DEF(br) { AddCycle(1); // Table.7-5 - EnterBranch(xip + D26); - ExitBranch(); + DoBranch(reg.xip + D26, false); } // 110001_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(br_n) { AddCycle(0); // Table.7-5 - EnterBranch(xip + D26); - ExitDelayBranch(); + DoBranch(reg.xip + D26, true); } // 110010_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(bsr) { AddCycle(1); // Table.7-5 - EnterBranch(xip + D26); - r[1] = nip; - ExitBranch(); + reg.r[1] = reg.nip; + DoBranch(reg.xip + D26, false); } // 110011_nnnnnnnnnn_nnnnnn_nnnnnnnnnn OP_DEF(bsr_n) { AddCycle(0); // Table.7-5 - EnterBranch(xip + D26); - r[1] = nip + 4; - ExitDelayBranch(); + reg.r[1] = reg.nip + 4; + DoBranch(reg.xip + D26, true); } // 110100_nnnnnSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(bb0) { - if ((rS1 & (1 << B5)) == 0) { + if ((rS1 & (1U << B5)) == 0) { AddCycle(1); // Table.7-5 - EnterBranch(xip + D16); - ExitBranch(); + DoBranch(reg.xip + D16, false); } } // 110101_nnnnnSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(bb0_n) { - if ((rS1 & (1 << B5)) == 0) { - EnterBranch(xip + D16); - ExitDelayBranch(); + if ((rS1 & (1U << B5)) == 0) { + DoBranch(reg.xip + D16, true); } } // 110110_nnnnnSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(bb1) { - if ((rS1 & (1 << B5)) != 0) { + if ((rS1 & (1U << B5)) != 0) { AddCycle(1); // Table.7-5 - EnterBranch(xip + D16); - ExitBranch(); + DoBranch(reg.xip + D16, false); } } // 110111_nnnnnSSSSS_nnnnnn_nnnnnnnnnn OP_DEF(bb1_n) { - if ((rS1 & (1 << B5)) != 0) { - EnterBranch(xip + D16); - ExitDelayBranch(); + if ((rS1 & (1U << B5)) != 0) { + DoBranch(reg.xip + D16, true); } } @@ -1217,8 +1211,7 @@ OP_DEF(bcnd) { if ((acc_cnd(rS1) & M5) != 0) { AddCycle(1); // Table.7-5 - EnterBranch(xip + D16); - ExitBranch(); + DoBranch(reg.xip + D16, false); } } @@ -1226,8 +1219,7 @@ OP_DEF(bcnd) OP_DEF(bcnd_n) { if ((acc_cnd(rS1) & M5) != 0) { - EnterBranch(xip + D16); - ExitDelayBranch(); + DoBranch(reg.xip + D16, true); } } @@ -1251,7 +1243,7 @@ OP_DEF(set_1) OP_DEF(ext_1) { int w, o, left; - uint32 tmp; + uint32 res; if (FLD_D == 0) return; @@ -1260,16 +1252,16 @@ OP_DEF(ext_1) w = 32; o = O5; left = 32 - w - o; - tmp = ASL(rS1, left); - tmp = ASR(tmp, left); - rD = ASR(tmp, o); + res = ASL(rS1, left); + res = ASR(res, left); + rD = ASR(res, o); } // 111100_DDDDDSSSSS_100110_wwwwwooooo OP_DEF(extu_1) { int w, o, left; - uint32 tmp; + uint32 res; if (FLD_D == 0) return; @@ -1278,9 +1270,9 @@ OP_DEF(extu_1) w = 32; o = O5; left = 32 - w - o; - tmp = ASL(rS1, left); - tmp = LSR(tmp, left); - rD = tmp >> o; + res = ASL(rS1, left); + res = LSR(res, left); + rD = res >> o; } // 111100_DDDDDSSSSS_101000_wwwwwooooo @@ -1303,11 +1295,11 @@ OP_DEF(rot_1) OP_DEF(tb0) { if (IsUser() && VEC9 < 128) { - Exception(M88K_EXCEP_PRIV); + Exception(EXCPRI_PRIV); return; } - if ((rS1 & (1 << B5)) == 0) { - ExceptionCore(VEC9, ExceptionKind::TRAP); + if ((rS1 & (1U << B5)) == 0) { + TrapException(VEC9); } } @@ -1315,11 +1307,11 @@ OP_DEF(tb0) OP_DEF(tb1) { if (IsUser() && VEC9 < 128) { - Exception(M88K_EXCEP_PRIV); + Exception(EXCPRI_PRIV); return; } - if ((rS1 & (1 << B5)) != 0) { - ExceptionCore(VEC9, ExceptionKind::TRAP); + if ((rS1 & (1U << B5)) != 0) { + TrapException(VEC9); } else if (pseudo_stop_enable) { // OpenBSD の STOP エミュレーション。 @@ -1340,7 +1332,7 @@ OP_DEF(tb1) if (IsSuper() && VEC9 == 0xff) { const auto& e = brhist.entry[brhist.top]; if (e.count == 3 - && e.to == xip + && e.to == reg.xip && e.from - e.to < 16) { ChangeState(CPU_STATE_STOP); } @@ -1352,18 +1344,18 @@ OP_DEF(tb1) OP_DEF(tcnd) { if (IsUser() && VEC9 < 128) { - Exception(M88K_EXCEP_PRIV); + Exception(EXCPRI_PRIV); return; } if ((acc_cnd(rS1) & M5) != 0) { - ExceptionCore(VEC9, ExceptionKind::TRAP); + TrapException(VEC9); } } // 111101_DDDDDSSSSS_000000_xU000sssss OP_DEF(xmem_bu) { - uint64 tmp; + busdata data; uint32 addr; uint32 usr; @@ -1374,22 +1366,23 @@ OP_DEF(xmem_bu) lastaddr = addr; // 例外安全のために都度 S/U ビットを制御 - if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].xmem_8(addr, rD & 0xff); - if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - XmemDataException(addr, DM_BU | DM_LOCK | usr); + ENTER_USR(); + data = cmmu[1]->xmem_1(addr, rD & 0xff); + LEAVE_USR(); + + if (__predict_false(data.IsBusErr())) { + XmemDataException(addr, DM_BU | usr); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data.Data(); } // 111101_DDDDDSSSSS_000001_xU000sssss OP_DEF(xmem_w) { - uint64 tmp; + busdata data; uint32 addr; uint32 usr; @@ -1400,23 +1393,24 @@ OP_DEF(xmem_w) lastaddr = addr; // 例外安全のために都度 S/U ビットを制御 - if (__predict_false(usr)) cmmu[1].SetSuper(false); - tmp = cmmu[1].xmem_32(addr, rD); - if (__predict_false(usr)) cmmu[1].SetSuper(true); - if ((int64)tmp < 0) { - XmemDataException(addr, DM_W | DM_LOCK | usr); + ENTER_USR(); + data = cmmu[1]->xmem_4(addr, rD); + LEAVE_USR(); + + if (__predict_false(data.IsBusErr())) { + XmemDataException(addr, DM_W | usr); return; } if (FLD_D == 0) return; - rD = tmp; + rD = data.Data(); } // 111101_DDDDDSSSSS_000010_xU000sssss OP_DEF(ld_hu) { - uint64 data; + busdata data; uint32 addr; uint32 usr; @@ -1426,24 +1420,24 @@ OP_DEF(ld_hu) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data = cmmu[1].load_16(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_2(addr); + LEAVE_USR(); - if ((int64)data < 0) { + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_HU | usr); return; } if (FLD_D == 0) return; - rD = data; + rD = data.Data(); } // 111101_DDDDDSSSSS_000011_xU000sssss OP_DEF(ld_bu) { - uint64 data; uint32 addr; + busdata data; uint32 usr; LDST_USR_SCALE_ALIGN(1); @@ -1452,24 +1446,24 @@ OP_DEF(ld_bu) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data = cmmu[1].load_8(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_1(addr); + LEAVE_USR(); - if ((int64)data < 0) { + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_BU | usr); return; } if (FLD_D == 0) return; - rD = data; + rD = data.Data(); } // 111101_DDDDDSSSSS_000100_xU000sssss OP_DEF(ld_d) { - uint64 data1, data2; - uint32 addr; + uint32 addr; // ReadDataException64() に渡すのは常に先頭アドレス。 + busdata data; uint32 usr; LDST_USR_SCALE_ALIGN(8); @@ -1479,34 +1473,36 @@ OP_DEF(ld_d) lastaddr = addr; // 例外安全のために都度 S/U ビットを制御 - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data1 = cmmu[1].load_32(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_4(addr); + LEAVE_USR(); - if ((int64)data1 < 0) { + if (__predict_false(data.IsBusErr())) { ReadDataException64(addr, DM_D1 | usr); return; } - addr += 4; + if (__predict_true(FLD_D != 0)) { + rD = data.Data(); + } - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data2 = cmmu[1].load_32(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_4(addr + 4); + LEAVE_USR(); - if ((int64)data2 < 0) { + if (__predict_false(data.IsBusErr())) { ReadDataException64(addr, DM_D2 | usr); return; } - rD = data1; - rD2 = data2; - r[0] = 0; + if (__predict_true(FLD_D2 != 0)) { + rD2 = data.Data(); + } } // 111101_DDDDDSSSSS_000101_xU000sssss OP_DEF(ld_w) { - uint64 data; uint32 addr; + busdata data; uint32 usr; LDST_USR_SCALE_ALIGN(4); @@ -1515,9 +1511,9 @@ OP_DEF(ld_w) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data = cmmu[1].load_32(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_4(addr); + LEAVE_USR(); if ((int64)data < 0) { ReadDataException32(addr, DM_W | usr); @@ -1531,8 +1527,8 @@ OP_DEF(ld_w) // 111101_DDDDDSSSSS_000110_xU000sssss OP_DEF(ld_h) { - uint64 data; uint32 addr; + busdata data; uint32 usr; LDST_USR_SCALE_ALIGN(2); @@ -1541,24 +1537,24 @@ OP_DEF(ld_h) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data = cmmu[1].load_16(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_2(addr); + LEAVE_USR(); - if ((int64)data < 0) { + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_H | usr); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int16)data; + rD = (uint32)(int32)(int16)data.Data(); } // 111101_DDDDDSSSSS_000111_xU000sssss OP_DEF(ld_b) { - uint64 data; uint32 addr; + busdata data; uint32 usr; LDST_USR_SCALE_ALIGN(1); @@ -1567,24 +1563,24 @@ OP_DEF(ld_b) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - data = cmmu[1].load_8(addr); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + data = cmmu[1]->load_1(addr); + LEAVE_USR(); - if ((int64)data < 0) { + if (__predict_false(data.IsBusErr())) { ReadDataException32(addr, DM_B | usr); return; } if (FLD_D == 0) return; - rD = (uint32)(int32)(int8)data; + rD = (uint32)(int32)(int8)data.Data(); } // 111101_DDDDDSSSSS_001000_xU000sssss OP_DEF(st_d) { - uint64 rv; - uint32 addr; + uint32 addr; // WriteDataException64() に渡すのは常に先頭アドレス。 + busdata r; uint32 usr; LDST_USR_SCALE_ALIGN(8); @@ -1593,22 +1589,20 @@ OP_DEF(st_d) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - rv = cmmu[1].store_32(addr, rD); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + r = cmmu[1]->store_4(addr, rD); + LEAVE_USR(); - if ((int64)rv < 0) { + if (__predict_false(r.IsBusErr())) { WriteDataException64(addr, DM_D1 | usr); return; } - addr += 4; - - if (__predict_false(usr)) cmmu[1].SetSuper(false); - rv = cmmu[1].store_32(addr, rD2); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + r = cmmu[1]->store_4(addr + 4, rD2); + LEAVE_USR(); - if ((int64)rv < 0) { + if (__predict_false(r.IsBusErr())) { WriteDataException64(addr, DM_D2 | usr); return; } @@ -1617,8 +1611,8 @@ OP_DEF(st_d) // 111101_DDDDDSSSSS_001001_xU000sssss OP_DEF(st_w) { - uint64 rv; uint32 addr; + busdata r; uint32 usr; LDST_USR_SCALE_ALIGN(4); @@ -1627,11 +1621,11 @@ OP_DEF(st_w) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - rv = cmmu[1].store_32(addr, rD); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + r = cmmu[1]->store_4(addr, rD); + LEAVE_USR(); - if ((int64)rv < 0) { + if (__predict_false(r.IsBusErr())) { WriteDataException32(addr, DM_W | usr); return; } @@ -1640,8 +1634,8 @@ OP_DEF(st_w) // 111101_DDDDDSSSSS_001010_xU000sssss OP_DEF(st_h) { - uint64 rv; uint32 addr; + busdata r; uint32 usr; LDST_USR_SCALE_ALIGN(2); @@ -1650,11 +1644,11 @@ OP_DEF(st_h) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - rv = cmmu[1].store_16(addr, rD & 0xffff); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + r = cmmu[1]->store_2(addr, rD & 0xffff); + LEAVE_USR(); - if ((int64)rv < 0) { + if (__predict_false(r.IsBusErr())) { WriteDataException32(addr, DM_H | usr); return; } @@ -1663,8 +1657,8 @@ OP_DEF(st_h) // 111101_DDDDDSSSSS_001011_xU000sssss OP_DEF(st_b) { - uint64 rv; uint32 addr; + busdata r; uint32 usr; LDST_USR_SCALE_ALIGN(1); @@ -1673,11 +1667,11 @@ OP_DEF(st_b) lastaddr = addr; - if (__predict_false(usr)) cmmu[1].SetSuper(false); - rv = cmmu[1].store_8(addr, rD & 0xff); - if (__predict_false(usr)) cmmu[1].SetSuper(true); + ENTER_USR(); + r = cmmu[1]->store_1(addr, rD & 0xff); + LEAVE_USR(); - if ((int64)rv < 0) { + if (__predict_false(r.IsBusErr())) { WriteDataException32(addr, DM_B | usr); return; } @@ -1823,15 +1817,12 @@ OP_DEF(subu) // 111101_DDDDDSSSSS_011010_zz000sssss OP_DEF(divu) { - if (!IsFPUEnable()) { - fpu_unimpl(); - return; - } + CHECK_FPU; AddCycle(38); // Table.7-6 (ただしざっくり) if (rS2 == 0) { - Exception(M88K_EXCEP_INT_DIV); + InternalException(EXCVEC_INT_DIV); return; } if (FLD_D == 0) @@ -1842,10 +1833,7 @@ OP_DEF(divu) // 111101_DDDDDSSSSS_011011_zz000sssss OP_DEF(mul) { - if (!IsFPUEnable()) { - fpu_unimpl(); - return; - } + CHECK_FPU; AddCycle(4); // Table.7-6 (ただしざっくり) @@ -1862,7 +1850,7 @@ OP_DEF(add) res += GetCY(); } if (isovf_add(rS1, rS2, res)) { - Exception(M88K_EXCEP_INT_OVF); + InternalException(EXCVEC_INT_OVF); return; } @@ -1888,7 +1876,7 @@ OP_DEF(sub) res += 1; } if (isovf_sub(rS1, rS2, res)) { - Exception(M88K_EXCEP_INT_OVF); + InternalException(EXCVEC_INT_OVF); return; } @@ -1904,15 +1892,12 @@ OP_DEF(sub) // 111101_DDDDDSSSSS_011110_zz000sssss OP_DEF(div) { - if (!IsFPUEnable()) { - fpu_unimpl(); - return; - } + CHECK_FPU; AddCycle(38); // Table.7-6 (ただしざっくり) if ((int32)rS1 < 0 || (int32)rS2 <= 0) { - Exception(M88K_EXCEP_INT_DIV); + InternalException(EXCVEC_INT_DIV); return; } if (FLD_D == 0) @@ -1948,7 +1933,7 @@ OP_DEF(set_2) OP_DEF(ext_2) { int w, o, left; - uint32 tmp; + uint32 res; if (FLD_D == 0) return; @@ -1957,16 +1942,16 @@ OP_DEF(ext_2) w = 32; o = (rS2 ) & 0x1f; left = 32 - w - o; - tmp = ASL(rS1, left); - tmp = ASR(tmp, left); - rD = ASR(tmp, o); + res = ASL(rS1, left); + res = ASR(res, left); + rD = ASR(res, o); } // 111101_DDDDDSSSSS_100110_00000sssss OP_DEF(extu_2) { int w, o, left; - uint32 tmp; + uint32 res; if (FLD_D == 0) return; @@ -1975,9 +1960,9 @@ OP_DEF(extu_2) w = 32; o = (rS2 ) & 0x1f; left = 32 - w - o; - tmp = ASL(rS1, left); - tmp = LSR(tmp, left); - rD = tmp >> o; + res = ASL(rS1, left); + res = LSR(res, left); + rD = res >> o; } // 111101_DDDDDSSSSS_101000_00000sssss @@ -2003,34 +1988,32 @@ OP_DEF(rot_2) OP_DEF(jmp) { AddCycle(1); // Table.7-5 - EnterBranch(rS2); - ExitBranch(); + DoBranch(rS2, false); } // 111101_zzzzzzzzzz_110001_00000sssss OP_DEF(jmp_n) { AddCycle(0); // Table.7-5 - EnterBranch(rS2); - ExitDelayBranch(); + DoBranch(rS2, true); } // 111101_zzzzzzzzzz_110010_00000sssss OP_DEF(jsr) { AddCycle(1); // Table.7-5 - EnterBranch(rS2); - r[1] = nip; - ExitBranch(); + uint32 toaddr = rS2; + reg.r[1] = reg.nip; + DoBranch(toaddr, false); } // 111101_zzzzzzzzzz_110011_00000sssss OP_DEF(jsr_n) { AddCycle(0); // Table.7-5 - EnterBranch(rS2); - r[1] = nip + 4; - ExitDelayBranch(); + uint32 toaddr = rS2; + reg.r[1] = reg.nip + 4; + DoBranch(toaddr, true); } // 111101_DDDDDzzzzz_111010_00000sssss @@ -2052,7 +2035,6 @@ OP_DEF(ff1) } rD = i; } - } // 111101_DDDDDzzzzz_111011_00000sssss @@ -2079,33 +2061,29 @@ OP_DEF(ff0) // 111101_zzzzzzzzzz_111111_0000000000 OP_DEF(rte) { + if (__predict_false(IsUser())) { + Exception(EXCPRI_PRIV); + return; + } + AddCycle(2); // Table.7-5 - SetPSR(epsr); + SetPSR(reg.epsr); - // LUNA88K の ROM1.2 は sxip, snip, sfip を制御してくる。 - // ROM1.2 の DAE ハンドラは、 - // sxip = INVALID - // snip = 0 (INVALID) - // sfip = original sxip - // で rte してくる。 - // CPU は sxip は評価しない。snip は 0 なので、無効として nop 扱い。 - // (実際はクロックが消費されるかも?) - // sfip が VALID なので、そこから実行を再開する。 - if ((snip & SIP_V)) { - EnterBranch(snip & SIP_MASK); - ExitBranch(); - fip = sfip & SIP_MASK; - } else { - EnterBranch(sfip & SIP_MASK); - ExitBranch(); + // 本当は有効な SxIP から順次パイプラインを埋めるだけで、 + // こんな条件分けになるわけではないのだが、分岐履歴とかのため。 + + if (__predict_false((reg.sfip & SIP_V) == 0)) { + // どうなる? + putlog(0, "rte: SFIP.V==0 (NOT IMPLEMENTED)"); } - // ディレイスロットにいた命令かどうかをやんわり復元する。 - // 88110 ではこの情報が E?IP に保持されているが - // 88100 にはない。 - if (nip + 4 != fip) { - ExitDelayBranch(); + if ((reg.snip & SIP_V)) { + DoBranch(reg.snip & SIP_MASK, false); + reg.fip = reg.sfip & SIP_MASK; + } else { + // PROM 1.20 の DAE ハンドラが snip の VALID を落として rte を呼ぶ。 + DoBranch(reg.sfip & SIP_MASK, false); } } @@ -2113,7 +2091,7 @@ OP_DEF(rte) OP_DEF(tbnd_1) { if (rS1 > rS2) { - Exception(M88K_EXCEP_BOUNDS); + InternalException(EXCVEC_BOUNDS); } } @@ -2121,7 +2099,7 @@ OP_DEF(tbnd_1) OP_DEF(tbnd_2) { if (rS1 > IMM16) { - Exception(M88K_EXCEP_BOUNDS); + InternalException(EXCVEC_BOUNDS); } }