mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
26
Commits
Alpha102
...
nuterpreterx
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ad4b28ed | ||
|
|
eb67b6ded0 | ||
|
|
cbaf0477f0 | ||
|
|
cbd24165bd | ||
|
|
e50a1a4d3e | ||
|
|
ce122da984 | ||
|
|
738b40c7b6 | ||
|
|
2a24b1c8f9 | ||
|
|
f1e6a2ce93 | ||
|
|
11de987ea9 | ||
|
|
804bb3da07 | ||
|
|
832d669890 | ||
|
|
262b7ccf68 | ||
|
|
de61c26484 | ||
|
|
cb39be991f | ||
|
|
55f9d08c30 | ||
|
|
f1a38e21d3 | ||
|
|
90536f79fe | ||
|
|
72308074da | ||
|
|
b5224ee805 | ||
|
|
3addc05ec4 | ||
|
|
f0cf315030 | ||
|
|
959e92e372 | ||
|
|
5ae9fcbd38 | ||
|
|
e2ed352533 | ||
|
|
4644ade362 |
No files matched your search
+3
-1
@@ -114,7 +114,8 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
platform_glob(SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
"${PROJECT_SOURCE_DIR}/*.h"
|
||||
"${PROJECT_SOURCE_DIR}/*.include")
|
||||
|
||||
if (APPLE)
|
||||
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
|
||||
@@ -184,6 +185,7 @@ if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.include"
|
||||
)
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
|
||||
# $<TARGET_OBJECTS:cpu_ppc>
|
||||
|
||||
@@ -27,9 +27,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <debugger/debugger.h>
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||
@@ -40,7 +42,7 @@ uint32_t cs_code[] = {
|
||||
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
|
||||
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
|
||||
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
|
||||
0x7C650194, /* 0x4E800020 */ 0x00005AF0
|
||||
0x7C650194, 0x4E800020
|
||||
};
|
||||
|
||||
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
|
||||
@@ -73,7 +75,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
|
||||
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
|
||||
mmu_write_vmem<uint32_t>(i * 4, 0, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
@@ -83,7 +85,7 @@ int main(int argc, char** argv) {
|
||||
bool did_lf = false;
|
||||
for (i = 0; i < test_size; i++) {
|
||||
uint8_t val = rand() % 256;
|
||||
mmu_write_vmem<uint8_t>(0x1000+i, val);
|
||||
mmu_write_vmem<uint8_t>(0x1000 + i, 0, val);
|
||||
if (i < 64) {
|
||||
printf("%02x", val);
|
||||
did_lf = false;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
|
||||
// such as names of functions and macros.
|
||||
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
|
||||
#define OPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODESHIFT(op, __VA_ARGS__) template <field_shift shift> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE(op, __VA_ARGS__) void dppc_interpreter::ppc_##op(uint32_t instr) {##__VA_ARGS__ }
|
||||
#define OPCODECARRY(op, __VA_ARGS__) template <field_carry carry, field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODELOGIC(op, __VA_ARGS__) template <logical_fun logical_op, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODELKAA(op, __VA_ARGS__) template <field_lk l, field_aa a> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE601L(op, __VA_ARGS__) template <field_lk l, field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODE(op, __VA_ARGS__) void dppc_interpreter::power_##op(uint32_t instr) {##__VA_ARGS__ }
|
||||
#define OPCODEMEM(op, __VA_ARGS__) template <class T> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODESHIFTREC(op, __VA_ARGS__) template <field_direction isleft, field_rc rec > void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE601REC(op, __VA_ARGS__) template <field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODEEXTSIGN(op, __VA_ARGS__) template <class T, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) ppc_state.gpr[reg] = ppc_result
|
||||
#define ppc_set_xer(entry) ppc_state.spr[SPR::XER] |= entry#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
|
||||
#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr)
|
||||
@@ -3,6 +3,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.include"
|
||||
)
|
||||
|
||||
add_library(cpu_ppc OBJECT ${SOURCES})
|
||||
+3
-635
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// Any shared opcodes are in ppcopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcdecodemacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -34,637 +34,5 @@ static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_abs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_clcs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_da(ppc_cur_instruction);
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
default: ppc_result_d = is_601 ? 64 : 32; break;
|
||||
case 7:
|
||||
case 23: ppc_result_d = is_601 ? 64 : 0; break;
|
||||
case 8:
|
||||
case 9:
|
||||
case 24:
|
||||
case 25: ppc_result_d = is_601 ? 64 : 4; break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 26:
|
||||
case 27: ppc_result_d = is_601 ? 64 : 0x4000; break;
|
||||
}
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_div() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t quotient;
|
||||
int32_t remainder;
|
||||
|
||||
if (dividend == -0x80000000 && divisor == -1) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else if (!divisor) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
quotient = dividend / divisor;
|
||||
remainder = dividend % divisor;
|
||||
ppc_result_d = uint32_t(quotient);
|
||||
if (ov) {
|
||||
if (((quotient >> 31) + 1) & ~1) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_state.spr[SPR::MQ] = remainder;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_div<RC0, OV0>();
|
||||
template void dppc_interpreter::power_div<RC0, OV1>();
|
||||
template void dppc_interpreter::power_div<RC1, OV0>();
|
||||
template void dppc_interpreter::power_div<RC1, OV1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_divs() {
|
||||
uint32_t ppc_result_d;
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
remainder = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
|
||||
ppc_result_d = 0x80000000U;
|
||||
remainder = 0;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else { // normal signed devision
|
||||
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
||||
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_state.spr[SPR::MQ] = remainder;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_divs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
if (ov) {
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(ppc_cur_instruction);
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_remaining = bytes_to_load;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
bool is_match = false;
|
||||
|
||||
// for storing each byte
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(ea);
|
||||
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
ppc_result_d = 0;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ea++;
|
||||
bytes_remaining--;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store partially loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
|
||||
|
||||
if (rec) {
|
||||
ppc_state.cr =
|
||||
(ppc_state.cr & 0x0FFFFFFFUL) |
|
||||
(is_match ? CRx_bit::CR_EQ : 0) |
|
||||
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_lscbx<RC0>();
|
||||
template void dppc_interpreter::power_lscbx<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskg<RC0>();
|
||||
template void dppc_interpreter::power_maskg<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskir<RC0>();
|
||||
template void dppc_interpreter::power_maskir<RC1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
|
||||
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
|
||||
ppc_state.spr[SPR::MQ] = uint32_t(product);
|
||||
|
||||
if (ov) {
|
||||
if (uint64_t(product >> 31) + 1 & ~1) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(uint32_t(product));
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_mul<RC0, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 0x1F;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 0x1F;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((ppc_cur_instruction & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_result_a |= (0x80000000U >> rot_sh);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000U >> rot_sh);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_rrib<RC0>();
|
||||
template void dppc_interpreter::power_rrib<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sle<RC0>();
|
||||
template void dppc_interpreter::power_sle<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sleq<RC0>();
|
||||
template void dppc_interpreter::power_sleq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sliq<RC0>();
|
||||
template void dppc_interpreter::power_sliq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slliq<RC0>();
|
||||
template void dppc_interpreter::power_slliq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sllq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
|
||||
} else {
|
||||
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sllq<RC0>();
|
||||
template void dppc_interpreter::power_sllq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slq<RC0>();
|
||||
template void dppc_interpreter::power_slq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraiq<RC0>();
|
||||
template void dppc_interpreter::power_sraiq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraq<RC0>();
|
||||
template void dppc_interpreter::power_sraq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sre<RC0>();
|
||||
template void dppc_interpreter::power_sre<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srea() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
uint32_t r = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>();
|
||||
template void dppc_interpreter::power_srea<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sreq<RC0>();
|
||||
template void dppc_interpreter::power_sreq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>();
|
||||
template void dppc_interpreter::power_sriq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>();
|
||||
template void dppc_interpreter::power_srliq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srlq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
} else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srlq<RC0>();
|
||||
template void dppc_interpreter::power_srlq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srq<RC0>();
|
||||
template void dppc_interpreter::power_srq<RC1>();
|
||||
#include "ppcopmacros.h"
|
||||
#include "poweropcodes.include"
|
||||
@@ -0,0 +1,531 @@
|
||||
POWEROPCODEOVREC (abs, 31, 360,
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(instr);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE31 (clcs, 31, 531,
|
||||
ppc_grab_da(instr);
|
||||
uint32_t ppc_result_d = 0;
|
||||
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
default:
|
||||
ppc_result_d = is_601 ? 64 : 32; break;
|
||||
case 7:
|
||||
case 23:
|
||||
ppc_result_d = is_601 ? 64 : 0; break;
|
||||
case 8:
|
||||
case 9:
|
||||
case 24:
|
||||
case 25:
|
||||
ppc_result_d = is_601 ? 64 : 4; break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 26:
|
||||
case 27:
|
||||
ppc_result_d = is_601 ? 64 : 0x4000; break;
|
||||
}
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (div, 31, 331,
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(instr);
|
||||
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t quotient;
|
||||
int32_t remainder;
|
||||
|
||||
if (dividend == -0x80000000 && divisor == -1) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else if (!divisor) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
quotient = dividend / divisor;
|
||||
remainder = dividend % divisor;
|
||||
ppc_result_d = uint32_t(quotient);
|
||||
if (ov) {
|
||||
if (((quotient >> 31) + 1) & ~1) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
power_store_mq(remainder);
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (divs, 31, 363,
|
||||
uint32_t ppc_result_d;
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(instr);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
remainder = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
|
||||
ppc_result_d = 0x80000000U;
|
||||
remainder = 0;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else { // normal signed devision
|
||||
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
||||
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
power_store_mq(remainder);;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (doz, 31, 264,
|
||||
ppc_grab_regsdab(instr);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
if (ov) {
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE (dozi, , 9,
|
||||
ppc_grab_regsdasimm(instr);
|
||||
uint32_t ppc_result_d = 0;
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
else {
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (lscbx, 31, 277,
|
||||
ppc_grab_regsdab(instr);
|
||||
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_remaining = bytes_to_load;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
bool is_match = false;
|
||||
|
||||
// for storing each byte
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(ea, instr);
|
||||
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b) {
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
}
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
ppc_result_d = 0;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ea++;
|
||||
bytes_remaining--;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store partially loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b) {
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
|
||||
|
||||
if (rec) { \
|
||||
ppc_state.cr = \
|
||||
(ppc_state.cr & 0x0FFFFFFFUL) | \
|
||||
(is_match ? CRx_bit::CR_EQ : 0) | \
|
||||
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
|
||||
}
|
||||
)
|
||||
|
||||
POWEROPCODEREC (maskg, 31, 29,
|
||||
ppc_grab_regssab(instr);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec){
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
}
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (maskir, 31, 541,
|
||||
ppc_grab_regssab(instr);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (mul, 31, 107,
|
||||
ppc_grab_regsdab(instr);
|
||||
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
|
||||
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
|
||||
ppc_state.spr[SPR::MQ] = uint32_t(product);
|
||||
|
||||
if (ov) {
|
||||
if (uint64_t(product >> 31) + 1 & ~1) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(uint32_t(product));
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (nabs, 31, 488,
|
||||
ppc_grab_regsda(instr);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE (rlmi, , 22,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_mb = (instr >> 6) & 0x1F;
|
||||
unsigned rot_me = (instr >> 1) & 0x1F;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((instr & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (rrib, 31, 537,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_result_a |= (0x80000000U >> rot_sh);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000U >> rot_sh);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sle, 31, 153,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sleq, 31, 217,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sliq, 31, 184,
|
||||
ppc_grab_regssash(instr);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (slliq, 31, 248,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sllq, 31, 216,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
|
||||
} else {
|
||||
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (slq, 31, 152,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sraiq, 31, 952,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sraq, 31, 920,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sre, 31, 665,
|
||||
ppc_grab_regssab(instr);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srea, 31, 921,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
uint32_t r = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sreq, 31, 729,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sriq, 31, 696,
|
||||
ppc_grab_regssash(instr);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srliq, 31, 760,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srlq, 31, 728,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
} else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srq, 31, 664,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
@@ -23,6 +23,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PPC_MACROS_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "ppcemu.h"
|
||||
|
||||
|
||||
#define ppc_set_cr(entry) \
|
||||
ppc_state.cr |= entry
|
||||
|
||||
#define ppc_unset_cr(entry) \
|
||||
ppc_state.cr &= ~entry
|
||||
|
||||
#define ppc_set_xer(entry) \
|
||||
ppc_state.spr[SPR::XER] |= entry
|
||||
|
||||
#define ppc_unset_xer(entry) \
|
||||
ppc_state.spr[SPR::XER] &= ~entry
|
||||
|
||||
#define power_store_mq(entry) \
|
||||
ppc_state.spr[SPR::MQ] = entry
|
||||
|
||||
#define power_store_ctr(entry) \
|
||||
ppc_state.spr[SPR::CTR] = entry
|
||||
|
||||
#define power_store_mq(entry) \
|
||||
ppc_state.spr[SPR::MQ] = entry
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
@@ -54,6 +77,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfds(opcode) \
|
||||
int crf_d = (instr >> 21) & 0x1C; \
|
||||
int crf_s = (instr >> 16) & 0x1C;
|
||||
|
||||
#define ppc_grab_da(opcode)\
|
||||
int reg_d = (opcode >> 21) & 31;\
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
@@ -80,7 +107,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
@@ -123,40 +150,38 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result;
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) \
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_sfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_sfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_store_dfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_dfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_grab_regsfpdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
@@ -213,4 +238,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_grab_mtfsf(opcode) \
|
||||
int reg_b = (opcode >> 11) & 0x1F; \
|
||||
uint8_t fm = (opcode >> 17) & 0xFF;
|
||||
|
||||
#define ppc_grab_mtfsfi(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
uint32_t imm = (opcode << 16) & 0xF0000000UL;
|
||||
|
||||
#define ppc_grab_crfd(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C;
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
+16
-225
@@ -47,7 +47,7 @@ enum EXEC_MODE:uint32_t {
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
typedef void (*PPCOpcode)(uint32_t);
|
||||
|
||||
union FPR_storage {
|
||||
double dbl64_r; // double floating-point representation
|
||||
@@ -328,12 +328,10 @@ extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
inline uint32_t ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
return READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
// Profiling Stats
|
||||
@@ -401,19 +399,11 @@ typedef enum {
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_illegalop(uint32_t null_val=0);
|
||||
void ppc_fpu_off();
|
||||
void ppc_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
template <field_601 for601> void ppc_opcode19();
|
||||
void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
|
||||
void initialize_ppc_opcode_tables(bool include_601);
|
||||
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
@@ -426,8 +416,8 @@ void update_fpscr(uint32_t new_fpscr);
|
||||
/* Exception handlers. */
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
void ppc_floating_point_exception();
|
||||
void ppc_alignment_exception(uint32_t ea);
|
||||
void ppc_floating_point_exception(uint32_t instr);
|
||||
void ppc_alignment_exception(uint32_t ea, uint32_t instr);
|
||||
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
@@ -435,217 +425,9 @@ extern MemCtrlBase* mem_ctrl_instance;
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
|
||||
namespace dppc_interpreter {
|
||||
template <field_lk l, field_601 for601> extern void ppc_bcctr();
|
||||
template <field_lk l> extern void ppc_bclr();
|
||||
extern void ppc_crand();
|
||||
extern void ppc_crandc();
|
||||
extern void ppc_creqv();
|
||||
extern void ppc_crnand();
|
||||
extern void ppc_crnor();
|
||||
extern void ppc_cror();
|
||||
extern void ppc_crorc();
|
||||
extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
|
||||
template <logical_fun logical_op, field_rc rec> extern void ppc_logical();
|
||||
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_adde();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addme();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addze();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
template <field_rc rec> extern void ppc_cntlzw();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divw();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divwu();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
template <class T, field_rc rec>extern void ppc_exts();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhaux();
|
||||
extern void ppc_lhax();
|
||||
extern void ppc_lhbrx();
|
||||
extern void ppc_lwarx();
|
||||
extern void ppc_lwbrx();
|
||||
template <class T> extern void ppc_lzx();
|
||||
template <class T> extern void ppc_lzux();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
template <field_rc rec> extern void ppc_mulhwu();
|
||||
template <field_rc rec> extern void ppc_mulhw();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_mullw();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_neg();
|
||||
template <field_direction shift, field_rc rec> extern void ppc_shift();
|
||||
template <field_rc rec> extern void ppc_sraw();
|
||||
template <field_rc rec> extern void ppc_srawi();
|
||||
template <class T> extern void ppc_stx();
|
||||
template <class T> extern void ppc_stux();
|
||||
extern void ppc_stfiwx();
|
||||
extern void ppc_sthbrx();
|
||||
extern void ppc_stwcx();
|
||||
extern void ppc_stwbrx();
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfe();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfme();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfze();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
extern void ppc_tlbli();
|
||||
extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
extern void ppc_stswi();
|
||||
extern void ppc_stswx();
|
||||
|
||||
extern void ppc_mfsr();
|
||||
extern void ppc_mfsrin();
|
||||
extern void ppc_mtsr();
|
||||
extern void ppc_mtsrin();
|
||||
|
||||
extern void ppc_mcrf();
|
||||
extern void ppc_mtcrf();
|
||||
extern void ppc_mfmsr();
|
||||
extern void ppc_mfspr();
|
||||
extern void ppc_mtmsr();
|
||||
extern void ppc_mtspr();
|
||||
|
||||
template <field_rc rec> extern void ppc_mtfsb0();
|
||||
template <field_rc rec> extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
template <field_rc rec> extern void ppc_fmr();
|
||||
template <field_601 for601, field_rc rec> extern void ppc_mffs();
|
||||
template <field_rc rec> extern void ppc_mtfsf();
|
||||
template <field_rc rec> extern void ppc_mtfsfi();
|
||||
|
||||
template <field_shift shift> extern void ppc_addi();
|
||||
template <field_rc rec> extern void ppc_addic();
|
||||
template <field_shift shift> extern void ppc_andirc();
|
||||
template <field_lk l, field_aa a> extern void ppc_b();
|
||||
template <field_lk l, field_aa a> extern void ppc_bc();
|
||||
extern void ppc_cmpi();
|
||||
extern void ppc_cmpli();
|
||||
template <class T> extern void ppc_lz();
|
||||
template <class T> extern void ppc_lzu();
|
||||
extern void ppc_lha();
|
||||
extern void ppc_lhau();
|
||||
extern void ppc_lmw();
|
||||
extern void ppc_mulli();
|
||||
template <field_shift shift> extern void ppc_ori();
|
||||
extern void ppc_rfi();
|
||||
extern void ppc_rlwimi();
|
||||
extern void ppc_rlwinm();
|
||||
extern void ppc_rlwnm();
|
||||
extern void ppc_sc();
|
||||
template <class T> extern void ppc_st();
|
||||
template <class T> extern void ppc_stu();
|
||||
extern void ppc_stmw();
|
||||
extern void ppc_subfic();
|
||||
extern void ppc_twi();
|
||||
template <field_shift shift> extern void ppc_xori();
|
||||
|
||||
extern void ppc_lfs();
|
||||
extern void ppc_lfsu();
|
||||
extern void ppc_lfsx();
|
||||
extern void ppc_lfsux();
|
||||
extern void ppc_lfd();
|
||||
extern void ppc_lfdu();
|
||||
extern void ppc_lfdx();
|
||||
extern void ppc_lfdux();
|
||||
extern void ppc_stfs();
|
||||
extern void ppc_stfsu();
|
||||
extern void ppc_stfsx();
|
||||
extern void ppc_stfsux();
|
||||
extern void ppc_stfd();
|
||||
extern void ppc_stfdu();
|
||||
extern void ppc_stfdx();
|
||||
extern void ppc_stfdux();
|
||||
|
||||
template <field_rc rec> extern void ppc_fadd();
|
||||
template <field_rc rec> extern void ppc_fsub();
|
||||
template <field_rc rec> extern void ppc_fmul();
|
||||
template <field_rc rec> extern void ppc_fdiv();
|
||||
template <field_rc rec> extern void ppc_fadds();
|
||||
template <field_rc rec> extern void ppc_fsubs();
|
||||
template <field_rc rec> extern void ppc_fmuls();
|
||||
template <field_rc rec> extern void ppc_fdivs();
|
||||
template <field_rc rec> extern void ppc_fmadd();
|
||||
template <field_rc rec> extern void ppc_fmsub();
|
||||
template <field_rc rec> extern void ppc_fnmadd();
|
||||
template <field_rc rec> extern void ppc_fnmsub();
|
||||
template <field_rc rec> extern void ppc_fmadds();
|
||||
template <field_rc rec> extern void ppc_fmsubs();
|
||||
template <field_rc rec> extern void ppc_fnmadds();
|
||||
template <field_rc rec> extern void ppc_fnmsubs();
|
||||
template <field_rc rec> extern void ppc_fabs();
|
||||
template <field_rc rec> extern void ppc_fnabs();
|
||||
template <field_rc rec> extern void ppc_fneg();
|
||||
template <field_rc rec> extern void ppc_fsel();
|
||||
template <field_rc rec> extern void ppc_fres();
|
||||
template <field_rc rec> extern void ppc_fsqrts();
|
||||
template <field_rc rec> extern void ppc_fsqrt();
|
||||
template <field_rc rec> extern void ppc_frsqrte();
|
||||
template <field_rc rec> extern void ppc_frsp();
|
||||
template <field_rc rec> extern void ppc_fctiw();
|
||||
template <field_rc rec> extern void ppc_fctiwz();
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
|
||||
// Power-specific instructions
|
||||
template <field_rc rec, field_ov ov> extern void power_abs();
|
||||
extern void power_clcs();
|
||||
template <field_rc rec, field_ov ov> extern void power_div();
|
||||
template <field_rc rec, field_ov ov> extern void power_divs();
|
||||
template <field_rc rec, field_ov ov> extern void power_doz();
|
||||
extern void power_dozi();
|
||||
template <field_rc rec> extern void power_lscbx();
|
||||
template <field_rc rec> extern void power_maskg();
|
||||
template <field_rc rec> extern void power_maskir();
|
||||
template <field_rc rec, field_ov ov> extern void power_mul();
|
||||
template <field_rc rec, field_ov ov> extern void power_nabs();
|
||||
extern void power_rlmi();
|
||||
template <field_rc rec> extern void power_rrib();
|
||||
template <field_rc rec> extern void power_sle();
|
||||
template <field_rc rec> extern void power_sleq();
|
||||
template <field_rc rec> extern void power_sliq();
|
||||
template <field_rc rec> extern void power_slliq();
|
||||
template <field_rc rec> extern void power_sllq();
|
||||
template <field_rc rec> extern void power_slq();
|
||||
template <field_rc rec> extern void power_sraiq();
|
||||
template <field_rc rec> extern void power_sraq();
|
||||
template <field_rc rec> extern void power_sre();
|
||||
template <field_rc rec> extern void power_srea();
|
||||
template <field_rc rec> extern void power_sreq();
|
||||
template <field_rc rec> extern void power_sriq();
|
||||
template <field_rc rec> extern void power_srliq();
|
||||
template <field_rc rec> extern void power_srlq();
|
||||
template <field_rc rec> extern void power_srq();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
|
||||
// 64-bit instructions
|
||||
|
||||
// G5+ instructions
|
||||
|
||||
extern uint64_t get_virt_time_ns(void);
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_main_opcode(uint32_t instr);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
@@ -656,4 +438,13 @@ void print_fprs(void); /* print content of the floating-point
|
||||
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
#include "ppcmacros_prototypes.h"
|
||||
|
||||
namespace dppc_interpreter {
|
||||
#include "ppcopcodes.include"
|
||||
#include "poweropcodes.include"
|
||||
#include "ppcfpopcodes.include"
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
#endif /* PPCEMU_H */
|
||||
+27
-27
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
@@ -135,7 +136,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
std::string exc_descriptor;
|
||||
@@ -195,17 +196,16 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception() {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, ppc_cur_instruction);
|
||||
void ppc_floating_point_exception(uint32_t instr) {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x", ppc_state.pc, instr);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t ea)
|
||||
void ppc_alignment_exception(uint32_t ea, uint32_t instr)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (ppc_cur_instruction & 0xfc000000) {
|
||||
switch (instr & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
@@ -227,11 +227,11 @@ void ppc_alignment_exception(uint32_t ea)
|
||||
case 0xd4000000: // stfsu
|
||||
case 0xdc000000: // stfdu
|
||||
// indirect with immediate index
|
||||
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
dsisr = ((instr >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((instr >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
break;
|
||||
case 0x7c000000:
|
||||
switch (ppc_cur_instruction & 0xfc0007ff) {
|
||||
switch (instr & 0xfc0007ff) {
|
||||
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
|
||||
case 0x7c0002aa: // lwax (64-bit only)
|
||||
case 0x7c00042a: // lswx
|
||||
@@ -265,12 +265,12 @@ void ppc_alignment_exception(uint32_t ea)
|
||||
case 0x7c00056e: // stfsux
|
||||
case 0x7c0005ee: // stfdux
|
||||
indirect_with_index:
|
||||
dsisr = ((ppc_cur_instruction << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((ppc_cur_instruction << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((ppc_cur_instruction << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
dsisr = ((instr << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((instr << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((instr << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
break;
|
||||
case 0x7c0007ec:
|
||||
if ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
if ((instr & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
@@ -281,31 +281,31 @@ indirect_with_index:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
ppc_cur_instruction);
|
||||
instr);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
|
||||
dsisr |= ((instr >> 16) & 0x000003e0);
|
||||
|
||||
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
|
||||
if ((instr & 0xfc000000) == 0xb8000000) { // lmw
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((instr & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((instr & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
|
||||
dsisr |= ((instr >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
|
||||
+128
-310
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include "ppcdisasm.h"
|
||||
#include "ppcoptablemacros.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
@@ -62,7 +63,6 @@ Po_Cause power_off_reason = po_enter_debugger;
|
||||
|
||||
SetPRS ppc_state;
|
||||
|
||||
uint32_t ppc_cur_instruction; // Current instruction for the PPC
|
||||
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
|
||||
|
||||
unsigned exec_flags; // execution control flags
|
||||
@@ -184,28 +184,21 @@ public:
|
||||
static PPCOpcode OpcodeGrabber[64];
|
||||
|
||||
/** Lookup tables for branch instructions. */
|
||||
const static PPCOpcode SubOpcode16Grabber[] = {
|
||||
dppc_interpreter::ppc_bc<LK0, AA0>, // bc
|
||||
dppc_interpreter::ppc_bc<LK1, AA0>, // bcl
|
||||
dppc_interpreter::ppc_bc<LK0, AA1>, // bca
|
||||
dppc_interpreter::ppc_bc<LK1, AA1>}; // bcla
|
||||
static PPCOpcode Opcode16Grabber[4]; // bcla
|
||||
|
||||
const static PPCOpcode SubOpcode18Grabber[] = {
|
||||
dppc_interpreter::ppc_b<LK0, AA0>, // b
|
||||
dppc_interpreter::ppc_b<LK1, AA0>, // bl
|
||||
dppc_interpreter::ppc_b<LK0, AA1>, // ba
|
||||
dppc_interpreter::ppc_b<LK1, AA1>}; // bla
|
||||
static PPCOpcode Opcode18Grabber[4]; // bla
|
||||
|
||||
/** Instructions decoding tables for integer,
|
||||
single floating-point, and double-floating point ops respectively */
|
||||
|
||||
static PPCOpcode SubOpcode31Grabber[2048];
|
||||
static PPCOpcode SubOpcode59Grabber[64];
|
||||
static PPCOpcode SubOpcode63Grabber[2048];
|
||||
static PPCOpcode Opcode19Grabber[2048];
|
||||
static PPCOpcode Opcode31Grabber[2048];
|
||||
static PPCOpcode Opcode59Grabber[64];
|
||||
static PPCOpcode Opcode63Grabber[2048];
|
||||
|
||||
/** Exception helpers. */
|
||||
|
||||
void ppc_illegalop() {
|
||||
void ppc_illegalop(uint32_t null_val) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
@@ -229,97 +222,128 @@ void ppc_release_int() {
|
||||
|
||||
/** Opcode decoding functions. */
|
||||
|
||||
void ppc_opcode16() {
|
||||
SubOpcode16Grabber[ppc_cur_instruction & 3]();
|
||||
static void ppc_opcode16(uint32_t subop, uint32_t instr) {
|
||||
Opcode16Grabber[instr & 3](instr);
|
||||
}
|
||||
|
||||
void ppc_opcode18() {
|
||||
SubOpcode18Grabber[ppc_cur_instruction & 3]();
|
||||
static void ppc_opcode18(uint32_t instr) {
|
||||
Opcode18Grabber[instr & 3](instr);
|
||||
}
|
||||
|
||||
template<field_601 for601>
|
||||
void ppc_opcode19() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FF;
|
||||
void ppc_opcode19(uint32_t instr) {
|
||||
uint16_t subop_grab = instr & 0x7FF;
|
||||
|
||||
switch (subop_grab) {
|
||||
case 0:
|
||||
ppc_mcrf();
|
||||
ppc_mcrf(instr);
|
||||
break;
|
||||
case 32:
|
||||
ppc_bclr<LK0>();
|
||||
ppc_bclr<LK0>(instr);
|
||||
break;
|
||||
case 33:
|
||||
ppc_bclr<LK1>();
|
||||
ppc_bclr<LK1>(instr);
|
||||
break;
|
||||
case 66:
|
||||
ppc_crnor();
|
||||
ppc_crnor(instr);
|
||||
break;
|
||||
case 100:
|
||||
ppc_rfi();
|
||||
ppc_rfi(instr);
|
||||
break;
|
||||
case 258:
|
||||
ppc_crandc();
|
||||
ppc_crandc(instr);
|
||||
break;
|
||||
case 300:
|
||||
ppc_isync();
|
||||
ppc_isync(instr);
|
||||
break;
|
||||
case 386:
|
||||
ppc_crxor();
|
||||
ppc_crxor(instr);
|
||||
break;
|
||||
case 450:
|
||||
ppc_crnand();
|
||||
ppc_crnand(instr);
|
||||
break;
|
||||
case 514:
|
||||
ppc_crand();
|
||||
ppc_crand(instr);
|
||||
break;
|
||||
case 578:
|
||||
ppc_creqv();
|
||||
ppc_creqv(instr);
|
||||
break;
|
||||
case 834:
|
||||
ppc_crorc();
|
||||
ppc_crorc(instr);
|
||||
break;
|
||||
case 898:
|
||||
ppc_cror();
|
||||
ppc_cror(instr);
|
||||
break;
|
||||
case 1056:
|
||||
ppc_bcctr<LK0, for601>();
|
||||
ppc_bcctr<LK0, for601>(instr);
|
||||
break;
|
||||
case 1057:
|
||||
ppc_bcctr<LK1, for601>();
|
||||
ppc_bcctr<LK1, for601>(instr);
|
||||
break;
|
||||
default:
|
||||
ppc_illegalop();
|
||||
}
|
||||
}
|
||||
|
||||
template void ppc_opcode19<NOT601>();
|
||||
template void ppc_opcode19<IS601>();
|
||||
template void ppc_opcode19<NOT601>(uint32_t);
|
||||
template void ppc_opcode19<IS601>(uint32_t);
|
||||
|
||||
void ppc_opcode31() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FFUL;
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
void ppc_opcode31(uint32_t instr) {
|
||||
}
|
||||
|
||||
void ppc_opcode59() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x3FUL;
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
void ppc_opcode59(uint32_t instr) {
|
||||
uint16_t subop_grab = instr & 0x3FUL;
|
||||
Opcode59Grabber[subop_grab](instr);
|
||||
}
|
||||
|
||||
void ppc_opcode63() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FFUL;
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
void ppc_opcode63(uint32_t instr) {
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode63Grabber[subop_grab](instr);
|
||||
}
|
||||
|
||||
/* Dispatch using main opcode */
|
||||
void ppc_main_opcode()
|
||||
{
|
||||
void ppc_main_opcode(uint32_t instr) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_executed_instrs++;
|
||||
#if defined(CPU_PROFILING_OPS)
|
||||
num_opcodes[ppc_cur_instruction]++;
|
||||
num_opcodes[instr]++;
|
||||
#endif
|
||||
#endif
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
uint32_t opcode = (instr >> 26) & 63;
|
||||
switch (opcode) {
|
||||
case 16:
|
||||
Opcode16Grabber[instr & 3](instr);
|
||||
break;
|
||||
case 18:
|
||||
Opcode16Grabber[instr & 3](instr);
|
||||
break;
|
||||
case 19:
|
||||
if (is_601)
|
||||
ppc_opcode19<IS601>(instr);
|
||||
else
|
||||
ppc_opcode19<NOT601>(instr);
|
||||
break;
|
||||
case 31:
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode31Grabber[subop_grab](instr);
|
||||
break;
|
||||
case 59:
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode31Grabber[subop_grab](instr);
|
||||
break;
|
||||
case 63:
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode31Grabber[subop_grab](instr);
|
||||
break;
|
||||
default:
|
||||
OpcodeGrabber[opcode](instr);
|
||||
}
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
uint32_t load_chk = (instr >> 26);
|
||||
if ((load_chk > 31) && (load_chk < 59))
|
||||
num_int_loads++;
|
||||
#endif
|
||||
}
|
||||
|
||||
static long long cpu_now_ns() {
|
||||
@@ -365,6 +389,9 @@ static void ppc_exec_inner()
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
uint32_t instr = 0;
|
||||
uint32_t i_params[5] = {0};
|
||||
double f_params[4] = {0};
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
@@ -376,11 +403,12 @@ static void ppc_exec_inner()
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && ppc_state.pc < eb_end) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(instr);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@@ -390,18 +418,19 @@ static void ppc_exec_inner()
|
||||
eb_start = ppc_next_instruction_address;
|
||||
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
pc_real += 4;
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,7 +462,11 @@ void ppc_exec_single()
|
||||
}
|
||||
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
|
||||
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
|
||||
uint32_t instr = ppc_set_cur_instruction(pc_real);
|
||||
ppc_main_opcode(instr);
|
||||
|
||||
g_icycles++;
|
||||
process_events();
|
||||
|
||||
@@ -453,6 +486,7 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
uint32_t instr;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
@@ -464,11 +498,12 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && ppc_state.pc < eb_end) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(instr);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@@ -478,18 +513,19 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
eb_start = ppc_next_instruction_address;
|
||||
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
|
||||
if (ppc_state.pc == goal_addr)
|
||||
@@ -520,6 +556,7 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
uint32_t instr = 0;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
@@ -531,12 +568,13 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)
|
||||
&& (ppc_state.pc < eb_end)) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(instr);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@@ -546,18 +584,19 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
eb_start = ppc_next_instruction_address;
|
||||
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -623,252 +662,30 @@ do { \
|
||||
opcode ## Grabber[1024+((subopcode)<<1)+1] = fn<carry, RC1, OV1>; \
|
||||
} while (0)
|
||||
|
||||
#define OP31(subopcode, fn) OPX(SubOpcode31, subopcode, fn)
|
||||
#define OP31d(subopcode, fn) OPXd(SubOpcode31, subopcode, fn)
|
||||
#define OP31od(subopcode, fn) OPXod(SubOpcode31, subopcode, fn)
|
||||
#define OP31dc(subopcode, fn, carry) OPXdc(SubOpcode31, subopcode, fn, carry)
|
||||
#define OP31cod(subopcode, fn, carry) OPXcod(SubOpcode31, subopcode, fn, carry)
|
||||
#define OP31(subopcode, fn) OPX(Opcode31, subopcode, fn)
|
||||
#define OP31d(subopcode, fn) OPXd(Opcode31, subopcode, fn)
|
||||
#define OP31od(subopcode, fn) OPXod(Opcode31, subopcode, fn)
|
||||
#define OP31dc(subopcode, fn, carry) OPXdc(Opcode31, subopcode, fn, carry)
|
||||
#define OP31cod(subopcode, fn, carry) OPXcod(Opcode31, subopcode, fn, carry)
|
||||
|
||||
#define OP59d(subopcode, fn) OPXd(SubOpcode59, subopcode, fn)
|
||||
#define OP59d(subopcode, fn) OPXd(Opcode59, subopcode, fn)
|
||||
|
||||
#define OP63(subopcode, fn) OPX(SubOpcode63, subopcode, fn)
|
||||
#define OP63d(subopcode, fn) OPXd(SubOpcode63, subopcode, fn)
|
||||
#define OP63dc(subopcode, fn, carry) OPXdc(SubOpcode63, subopcode, fn, carry)
|
||||
#define OP63(subopcode, fn) OPX(Opcode63, subopcode, fn)
|
||||
#define OP63d(subopcode, fn) OPXd(Opcode63, subopcode, fn)
|
||||
#define OP63dc(subopcode, fn, carry) OPXdc(Opcode63, subopcode, fn, carry)
|
||||
|
||||
void initialize_ppc_opcode_tables(bool include_601) {
|
||||
inline void initialize_ppc_opcode_tables(bool include_601) {
|
||||
std::fill_n(OpcodeGrabber, 64, ppc_illegalop);
|
||||
OP(3, ppc_twi);
|
||||
//OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented.
|
||||
OP(7, ppc_mulli);
|
||||
OP(8, ppc_subfic);
|
||||
if (is_601 || include_601) OP(9, power_dozi);
|
||||
OP(10, ppc_cmpli);
|
||||
OP(11, ppc_cmpi);
|
||||
OP(12, ppc_addic<RC0>);
|
||||
OP(13, ppc_addic<RC1>);
|
||||
OP(14, ppc_addi<SHFT0>);
|
||||
OP(15, ppc_addi<SHFT1>);
|
||||
OP(16, ppc_opcode16);
|
||||
OP(17, ppc_sc);
|
||||
OP(18, ppc_opcode18);
|
||||
if (is_601) OP(19, ppc_opcode19<IS601>); else OP(19, ppc_opcode19<NOT601>);
|
||||
OP(20, ppc_rlwimi);
|
||||
OP(21, ppc_rlwinm);
|
||||
if (is_601 || include_601) OP(22, power_rlmi);
|
||||
OP(23, ppc_rlwnm);
|
||||
OP(24, ppc_ori<SHFT0>);
|
||||
OP(25, ppc_ori<SHFT1>);
|
||||
OP(26, ppc_xori<SHFT0>);
|
||||
OP(27, ppc_xori<SHFT1>);
|
||||
OP(28, ppc_andirc<SHFT0>);
|
||||
OP(29, ppc_andirc<SHFT1>);
|
||||
OP(31, ppc_opcode31);
|
||||
OP(32, ppc_lz<uint32_t>);
|
||||
OP(33, ppc_lzu<uint32_t>);
|
||||
OP(34, ppc_lz<uint8_t>);
|
||||
OP(35, ppc_lzu<uint8_t>);
|
||||
OP(36, ppc_st<uint32_t>);
|
||||
OP(37, ppc_stu<uint32_t>);
|
||||
OP(38, ppc_st<uint8_t>);
|
||||
OP(39, ppc_stu<uint8_t>);
|
||||
OP(40, ppc_lz<uint16_t>);
|
||||
OP(41, ppc_lzu<uint16_t>);
|
||||
OP(42, ppc_lha);
|
||||
OP(43, ppc_lhau);
|
||||
OP(44, ppc_st<uint16_t>);
|
||||
OP(45, ppc_stu<uint16_t>);
|
||||
OP(46, ppc_lmw);
|
||||
OP(47, ppc_stmw);
|
||||
OP(48, ppc_lfs);
|
||||
OP(49, ppc_lfsu);
|
||||
OP(50, ppc_lfd);
|
||||
OP(51, ppc_lfdu);
|
||||
OP(52, ppc_stfs);
|
||||
OP(53, ppc_stfsu);
|
||||
OP(54, ppc_stfd);
|
||||
OP(55, ppc_stfdu);
|
||||
OP(59, ppc_opcode59);
|
||||
OP(63, ppc_opcode63);
|
||||
std::fill_n(Opcode16Grabber, 3, ppc_illegalop);
|
||||
std::fill_n(Opcode18Grabber, 3, ppc_illegalop);
|
||||
std::fill_n(Opcode19Grabber, 2048, ppc_illegalop);
|
||||
std::fill_n(Opcode31Grabber, 2048, ppc_illegalop);
|
||||
std::fill_n(Opcode59Grabber, 64, ppc_illegalop);
|
||||
std::fill_n(Opcode63Grabber, 2048, ppc_illegalop);
|
||||
|
||||
std::fill_n(SubOpcode31Grabber, 2048, ppc_illegalop);
|
||||
OP31(0, ppc_cmp);
|
||||
OP31(4, ppc_tw);
|
||||
OP31(32, ppc_cmpl);
|
||||
|
||||
OP31cod(8, ppc_subf, CARRY1);
|
||||
OP31cod(40, ppc_subf, CARRY0);
|
||||
OP31od(104, ppc_neg);
|
||||
OP31od(136, ppc_subfe);
|
||||
OP31od(200, ppc_subfze);
|
||||
OP31od(232, ppc_subfme);
|
||||
|
||||
OP31cod(10, ppc_add, CARRY1);
|
||||
OP31od(138, ppc_adde);
|
||||
OP31od(202, ppc_addze);
|
||||
OP31od(234, ppc_addme);
|
||||
OP31cod(266, ppc_add, CARRY0);
|
||||
|
||||
OP31d(11, ppc_mulhwu);
|
||||
OP31d(75, ppc_mulhw);
|
||||
OP31od(235, ppc_mullw);
|
||||
OP31od(459, ppc_divwu);
|
||||
OP31od(491, ppc_divw);
|
||||
|
||||
OP31(20, ppc_lwarx);
|
||||
OP31(23, ppc_lzx<uint32_t>);
|
||||
OP31(55, ppc_lzux<uint32_t>);
|
||||
OP31(87, ppc_lzx<uint8_t>);
|
||||
OP31(119, ppc_lzux<uint8_t>);
|
||||
OP31(279, ppc_lzx<uint16_t>);
|
||||
OP31(311, ppc_lzux<uint16_t>);
|
||||
OP31(343, ppc_lhax);
|
||||
OP31(375, ppc_lhaux);
|
||||
OP31(533, ppc_lswx);
|
||||
OP31(534, ppc_lwbrx);
|
||||
OP31(535, ppc_lfsx);
|
||||
OP31(567, ppc_lfsux);
|
||||
OP31(597, ppc_lswi);
|
||||
OP31(599, ppc_lfdx);
|
||||
OP31(631, ppc_lfdux);
|
||||
OP31(790, ppc_lhbrx);
|
||||
|
||||
SubOpcode31Grabber[(150<<1)+1] = ppc_stwcx; // No Rc=0 variant.
|
||||
OP31(151, ppc_stx<uint32_t>);
|
||||
OP31(183, ppc_stux<uint32_t>);
|
||||
OP31(215, ppc_stx<uint8_t>);
|
||||
OP31(247, ppc_stux<uint8_t>);
|
||||
OP31(407, ppc_stx<uint16_t>);
|
||||
OP31(439, ppc_stux<uint16_t>);
|
||||
OP31(661, ppc_stswx);
|
||||
OP31(662, ppc_stwbrx);
|
||||
OP31(663, ppc_stfsx);
|
||||
OP31(695, ppc_stfsux);
|
||||
OP31(725, ppc_stswi);
|
||||
OP31(727, ppc_stfdx);
|
||||
OP31(759, ppc_stfdux);
|
||||
OP31(918, ppc_sthbrx);
|
||||
if (!is_601) OP31(983, ppc_stfiwx);
|
||||
|
||||
OP31(310, ppc_eciwx);
|
||||
OP31(438, ppc_ecowx);
|
||||
|
||||
OP31dc(24, ppc_shift, LEFT1); // slw
|
||||
OP31dc(28, ppc_logical, ppc_and);
|
||||
OP31dc(60, ppc_logical, ppc_andc);
|
||||
OP31dc(124, ppc_logical, ppc_nor);
|
||||
OP31dc(284, ppc_logical, ppc_eqv);
|
||||
OP31dc(316, ppc_logical, ppc_xor);
|
||||
OP31dc(412, ppc_logical, ppc_orc);
|
||||
OP31dc(444, ppc_logical, ppc_or);
|
||||
OP31dc(476, ppc_logical, ppc_nand);
|
||||
OP31dc(536, ppc_shift, RIGHT0); // srw
|
||||
OP31d(792, ppc_sraw);
|
||||
OP31d(824, ppc_srawi);
|
||||
OP31dc(922, ppc_exts, int16_t);
|
||||
OP31dc(954, ppc_exts, int8_t);
|
||||
|
||||
OP31d(26, ppc_cntlzw);
|
||||
|
||||
OP31(19, ppc_mfcr);
|
||||
OP31(83, ppc_mfmsr);
|
||||
OP31(144, ppc_mtcrf);
|
||||
OP31(146, ppc_mtmsr);
|
||||
OP31(210, ppc_mtsr);
|
||||
OP31(242, ppc_mtsrin);
|
||||
OP31(339, ppc_mfspr);
|
||||
if (!is_601) OP31(371, ppc_mftb);
|
||||
OP31(467, ppc_mtspr);
|
||||
OP31(512, ppc_mcrxr);
|
||||
OP31(595, ppc_mfsr);
|
||||
OP31(659, ppc_mfsrin);
|
||||
|
||||
OP31(54, ppc_dcbst);
|
||||
OP31(86, ppc_dcbf);
|
||||
OP31(246, ppc_dcbtst);
|
||||
OP31(278, ppc_dcbt);
|
||||
OP31(598, ppc_sync);
|
||||
OP31(470, ppc_dcbi);
|
||||
OP31(1014, ppc_dcbz);
|
||||
|
||||
if (is_601 || include_601) {
|
||||
OP31d(29, power_maskg);
|
||||
OP31od(107, power_mul);
|
||||
OP31d(152, power_slq);
|
||||
OP31d(153, power_sle);
|
||||
OP31d(184, power_sliq);
|
||||
OP31d(216, power_sllq);
|
||||
OP31d(217, power_sleq);
|
||||
OP31d(248, power_slliq);
|
||||
OP31od(264, power_doz);
|
||||
OP31d(277, power_lscbx);
|
||||
OP31od(331, power_div);
|
||||
OP31od(360, power_abs);
|
||||
OP31od(363, power_divs);
|
||||
OP31od(488, power_nabs);
|
||||
OP31(531, power_clcs);
|
||||
OP31d(537, power_rrib);
|
||||
OP31d(541, power_maskir);
|
||||
OP31d(664, power_srq);
|
||||
OP31d(665, power_sre);
|
||||
OP31d(696, power_sriq);
|
||||
OP31d(728, power_srlq);
|
||||
OP31d(729, power_sreq);
|
||||
OP31d(760, power_srliq);
|
||||
OP31d(920, power_sraq);
|
||||
OP31d(921, power_srea);
|
||||
OP31d(952, power_sraiq);
|
||||
}
|
||||
|
||||
OP31(306, ppc_tlbie);
|
||||
if (!is_601) OP31(370, ppc_tlbia);
|
||||
if (!is_601) OP31(566, ppc_tlbsync);
|
||||
OP31(854, ppc_eieio);
|
||||
OP31(982, ppc_icbi);
|
||||
if (!is_601) OP31(978, ppc_tlbld);
|
||||
if (!is_601) OP31(1010, ppc_tlbli);
|
||||
|
||||
std::fill_n(SubOpcode59Grabber, 64, ppc_illegalop);
|
||||
OP59d(18, ppc_fdivs);
|
||||
OP59d(20, ppc_fsubs);
|
||||
OP59d(21, ppc_fadds);
|
||||
if (ppc_state.spr[SPR::PVR] == PPC_VER::MPC970MP) OP59d(22, ppc_fsqrts);
|
||||
if (!is_601) OP59d(24, ppc_fres);
|
||||
OP59d(25, ppc_fmuls);
|
||||
OP59d(28, ppc_fmsubs);
|
||||
OP59d(29, ppc_fmadds);
|
||||
OP59d(30, ppc_fnmsubs);
|
||||
OP59d(31, ppc_fnmadds);
|
||||
|
||||
std::fill_n(SubOpcode63Grabber, 2048, ppc_illegalop);
|
||||
OP63(0, ppc_fcmpu);
|
||||
OP63d(12, ppc_frsp);
|
||||
OP63d(14, ppc_fctiw);
|
||||
OP63d(15, ppc_fctiwz);
|
||||
OP63d(18, ppc_fdiv);
|
||||
OP63d(20, ppc_fsub);
|
||||
OP63d(21, ppc_fadd);
|
||||
if (ppc_state.spr[SPR::PVR] == PPC_VER::MPC970MP) OP63d(22, ppc_fsqrt);
|
||||
if (!is_601) OP63d(26, ppc_frsqrte);
|
||||
OP63(32, ppc_fcmpo);
|
||||
OP63d(38, ppc_mtfsb1);
|
||||
OP63d(40, ppc_fneg);
|
||||
OP63(64, ppc_mcrfs);
|
||||
OP63d(70, ppc_mtfsb0);
|
||||
OP63d(72, ppc_fmr);
|
||||
OP63d(134, ppc_mtfsfi);
|
||||
OP63d(136, ppc_fnabs);
|
||||
OP63d(264, ppc_fabs);
|
||||
if (is_601) OP63dc(583, ppc_mffs, IS601); else OP63dc(583, ppc_mffs, NOT601);
|
||||
OP63d(711, ppc_mtfsf);
|
||||
|
||||
for (int i = 0; i < 1024; i += 32) {
|
||||
if (!is_601) OP63d(i + 23, ppc_fsel);
|
||||
OP63d(i + 25, ppc_fmul);
|
||||
OP63d(i + 28, ppc_fmsub);
|
||||
OP63d(i + 29, ppc_fmadd);
|
||||
OP63d(i + 30, ppc_fnmsub);
|
||||
OP63d(i + 31, ppc_fnmadd);
|
||||
}
|
||||
#include "ppcopcodes.include"
|
||||
#include "poweropcodes.include"
|
||||
#include "ppcfpopcodes.include"
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq)
|
||||
@@ -928,8 +745,9 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601,
|
||||
}
|
||||
|
||||
void print_fprs() {
|
||||
for (int i = 0; i < 32; i++)
|
||||
for (int i = 0; i < 32; i++) {
|
||||
cout << "FPR " << dec << i << " : " << ppc_state.fpr[i].dbl64_r << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static map<string, int> SPRName2Num = {
|
||||
|
||||
+18
-827
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// The floating point opcodes for the processor - ppcfpopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcdecodemacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdlib.h>
|
||||
#include <cfenv>
|
||||
@@ -116,7 +116,7 @@ inline static bool check_qnan(int check_reg) {
|
||||
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
|
||||
}
|
||||
|
||||
static void fpresult_update(double set_result) {
|
||||
inline static void fpresult_update(double set_result) {
|
||||
if (std::isnan(set_result)) {
|
||||
ppc_state.fpscr |= FPCC_FUNAN | FPRCD;
|
||||
} else {
|
||||
@@ -128,12 +128,16 @@ static void fpresult_update(double set_result) {
|
||||
ppc_state.fpscr |= FPCC_ZERO;
|
||||
}
|
||||
|
||||
if (std::fetestexcept(FE_INEXACT)) {
|
||||
ppc_state.fpscr |= XX;
|
||||
}
|
||||
|
||||
if (std::isinf(set_result))
|
||||
ppc_state.fpscr |= FPCC_FUNAN;
|
||||
}
|
||||
}
|
||||
|
||||
static void ppc_update_vx() {
|
||||
inline static void ppc_update_vx() {
|
||||
uint32_t fpscr_check = ppc_state.fpscr & 0x1F80700U;
|
||||
if (fpscr_check)
|
||||
ppc_state.fpscr |= VX;
|
||||
@@ -141,7 +145,7 @@ static void ppc_update_vx() {
|
||||
ppc_state.fpscr &= ~VX;
|
||||
}
|
||||
|
||||
static void ppc_update_fex() {
|
||||
inline static void ppc_update_fex() {
|
||||
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
|
||||
((ppc_state.fpscr >> 3) & 0x1F));
|
||||
|
||||
@@ -151,477 +155,30 @@ static void ppc_update_fex() {
|
||||
ppc_state.fpscr &= ~VX;
|
||||
}
|
||||
|
||||
// Floating Point Arithmetic
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fadd() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
max_double_check(val_reg_a, val_reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a + val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fadd<RC0>();
|
||||
template void dppc_interpreter::ppc_fadd<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsub() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a - val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsub<RC0>();
|
||||
template void dppc_interpreter::ppc_fsub<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fdiv() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a / val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fdiv<RC0>();
|
||||
template void dppc_interpreter::ppc_fdiv<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmul() {
|
||||
ppc_grab_regsfpdac(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a * val_reg_c;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmul<RC0>();
|
||||
template void dppc_interpreter::ppc_fmul<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmadd() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmadd<RC0>();
|
||||
template void dppc_interpreter::ppc_fmadd<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmsub() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmsub<RC0>();
|
||||
template void dppc_interpreter::ppc_fmsub<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmadd() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmadd<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmadd<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmsub() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmsub<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmsub<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fadds() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fadds<RC0>();
|
||||
template void dppc_interpreter::ppc_fadds<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsubs() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
||||
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsubs<RC0>();
|
||||
template void dppc_interpreter::ppc_fsubs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fdivs() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fdivs<RC0>();
|
||||
template void dppc_interpreter::ppc_fdivs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmuls() {
|
||||
ppc_grab_regsfpdac(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmuls<RC0>();
|
||||
template void dppc_interpreter::ppc_fmuls<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmadds() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmadds<RC0>();
|
||||
template void dppc_interpreter::ppc_fmadds<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmsubs() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmsubs<RC0>();
|
||||
template void dppc_interpreter::ppc_fmsubs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmadds() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmadds<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmadds<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmsubs() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmsubs<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmsubs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fabs() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fabs<RC0>();
|
||||
template void dppc_interpreter::ppc_fabs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnabs() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
ppc_dblresult64_d = -ppc_dblresult64_d;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnabs<RC0>();
|
||||
template void dppc_interpreter::ppc_fnabs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fneg() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fneg<RC0>();
|
||||
template void dppc_interpreter::ppc_fneg<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsel() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
double ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsel<RC0>();
|
||||
template void dppc_interpreter::ppc_fsel<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsqrt() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = std::sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsqrt<RC0>();
|
||||
template void dppc_interpreter::ppc_fsqrt<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsqrts() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = (float)std::sqrt(testd2);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsqrts<RC0>();
|
||||
template void dppc_interpreter::ppc_fsqrts<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_frsqrte() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = 1.0 / sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_frsqrte<RC0>();
|
||||
template void dppc_interpreter::ppc_frsqrte<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_frsp() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_frsp<RC0>();
|
||||
template void dppc_interpreter::ppc_frsp<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fres() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double start_num = GET_FPR(reg_b);
|
||||
double ppc_dblresult64_d = (float)(1.0 / start_num);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (start_num == 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::ZX;
|
||||
}
|
||||
else if (std::isnan(start_num)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
else if (std::isinf(start_num)){
|
||||
ppc_state.fpscr &= 0xFFF9FFFF;
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fres<RC0>();
|
||||
template void dppc_interpreter::ppc_fres<RC1>();
|
||||
|
||||
static void round_to_int(const uint8_t mode, field_rc rec) {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
inline static void round_to_int(uint32_t instr, const uint8_t mode, field_rc rec) {
|
||||
ppc_grab_regsfpdb(instr);
|
||||
double val_reg_b = GET_FPR(reg_b);
|
||||
|
||||
if (std::isnan(val_reg_b)) {
|
||||
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
|
||||
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
|
||||
|
||||
if (check_snan(reg_b)) // issnan
|
||||
if (check_snan(reg_b)) // issnan
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
|
||||
if (ppc_state.fpscr & FPSCR::VE) {
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception();
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception(instr);
|
||||
} else {
|
||||
ppc_state.fpr[reg_d].int64_r = 0xFFF8000080000000ULL;
|
||||
}
|
||||
} else if (val_reg_b > static_cast<double>(0x7fffffff) ||
|
||||
val_reg_b < -static_cast<double>(0x80000000)) {
|
||||
} else if (val_reg_b > static_cast<double>(0x7fffffff) || val_reg_b < -static_cast<double>(0x80000000)) {
|
||||
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
|
||||
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
|
||||
|
||||
if (ppc_state.fpscr & FPSCR::VE) {
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception();
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception(instr);
|
||||
} else {
|
||||
if (val_reg_b >= 0.0f)
|
||||
ppc_state.fpr[reg_d].int64_r = 0xFFF800007FFFFFFFULL;
|
||||
@@ -654,371 +211,5 @@ static void round_to_int(const uint8_t mode, field_rc rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fctiw() {
|
||||
round_to_int(ppc_state.fpscr & 0x3, rec);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fctiw<RC0>();
|
||||
template void dppc_interpreter::ppc_fctiw<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fctiwz() {
|
||||
round_to_int(1, rec);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fctiwz<RC0>();
|
||||
template void dppc_interpreter::ppc_fctiwz<RC1>();
|
||||
|
||||
// Floating Point Store and Load
|
||||
|
||||
void dppc_interpreter::ppc_lfs() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfsu() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfsx() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfsux() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfd() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdu() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += val_reg_a;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdx() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdux() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfs() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfsu() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += val_reg_a;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfsx() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfsux() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfd() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += reg_a ? val_reg_a : 0;
|
||||
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfdu() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
|
||||
ea += val_reg_a;
|
||||
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfdx() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfdux() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfiwx() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint32_t>(ea, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
}
|
||||
|
||||
// Floating Point Register Transfer
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmr() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmr<RC0>();
|
||||
template void dppc_interpreter::ppc_fmr<RC1>();
|
||||
|
||||
template <field_601 for601, field_rc rec>
|
||||
void dppc_interpreter::ppc_mffs() {
|
||||
int reg_d = (ppc_cur_instruction >> 21) & 31;
|
||||
|
||||
ppc_state.fpr[reg_d].int64_r = uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mffs<NOT601, RC0>();
|
||||
template void dppc_interpreter::ppc_mffs<NOT601, RC1>();
|
||||
template void dppc_interpreter::ppc_mffs<IS601, RC0>();
|
||||
template void dppc_interpreter::ppc_mffs<IS601, RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsf() {
|
||||
int reg_b = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
uint8_t fm = (ppc_cur_instruction >> 17) & 0xFF;
|
||||
|
||||
uint32_t cr_mask = 0;
|
||||
|
||||
if (fm == 0xFFU) // the fast case
|
||||
cr_mask = 0xFFFFFFFFUL;
|
||||
else { // the slow case
|
||||
if (fm & 0x80) cr_mask |= 0xF0000000UL;
|
||||
if (fm & 0x40) cr_mask |= 0x0F000000UL;
|
||||
if (fm & 0x20) cr_mask |= 0x00F00000UL;
|
||||
if (fm & 0x10) cr_mask |= 0x000F0000UL;
|
||||
if (fm & 0x08) cr_mask |= 0x0000F000UL;
|
||||
if (fm & 0x04) cr_mask |= 0x00000F00UL;
|
||||
if (fm & 0x02) cr_mask |= 0x000000F0UL;
|
||||
if (fm & 0x01) cr_mask |= 0x0000000FUL;
|
||||
}
|
||||
|
||||
// ensure neither FEX nor VX will be changed
|
||||
cr_mask &= ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy FPR[reg_b] to FPSCR under control of cr_mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (ppc_state.fpr[reg_b].int64_r & cr_mask);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsf<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsf<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsfi() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
||||
uint32_t imm = (ppc_cur_instruction << 16) & 0xF0000000UL;
|
||||
|
||||
// prepare field mask and ensure that neither FEX nor VX will be changed
|
||||
uint32_t mask = (0xF0000000UL >> crf_d) & ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy imm to FPSCR[crf_d] under control of the field mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~mask) | ((imm >> crf_d) & mask);
|
||||
|
||||
// Update FEX and VX according to the "usual rule"
|
||||
ppc_update_vx();
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsfi<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsfi<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsb0() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
|
||||
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsb0<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsb0<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsb1() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
|
||||
ppc_state.fpscr |= (0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsb1<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsb1<RC1>();
|
||||
|
||||
void dppc_interpreter::ppc_mcrfs() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
||||
int crf_s = (ppc_cur_instruction >> 16) & 0x1C;
|
||||
ppc_state.cr = (
|
||||
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
||||
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
|
||||
);
|
||||
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
|
||||
// keep only the FPSCR bits that can be explicitly cleared
|
||||
FPSCR::FX | FPSCR::OX |
|
||||
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
|
||||
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
|
||||
FPSCR::VXVC |
|
||||
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
|
||||
));
|
||||
}
|
||||
|
||||
// Floating Point Comparisons
|
||||
|
||||
void dppc_interpreter::ppc_fcmpo() {
|
||||
ppc_grab_regsfpsab(ppc_cur_instruction);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
ppc_state.fpscr |= FX | VX;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= VXSNAN;
|
||||
}
|
||||
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
|
||||
ppc_state.fpscr |= VXVC;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fcmpu() {
|
||||
ppc_grab_regsfpsab(ppc_cur_instruction);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= FX | VX | VXSNAN;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
}
|
||||
#include "ppcopmacros.h"
|
||||
#include "ppcfpopcodes.include"
|
||||
@@ -0,0 +1,681 @@
|
||||
// Floating Point Arithmetic
|
||||
OPCODEREC (fadd, 63, 21,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
max_double_check(val_reg_a, val_reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a + val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fsub, 63, 20,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a - val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fdiv, 63, 18,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a / val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmul, 63, 25,
|
||||
ppc_grab_regsfpdac(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a * val_reg_c;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmadd, 63, 29,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmsub, 63, 28,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fnmadd, 63, 31,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fnmsub, 63, 30,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fadds, 59, 21,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fsubs, 59, 20,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
||||
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fdivs, 59, 18,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmuls, 59, 25,
|
||||
ppc_grab_regsfpdac(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmadds, 59, 29,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmsubs, 59, 28,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fnmadds, 59, 31,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fnmsubs, 59, 30,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fabs, 63, 264,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fnabs, 63, 136,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
ppc_dblresult64_d = -ppc_dblresult64_d;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fneg, 63, 40,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF(fsel, 63, 23,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
double ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fsqrt, 63, 22,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = std::sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fsqrts, 59, 22,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = (float)std::sqrt(testd2);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (frsqrte, 63, 26,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = 1.0 / sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (frsp, 63, 12,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fres, 63, 24,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double start_num = GET_FPR(reg_b);
|
||||
double ppc_dblresult64_d = (float)(1.0 / start_num);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (start_num == 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::ZX;
|
||||
}
|
||||
else if (std::isnan(start_num)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
else if (std::isinf(start_num)){
|
||||
ppc_state.fpscr &= 0xFFF9FFFF;
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fctiw, 63, 14,
|
||||
round_to_int(instr, ppc_state.fpscr & 0x3, rec);
|
||||
)
|
||||
|
||||
OPCODEREC (fctiwz, 63, 15,
|
||||
round_to_int(instr, 1, rec);
|
||||
)
|
||||
|
||||
// Floating Point Store and Load
|
||||
|
||||
OPCODE (lfs, , 48,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
)
|
||||
|
||||
OPCODE (lfsu, , 49,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (lfsx, 31, 535,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
)
|
||||
|
||||
OPCODE31 (lfsux, 31, 567,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (lfd, , 50,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
)
|
||||
|
||||
OPCODE (lfdu, , 51,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (lfdx, 31, 599,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
)
|
||||
|
||||
OPCODE31 (lfdux, 31, 631,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (stfs, , 52,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
)
|
||||
|
||||
OPCODE (stfsu, , 53,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfsx, 31, 663,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
)
|
||||
|
||||
OPCODE31 (stfsux, 31, 695,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (stfd, , 54,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += reg_a ? val_reg_a : 0;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
)
|
||||
|
||||
OPCODE (stfdu, , 55,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfdx, 31, 727,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
)
|
||||
|
||||
OPCODE31 (stfdux, 31, 759,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfiwx, 31, 983,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
)
|
||||
|
||||
// Floating Point Register Transfer
|
||||
|
||||
OPCODEREC (fmr, 63, 72,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODE601REC (mffs, 63, 583,
|
||||
int reg_d = (instr >> 21) & 31;
|
||||
|
||||
ppc_state.fpr[reg_d].int64_r = uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (mtfsf, 63, 711,
|
||||
ppc_grab_mtfsf(instr);
|
||||
|
||||
uint32_t cr_mask = 0;
|
||||
|
||||
if (fm == 0xFFU) { // the fast case
|
||||
cr_mask = 0xFFFFFFFFUL;
|
||||
}
|
||||
else { // the slow case
|
||||
if (fm & 0x80) cr_mask |= 0xF0000000UL;
|
||||
if (fm & 0x40) cr_mask |= 0x0F000000UL;
|
||||
if (fm & 0x20) cr_mask |= 0x00F00000UL;
|
||||
if (fm & 0x10) cr_mask |= 0x000F0000UL;
|
||||
if (fm & 0x08) cr_mask |= 0x0000F000UL;
|
||||
if (fm & 0x04) cr_mask |= 0x00000F00UL;
|
||||
if (fm & 0x02) cr_mask |= 0x000000F0UL;
|
||||
if (fm & 0x01) cr_mask |= 0x0000000FUL;
|
||||
}
|
||||
|
||||
// ensure neither FEX nor VX will be changed
|
||||
cr_mask &= ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy FPR[reg_b] to FPSCR under control of cr_mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (ppc_state.fpr[reg_b].int64_r & cr_mask);
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODEREC (mtfsfi, 63, 134,
|
||||
ppc_grab_mtfsfi(instr);
|
||||
|
||||
// prepare field mask and ensure that neither FEX nor VX will be changed
|
||||
uint32_t mask = (0xF0000000UL >> crf_d) & ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy imm to FPSCR[crf_d] under control of the field mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~mask) | ((imm >> crf_d) & mask);
|
||||
|
||||
// Update FEX and VX according to the "usual rule"
|
||||
ppc_update_vx();
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (mtfsb0, 63, 70,
|
||||
int crf_d = (instr >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
|
||||
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODE31 (mtfsb1, 63, 38,
|
||||
ppc_grab_crfd(instr);
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
|
||||
ppc_state.fpscr |= (0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (mcrfs, 63, 64,
|
||||
ppc_grab_crfds(instr);
|
||||
ppc_state.cr = (
|
||||
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
||||
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
|
||||
);
|
||||
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
|
||||
// keep only the FPSCR bits that can be explicitly cleared
|
||||
FPSCR::FX | FPSCR::OX |
|
||||
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
|
||||
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
|
||||
FPSCR::VXVC |
|
||||
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
|
||||
));
|
||||
)
|
||||
|
||||
// Floating Point Comparisons
|
||||
|
||||
OPCODE31 (fcmpo, 63, 32,
|
||||
ppc_grab_regsfpsab(instr);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
ppc_state.fpscr |= FX | VX;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= VXSNAN;
|
||||
}
|
||||
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
|
||||
ppc_state.fpscr |= VXVC;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
)
|
||||
|
||||
OPCODE (fcmpu, 63, 0,
|
||||
ppc_grab_regsfpsab(instr);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= FX | VX | VXSNAN;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
)
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(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/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
template <field_shift shift> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
template <field_direction isleft, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
template <class T, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
template <logical_fun logical_op, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
template <field_lk l, field_aa a> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
template <field_601 for601, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
template <field_lk l, field_601 for601> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
template <field_lk l> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
+36
-37
@@ -741,7 +741,6 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
ppc_set_cur_instruction(host_va);
|
||||
if (paddr)
|
||||
*paddr = tlb1_entry->phys_tag | (vaddr & 0xFFFUL);
|
||||
|
||||
@@ -985,13 +984,12 @@ void mmu_pat_ctx_changed()
|
||||
|
||||
// Forward declarations.
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va);
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value);
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr, T value);
|
||||
|
||||
template <class T>
|
||||
inline T mmu_read_vmem(uint32_t guest_va)
|
||||
{
|
||||
inline T mmu_read_vmem(uint32_t guest_va, uint32_t instr) {
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
@@ -1034,7 +1032,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
@@ -1061,7 +1059,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
return read_unaligned<T>(guest_va, host_va);
|
||||
return read_unaligned<T>(guest_va, host_va, instr);
|
||||
}
|
||||
|
||||
// handle aligned memory accesses
|
||||
@@ -1078,14 +1076,13 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required mmu_read_vmem variants
|
||||
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va);
|
||||
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va);
|
||||
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va);
|
||||
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va);
|
||||
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va, uint32_t instr);
|
||||
|
||||
template <class T>
|
||||
inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
{
|
||||
inline void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value) {
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
@@ -1156,7 +1153,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
@@ -1179,7 +1176,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
write_unaligned<T>(guest_va, host_va, value);
|
||||
write_unaligned<T>(guest_va, host_va, instr, value);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1201,17 +1198,16 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required mmu_write_vmem variants
|
||||
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint8_t value);
|
||||
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint64_t value);
|
||||
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint32_t instr, uint8_t value);
|
||||
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint32_t instr, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t instr, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint32_t instr, uint64_t value);
|
||||
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
{
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr) {
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1226,7 +1222,7 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't waste time optimizing the code below.
|
||||
for (int i = 0; i < sizeof(T); guest_va++, i++) {
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va);
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va, instr);
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -1247,16 +1243,16 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required read_unaligned variants
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t instr, T value)
|
||||
{
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1272,7 +1268,7 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
uint32_t shift = (sizeof(T) - 1) * 8;
|
||||
|
||||
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
|
||||
mmu_write_vmem<uint8_t>(guest_va, (value >> shift) & 0xFF);
|
||||
mmu_write_vmem<uint8_t>(guest_va, instr, ((value >> shift) & 0xFF));
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -1296,9 +1292,12 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required write_unaligned variants
|
||||
template void write_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va, uint64_t value);
|
||||
template void write_unaligned<uint16_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint64_t value);
|
||||
|
||||
|
||||
/* MMU profiling. */
|
||||
@@ -1438,19 +1437,19 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
try {
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
|
||||
break;
|
||||
case 2:
|
||||
ret_val = mmu_read_vmem<uint16_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint16_t>(virt_addr, 0);
|
||||
break;
|
||||
case 4:
|
||||
ret_val = mmu_read_vmem<uint32_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint32_t>(virt_addr, 0);
|
||||
break;
|
||||
case 8:
|
||||
ret_val = mmu_read_vmem<uint64_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint64_t>(virt_addr, 0);
|
||||
break;
|
||||
default:
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
|
||||
}
|
||||
} catch (std::invalid_argument& exc) {
|
||||
/* restore MMU-related CPU state */
|
||||
|
||||
+2
-2
@@ -130,8 +130,8 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
|
||||
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
extern T mmu_read_vmem(uint32_t guest_va, uint32_t instr);
|
||||
template <class T>
|
||||
extern void mmu_write_vmem(uint32_t guest_va, T value);
|
||||
extern void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value);
|
||||
|
||||
#endif // PPCMMU_H
|
||||
+10
-1842
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(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/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
template <field_shift shift> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<SHFT0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<SHFT1>(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
template <field_direction isleft, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RIGHT0, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LEFT1, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RIGHT0, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LEFT1, RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC0, OV1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1, OV1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
template <class T, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<int8_t, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int16_t, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int8_t, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int16_t, RC1>(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::power_##op<RC0, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC0, OV1>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1, OV1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::power_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
template <logical_fun logical_op, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<ppc_and, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_andc, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_eqv, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nand, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nor, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_or, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_orc, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_xor, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_and, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_andc, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_eqv, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nand, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nor, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_or, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_orc, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_xor, RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
template <field_lk l, field_aa a> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0, AA0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK0, AA1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, AA0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, AA1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
template <field_601 for601, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<NOT601, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<IS601, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<NOT601, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<IS601, RC1>(uint32_t instr); \
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
template <field_lk l, field_601 for601> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0, NOT601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK0, IS601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, NOT601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, IS601>(uint32_t instr); \
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
template <field_lk l> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(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/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number] = ppc_##op;
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number << 1] = ppc_##op;
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
if (is_601) \
|
||||
Opcode##grabber##Grabber[number] = power_##op;
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
if (is_601) \
|
||||
Opcode##grabber##Grabber[number << 1] = power_##op;
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<SHFT0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<SHFT1>;
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LEFT1 , RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LEFT1 , RC1>; \
|
||||
Opcode##grabber##Grabber[number + (1 << 9) ] = ppc_##op<RIGHT0, RC0>; \
|
||||
Opcode##grabber##Grabber[number + (1 << 9) + 1] = ppc_##op<RIGHT0, RC1>; \
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<RC0, OV0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<RC1, OV0>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<RC0, OV1>; \
|
||||
Opcode##grabber##Grabber[number + 3] = ppc_##op<RC1, OV1>;
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<int16_t, RC0>; \
|
||||
Opcode##grabber##Grabber[( number << 1) + 1] = ppc_##op<int16_t, RC1>; \
|
||||
Opcode##grabber##Grabber[ (number + 32) << 1 ] = ppc_##op<int8_t, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<int8_t, RC1>;
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0, OV0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1, OV0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 2] = power_##op<RC0, OV1>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 3] = power_##op<RC1, OV1>; \
|
||||
}
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = ppc_##op<RC1>; \
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
for (int i = 0; i < 2048; i += 32) { \
|
||||
Opcode##grabber##Grabber[(number + i) << 1 ] = ppc_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[((number + i) << 1) + 1] = ppc_##op<RC1>; \
|
||||
}
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1>; \
|
||||
}
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number ] = ppc_##op<ppc_and , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 1) << 1) ] = ppc_##op<ppc_and , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) ] = ppc_##op<ppc_andc, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<ppc_andc, RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 96) << 1) ] = ppc_##op<ppc_nor , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 96) << 1) + 1] = ppc_##op<ppc_nor , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 256) << 1) ] = ppc_##op<ppc_eqv , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 256) << 1) + 1] = ppc_##op<ppc_eqv , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 288) << 1) ] = ppc_##op<ppc_xor , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 288) << 1) + 1] = ppc_##op<ppc_xor , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 384) << 1) ] = ppc_##op<ppc_orc , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 384) << 1) + 1] = ppc_##op<ppc_orc , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 416) << 1) ] = ppc_##op<ppc_or , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 416) << 1) + 1] = ppc_##op<ppc_or , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 448) << 1) ] = ppc_##op<ppc_nand, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 448) << 1) + 1] = ppc_##op<ppc_nand, RC1>; \
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, AA0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, AA0>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<LK0, AA1>; \
|
||||
Opcode##grabber##Grabber[number + 3] = ppc_##op<LK1, AA1>;
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<uint32_t>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<uint8_t>; \
|
||||
Opcode##grabber##Grabber[number + 8] = ppc_##op<uint16_t>;
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<uint32_t>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + (1 << 6)] = ppc_##op<uint8_t>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + (1 << 8)] = ppc_##op<uint16_t>;
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<IS601, RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<IS601, RC1>; \
|
||||
} else { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<NOT601, RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<NOT601, RC1>; \
|
||||
}
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, IS601>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, IS601>; \
|
||||
} \
|
||||
else { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, NOT601>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, NOT601>; \
|
||||
}
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1>;
|
||||
@@ -36,12 +36,17 @@ using namespace std;
|
||||
int ntested; // number of tested instructions
|
||||
int nfailed; // number of failed instructions
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
#if defined(PPC_TESTS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
|
||||
ppc_cur_instruction = opcode;
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
|
||||
nfailed++;
|
||||
@@ -145,9 +150,7 @@ static void read_test_data() {
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
@@ -289,9 +292,7 @@ static void read_test_float_data() {
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ print_bin:
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
void exec_single_68k(uint32_t instr)
|
||||
{
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
@@ -174,7 +174,7 @@ void exec_single_68k()
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc, 0) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
@@ -621,7 +621,7 @@ void enter_debugger() {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
exec_single_68k(0);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user