mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-02-12 11:30:26 +00:00
Remove ppc_cur_instruction global variable
Replace it wth an explicit opcode parameter that is passed around. That is both slightly easier to reason about (to trace where it comes from) and slightly faster, since it can be read from a register. On my machine takes booting to "Welcome to Macintosh" being output in a verbose boot of Mac OS X 10.2.8 from 31.8s to 30.6s (average of 5 runs, measured using deterministic mode and looking at when execution reaches PC 0x90004a88).
This commit is contained in:
parent
31bc6f79e5
commit
564c43c907
@ -35,9 +35,9 @@ static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
}
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_abs() {
|
||||
void dppc_interpreter::power_abs(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
ppc_grab_regsda(opcode);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
@ -54,14 +54,14 @@ void dppc_interpreter::power_abs() {
|
||||
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>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
void dppc_interpreter::power_clcs() {
|
||||
void dppc_interpreter::power_clcs(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_da(ppc_cur_instruction);
|
||||
ppc_grab_da(opcode);
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
@ -84,9 +84,9 @@ void dppc_interpreter::power_clcs() {
|
||||
}
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_div() {
|
||||
void dppc_interpreter::power_div(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_grab_regsdab(opcode);
|
||||
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
@ -123,16 +123,16 @@ void dppc_interpreter::power_div() {
|
||||
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 void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_divs() {
|
||||
void dppc_interpreter::power_divs(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_grab_regsdab(opcode);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
@ -157,14 +157,14 @@ void dppc_interpreter::power_divs() {
|
||||
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 void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_doz(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
@ -181,14 +181,14 @@ void dppc_interpreter::power_doz() {
|
||||
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>();
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
void dppc_interpreter::power_dozi(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(ppc_cur_instruction);
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
@ -198,8 +198,8 @@ void dppc_interpreter::power_dozi() {
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_lscbx(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
@ -212,7 +212,7 @@ void dppc_interpreter::power_lscbx() {
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(ea);
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(opcode, ea);
|
||||
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
@ -248,12 +248,12 @@ void dppc_interpreter::power_lscbx() {
|
||||
}
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_lscbx<RC0>();
|
||||
template void dppc_interpreter::power_lscbx<RC1>();
|
||||
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_lscbx<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_maskg(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
@ -276,12 +276,12 @@ void dppc_interpreter::power_maskg() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskg<RC0>();
|
||||
template void dppc_interpreter::power_maskg<RC1>();
|
||||
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_maskg<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_maskir(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
@ -290,12 +290,12 @@ void dppc_interpreter::power_maskir() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskir<RC0>();
|
||||
template void dppc_interpreter::power_maskir<RC1>();
|
||||
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_maskir<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_mul(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
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);
|
||||
@ -312,14 +312,14 @@ void dppc_interpreter::power_mul() {
|
||||
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 void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_nabs(uint32_t opcode) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
@ -330,15 +330,15 @@ void dppc_interpreter::power_nabs() {
|
||||
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>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
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;
|
||||
void dppc_interpreter::power_rlmi(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_mb = (opcode >> 6) & 0x1F;
|
||||
unsigned rot_me = (opcode >> 1) & 0x1F;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
@ -346,15 +346,15 @@ void dppc_interpreter::power_rlmi() {
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((ppc_cur_instruction & 0x01) == 1)
|
||||
if ((opcode & 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);
|
||||
void dppc_interpreter::power_rrib(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
@ -369,12 +369,12 @@ void dppc_interpreter::power_rrib() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_rrib<RC0>();
|
||||
template void dppc_interpreter::power_rrib<RC1>();
|
||||
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_rrib<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sle(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
@ -388,12 +388,12 @@ void dppc_interpreter::power_sle() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sle<RC0>();
|
||||
template void dppc_interpreter::power_sle<RC1>();
|
||||
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sle<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sleq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
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);
|
||||
@ -407,12 +407,12 @@ void dppc_interpreter::power_sleq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sleq<RC0>();
|
||||
template void dppc_interpreter::power_sleq<RC1>();
|
||||
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sleq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sliq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
@ -423,12 +423,12 @@ void dppc_interpreter::power_sliq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sliq<RC0>();
|
||||
template void dppc_interpreter::power_sliq<RC1>();
|
||||
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_slliq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
@ -441,12 +441,12 @@ void dppc_interpreter::power_slliq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slliq<RC0>();
|
||||
template void dppc_interpreter::power_slliq<RC1>();
|
||||
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_slliq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sllq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sllq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
@ -461,12 +461,12 @@ void dppc_interpreter::power_sllq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sllq<RC0>();
|
||||
template void dppc_interpreter::power_sllq<RC1>();
|
||||
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sllq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_slq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
@ -482,12 +482,12 @@ void dppc_interpreter::power_slq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slq<RC0>();
|
||||
template void dppc_interpreter::power_slq<RC1>();
|
||||
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_slq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sraiq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
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));
|
||||
@ -504,12 +504,12 @@ void dppc_interpreter::power_sraiq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraiq<RC0>();
|
||||
template void dppc_interpreter::power_sraiq<RC1>();
|
||||
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sraiq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sraq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
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);
|
||||
@ -529,12 +529,12 @@ void dppc_interpreter::power_sraq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraq<RC0>();
|
||||
template void dppc_interpreter::power_sraq<RC1>();
|
||||
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sraq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sre(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
@ -547,12 +547,12 @@ void dppc_interpreter::power_sre() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sre<RC0>();
|
||||
template void dppc_interpreter::power_sre<RC1>();
|
||||
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sre<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srea() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_srea(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
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)));
|
||||
@ -571,12 +571,12 @@ void dppc_interpreter::power_srea() {
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>();
|
||||
template void dppc_interpreter::power_srea<RC1>();
|
||||
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srea<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sreq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
@ -589,12 +589,12 @@ void dppc_interpreter::power_sreq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sreq<RC0>();
|
||||
template void dppc_interpreter::power_sreq<RC1>();
|
||||
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sreq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_sriq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
@ -604,12 +604,12 @@ void dppc_interpreter::power_sriq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>();
|
||||
template void dppc_interpreter::power_sriq<RC1>();
|
||||
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_srliq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
@ -622,12 +622,12 @@ void dppc_interpreter::power_srliq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>();
|
||||
template void dppc_interpreter::power_srliq<RC1>();
|
||||
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srliq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srlq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_srlq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
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);
|
||||
@ -644,12 +644,12 @@ void dppc_interpreter::power_srlq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srlq<RC0>();
|
||||
template void dppc_interpreter::power_srlq<RC1>();
|
||||
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srlq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
void dppc_interpreter::power_srq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
@ -666,5 +666,5 @@ void dppc_interpreter::power_srq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srq<RC0>();
|
||||
template void dppc_interpreter::power_srq<RC1>();
|
||||
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srq<RC1>(uint32_t opcode);
|
||||
|
385
cpu/ppc/ppcemu.h
385
cpu/ppc/ppcemu.h
@ -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 opcode);
|
||||
|
||||
union FPR_storage {
|
||||
double dbl64_r; // double floating-point representation
|
||||
@ -333,11 +333,10 @@ extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
extern bool is_deterministic;
|
||||
|
||||
// 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_read_instruction(const uint8_t* ptr) {
|
||||
return READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
// Profiling Stats
|
||||
@ -405,7 +404,7 @@ 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 opcode);
|
||||
void ppc_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
@ -418,8 +417,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 opcode);
|
||||
void ppc_alignment_exception(uint32_t opcode, uint32_t ea);
|
||||
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
@ -430,203 +429,203 @@ 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 <field_lk l, field_601 for601> extern void ppc_bcctr(uint32_t opcode);
|
||||
template <field_lk l> extern void ppc_bclr(uint32_t opcode);
|
||||
extern void ppc_crand(uint32_t opcode);
|
||||
extern void ppc_crandc(uint32_t opcode);
|
||||
extern void ppc_creqv(uint32_t opcode);
|
||||
extern void ppc_crnand(uint32_t opcode);
|
||||
extern void ppc_crnor(uint32_t opcode);
|
||||
extern void ppc_cror(uint32_t opcode);
|
||||
extern void ppc_crorc(uint32_t opcode);
|
||||
extern void ppc_crxor(uint32_t opcode);
|
||||
extern void ppc_isync(uint32_t opcode);
|
||||
|
||||
template <logical_fun logical_op, field_rc rec> extern void ppc_logical();
|
||||
template <logical_fun logical_op, field_rc rec> extern void ppc_logical(uint32_t opcode);
|
||||
|
||||
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();
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_adde(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addme(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addze(uint32_t opcode);
|
||||
extern void ppc_cmp(uint32_t opcode);
|
||||
extern void ppc_cmpl(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_cntlzw(uint32_t opcode);
|
||||
extern void ppc_dcbf(uint32_t opcode);
|
||||
extern void ppc_dcbi(uint32_t opcode);
|
||||
extern void ppc_dcbst(uint32_t opcode);
|
||||
extern void ppc_dcbt(uint32_t opcode);
|
||||
extern void ppc_dcbtst(uint32_t opcode);
|
||||
extern void ppc_dcbz(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divw(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divwu(uint32_t opcode);
|
||||
extern void ppc_eciwx(uint32_t opcode);
|
||||
extern void ppc_ecowx(uint32_t opcode);
|
||||
extern void ppc_eieio(uint32_t opcode);
|
||||
template <class T, field_rc rec>extern void ppc_exts(uint32_t opcode);
|
||||
extern void ppc_icbi(uint32_t opcode);
|
||||
extern void ppc_mftb(uint32_t opcode);
|
||||
extern void ppc_lhaux(uint32_t opcode);
|
||||
extern void ppc_lhax(uint32_t opcode);
|
||||
extern void ppc_lhbrx(uint32_t opcode);
|
||||
extern void ppc_lwarx(uint32_t opcode);
|
||||
extern void ppc_lwbrx(uint32_t opcode);
|
||||
template <class T> extern void ppc_lzx(uint32_t opcode);
|
||||
template <class T> extern void ppc_lzux(uint32_t opcode);
|
||||
extern void ppc_mcrxr(uint32_t opcode);
|
||||
extern void ppc_mfcr(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mulhwu(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mulhw(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_mullw(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_neg(uint32_t opcode);
|
||||
template <field_direction shift, field_rc rec> extern void ppc_shift(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_sraw(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_srawi(uint32_t opcode);
|
||||
template <class T> extern void ppc_stx(uint32_t opcode);
|
||||
template <class T> extern void ppc_stux(uint32_t opcode);
|
||||
extern void ppc_stfiwx(uint32_t opcode);
|
||||
extern void ppc_sthbrx(uint32_t opcode);
|
||||
extern void ppc_stwcx(uint32_t opcode);
|
||||
extern void ppc_stwbrx(uint32_t opcode);
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfe(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfme(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfze(uint32_t opcode);
|
||||
extern void ppc_sync(uint32_t opcode);
|
||||
extern void ppc_tlbia(uint32_t opcode);
|
||||
extern void ppc_tlbie(uint32_t opcode);
|
||||
extern void ppc_tlbli(uint32_t opcode);
|
||||
extern void ppc_tlbld(uint32_t opcode);
|
||||
extern void ppc_tlbsync(uint32_t opcode);
|
||||
extern void ppc_tw(uint32_t opcode);
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
extern void ppc_stswi();
|
||||
extern void ppc_stswx();
|
||||
extern void ppc_lswi(uint32_t opcode);
|
||||
extern void ppc_lswx(uint32_t opcode);
|
||||
extern void ppc_stswi(uint32_t opcode);
|
||||
extern void ppc_stswx(uint32_t opcode);
|
||||
|
||||
extern void ppc_mfsr();
|
||||
extern void ppc_mfsrin();
|
||||
extern void ppc_mtsr();
|
||||
extern void ppc_mtsrin();
|
||||
extern void ppc_mfsr(uint32_t opcode);
|
||||
extern void ppc_mfsrin(uint32_t opcode);
|
||||
extern void ppc_mtsr(uint32_t opcode);
|
||||
extern void ppc_mtsrin(uint32_t opcode);
|
||||
|
||||
extern void ppc_mcrf();
|
||||
extern void ppc_mtcrf();
|
||||
extern void ppc_mfmsr();
|
||||
extern void ppc_mfspr();
|
||||
extern void ppc_mtmsr();
|
||||
extern void ppc_mtspr();
|
||||
extern void ppc_mcrf(uint32_t opcode);
|
||||
extern void ppc_mtcrf(uint32_t opcode);
|
||||
extern void ppc_mfmsr(uint32_t opcode);
|
||||
extern void ppc_mfspr(uint32_t opcode);
|
||||
extern void ppc_mtmsr(uint32_t opcode);
|
||||
extern void ppc_mtspr(uint32_t opcode);
|
||||
|
||||
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_rc rec> extern void ppc_mtfsb0(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mtfsb1(uint32_t opcode);
|
||||
extern void ppc_mcrfs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmr(uint32_t opcode);
|
||||
template <field_601 for601, field_rc rec> extern void ppc_mffs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mtfsf(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mtfsfi(uint32_t opcode);
|
||||
|
||||
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();
|
||||
template <field_shift shift> extern void ppc_addi(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_addic(uint32_t opcode);
|
||||
template <field_shift shift> extern void ppc_andirc(uint32_t opcode);
|
||||
template <field_lk l, field_aa a> extern void ppc_b(uint32_t opcode);
|
||||
template <field_lk l, field_aa a> extern void ppc_bc(uint32_t opcode);
|
||||
extern void ppc_cmpi(uint32_t opcode);
|
||||
extern void ppc_cmpli(uint32_t opcode);
|
||||
template <class T> extern void ppc_lz(uint32_t opcode);
|
||||
template <class T> extern void ppc_lzu(uint32_t opcode);
|
||||
extern void ppc_lha(uint32_t opcode);
|
||||
extern void ppc_lhau(uint32_t opcode);
|
||||
extern void ppc_lmw(uint32_t opcode);
|
||||
extern void ppc_mulli(uint32_t opcode);
|
||||
template <field_shift shift> extern void ppc_ori(uint32_t opcode);
|
||||
extern void ppc_rfi(uint32_t opcode);
|
||||
extern void ppc_rlwimi(uint32_t opcode);
|
||||
extern void ppc_rlwinm(uint32_t opcode);
|
||||
extern void ppc_rlwnm(uint32_t opcode);
|
||||
extern void ppc_sc(uint32_t opcode);
|
||||
template <class T> extern void ppc_st(uint32_t opcode);
|
||||
template <class T> extern void ppc_stu(uint32_t opcode);
|
||||
extern void ppc_stmw(uint32_t opcode);
|
||||
extern void ppc_subfic(uint32_t opcode);
|
||||
extern void ppc_twi(uint32_t opcode);
|
||||
template <field_shift shift> extern void ppc_xori(uint32_t opcode);
|
||||
|
||||
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();
|
||||
extern void ppc_lfs(uint32_t opcode);
|
||||
extern void ppc_lfsu(uint32_t opcode);
|
||||
extern void ppc_lfsx(uint32_t opcode);
|
||||
extern void ppc_lfsux(uint32_t opcode);
|
||||
extern void ppc_lfd(uint32_t opcode);
|
||||
extern void ppc_lfdu(uint32_t opcode);
|
||||
extern void ppc_lfdx(uint32_t opcode);
|
||||
extern void ppc_lfdux(uint32_t opcode);
|
||||
extern void ppc_stfs(uint32_t opcode);
|
||||
extern void ppc_stfsu(uint32_t opcode);
|
||||
extern void ppc_stfsx(uint32_t opcode);
|
||||
extern void ppc_stfsux(uint32_t opcode);
|
||||
extern void ppc_stfd(uint32_t opcode);
|
||||
extern void ppc_stfdu(uint32_t opcode);
|
||||
extern void ppc_stfdx(uint32_t opcode);
|
||||
extern void ppc_stfdux(uint32_t opcode);
|
||||
|
||||
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();
|
||||
template <field_rc rec> extern void ppc_fadd(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsub(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmul(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fdiv(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fadds(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsubs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmuls(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fdivs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmadd(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmsub(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmadd(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmsub(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmadds(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmsubs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmadds(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmsubs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fabs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnabs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fneg(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsel(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fres(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsqrts(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsqrt(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_frsqrte(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_frsp(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fctiw(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fctiwz(uint32_t opcode);
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
extern void ppc_fcmpo(uint32_t opcode);
|
||||
extern void ppc_fcmpu(uint32_t opcode);
|
||||
|
||||
// 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();
|
||||
template <field_rc rec, field_ov ov> extern void power_abs(uint32_t opcode);
|
||||
extern void power_clcs(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_div(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_divs(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_doz(uint32_t opcode);
|
||||
extern void power_dozi(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_lscbx(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_maskg(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_maskir(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_mul(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_nabs(uint32_t opcode);
|
||||
extern void power_rlmi(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_rrib(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sle(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sleq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sliq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_slliq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sllq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_slq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sraiq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sraq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sre(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srea(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sreq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sriq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srliq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srlq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srq(uint32_t opcode);
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
@ -637,7 +636,7 @@ template <field_rc rec> extern void power_srq();
|
||||
|
||||
extern uint64_t get_virt_time_ns(void);
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_main_opcode(uint32_t opcode);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
|
@ -196,17 +196,17 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception() {
|
||||
void ppc_floating_point_exception(uint32_t opcode) {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, ppc_cur_instruction);
|
||||
ppc_state.pc, opcode);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t ea)
|
||||
void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (ppc_cur_instruction & 0xfc000000) {
|
||||
switch (opcode & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
@ -228,11 +228,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 = ((opcode >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((opcode >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
break;
|
||||
case 0x7c000000:
|
||||
switch (ppc_cur_instruction & 0xfc0007ff) {
|
||||
switch (opcode & 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
|
||||
@ -266,12 +266,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 = ((opcode << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((opcode << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((opcode << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
break;
|
||||
case 0x7c0007ec:
|
||||
if ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
if ((opcode & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
@ -282,31 +282,31 @@ indirect_with_index:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
ppc_cur_instruction);
|
||||
opcode);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
|
||||
dsisr |= ((opcode >> 16) & 0x000003e0);
|
||||
|
||||
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
|
||||
if ((opcode & 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
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
else if ((opcode & 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
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
else if ((opcode & 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?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
|
||||
dsisr |= ((opcode >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
|
@ -65,7 +65,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
|
||||
@ -208,7 +207,7 @@ static PPCOpcode SubOpcode63Grabber[2048];
|
||||
|
||||
/** Exception helpers. */
|
||||
|
||||
void ppc_illegalop() {
|
||||
void ppc_illegalop(uint32_t opcode) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
@ -228,97 +227,97 @@ void ppc_release_int() {
|
||||
|
||||
/** Opcode decoding functions. */
|
||||
|
||||
static void ppc_opcode16() {
|
||||
SubOpcode16Grabber[ppc_cur_instruction & 3]();
|
||||
static void ppc_opcode16(uint32_t opcode) {
|
||||
SubOpcode16Grabber[opcode & 3](opcode);
|
||||
}
|
||||
|
||||
static void ppc_opcode18() {
|
||||
SubOpcode18Grabber[ppc_cur_instruction & 3]();
|
||||
static void ppc_opcode18(uint32_t opcode) {
|
||||
SubOpcode18Grabber[opcode & 3](opcode);
|
||||
}
|
||||
|
||||
template<field_601 for601>
|
||||
static void ppc_opcode19() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FF;
|
||||
static void ppc_opcode19(uint32_t opcode) {
|
||||
uint16_t subop_grab = opcode & 0x7FF;
|
||||
|
||||
switch (subop_grab) {
|
||||
case 0:
|
||||
ppc_mcrf();
|
||||
ppc_mcrf(opcode);
|
||||
break;
|
||||
case 32:
|
||||
ppc_bclr<LK0>();
|
||||
ppc_bclr<LK0>(opcode);
|
||||
break;
|
||||
case 33:
|
||||
ppc_bclr<LK1>();
|
||||
ppc_bclr<LK1>(opcode);
|
||||
break;
|
||||
case 66:
|
||||
ppc_crnor();
|
||||
ppc_crnor(opcode);
|
||||
break;
|
||||
case 100:
|
||||
ppc_rfi();
|
||||
ppc_rfi(opcode);
|
||||
break;
|
||||
case 258:
|
||||
ppc_crandc();
|
||||
ppc_crandc(opcode);
|
||||
break;
|
||||
case 300:
|
||||
ppc_isync();
|
||||
ppc_isync(opcode);
|
||||
break;
|
||||
case 386:
|
||||
ppc_crxor();
|
||||
ppc_crxor(opcode);
|
||||
break;
|
||||
case 450:
|
||||
ppc_crnand();
|
||||
ppc_crnand(opcode);
|
||||
break;
|
||||
case 514:
|
||||
ppc_crand();
|
||||
ppc_crand(opcode);
|
||||
break;
|
||||
case 578:
|
||||
ppc_creqv();
|
||||
ppc_creqv(opcode);
|
||||
break;
|
||||
case 834:
|
||||
ppc_crorc();
|
||||
ppc_crorc(opcode);
|
||||
break;
|
||||
case 898:
|
||||
ppc_cror();
|
||||
ppc_cror(opcode);
|
||||
break;
|
||||
case 1056:
|
||||
ppc_bcctr<LK0, for601>();
|
||||
ppc_bcctr<LK0, for601>(opcode);
|
||||
break;
|
||||
case 1057:
|
||||
ppc_bcctr<LK1, for601>();
|
||||
ppc_bcctr<LK1, for601>(opcode);
|
||||
break;
|
||||
default:
|
||||
ppc_illegalop();
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
template void ppc_opcode19<NOT601>();
|
||||
template void ppc_opcode19<IS601>();
|
||||
template void ppc_opcode19<NOT601>(uint32_t opcode);
|
||||
template void ppc_opcode19<IS601>(uint32_t opcode);
|
||||
|
||||
static void ppc_opcode31() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FFUL;
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
static void ppc_opcode31(uint32_t opcode) {
|
||||
uint16_t subop_grab = opcode & 0x7FFUL;
|
||||
SubOpcode31Grabber[subop_grab](opcode);
|
||||
}
|
||||
|
||||
static void ppc_opcode59() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x3FUL;
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
static void ppc_opcode59(uint32_t opcode) {
|
||||
uint16_t subop_grab = opcode & 0x3FUL;
|
||||
SubOpcode59Grabber[subop_grab](opcode);
|
||||
}
|
||||
|
||||
static void ppc_opcode63() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FFUL;
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
static void ppc_opcode63(uint32_t opcode) {
|
||||
uint16_t subop_grab = opcode & 0x7FFUL;
|
||||
SubOpcode63Grabber[subop_grab](opcode);
|
||||
}
|
||||
|
||||
/* Dispatch using main opcode */
|
||||
void ppc_main_opcode()
|
||||
void ppc_main_opcode(uint32_t opcode)
|
||||
{
|
||||
#ifdef CPU_PROFILING
|
||||
num_executed_instrs++;
|
||||
#if defined(CPU_PROFILING_OPS)
|
||||
num_opcodes[ppc_cur_instruction]++;
|
||||
num_opcodes[opcode]++;
|
||||
#endif
|
||||
#endif
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
OpcodeGrabber[(opcode >> 26) & 0x3F](opcode);
|
||||
}
|
||||
|
||||
static long long cpu_now_ns() {
|
||||
@ -363,6 +362,7 @@ static void ppc_exec_inner()
|
||||
{
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint32_t opcode;
|
||||
uint8_t* pc_real;
|
||||
|
||||
max_cycles = 0;
|
||||
@ -376,10 +376,11 @@ static void ppc_exec_inner()
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
opcode = ppc_read_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && ppc_state.pc < eb_end) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@ -389,18 +390,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);
|
||||
opcode = ppc_read_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);
|
||||
opcode = ppc_read_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);
|
||||
opcode = ppc_read_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,8 +433,9 @@ void ppc_exec_single()
|
||||
return;
|
||||
}
|
||||
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
|
||||
uint32_t opcode = ppc_read_instruction(pc_real);
|
||||
ppc_main_opcode(opcode);
|
||||
g_icycles++;
|
||||
process_events();
|
||||