From f1e6a2ce9334917ad176cc5011f257e2b9546f58 Mon Sep 17 00:00:00 2001 From: dingusdev <52434309+dingusdev@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:37:32 -0700 Subject: [PATCH] Small fixes --- cpp.hint | 2 ++ cpu/ppc/ppcopcodes.cpp | 75 ++++++++++++++++++++++++++---------------- cpu/ppc/ppcopmacros.h | 2 +- 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/cpp.hint b/cpp.hint index a4544ae..081ad66 100644 --- a/cpp.hint +++ b/cpp.hint @@ -16,3 +16,5 @@ #define OPCODESHIFTREC(op, __VA_ARGS__) template void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } #define OPCODE601REC(op, __VA_ARGS__) template void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } #define OPCODEEXTSIGN(op, __VA_ARGS__) template void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } +#define ppc_store_iresult_reg(reg, ppc_result) ppc_state.gpr[reg] = ppc_result +#define ppc_set_xer(entry) ppc_state.spr[SPR::XER] |= entry \ No newline at end of file diff --git a/cpu/ppc/ppcopcodes.cpp b/cpu/ppc/ppcopcodes.cpp index 2971f2b..952c02c 100644 --- a/cpu/ppc/ppcopcodes.cpp +++ b/cpu/ppc/ppcopcodes.cpp @@ -232,20 +232,26 @@ OPCODEOVREC (subfme, uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA); uint32_t ppc_result_d = ~ppc_result_a + grab_ca - 1; - if (ppc_result_a == 0xFFFFFFFFUL && !grab_ca) - ppc_unset_xer(XER::CA); - else + if (ppc_result_a == 0xFFFFFFFFUL && !grab_ca) { + ppc_unset_xer(XER::CA); + } + else { ppc_set_xer(XER::CA); - - if (ov) { - if (ppc_result_d == ppc_result_a && int32_t(ppc_result_d) > 0) - ppc_set_xer(XER::SO | XER::OV); - else - ppc_unset_xer(XER::OV); } - if (rec) - ppc_changecrf0(ppc_result_d); + if (ov) { + if (ppc_result_d == ppc_result_a && int32_t(ppc_result_d) > 0) { + ppc_set_xer(XER::SO | XER::OV); + } + else { + ppc_unset_xer(XER::OV); + } + } + + if (rec) { + ppc_changecrf0(ppc_result_d); + } + ppc_store_iresult_reg(reg_d, ppc_result_d); ) @@ -276,7 +282,7 @@ OPCODEOVREC (subfze, } ppc_store_iresult_reg(reg_d, ppc_result_d); -) + ) OPCODESHIFT (andirc, ppc_grab_regssauimm(instr); @@ -442,16 +448,19 @@ OPCODEOVREC (divw, ppc_result_d = 0; // tested on G4 in Mac OS X 10.4 and Open Firmware. // ppc_result_d = (int32_t(ppc_result_a) < 0) ? -1 : 0; /* UNDOCUMENTED! */ - if (ov) + if (ov) { ppc_set_xer(XER::SO | XER::OV); + } - } else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) { + } + else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) { ppc_result_d = 0; // tested on G4 in Mac OS X 10.4 and Open Firmware. if (ov) ppc_set_xer(XER::SO | XER::OV); - } else { // normal signed devision + } + else { // normal signed devision ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b); if (ov) @@ -470,21 +479,27 @@ OPCODEOVREC (divwu, if (!ppc_result_b) { // division by zero - if (ov) + if (ov) { ppc_set_xer(XER::SO | XER::OV); + } - if (rec) + if (rec) { ppc_state.cr |= XER::CA; + } + } else { ppc_result_d = ppc_result_a / ppc_result_b; - if (ov) + if (ov) { ppc_unset_xer(XER::OV); - } - if (rec) + } + } + if (rec) { ppc_changecrf0(ppc_result_d); + } + ppc_store_iresult_reg(reg_d, ppc_result_d); ) @@ -496,13 +511,12 @@ OPCODESHIFTREC (shift, ppc_result_a = 0; } else { - ppc_result_a = isleft ? (ppc_result_d << (ppc_result_b & 0x1F)) - : (ppc_result_d >> (ppc_result_b & 0x1F)); - } - - if (rec) + ppc_result_a = (isleft ? (ppc_result_d << (ppc_result_b & 0x1F)) + : (ppc_result_d >> (ppc_result_b & 0x1F))); + } + if (rec) { ppc_changecrf0(ppc_result_a); - + } ppc_store_iresult_reg(reg_a, ppc_result_a); ) @@ -1007,10 +1021,12 @@ OPCODELKAA (bc, cnd_ok = (br_bo & 0x10) | (!(ppc_state.cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08)); if (ctr_ok && cnd_ok) { - if (a) + if (a) { ppc_next_instruction_address = br_bd; - else + } + else { ppc_next_instruction_address = uint32_t(ppc_state.pc + br_bd); + } exec_flags = EXEF_BRANCH; } @@ -1391,7 +1407,8 @@ OPCODEMEM (stux, uint32_t ea = ppc_result_a + ppc_result_b; mmu_write_vmem(ea, instr, ppc_result_d); ppc_state.gpr[reg_a] = ea; - } else { + } + else { ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); } ) diff --git a/cpu/ppc/ppcopmacros.h b/cpu/ppc/ppcopmacros.h index ea67291..06ab142 100644 --- a/cpu/ppc/ppcopmacros.h +++ b/cpu/ppc/ppcopmacros.h @@ -117,7 +117,7 @@ along with this program. If not, see . void dppc_interpreter::ppc_##op(uint32_t instr) { \ __VA_ARGS__ \ } \ - template void dppc_interpreter::ppc_##op(uint32_t instr) \ + template void dppc_interpreter::ppc_##op(uint32_t instr); \ template void dppc_interpreter::ppc_##op(uint32_t instr); \ template void dppc_interpreter::ppc_##op(uint32_t instr); \ template void dppc_interpreter::ppc_##op(uint32_t instr); \