2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2024-03-26 23:12:47 +00:00
|
|
|
Copyright (C) 2018-24 divingkatae and maximum
|
2020-02-28 16:04:28 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
// General opcodes for the processor - ppcopcodes.cpp
|
|
|
|
|
2022-01-10 15:36:14 +00:00
|
|
|
#include <core/timermanager.h>
|
2022-09-16 04:22:37 +00:00
|
|
|
#include <core/mathutils.h>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include "ppcemu.h"
|
2024-03-22 15:01:29 +00:00
|
|
|
#include "ppcmacros.h"
|
2020-05-12 18:55:45 +00:00
|
|
|
#include "ppcmmu.h"
|
|
|
|
#include <cinttypes>
|
2021-08-03 14:01:32 +00:00
|
|
|
#include <vector>
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
//Extract the registers desired and the values of the registers.
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Affects CR Field 0 - For integer operations
|
2020-01-26 02:30:55 +00:00
|
|
|
void ppc_changecrf0(uint32_t set_result) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= 0x0FFFFFFFUL;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (set_result == 0) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= 0x20000000UL;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-02-10 22:07:39 +00:00
|
|
|
if (set_result & 0x80000000) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= 0x80000000UL;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= 0x40000000UL;
|
2020-02-10 22:07:39 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 22:07:39 +00:00
|
|
|
/* copy XER[SO] into CR0[SO]. */
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= (ppc_state.spr[SPR::XER] >> 3) & 0x10000000UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Affects the XER register's Carry Bit
|
2020-02-09 07:01:26 +00:00
|
|
|
inline void ppc_carry(uint32_t a, uint32_t b) {
|
|
|
|
if (b < a) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 06:41:03 +00:00
|
|
|
inline void ppc_carry_sub(uint32_t a, uint32_t b) {
|
2020-02-09 07:01:26 +00:00
|
|
|
if (b >= a) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
2020-02-09 06:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Affects the XER register's SO and OV Bits
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-02-03 18:42:33 +00:00
|
|
|
inline void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
|
|
|
if ((a ^ b) & (a ^ d) & 0x80000000UL) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 14:01:32 +00:00
|
|
|
typedef std::function<void()> CtxSyncCallback;
|
|
|
|
std::vector<CtxSyncCallback> gCtxSyncCallbacks;
|
|
|
|
|
|
|
|
// perform context synchronization by executing registered actions if any
|
|
|
|
void do_ctx_sync() {
|
|
|
|
while (!gCtxSyncCallbacks.empty()) {
|
|
|
|
gCtxSyncCallbacks.back()();
|
|
|
|
gCtxSyncCallbacks.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_ctx_sync_action(const CtxSyncCallback &cb) {
|
|
|
|
gCtxSyncCallbacks.push_back(cb);
|
|
|
|
}
|
|
|
|
|
2019-07-02 02:15:33 +00:00
|
|
|
/**
|
|
|
|
The core functionality of this PPC emulation is within all of these void functions.
|
2020-05-12 18:55:45 +00:00
|
|
|
This is where the opcode tables in the ppcemumain.h come into play - reducing the number of
|
|
|
|
comparisons needed. This means loads of functions, but less CPU cycles needed to determine the
|
|
|
|
function (theoretically).
|
2019-07-02 02:15:33 +00:00
|
|
|
**/
|
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_shift shift>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_addi() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdasimm(ppc_cur_instruction);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (shift)
|
|
|
|
ppc_state.gpr[reg_d] = (reg_a == 0) ? (simm << 16) : (ppc_result_a + (simm << 16));
|
|
|
|
else
|
|
|
|
ppc_state.gpr[reg_d] = (reg_a == 0) ? simm : (ppc_result_a + simm);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 21:06:07 +00:00
|
|
|
template void dppc_interpreter::ppc_addi<SHFT0>();
|
|
|
|
template void dppc_interpreter::ppc_addi<SHFT1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_addic() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdasimm(ppc_cur_instruction);
|
|
|
|
uint32_t ppc_result_d = (ppc_result_a + simm);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
|
|
|
ppc_changecrf0(ppc_result_d);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_addic<RC0>();
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_addic<RC1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_carry carry, field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_add() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
|
|
|
uint32_t ppc_result_d = ppc_result_a + ppc_result_b;
|
2024-03-25 00:00:46 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (carry)
|
|
|
|
ppc_carry(ppc_result_a, ppc_result_d);
|
|
|
|
if (ov)
|
2024-03-25 06:20:18 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_add<CARRY0, RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY0, RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY0, RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY0, RC1, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY1, RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY1, RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY1, RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_add<CARRY1, RC1, OV1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_adde() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_adde<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_adde<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_adde<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_adde<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_addme() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = ppc_result_a + xer_ca - 1;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-23 22:10:08 +00:00
|
|
|
if (((xer_ca - 1) < 0xFFFFFFFFUL) || (ppc_result_d < ppc_result_a)) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_setsoov(ppc_result_a, 0, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_addme<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_addme<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_addme<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_addme<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_addze() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t grab_xer = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = ppc_result_a + grab_xer;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ppc_result_d < ppc_result_a) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-11-29 22:53:03 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_addze<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_addze<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_addze<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_addze<RC1, OV1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
void dppc_interpreter::ppc_subfic() {
|
|
|
|
ppc_grab_regsdasimm(ppc_cur_instruction);
|
|
|
|
uint32_t ppc_result_d = simm - ppc_result_a;
|
|
|
|
if (simm == -1)
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
|
|
|
else
|
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_carry carry, field_rc rec, field_ov ov>
|
2024-03-24 19:21:19 +00:00
|
|
|
void dppc_interpreter::ppc_subf() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
|
|
|
uint32_t ppc_result_d = ppc_result_b - ppc_result_a;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (carry)
|
|
|
|
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
|
|
|
if (ov)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_subf<CARRY0, RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY0, RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY0, RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY0, RC1, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY1, RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY1, RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY1, RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subf<CARRY1, RC1, OV1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_subfe() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
|
|
|
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
|
|
|
uint32_t ppc_result_d = ~ppc_result_a + ppc_result_b + grab_ca;
|
2023-12-18 00:59:07 +00:00
|
|
|
if (grab_ca && ppc_result_b == 0xFFFFFFFFUL)
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
|
|
|
else
|
|
|
|
ppc_carry(~ppc_result_a, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2020-02-03 23:58:04 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_subfe<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subfe<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_subfe<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subfe<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_subfme() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
|
|
|
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
|
|
|
uint32_t ppc_result_d = ~ppc_result_a + grab_ca - 1;
|
2020-11-29 22:53:03 +00:00
|
|
|
|
2023-12-24 01:35:38 +00:00
|
|
|
if (ppc_result_a == 0xFFFFFFFFUL && !grab_ca)
|
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
|
|
|
else
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov) {
|
2024-02-18 14:06:27 +00:00
|
|
|
if (ppc_result_d == ppc_result_a && int32_t(ppc_result_d) > 0)
|
2023-12-24 01:35:38 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
|
|
|
else
|
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2023-12-17 03:09:09 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_subfme<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subfme<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_subfme<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subfme<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_subfze() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
|
|
|
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
|
|
|
uint32_t ppc_result_d = ~ppc_result_a + grab_ca;
|
2023-12-30 14:58:21 +00:00
|
|
|
|
|
|
|
if (!ppc_result_d && grab_ca) // special case: ppc_result_d = 0 and CA=1
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
|
|
|
else
|
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov) {
|
2023-12-30 14:58:21 +00:00
|
|
|
if (ppc_result_d && ppc_result_d == ppc_result_a)
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
|
|
|
else
|
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2023-12-17 07:31:54 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2020-02-03 23:58:04 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2020-02-03 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_subfze<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subfze<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_subfze<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_subfze<RC1, OV1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_shift shift>
|
2024-03-24 19:21:19 +00:00
|
|
|
void dppc_interpreter::ppc_andirc() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssauimm(ppc_cur_instruction);
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = shift ? (ppc_result_d & (uimm << 16)) : (ppc_result_d & uimm);
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2024-03-26 22:47:42 +00:00
|
|
|
}
|
2020-10-17 21:30:37 +00:00
|
|
|
|
2024-03-24 21:06:07 +00:00
|
|
|
template void dppc_interpreter::ppc_andirc<SHFT0>();
|
|
|
|
template void dppc_interpreter::ppc_andirc<SHFT1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_shift shift>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_ori() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssauimm(ppc_cur_instruction);
|
2024-03-25 00:24:36 +00:00
|
|
|
ppc_result_a = shift ? (ppc_result_d | (uimm << 16)) : (ppc_result_d | uimm);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 21:06:07 +00:00
|
|
|
template void dppc_interpreter::ppc_ori<SHFT0>();
|
|
|
|
template void dppc_interpreter::ppc_ori<SHFT1>();
|
2020-10-17 21:30:37 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_shift shift>
|
2024-03-24 19:21:19 +00:00
|
|
|
void dppc_interpreter::ppc_xori() {
|
|
|
|
ppc_grab_regssauimm(ppc_cur_instruction);
|
|
|
|
ppc_result_a = shift ? (ppc_result_d ^ (uimm << 16)) : (ppc_result_d ^ uimm);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 21:06:07 +00:00
|
|
|
template void dppc_interpreter::ppc_xori<SHFT0>();
|
|
|
|
template void dppc_interpreter::ppc_xori<SHFT1>();
|
2020-10-17 21:30:37 +00:00
|
|
|
|
2024-03-27 01:51:42 +00:00
|
|
|
template <logical_fun logical_op, field_rc rec>
|
|
|
|
void dppc_interpreter::ppc_logical() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-27 01:51:42 +00:00
|
|
|
if (logical_op == logical_fun::ppc_and)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ppc_result_d & ppc_result_b;
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_andc)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ppc_result_d & ~(ppc_result_b);
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_eqv)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ~(ppc_result_d ^ ppc_result_b);
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_nand)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ~(ppc_result_d & ppc_result_b);
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_nor)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ~(ppc_result_d | ppc_result_b);
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_or)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ppc_result_d | ppc_result_b;
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_orc)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ppc_result_d | ~(ppc_result_b);
|
2024-03-27 01:51:42 +00:00
|
|
|
else if (logical_op == logical_fun::ppc_xor)
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = ppc_result_d ^ ppc_result_b;
|
|
|
|
|
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-27 01:51:42 +00:00
|
|
|
template void dppc_interpreter::ppc_logical<ppc_and, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_andc, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_eqv, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_nand, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_nor, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_or, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_orc, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_xor, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_and, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_andc, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_eqv, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_nand, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_nor, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_or, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_orc, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_logical<ppc_xor, RC1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_neg() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
|
|
|
uint32_t ppc_result_d = ~(ppc_result_a) + 1;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov) {
|
2020-10-17 21:30:37 +00:00
|
|
|
if (ppc_result_a == 0x80000000)
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
2020-10-17 21:30:37 +00:00
|
|
|
else
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2020-10-17 21:30:37 +00:00
|
|
|
}
|
2020-11-29 22:53:03 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_neg<RC0, OV0>();
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_neg<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_neg<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_neg<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_cntlzw() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2019-10-09 01:39:39 +00:00
|
|
|
|
|
|
|
uint32_t bit_check = ppc_result_d;
|
|
|
|
|
2024-02-21 14:14:21 +00:00
|
|
|
#ifdef __builtin_clz //for GCC and Clang users
|
2020-12-18 17:31:05 +00:00
|
|
|
uint32_t lead = !bit_check ? 32 : __builtin_clz(bit_check);
|
2024-02-21 14:14:21 +00:00
|
|
|
#elif defined __lzcnt //for Visual C++ users
|
2020-12-18 17:31:05 +00:00
|
|
|
uint32_t lead = __lzcnt(bit_check);
|
2020-01-26 02:30:55 +00:00
|
|
|
#else
|
2020-12-18 17:31:05 +00:00
|
|
|
uint32_t lead, mask;
|
|
|
|
|
|
|
|
for (mask = 0x80000000UL, lead = 0; mask != 0; lead++, mask >>= 1) {
|
2020-01-31 17:03:27 +00:00
|
|
|
if (bit_check & mask)
|
|
|
|
break;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-10-09 01:39:39 +00:00
|
|
|
ppc_result_a = lead;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec) {
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
2020-01-31 17:03:27 +00:00
|
|
|
}
|
2020-10-17 21:30:37 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_cntlzw<RC0>();
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_cntlzw<RC1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mulhwu() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-02-16 13:55:13 +00:00
|
|
|
uint64_t product = uint64_t(ppc_result_a) * uint64_t(ppc_result_b);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = uint32_t(product >> 32);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_mulhwu<RC0>();
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_mulhwu<RC1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mulhw() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-02-16 13:55:13 +00:00
|
|
|
int64_t product = int64_t(int32_t(ppc_result_a)) * int64_t(int32_t(ppc_result_b));
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = product >> 32;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_mulhw<RC0>();
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_mulhw<RC1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mullw() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-02-16 13:55:13 +00:00
|
|
|
int64_t product = int64_t(int32_t(ppc_result_a)) * int64_t(int32_t(ppc_result_b));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov) {
|
2024-02-16 13:55:13 +00:00
|
|
|
if (product != int64_t(int32_t(product))) {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
2020-10-17 21:30:37 +00:00
|
|
|
} else {
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2020-10-17 21:30:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = (uint32_t)product;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_mullw<RC0, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_mullw<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_mullw<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_mullw<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mulli() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdasimm(ppc_cur_instruction);
|
|
|
|
int64_t product = int64_t(int32_t(ppc_result_a)) * int64_t(int32_t(simm));
|
|
|
|
uint32_t ppc_result_d = uint32_t(product);
|
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_divw() {
|
2024-03-25 00:00:46 +00:00
|
|
|
uint32_t ppc_result_d;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2024-03-26 22:47:42 +00:00
|
|
|
if (!ppc_result_b) { // handle the "anything / 0" case
|
2023-12-17 13:32:54 +00:00
|
|
|
ppc_result_d = 0; // tested on G4 in Mac OS X 10.4 and Open Firmware.
|
|
|
|
// ppc_result_d = (ppc_result_a & 0x80000000) ? -1 : 0; /* UNDOCUMENTED! */
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
} else if (ppc_result_a == 0x80000000UL && ppc_result_b == 0xFFFFFFFFUL) {
|
2024-02-17 09:01:27 +00:00
|
|
|
ppc_result_d = 0; // tested on G4 in Mac OS X 10.4 and Open Firmware.
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
2019-10-09 01:39:39 +00:00
|
|
|
|
2024-03-26 22:47:42 +00:00
|
|
|
} else { // normal signed devision
|
2024-02-16 13:55:13 +00:00
|
|
|
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2020-02-10 15:06:56 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_divw<RC0, OV0>();
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_divw<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_divw<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_divw<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec, field_ov ov>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_divwu() {
|
2024-03-25 00:00:46 +00:00
|
|
|
uint32_t ppc_result_d;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2024-03-26 22:47:42 +00:00
|
|
|
if (!ppc_result_b) { // division by zero
|
2019-07-12 05:27:14 +00:00
|
|
|
ppc_result_d = 0;
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_state.cr |= 0x20000000;
|
2019-07-12 05:27:14 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-02-10 16:16:18 +00:00
|
|
|
ppc_result_d = ppc_result_a / ppc_result_b;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ov)
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
2019-07-12 05:27:14 +00:00
|
|
|
}
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_d);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_divwu<RC0, OV0>();
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_divwu<RC0, OV1>();
|
|
|
|
template void dppc_interpreter::ppc_divwu<RC1, OV0>();
|
|
|
|
template void dppc_interpreter::ppc_divwu<RC1, OV1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Value shifting
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-27 01:53:11 +00:00
|
|
|
template <field_direction isleft, field_rc rec>
|
2024-03-24 19:21:19 +00:00
|
|
|
void dppc_interpreter::ppc_shift() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
|
|
|
ppc_result_a = 0;
|
2024-03-26 22:47:42 +00:00
|
|
|
}
|
2024-03-24 19:21:19 +00:00
|
|
|
else {
|
2024-03-27 01:53:11 +00:00
|
|
|
ppc_result_a = isleft ? (ppc_result_d << (ppc_result_b & 0x1F))
|
|
|
|
: (ppc_result_d >> (ppc_result_b & 0x1F));
|
2020-02-03 19:36:22 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-27 01:53:11 +00:00
|
|
|
template void dppc_interpreter::ppc_shift<RIGHT0, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_shift<RIGHT0, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_shift<LEFT1, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_shift<LEFT1, RC1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_sraw() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2023-12-17 06:01:02 +00:00
|
|
|
|
|
|
|
// clear XER[CA] by default
|
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
|
|
|
|
2020-02-03 19:36:22 +00:00
|
|
|
if (ppc_result_b & 0x20) {
|
2023-12-17 06:01:02 +00:00
|
|
|
// fill rA with the sign bit of rS
|
2024-03-25 00:24:36 +00:00
|
|
|
ppc_result_a = int32_t(ppc_result_d) >> 31;
|
2023-12-17 06:01:02 +00:00
|
|
|
if (ppc_result_a) // if rA is negative
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-02-03 19:36:22 +00:00
|
|
|
uint32_t shift = ppc_result_b & 0x1F;
|
2024-02-15 05:19:08 +00:00
|
|
|
ppc_result_a = int32_t(ppc_result_d) >> shift;
|
2023-12-17 06:01:02 +00:00
|
|
|
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & ((1U << shift) - 1)))
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_sraw<RC0>();
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_sraw<RC1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_rc rec>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_srawi() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-02-15 05:19:08 +00:00
|
|
|
uint32_t shift = (ppc_cur_instruction >> 11) & 0x1F;
|
|
|
|
|
|
|
|
// clear XER[CA] by default
|
|
|
|
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
|
|
|
|
|
|
|
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & ((1U << shift) - 1)))
|
|
|
|
ppc_state.spr[SPR::XER] |= XER::CA;
|
|
|
|
|
2024-02-18 10:22:52 +00:00
|
|
|
ppc_result_a = int32_t(ppc_result_d) >> shift;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_srawi<RC0>();
|
2024-03-28 11:50:38 +00:00
|
|
|
template void dppc_interpreter::ppc_srawi<RC1>();
|
2024-03-24 19:21:19 +00:00
|
|
|
|
2019-08-05 16:42:15 +00:00
|
|
|
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
2020-05-12 18:55:45 +00:00
|
|
|
static inline uint32_t rot_mask(unsigned rot_mb, unsigned rot_me) {
|
2019-08-05 16:42:15 +00:00
|
|
|
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
2022-12-21 11:20:39 +00:00
|
|
|
uint32_t m2 = (uint32_t)(0xFFFFFFFFUL << (31 - rot_me));
|
2019-08-05 16:42:15 +00:00
|
|
|
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_rlwimi() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-03-26 23:12:47 +00:00
|
|
|
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
|
|
|
|
unsigned rot_mb = (ppc_cur_instruction >> 6) & 0x1F;
|
|
|
|
unsigned rot_me = (ppc_cur_instruction >> 1) & 0x1F;
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t mask = rot_mask(rot_mb, rot_me);
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) |
|
|
|
|
(ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result_a = (ppc_result_a & ~mask) | (r & mask);
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_cur_instruction & 0x01) == 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
}
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_rlwinm() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-03-26 23:12:47 +00:00
|
|
|
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
|
|
|
|
unsigned rot_mb = (ppc_cur_instruction >> 6) & 0x1F;
|
|
|
|
unsigned rot_me = (ppc_cur_instruction >> 1) & 0x1F;
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t mask = rot_mask(rot_mb, rot_me);
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) |
|
|
|
|
(ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result_a = r & mask;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_cur_instruction & 0x01) == 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
}
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_rlwnm() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-26 23:12:47 +00:00
|
|
|
ppc_result_b &= 0x1F;
|
|
|
|
unsigned rot_mb = (ppc_cur_instruction >> 6) & 0x1F;
|
|
|
|
unsigned rot_me = (ppc_cur_instruction >> 1) & 0x1F;
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t mask = rot_mask(rot_mb, rot_me);
|
2023-12-08 07:59:49 +00:00
|
|
|
uint32_t rot = ppc_result_b & 0x1F;
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t r = rot ? ((ppc_result_d << rot) |
|
|
|
|
(ppc_result_d >> (32 - rot))) : ppc_result_d;
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result_a = r & mask;
|
2020-01-26 02:30:55 +00:00
|
|
|
if ((ppc_cur_instruction & 0x01) == 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
}
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mfcr() {
|
2024-03-26 23:12:47 +00:00
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 0x1F;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.gpr[reg_d] = ppc_state.cr;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtsr() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::PR) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-26 23:12:47 +00:00
|
|
|
int reg_s = (ppc_cur_instruction >> 21) & 0x1F;
|
|
|
|
uint32_t grab_sr = (ppc_cur_instruction >> 16) & 0x0F;
|
2023-11-21 15:06:50 +00:00
|
|
|
ppc_state.sr[grab_sr] = ppc_state.gpr[reg_s];
|
|
|
|
mmu_pat_ctx_changed();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtsrin() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::PR) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssb(ppc_cur_instruction);
|
2024-01-05 22:11:37 +00:00
|
|
|
uint32_t grab_sr = ppc_result_b >> 28;
|
2023-11-21 15:06:50 +00:00
|
|
|
ppc_state.sr[grab_sr] = ppc_result_d;
|
|
|
|
mmu_pat_ctx_changed();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mfsr() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::PR) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-26 23:12:47 +00:00
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 0x1F;
|
|
|
|
uint32_t grab_sr = (ppc_cur_instruction >> 16) & 0x0F;
|
2023-11-21 15:06:50 +00:00
|
|
|
ppc_state.gpr[reg_d] = ppc_state.sr[grab_sr];
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mfsrin() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::PR) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdb(ppc_cur_instruction);
|
2024-01-05 22:11:37 +00:00
|
|
|
uint32_t grab_sr = ppc_result_b >> 28;
|
2023-11-21 15:06:50 +00:00
|
|
|
ppc_state.gpr[reg_d] = ppc_state.sr[grab_sr];
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mfmsr() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::PR) {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t reg_d = (ppc_cur_instruction >> 21) & 0x1F;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.gpr[reg_d] = ppc_state.msr;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtmsr() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::PR) {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
2020-01-11 20:48:56 +00:00
|
|
|
}
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t reg_s = (ppc_cur_instruction >> 21) & 0x1F;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.msr = ppc_state.gpr[reg_s];
|
2022-08-24 10:51:43 +00:00
|
|
|
|
|
|
|
// generate External Interrupt Exception
|
|
|
|
// if CPU interrupt line is asserted
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::EE && int_pin) {
|
2023-09-25 01:25:50 +00:00
|
|
|
//LOG_F(WARNING, "MTMSR: CPU INT pending, generate CPU exception");
|
2022-08-24 10:51:43 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
2023-11-21 15:06:50 +00:00
|
|
|
} else if ((ppc_state.msr & MSR::EE) && dec_exception_pending) {
|
2023-08-07 18:11:02 +00:00
|
|
|
dec_exception_pending = false;
|
|
|
|
//LOG_F(WARNING, "MTMSR: decrementer exception triggered");
|
|
|
|
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
2022-08-24 10:51:43 +00:00
|
|
|
} else {
|
|
|
|
mmu_change_mode();
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 03:54:22 +00:00
|
|
|
static inline void calc_rtcl_value()
|
2022-03-22 11:23:54 +00:00
|
|
|
{
|
2022-09-16 03:54:22 +00:00
|
|
|
uint64_t new_ts = get_virt_time_ns();
|
2022-09-16 04:05:08 +00:00
|
|
|
uint64_t rtc_l = new_ts - rtc_timestamp + rtc_lo;
|
2022-03-22 11:23:54 +00:00
|
|
|
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
|
2022-12-21 11:20:39 +00:00
|
|
|
rtc_hi += (uint32_t)(rtc_l / ONE_BILLION_NS);
|
2022-03-22 11:23:54 +00:00
|
|
|
rtc_lo = rtc_l % ONE_BILLION_NS;
|
|
|
|
}
|
2022-09-16 03:54:22 +00:00
|
|
|
else {
|
2022-12-21 11:20:39 +00:00
|
|
|
rtc_lo = (uint32_t)rtc_l;
|
2022-09-16 03:54:22 +00:00
|
|
|
}
|
|
|
|
rtc_timestamp = new_ts;
|
2022-03-22 11:23:54 +00:00
|
|
|
}
|
|
|
|
|
2023-02-09 00:38:55 +00:00
|
|
|
static inline uint64_t calc_tbr_value()
|
|
|
|
{
|
|
|
|
uint64_t tbr_inc;
|
|
|
|
uint32_t tbr_inc_lo;
|
|
|
|
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
|
|
|
|
_u32xu64(tbr_freq_ghz, diff, tbr_inc, tbr_inc_lo);
|
|
|
|
return (tbr_wr_value + tbr_inc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t calc_dec_value() {
|
|
|
|
uint64_t dec_adj;
|
|
|
|
uint32_t dec_adj_lo;
|
|
|
|
uint64_t diff = get_virt_time_ns() - dec_wr_timestamp;
|
|
|
|
_u32xu64(tbr_freq_ghz, diff, dec_adj, dec_adj_lo);
|
2023-06-02 08:23:21 +00:00
|
|
|
return (dec_wr_value - static_cast<uint32_t>(dec_adj));
|
2023-02-09 00:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_timebase(uint64_t mask, uint64_t new_val)
|
|
|
|
{
|
|
|
|
uint64_t tbr_value = calc_tbr_value();
|
|
|
|
tbr_wr_value = (tbr_value & mask) | new_val;
|
|
|
|
tbr_wr_timestamp = get_virt_time_ns();
|
|
|
|
}
|
|
|
|
|
2023-08-07 18:11:02 +00:00
|
|
|
|
|
|
|
static uint32_t decrementer_timer_id = 0;
|
|
|
|
|
|
|
|
static void trigger_decrementer_exception() {
|
|
|
|
decrementer_timer_id = 0;
|
|
|
|
dec_wr_value = -1;
|
|
|
|
dec_wr_timestamp = get_virt_time_ns();
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::EE) {
|
2023-08-07 18:11:02 +00:00
|
|
|
dec_exception_pending = false;
|
|
|
|
//LOG_F(WARNING, "decrementer exception triggered");
|
|
|
|
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//LOG_F(WARNING, "decrementer exception pending");
|
|
|
|
dec_exception_pending = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 00:38:55 +00:00
|
|
|
static void update_decrementer(uint32_t val) {
|
|
|
|
dec_wr_value = val;
|
|
|
|
dec_wr_timestamp = get_virt_time_ns();
|
2023-08-07 18:11:02 +00:00
|
|
|
|
|
|
|
dec_exception_pending = false;
|
|
|
|
|
2023-09-18 19:20:02 +00:00
|
|
|
if (is_601)
|
|
|
|
return;
|
|
|
|
|
2023-08-07 18:11:02 +00:00
|
|
|
if (decrementer_timer_id) {
|
|
|
|
//LOG_F(WARNING, "decrementer cancel timer");
|
|
|
|
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t time_out;
|
|
|
|
uint32_t time_out_lo;
|
|
|
|
_u32xu64(val, tbr_period_ns, time_out, time_out_lo);
|
|
|
|
//LOG_F(WARNING, "decrementer:0x%08X ns:%llu", val, time_out);
|
|
|
|
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
|
|
|
time_out,
|
|
|
|
trigger_decrementer_exception
|
|
|
|
);
|
2023-02-09 00:38:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mfspr() {
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 0x1F) << 5) |
|
|
|
|
((ppc_cur_instruction >> 16) & 0x1F);
|
2020-01-15 03:50:01 +00:00
|
|
|
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
2020-01-15 03:50:01 +00:00
|
|
|
if (ref_spr > 31) {
|
2021-04-29 00:26:17 +00:00
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
2022-03-22 11:23:54 +00:00
|
|
|
|
|
|
|
switch (ref_spr) {
|
|
|
|
case SPR::RTCL_U:
|
2022-09-16 03:54:22 +00:00
|
|
|
calc_rtcl_value();
|
|
|
|
ppc_state.spr[SPR::RTCL_U] = rtc_lo & 0x3FFFFF80UL;
|
2022-03-22 11:23:54 +00:00
|
|
|
break;
|
|
|
|
case SPR::RTCU_U:
|
2022-09-16 03:54:22 +00:00
|
|
|
calc_rtcl_value();
|
2022-09-14 07:33:44 +00:00
|
|
|
ppc_state.spr[SPR::RTCU_U] = rtc_hi;
|
2022-03-22 11:23:54 +00:00
|
|
|
break;
|
2023-02-09 00:38:55 +00:00
|
|
|
case SPR::DEC:
|
|
|
|
ppc_state.spr[SPR::DEC] = calc_dec_value();
|
|
|
|
break;
|
2022-03-22 11:23:54 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 23:12:47 +00:00
|
|
|
ppc_state.gpr[(ppc_cur_instruction >> 21) & 0x1F] = ppc_state.spr[ref_spr];
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtspr() {
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 0x1F) << 5) |
|
|
|
|
((ppc_cur_instruction >> 16) & 0x1F);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
2020-01-15 03:50:01 +00:00
|
|
|
if (ref_spr > 31) {
|
2021-04-29 00:26:17 +00:00
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-03-02 09:45:24 +00:00
|
|
|
if (ref_spr == SPR::PVR || (
|
|
|
|
ref_spr == SPR::MQ && !is_601
|
|
|
|
)) { // prevent writes to the read-only registers
|
2024-02-17 08:40:24 +00:00
|
|
|
return;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t val = ppc_state.gpr[(ppc_cur_instruction >> 21) & 0x1F];
|
2024-02-17 08:40:24 +00:00
|
|
|
ppc_state.spr[ref_spr] = val;
|
2021-08-03 14:01:32 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
switch (ref_spr) {
|
2024-02-17 08:40:24 +00:00
|
|
|
case SPR::XER:
|
|
|
|
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
|
|
|
|
break;
|
|
|
|
case SPR::SDR1:
|
|
|
|
mmu_pat_ctx_changed(); // adapt to SDR1 changes
|
|
|
|
break;
|
2022-03-22 11:23:54 +00:00
|
|
|
case SPR::RTCL_S:
|
2022-09-16 03:59:56 +00:00
|
|
|
calc_rtcl_value();
|
2022-03-22 11:23:54 +00:00
|
|
|
rtc_lo = val & 0x3FFFFF80UL;
|
|
|
|
break;
|
|
|
|
case SPR::RTCU_S:
|
2022-09-16 03:59:56 +00:00
|
|
|
calc_rtcl_value();
|
2022-03-22 11:23:54 +00:00
|
|
|
rtc_hi = val;
|
|
|
|
break;
|
2023-02-09 00:38:55 +00:00
|
|
|
case SPR::DEC:
|
|
|
|
update_decrementer(val);
|
|
|
|
break;
|
2022-03-22 11:23:54 +00:00
|
|
|
case SPR::TBL_S:
|
|
|
|
update_timebase(0xFFFFFFFF00000000ULL, val);
|
2020-01-26 02:30:55 +00:00
|
|
|
break;
|
2022-03-22 11:23:54 +00:00
|
|
|
case SPR::TBU_S:
|
2024-02-16 13:55:13 +00:00
|
|
|
update_timebase(0x00000000FFFFFFFFULL, uint64_t(val) << 32);
|
2020-01-26 02:30:55 +00:00
|
|
|
break;
|
|
|
|
case 528:
|
|
|
|
case 529:
|
|
|
|
case 530:
|
|
|
|
case 531:
|
|
|
|
case 532:
|
|
|
|
case 533:
|
|
|
|
case 534:
|
|
|
|
case 535:
|
|
|
|
ibat_update(ref_spr);
|
|
|
|
break;
|
|
|
|
case 536:
|
|
|
|
case 537:
|
|
|
|
case 538:
|
|
|
|
case 539:
|
|
|
|
case 540:
|
|
|
|
case 541:
|
|
|
|
case 542:
|
|
|
|
case 543:
|
|
|
|
dbat_update(ref_spr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mftb() {
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 0x1F) << 5) |
|
|
|
|
((ppc_cur_instruction >> 16) & 0x1F);
|
|
|
|
int reg_d = (ppc_cur_instruction >> 21) & 0x1F;
|
2021-12-19 23:12:44 +00:00
|
|
|
|
|
|
|
uint64_t tbr_value = calc_tbr_value();
|
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
switch (ref_spr) {
|
2022-03-22 11:23:54 +00:00
|
|
|
case SPR::TBL_U:
|
2024-02-18 10:22:52 +00:00
|
|
|
ppc_state.gpr[reg_d] = uint32_t(tbr_value);
|
2021-12-19 23:12:44 +00:00
|
|
|
break;
|
2022-03-22 11:23:54 +00:00
|
|
|
case SPR::TBU_U:
|
2024-02-18 10:22:52 +00:00
|
|
|
ppc_state.gpr[reg_d] = uint32_t(tbr_value >> 32);
|
2021-12-19 23:12:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2021-10-06 00:40:09 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mtcrf() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-01-02 16:43:17 +00:00
|
|
|
uint8_t crm = (ppc_cur_instruction >> 12) & 0xFFU;
|
|
|
|
|
|
|
|
uint32_t cr_mask = 0;
|
|
|
|
|
|
|
|
if (crm == 0xFFU) // the fast case
|
|
|
|
cr_mask = 0xFFFFFFFFUL;
|
|
|
|
else { // the slow case
|
|
|
|
if (crm & 0x80) cr_mask |= 0xF0000000UL;
|
|
|
|
if (crm & 0x40) cr_mask |= 0x0F000000UL;
|
|
|
|
if (crm & 0x20) cr_mask |= 0x00F00000UL;
|
|
|
|
if (crm & 0x10) cr_mask |= 0x000F0000UL;
|
|
|
|
if (crm & 0x08) cr_mask |= 0x0000F000UL;
|
|
|
|
if (crm & 0x04) cr_mask |= 0x00000F00UL;
|
|
|
|
if (crm & 0x02) cr_mask |= 0x000000F0UL;
|
|
|
|
if (crm & 0x01) cr_mask |= 0x0000000FUL;
|
|
|
|
}
|
|
|
|
ppc_state.cr = (ppc_state.cr & ~cr_mask) | (ppc_result_d & cr_mask);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_mcrxr() {
|
2021-01-08 21:34:01 +00:00
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_state.cr = (ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
|
|
|
((ppc_state.spr[SPR::XER] & 0xF0000000UL) >> crf_d);
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.spr[SPR::XER] &= 0x0FFFFFFF;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <class T, field_rc rec>
|
2024-03-24 19:21:19 +00:00
|
|
|
void dppc_interpreter::ppc_exts() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_result_a = int32_t(T(ppc_result_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
if (rec)
|
2020-10-17 21:30:37 +00:00
|
|
|
ppc_changecrf0(ppc_result_a);
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 00:24:36 +00:00
|
|
|
template void dppc_interpreter::ppc_exts<int8_t, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_exts<int16_t, RC0>();
|
|
|
|
template void dppc_interpreter::ppc_exts<int8_t, RC1>();
|
|
|
|
template void dppc_interpreter::ppc_exts<int16_t, RC1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Branching Instructions
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_lk l, field_aa a>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_b() {
|
2024-03-26 23:12:47 +00:00
|
|
|
int32_t adr_li = int32_t((ppc_cur_instruction & ~3UL) << 6) >> 6;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-09 02:22:25 +00:00
|
|
|
if (a)
|
|
|
|
ppc_next_instruction_address = adr_li;
|
|
|
|
else
|
|
|
|
ppc_next_instruction_address = uint32_t(ppc_state.pc + adr_li);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-09 02:22:25 +00:00
|
|
|
if (l)
|
|
|
|
ppc_state.spr[SPR::LR] = uint32_t(ppc_state.pc + 4);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2022-03-02 15:55:20 +00:00
|
|
|
exec_flags = EXEF_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_b<LK0, AA0>();
|
|
|
|
template void dppc_interpreter::ppc_b<LK0, AA1>();
|
|
|
|
template void dppc_interpreter::ppc_b<LK1, AA0>();
|
|
|
|
template void dppc_interpreter::ppc_b<LK1, AA1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_lk l, field_aa a>
|
2024-03-09 02:22:25 +00:00
|
|
|
void dppc_interpreter::ppc_bc() {
|
2019-08-03 05:00:04 +00:00
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 0x1F;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 0x1F;
|
2024-03-07 10:41:23 +00:00
|
|
|
int32_t br_bd = int32_t(int16_t(ppc_cur_instruction & ~3UL));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-03-05 04:29:04 +00:00
|
|
|
(ppc_state.spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-01-05 22:11:37 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) | ((ppc_state.spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
|
|
|
cnd_ok = (br_bo & 0x10) | (!(ppc_state.cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2024-03-09 02:22:25 +00:00
|
|
|
if (a)
|
|
|
|
ppc_next_instruction_address = br_bd;
|
|
|
|
else
|
|
|
|
ppc_next_instruction_address = uint32_t(ppc_state.pc + br_bd);
|
2022-03-02 15:55:20 +00:00
|
|
|
exec_flags = EXEF_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-09 02:22:25 +00:00
|
|
|
if (l)
|
|
|
|
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_bc<LK0, AA0>();
|
|
|
|
template void dppc_interpreter::ppc_bc<LK0, AA1>();
|
|
|
|
template void dppc_interpreter::ppc_bc<LK1, AA0>();
|
|
|
|
template void dppc_interpreter::ppc_bc<LK1, AA1>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template<field_lk l, field_601 for601>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_bcctr() {
|
2024-03-07 10:36:43 +00:00
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 0x1F;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 0x1F;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-07 10:36:43 +00:00
|
|
|
uint32_t ctr = ppc_state.spr[SPR::CTR];
|
|
|
|
uint32_t new_ctr;
|
|
|
|
if (for601) {
|
|
|
|
new_ctr = ctr - 1;
|
|
|
|
if (!(br_bo & 0x04)) {
|
|
|
|
ppc_state.spr[SPR::CTR] = new_ctr; /* decrement CTR */
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-07 10:36:43 +00:00
|
|
|
else {
|
|
|
|
new_ctr = ctr;
|
|
|
|
}
|
|
|
|
ctr_ok = (br_bo & 0x04) | ((new_ctr != 0) == !(br_bo & 0x02));
|
|
|
|
cnd_ok = (br_bo & 0x10) | (!(ppc_state.cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-07 10:36:43 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
|
|
|
ppc_next_instruction_address = (ctr & ~3UL);
|
2022-03-02 15:55:20 +00:00
|
|
|
exec_flags = EXEF_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-07 10:36:43 +00:00
|
|
|
|
|
|
|
if (l)
|
|
|
|
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_bcctr<LK0, NOT601>();
|
|
|
|
template void dppc_interpreter::ppc_bcctr<LK0, IS601>();
|
|
|
|
template void dppc_interpreter::ppc_bcctr<LK1, NOT601>();
|
|
|
|
template void dppc_interpreter::ppc_bcctr<LK1, IS601>();
|
2024-03-07 10:36:43 +00:00
|
|
|
|
2024-03-26 08:14:23 +00:00
|
|
|
template <field_lk l>
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_bclr() {
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t br_bo = (ppc_cur_instruction >> 21) & 0x1F;
|
|
|
|
uint32_t br_bi = (ppc_cur_instruction >> 16) & 0x1F;
|
2019-08-03 05:00:04 +00:00
|
|
|
uint32_t ctr_ok;
|
|
|
|
uint32_t cnd_ok;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (!(br_bo & 0x04)) {
|
2020-03-05 04:29:04 +00:00
|
|
|
(ppc_state.spr[SPR::CTR])--; /* decrement CTR */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-01-05 22:11:37 +00:00
|
|
|
ctr_ok = (br_bo & 0x04) | ((ppc_state.spr[SPR::CTR] != 0) == !(br_bo & 0x02));
|
|
|
|
cnd_ok = (br_bo & 0x10) | (!(ppc_state.cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-26 02:30:55 +00:00
|
|
|
if (ctr_ok && cnd_ok) {
|
2024-02-18 10:22:52 +00:00
|
|
|
ppc_next_instruction_address = (ppc_state.spr[SPR::LR] & ~3UL);
|
2022-03-02 15:55:20 +00:00
|
|
|
exec_flags = EXEF_BRANCH;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-03-08 03:44:36 +00:00
|
|
|
|
|
|
|
if (l)
|
|
|
|
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_bclr<LK0>();
|
|
|
|
template void dppc_interpreter::ppc_bclr<LK1>();
|
2019-08-03 05:00:04 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Compare Instructions
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_cmp() {
|
2020-02-25 02:50:52 +00:00
|
|
|
#ifdef CHECK_INVALID
|
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2022-08-14 12:26:56 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMP instruction form (L=1)!");
|
2020-02-25 02:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-08 21:34:01 +00:00
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3;
|
2024-02-15 05:19:08 +00:00
|
|
|
uint32_t cmp_c = (int32_t(ppc_result_a) == int32_t(ppc_result_b)) ? 0x20000000UL : \
|
|
|
|
(int32_t(ppc_result_a) > int32_t(ppc_result_b)) ? 0x40000000UL : 0x80000000UL;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_cmpi() {
|
2020-01-26 02:30:55 +00:00
|
|
|
#ifdef CHECK_INVALID
|
2019-08-03 04:38:23 +00:00
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2022-08-14 12:26:56 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMPI instruction form (L=1)!");
|
2019-08-03 04:38:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-08-03 04:38:23 +00:00
|
|
|
|
2021-01-08 21:34:01 +00:00
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsasimm(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3;
|
2024-02-15 05:19:08 +00:00
|
|
|
uint32_t cmp_c = (int32_t(ppc_result_a) == simm) ? 0x20000000UL : \
|
|
|
|
(int32_t(ppc_result_a) > simm) ? 0x40000000UL : 0x80000000UL;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_cmpl() {
|
2020-01-26 02:30:55 +00:00
|
|
|
#ifdef CHECK_INVALID
|
2019-08-03 04:38:23 +00:00
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2022-08-14 12:26:56 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMPL instruction form (L=1)!");
|
2019-08-03 04:38:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-08-03 04:38:23 +00:00
|
|
|
|
2021-01-08 21:34:01 +00:00
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3;
|
2024-02-15 05:19:08 +00:00
|
|
|
uint32_t cmp_c = (ppc_result_a == ppc_result_b) ? 0x20000000UL : \
|
|
|
|
(ppc_result_a > ppc_result_b) ? 0x40000000UL : 0x80000000UL;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_cmpli() {
|
2020-01-26 02:30:55 +00:00
|
|
|
#ifdef CHECK_INVALID
|
2019-08-03 04:38:23 +00:00
|
|
|
if (ppc_cur_instruction & 0x200000) {
|
2022-08-14 12:26:56 +00:00
|
|
|
LOG_F(WARNING, "Invalid CMPLI instruction form (L=1)!");
|
2019-08-03 04:38:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2019-08-03 04:38:23 +00:00
|
|
|
|
2021-01-08 21:34:01 +00:00
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssauimm(ppc_cur_instruction);
|
2024-03-26 22:47:42 +00:00
|
|
|
uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3;
|
2024-02-15 05:19:08 +00:00
|
|
|
uint32_t cmp_c = (ppc_result_a == uimm) ? 0x20000000UL : \
|
|
|
|
(ppc_result_a > uimm) ? 0x40000000UL : 0x80000000UL;
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr = ((ppc_state.cr & ~(0xf0000000UL >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Condition Register Changes
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-01-08 03:38:32 +00:00
|
|
|
void dppc_interpreter::ppc_mcrf() {
|
2021-01-08 21:34:01 +00:00
|
|
|
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
|
|
|
int crf_s = (ppc_cur_instruction >> 16) & 0x1C;
|
2021-01-08 20:58:57 +00:00
|
|
|
|
2022-05-17 06:44:50 +00:00
|
|
|
// extract and right justify source flags field
|
|
|
|
uint32_t grab_s = (ppc_state.cr >> (28 - crf_s)) & 0xF;
|
|
|
|
|
|
|
|
ppc_state.cr = (ppc_state.cr & ~(0xf0000000UL >> crf_d)) | (grab_s << (28 - crf_d));
|
2021-01-08 03:38:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_crand() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-21 13:56:10 +00:00
|
|
|
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) & (ppc_state.cr >> (31 - reg_b));
|
|
|
|
if (ir & 1) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-08 03:38:32 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_crandc() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-10 17:10:39 +00:00
|
|
|
if ((ppc_state.cr & (0x80000000UL >> reg_a)) && !(ppc_state.cr & (0x80000000UL >> reg_b))) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_creqv() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-21 15:32:07 +00:00
|
|
|
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) ^ (ppc_state.cr >> (31 - reg_b));
|
|
|
|
if (ir & 1) { // compliment is implemented by swapping the following if/else bodies
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2022-01-21 15:32:07 +00:00
|
|
|
} else {
|
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_crnand() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-23 05:33:13 +00:00
|
|
|
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) & (ppc_state.cr >> (31 - reg_b));
|
|
|
|
if (ir & 1) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2022-01-23 05:33:13 +00:00
|
|
|
} else {
|
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-23 05:33:13 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_crnor() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-23 05:33:13 +00:00
|
|
|
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) | (ppc_state.cr >> (31 - reg_b));
|
|
|
|
if (ir & 1) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2022-01-23 05:33:13 +00:00
|
|
|
} else {
|
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_cror() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-21 13:37:51 +00:00
|
|
|
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) | (ppc_state.cr >> (31 - reg_b));
|
|
|
|
if (ir & 1) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-21 13:37:51 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_crorc() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-10 17:10:39 +00:00
|
|
|
if ((ppc_state.cr & (0x80000000UL >> reg_a)) || !(ppc_state.cr & (0x80000000UL >> reg_b))) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_crxor() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_dab(ppc_cur_instruction);
|
2022-01-08 03:21:09 +00:00
|
|
|
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) ^ (ppc_state.cr >> (31 - reg_b));
|
|
|
|
if (ir & 1) {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr |= (0x80000000UL >> reg_d);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.cr &= ~(0x80000000UL >> reg_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Processor MGMT Fns.
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_rfi() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t new_srr1_val = (ppc_state.spr[SPR::SRR1] & 0x87C0FF73UL);
|
|
|
|
uint32_t new_msr_val = (ppc_state.msr & ~0x87C0FF73UL);
|
|
|
|
ppc_state.msr = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
|
2022-08-24 10:51:43 +00:00
|
|
|
|
|
|
|
// generate External Interrupt Exception
|
|
|
|
// if CPU interrupt line is still asserted
|
2023-11-21 15:06:50 +00:00
|
|
|
if (ppc_state.msr & MSR::EE && int_pin) {
|
2024-02-18 10:22:52 +00:00
|
|
|
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
|
2022-08-24 10:51:43 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
|
|
|
ppc_state.spr[SPR::SRR0] = save_srr0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-21 15:06:50 +00:00
|
|
|
if ((ppc_state.msr & MSR::EE) && dec_exception_pending) {
|
2023-08-07 18:11:02 +00:00
|
|
|
dec_exception_pending = false;
|
|
|
|
//LOG_F(WARNING, "decrementer exception from rfi msr:0x%X", ppc_state.msr);
|
2024-02-18 10:22:52 +00:00
|
|
|
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
|
2023-08-07 18:11:02 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
|
|
|
ppc_state.spr[SPR::SRR0] = save_srr0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-18 10:22:52 +00:00
|
|
|
ppc_next_instruction_address = ppc_state.spr[SPR::SRR0] & ~3UL;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2021-10-13 18:58:09 +00:00
|
|
|
do_ctx_sync(); // RFI is context synchronizing
|
|
|
|
|
2021-05-15 22:53:15 +00:00
|
|
|
mmu_change_mode();
|
|
|
|
|
2019-07-02 02:15:33 +00:00
|
|
|
grab_return = true;
|
2022-03-02 15:55:20 +00:00
|
|
|
exec_flags = EXEF_RFI;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_sc() {
|
2021-10-13 18:58:09 +00:00
|
|
|
do_ctx_sync(); // SC is context synchronizing!
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_SYSCALL, 0x20000);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_tw() {
|
2024-03-26 23:12:47 +00:00
|
|
|
uint32_t reg_a = (ppc_cur_instruction >> 11) & 0x1F;
|
|
|
|
uint32_t reg_b = (ppc_cur_instruction >> 16) & 0x1F;
|
|
|
|
uint32_t ppc_to = (ppc_cur_instruction >> 21) & 0x1F;
|
2024-02-18 14:06:27 +00:00
|
|
|
if (((int32_t(ppc_state.gpr[reg_a]) < int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x10)) ||
|
|
|
|
((int32_t(ppc_state.gpr[reg_a]) > int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x08)) ||
|
|
|
|
((int32_t(ppc_state.gpr[reg_a]) == int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x04)) ||
|
2021-01-08 03:38:32 +00:00
|
|
|
((ppc_state.gpr[reg_a] < ppc_state.gpr[reg_b]) && (ppc_to & 0x02)) ||
|
|
|
|
((ppc_state.gpr[reg_a] > ppc_state.gpr[reg_b]) && (ppc_to & 0x01))) {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_twi() {
|
2024-03-22 15:01:29 +00:00
|
|
|
int32_t simm = int32_t(int16_t(ppc_cur_instruction));
|
|
|
|
uint32_t reg_a = (ppc_cur_instruction >> 16) & 0x1F;
|
2024-01-08 00:04:51 +00:00
|
|
|
uint32_t ppc_to = (ppc_cur_instruction >> 21) & 0x1F;
|
2024-02-16 13:55:13 +00:00
|
|
|
if (((int32_t(ppc_state.gpr[reg_a]) < simm) && (ppc_to & 0x10)) ||
|
|
|
|
((int32_t(ppc_state.gpr[reg_a]) > simm) && (ppc_to & 0x08)) ||
|
|
|
|
((int32_t(ppc_state.gpr[reg_a]) == simm) && (ppc_to & 0x04)) ||
|
|
|
|
(ppc_state.gpr[reg_a] < uint32_t(simm) && (ppc_to & 0x02)) ||
|
|
|
|
(ppc_state.gpr[reg_a] > uint32_t(simm) && (ppc_to & 0x01))) {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_eieio() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_isync() {
|
2021-08-03 14:01:32 +00:00
|
|
|
do_ctx_sync();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_sync() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_icbi() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_dcbf() {
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_dcbi() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-26 02:30:55 +00:00
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_dcbst() {
|
2023-09-18 18:45:35 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_dcbt() {
|
2020-05-12 18:55:45 +00:00
|
|
|
// Not needed, the HDI reg is touched to no-op this instruction.
|
2019-07-02 02:15:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_dcbtst() {
|
2020-05-12 18:55:45 +00:00
|
|
|
// Not needed, the HDI reg is touched to no-op this instruction.
|
2019-07-02 02:15:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_dcbz() {
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2021-01-07 03:25:27 +00:00
|
|
|
|
2023-06-17 18:57:48 +00:00
|
|
|
ppc_effective_address &= 0xFFFFFFE0UL; // align EA on a 32-byte boundary
|
|
|
|
|
|
|
|
// the following is not especially efficient but necessary
|
|
|
|
// to make BlockZero under Mac OS 8.x and later to work
|
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address + 0, 0);
|
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address + 8, 0);
|
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address + 16, 0);
|
|
|
|
mmu_write_vmem<uint64_t>(ppc_effective_address + 24, 0);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:25:50 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// Integer Load and Store Functions
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_st() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2021-01-26 04:03:17 +00:00
|
|
|
ppc_effective_address += reg_a ? ppc_result_a : 0;
|
2024-03-25 08:03:11 +00:00
|
|
|
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_st<uint8_t>();
|
|
|
|
template void dppc_interpreter::ppc_st<uint16_t>();
|
|
|
|
template void dppc_interpreter::ppc_st<uint32_t>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_stx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
|
|
|
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_stx<uint8_t>();
|
|
|
|
template void dppc_interpreter::ppc_stx<uint16_t>();
|
|
|
|
template void dppc_interpreter::ppc_stx<uint32_t>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_stu() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2020-01-18 04:06:26 +00:00
|
|
|
if (reg_a != 0) {
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address += ppc_result_a;
|
2024-03-24 19:21:19 +00:00
|
|
|
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-18 04:06:26 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_stu<uint8_t>();
|
|
|
|
template void dppc_interpreter::ppc_stu<uint16_t>();
|
|
|
|
template void dppc_interpreter::ppc_stu<uint32_t>();
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_stux() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2020-01-18 04:06:26 +00:00
|
|
|
if (reg_a != 0) {
|
2020-01-18 04:26:09 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2024-03-24 19:21:19 +00:00
|
|
|
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
|
2020-03-05 04:29:04 +00:00
|
|
|
ppc_state.gpr[reg_a] = ppc_effective_address;
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2020-01-18 04:06:26 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_stux<uint8_t>();
|
|
|
|
template void dppc_interpreter::ppc_stux<uint16_t>();
|
|
|
|
template void dppc_interpreter::ppc_stux<uint32_t>();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_sthbrx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-02-18 14:06:27 +00:00
|
|
|
ppc_result_d = uint32_t(BYTESWAP_16(uint16_t(ppc_result_d)));
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stwcx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
|
|
|
ppc_state.cr &= 0x0FFFFFFFUL; // clear CR0
|
2024-03-26 22:47:42 +00:00
|
|
|
ppc_state.cr |= (ppc_state.spr[SPR::XER] & XER::SO) >> 3; // copy XER[SO] to CR0[SO]
|
2024-03-24 19:21:19 +00:00
|
|
|
if (ppc_state.reserve) {
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
2024-03-24 19:21:19 +00:00
|
|
|
ppc_state.reserve = false;
|
|
|
|
ppc_state.cr |= 0x20000000UL; // set CR0[EQ]
|
2020-01-18 04:06:26 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stwbrx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result_d = BYTESWAP_32(ppc_result_d);
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stmw() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2024-02-18 14:06:27 +00:00
|
|
|
ppc_effective_address += reg_a ? ppc_result_a : 0;
|
2020-04-21 02:47:51 +00:00
|
|
|
|
|
|
|
/* what should we do if EA is unaligned? */
|
|
|
|
if (ppc_effective_address & 3) {
|
2023-12-16 13:34:43 +00:00
|
|
|
ppc_alignment_exception(ppc_effective_address);
|
2020-04-21 02:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (; reg_s <= 31; reg_s++) {
|
2021-08-03 14:01:32 +00:00
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address += 4;
|
2020-04-21 02:47:51 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_lz() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2024-02-18 14:06:27 +00:00
|
|
|
ppc_effective_address += reg_a ? ppc_result_a : 0;
|
2024-03-24 19:21:19 +00:00
|
|
|
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_lz<uint8_t>();
|
|
|
|
template void dppc_interpreter::ppc_lz<uint16_t>();
|
|
|
|
template void dppc_interpreter::ppc_lz<uint32_t>();
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_lzu() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2024-02-18 14:06:27 +00:00
|
|
|
if ((reg_a != reg_d) && reg_a != 0) {
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address += ppc_result_a;
|
2024-03-24 19:21:19 +00:00
|
|
|
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_lzu<uint8_t>();
|
|
|
|
template void dppc_interpreter::ppc_lzu<uint16_t>();
|
|
|
|
template void dppc_interpreter::ppc_lzu<uint32_t>();
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_lzx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-03-24 19:21:19 +00:00
|
|
|
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_lzx<uint8_t>(void);
|
|
|
|
template void dppc_interpreter::ppc_lzx<uint16_t>(void);
|
|
|
|
template void dppc_interpreter::ppc_lzx<uint32_t>(void);
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void dppc_interpreter::ppc_lzux() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-02-18 14:06:27 +00:00
|
|
|
if ((reg_a != reg_d) && reg_a != 0) {
|
2019-07-02 02:15:33 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2024-03-24 19:21:19 +00:00
|
|
|
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_result_a = ppc_effective_address;
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-24 19:21:19 +00:00
|
|
|
template void dppc_interpreter::ppc_lzux<uint8_t>(void);
|
|
|
|
template void dppc_interpreter::ppc_lzux<uint16_t>(void);
|
|
|
|
template void dppc_interpreter::ppc_lzux<uint32_t>(void);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lha() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2024-03-02 14:57:15 +00:00
|
|
|
ppc_effective_address += (reg_a ? ppc_result_a : 0);
|
2024-03-28 11:50:38 +00:00
|
|
|
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, int32_t(val));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lhau() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-02-18 14:06:27 +00:00
|
|
|
if ((reg_a != reg_d) && reg_a != 0) {
|
2024-01-31 15:06:33 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2020-01-22 02:25:50 +00:00
|
|
|
ppc_effective_address += ppc_result_a;
|
2024-03-28 11:50:38 +00:00
|
|
|
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, int32_t(val));
|
|
|
|
uint32_t ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lhaux() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-02-18 14:06:27 +00:00
|
|
|
if ((reg_a != reg_d) && reg_a != 0) {
|
2024-01-06 02:10:05 +00:00
|
|
|
ppc_effective_address = ppc_result_a + ppc_result_b;
|
2024-03-28 11:50:38 +00:00
|
|
|
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, int32_t(val));
|
|
|
|
uint32_t ppc_result_a = ppc_effective_address;
|
|
|
|
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
2024-01-06 02:10:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lhax() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-03-28 11:50:38 +00:00
|
|
|
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, int32_t(val));
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lhbrx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = uint32_t(BYTESWAP_16(mmu_read_vmem<uint16_t>(ppc_effective_address)));
|
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lwbrx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = BYTESWAP_32(mmu_read_vmem<uint32_t>(ppc_effective_address));
|
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lwarx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2020-05-12 18:55:45 +00:00
|
|
|
// Placeholder - Get the reservation of memory implemented!
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-02 14:57:15 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2020-05-12 18:55:45 +00:00
|
|
|
ppc_state.reserve = true;
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lmw() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2024-02-18 10:22:52 +00:00
|
|
|
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
2024-03-02 14:57:15 +00:00
|
|
|
ppc_effective_address += (reg_a ? ppc_result_a : 0);
|
2024-01-08 00:45:05 +00:00
|
|
|
// How many words to load in memory - using a do-while for this
|
|
|
|
do {
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
ppc_effective_address += 4;
|
|
|
|
reg_d++;
|
|
|
|
} while (reg_d < 32);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lswi() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsda(ppc_cur_instruction);
|
2022-02-19 22:21:18 +00:00
|
|
|
ppc_effective_address = reg_a ? ppc_result_a : 0;
|
2024-01-05 22:11:37 +00:00
|
|
|
uint32_t grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
|
2022-02-19 22:21:18 +00:00
|
|
|
grab_inb = grab_inb ? grab_inb : 32;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2023-10-30 00:23:31 +00:00
|
|
|
while (grab_inb >= 4) {
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
|
|
|
reg_d++;
|
|
|
|
if (reg_d >= 32) { // wrap around through GPR0
|
|
|
|
reg_d = 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2023-10-30 00:23:31 +00:00
|
|
|
ppc_effective_address += 4;
|
|
|
|
grab_inb -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle remaining bytes
|
|
|
|
switch (grab_inb) {
|
|
|
|
case 1:
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
|
|
|
ppc_state.gpr[reg_d] += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_lswx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_loads++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2021-01-26 04:03:17 +00:00
|
|
|
|
2024-01-10 13:54:51 +00:00
|
|
|
/*
|
2020-05-12 18:55:45 +00:00
|
|
|
// Invalid instruction forms
|
2024-01-08 00:21:11 +00:00
|
|
|
if ((reg_d == 0 && reg_a == 0) || (reg_d == reg_a) || (reg_d == reg_b)) {
|
2024-01-10 13:54:51 +00:00
|
|
|
// UNTESTED! Does invalid form really cause exception?
|
|
|
|
// G4 doesn't do exception
|
2020-11-30 19:59:36 +00:00
|
|
|
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-01-10 13:54:51 +00:00
|
|
|
*/
|
2021-01-26 04:03:17 +00:00
|
|
|
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-01-05 22:11:37 +00:00
|
|
|
uint32_t grab_inb = ppc_state.spr[SPR::XER] & 0x7F;
|
2021-01-26 04:03:17 +00:00
|
|
|
|
2024-01-10 13:54:51 +00:00
|
|
|
for (;;) {
|
|
|
|
if (is_601 && (reg_d == reg_b || (reg_a != 0 && reg_d == reg_a))) {
|
|
|
|
// UNTESTED! MPC601 manual is inconsistant on whether reg_b is skipped or not
|
2024-03-26 23:12:47 +00:00
|
|
|
reg_d = (reg_d + 1) & 0x1F; // wrap around through GPR0
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2024-01-10 13:54:51 +00:00
|
|
|
switch (grab_inb) {
|
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
ppc_state.gpr[reg_d] = (mmu_read_vmem<uint16_t>(ppc_effective_address) << 16)
|
|
|
|
| (mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
2024-03-26 23:12:47 +00:00
|
|
|
reg_d = (reg_d + 1) & 0x1F; // wrap around through GPR0
|
2023-10-30 00:23:31 +00:00
|
|
|
ppc_effective_address += 4;
|
|
|
|
grab_inb -= 4;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stswi() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssa(ppc_cur_instruction);
|
2022-02-19 22:21:18 +00:00
|
|
|
ppc_effective_address = reg_a ? ppc_result_a : 0;
|
2024-01-05 22:11:37 +00:00
|
|
|
uint32_t grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
|
2022-02-19 22:21:18 +00:00
|
|
|
grab_inb = grab_inb ? grab_inb : 32;
|
2021-01-26 04:03:17 +00:00
|
|
|
|
2023-10-30 00:23:31 +00:00
|
|
|
while (grab_inb >= 4) {
|
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
|
|
|
|
reg_s++;
|
|
|
|
if (reg_s >= 32) { // wrap around through GPR0
|
|
|
|
reg_s = 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2023-10-30 00:23:31 +00:00
|
|
|
ppc_effective_address += 4;
|
|
|
|
grab_inb -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle remaining bytes
|
|
|
|
switch (grab_inb) {
|
|
|
|
case 1:
|
|
|
|
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 24);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
|
|
|
|
mmu_write_vmem<uint8_t>(ppc_effective_address + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_stswx() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_int_stores++;
|
|
|
|
#endif
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-01 14:57:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2024-01-05 22:11:37 +00:00
|
|
|
uint32_t grab_inb = ppc_state.spr[SPR::XER] & 127;
|
2021-01-26 04:03:17 +00:00
|
|
|
|
2023-10-30 00:23:31 +00:00
|
|
|
while (grab_inb >= 4) {
|
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
|
|
|
|
reg_s++;
|
|
|
|
if (reg_s >= 32) { // wrap around through GPR0
|
|
|
|
reg_s = 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2023-10-30 00:23:31 +00:00
|
|
|
ppc_effective_address += 4;
|
|
|
|
grab_inb -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle remaining bytes
|
|
|
|
switch (grab_inb) {
|
|
|
|
case 1:
|
|
|
|
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 24);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
|
|
|
|
mmu_write_vmem<uint8_t>(ppc_effective_address + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-01-26 02:30:55 +00:00
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 00:40:09 +00:00
|
|
|
void dppc_interpreter::ppc_eciwx() {
|
|
|
|
uint32_t ear_enable = 0x80000000;
|
|
|
|
|
|
|
|
// error if EAR[E] != 1
|
|
|
|
if (!(ppc_state.spr[282] && ear_enable)) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
|
|
|
|
}
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regsdab(ppc_cur_instruction);
|
2024-03-02 02:40:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2021-10-06 00:40:09 +00:00
|
|
|
|
|
|
|
if (ppc_effective_address & 0x3) {
|
2023-12-16 13:34:43 +00:00
|
|
|
ppc_alignment_exception(ppc_effective_address);
|
2021-10-06 00:40:09 +00:00
|
|
|
}
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
uint32_t ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
2021-10-06 00:40:09 +00:00
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
2021-10-06 00:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dppc_interpreter::ppc_ecowx() {
|
|
|
|
uint32_t ear_enable = 0x80000000;
|
|
|
|
|
|
|
|
// error if EAR[E] != 1
|
|
|
|
if (!(ppc_state.spr[282] && ear_enable)) {
|
|
|
|
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
|
|
|
|
}
|
|
|
|
|
2024-03-22 15:01:29 +00:00
|
|
|
ppc_grab_regssab(ppc_cur_instruction);
|
2024-03-02 02:40:46 +00:00
|
|
|
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
2021-10-06 00:40:09 +00:00
|
|
|
|
|
|
|
if (ppc_effective_address & 0x3) {
|
2023-12-16 13:34:43 +00:00
|
|
|
ppc_alignment_exception(ppc_effective_address);
|
2021-10-06 00:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// TLB Instructions
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_tlbie() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2021-05-16 11:32:21 +00:00
|
|
|
|
2024-03-26 23:12:47 +00:00
|
|
|
tlb_flush_entry(ppc_state.gpr[(ppc_cur_instruction >> 11) & 0x1F]);
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_tlbia() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_tlbld() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_tlbli() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2020-01-15 03:50:01 +00:00
|
|
|
|
2020-10-18 04:46:38 +00:00
|
|
|
void dppc_interpreter::ppc_tlbsync() {
|
2021-04-29 00:26:17 +00:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
num_supervisor_instrs++;
|
2020-01-15 03:50:01 +00:00
|
|
|
#endif
|
2020-02-27 15:31:22 +00:00
|
|
|
/* placeholder */
|
|
|
|
}
|