From b45b0a8df417826dfcee479a421919f42147aa5e Mon Sep 17 00:00:00 2001 From: joevt Date: Mon, 2 Dec 2024 00:56:02 -0800 Subject: [PATCH] ppcopcodes: Fix divw for MPC601. --- cpu/ppc/ppcopcodes.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cpu/ppc/ppcopcodes.cpp b/cpu/ppc/ppcopcodes.cpp index 1ad5e5b..272e2da 100644 --- a/cpu/ppc/ppcopcodes.cpp +++ b/cpu/ppc/ppcopcodes.cpp @@ -529,14 +529,20 @@ void dppc_interpreter::ppc_divw(uint32_t opcode) { ppc_grab_regsdab(opcode); if (!ppc_result_b) { // handle the "anything / 0" case - ppc_result_d = 0; // tested on G4 in Mac OS X 10.4 and Open Firmware. + if (is_601) + ppc_result_d = (int32_t(ppc_result_a) < 0) ? 1 : -1; // tested on 601 in Mac OS 9.1 + else + 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) ppc_state.spr[SPR::XER] |= XER::SO | XER::OV; } 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 (is_601) + ppc_result_d = 0x80000000U; // tested on 601 in Mac OS 9.1 + else + ppc_result_d = 0; // tested on G4 in Mac OS X 10.4 and Open Firmware. if (ov) ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;