Compare commits

...
5 changed files with 269 additions and 408 deletions

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 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/>.
*/
#ifndef PPC_DEFS_H
#define PPC_DEFS_H
#include <cinttypes>
#define GET_rD_rA_OFFS(opcode) \
uint32_t reg_d = ((opcode) >> 21) & 31; \
uint32_t reg_a = ((opcode) >> 16) & 31; \
int32_t offs = (int32_t)((int16_t)((opcode) & 0xFFFF));
#define GET_GPR(reg) ppc_state.gpr[(reg)]
#define SET_GPR(reg, val) ppc_state.gpr[(reg)] = (val)
#define GET_rD_iA_iB(opcode) \
uint32_t reg_d = ((opcode) >> 21) & 31; \
uint32_t imm_a = ppc_state.gpr[((opcode) >> 16) & 31]; \
uint32_t imm_b = ppc_state.gpr[((opcode) >> 11) & 31];
#define GET_rD_rA_iA_iB(opcode) \
uint32_t reg_d = ((opcode) >> 21) & 31; \
uint32_t reg_a = ((opcode) >> 16) & 31; \
uint32_t imm_a = ppc_state.gpr[reg_a]; \
uint32_t imm_b = ppc_state.gpr[((opcode) >> 11) & 31];
#define GET_rA_iS(opcode) \
uint32_t reg_a = ((opcode) >> 16) & 31; \
uint32_t imm_d = ppc_state.gpr[((opcode) >> 21) & 31];
#define GET_rS_rA_OFFS(opcode) \
uint32_t reg_s = ((opcode) >> 21) & 31; \
uint32_t reg_a = ((opcode) >> 16) & 31; \
int32_t offs = (int32_t)((int16_t)((opcode) & 0xFFFF));
#define GET_rS_rA_iA_iB(opcode) \
uint32_t reg_s = ((opcode) >> 21) & 31; \
uint32_t reg_a = ((opcode) >> 16) & 31; \
uint32_t imm_a = ppc_state.gpr[reg_a]; \
uint32_t imm_b = ppc_state.gpr[((opcode) >> 11) & 31];
#endif // PPC_DEFS_H
+8 -12
View File
@@ -505,14 +505,16 @@ extern void ppc_bcl();
extern void ppc_bcla(); extern void ppc_bcla();
extern void ppc_cmpi(); extern void ppc_cmpi();
extern void ppc_cmpli(); extern void ppc_cmpli();
extern void ppc_lbz();
extern void ppc_lbzu();
extern void ppc_lha(); extern void ppc_lha();
extern void ppc_lhau(); extern void ppc_lhau();
extern void ppc_lhz(); template <class T> void ppc_lz(void);
extern void ppc_lhzu(); template <class T> void ppc_lzu(void);
extern void ppc_lwz(); template <class T> void ppc_lzux(void);
extern void ppc_lwzu(); template <class T> void ppc_lzx(void);
template <class T> void ppc_st(void);
template <class T> void ppc_stu(void);
template <class T> void ppc_stux(void);
template <class T> void ppc_stx(void);
extern void ppc_lmw(); extern void ppc_lmw();
extern void ppc_mulli(); extern void ppc_mulli();
extern void ppc_ori(); extern void ppc_ori();
@@ -522,12 +524,6 @@ extern void ppc_rlwimi();
extern void ppc_rlwinm(); extern void ppc_rlwinm();
extern void ppc_rlwnm(); extern void ppc_rlwnm();
extern void ppc_sc(); extern void ppc_sc();
extern void ppc_stb();
extern void ppc_stbu();
extern void ppc_sth();
extern void ppc_sthu();
extern void ppc_stw();
extern void ppc_stwu();
extern void ppc_stmw(); extern void ppc_stmw();
extern void ppc_subfic(); extern void ppc_subfic();
extern void ppc_twi(); extern void ppc_twi();
+15 -15
View File
@@ -136,9 +136,9 @@ static PPCOpcode OpcodeGrabber[] = {
ppc_addic, ppc_addicdot, ppc_addi, ppc_addis, ppc_opcode16, ppc_sc, ppc_addic, ppc_addicdot, ppc_addi, ppc_addis, ppc_opcode16, ppc_sc,
ppc_opcode18, ppc_opcode19, ppc_rlwimi, ppc_rlwinm, power_rlmi, ppc_rlwnm, ppc_opcode18, ppc_opcode19, ppc_rlwimi, ppc_rlwinm, power_rlmi, ppc_rlwnm,
ppc_ori, ppc_oris, ppc_xori, ppc_xoris, ppc_andidot, ppc_andisdot, ppc_ori, ppc_oris, ppc_xori, ppc_xoris, ppc_andidot, ppc_andisdot,
ppc_illegalop, ppc_opcode31, ppc_lwz, ppc_lwzu, ppc_lbz, ppc_lbzu, ppc_illegalop, ppc_opcode31, ppc_lz<uint32_t>, ppc_lzu<uint32_t>, ppc_lz<uint8_t>, ppc_lzu<uint8_t>,
ppc_stw, ppc_stwu, ppc_stb, ppc_stbu, ppc_lhz, ppc_lhzu, ppc_st<uint32_t>, ppc_stu<uint32_t>, ppc_st<uint8_t>, ppc_stu<uint8_t>, ppc_lz<uint16_t>, ppc_lzu<uint16_t>,
ppc_lha, ppc_lhau, ppc_sth, ppc_sthu, ppc_lmw, ppc_stmw, ppc_lha, ppc_lhau, ppc_st<uint16_t>, ppc_stu<uint16_t>, ppc_lmw, ppc_stmw,
ppc_lfs, ppc_lfsu, ppc_lfd, ppc_lfdu, ppc_stfs, ppc_stfsu, ppc_lfs, ppc_lfsu, ppc_lfd, ppc_lfdu, ppc_stfs, ppc_stfsu,
ppc_stfd, ppc_stfdu, ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode59, ppc_stfd, ppc_stfdu, ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode59,
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode63}; ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode63};
@@ -818,12 +818,12 @@ void initialize_ppc_opcode_tables() {
SubOpcode31Grabber[491] = SubOpcode31Grabber[1003] = ppc_divw; SubOpcode31Grabber[491] = SubOpcode31Grabber[1003] = ppc_divw;
SubOpcode31Grabber[20] = ppc_lwarx; SubOpcode31Grabber[20] = ppc_lwarx;
SubOpcode31Grabber[23] = ppc_lwzx; SubOpcode31Grabber[23] = ppc_lzx<uint32_t>;
SubOpcode31Grabber[55] = ppc_lwzux; SubOpcode31Grabber[55] = ppc_lzux<uint32_t>;
SubOpcode31Grabber[87] = ppc_lbzx; SubOpcode31Grabber[87] = ppc_lzx<uint8_t>;
SubOpcode31Grabber[119] = ppc_lbzux; SubOpcode31Grabber[119] = ppc_lzux<uint8_t>;
SubOpcode31Grabber[279] = ppc_lhzx; SubOpcode31Grabber[279] = ppc_lzx<uint16_t>;
SubOpcode31Grabber[311] = ppc_lhzux; SubOpcode31Grabber[311] = ppc_lzux<uint16_t>;
SubOpcode31Grabber[343] = ppc_lhax; SubOpcode31Grabber[343] = ppc_lhax;
SubOpcode31Grabber[375] = ppc_lhaux; SubOpcode31Grabber[375] = ppc_lhaux;
SubOpcode31Grabber[533] = ppc_lswx; SubOpcode31Grabber[533] = ppc_lswx;
@@ -836,12 +836,12 @@ void initialize_ppc_opcode_tables() {
SubOpcode31Grabber[790] = ppc_lhbrx; SubOpcode31Grabber[790] = ppc_lhbrx;
SubOpcode31Grabber[150] = ppc_stwcx; SubOpcode31Grabber[150] = ppc_stwcx;
SubOpcode31Grabber[151] = ppc_stwx; SubOpcode31Grabber[151] = ppc_stx<uint32_t>;
SubOpcode31Grabber[183] = ppc_stwux; SubOpcode31Grabber[183] = ppc_stux<uint32_t>;
SubOpcode31Grabber[215] = ppc_stbx; SubOpcode31Grabber[215] = ppc_stx<uint8_t>;
SubOpcode31Grabber[247] = ppc_stbux; SubOpcode31Grabber[247] = ppc_stux<uint8_t>;
SubOpcode31Grabber[407] = ppc_sthx; SubOpcode31Grabber[407] = ppc_stx<uint16_t>;
SubOpcode31Grabber[439] = ppc_sthux; SubOpcode31Grabber[439] = ppc_stux<uint16_t>;
SubOpcode31Grabber[661] = ppc_stswx; SubOpcode31Grabber[661] = ppc_stswx;
SubOpcode31Grabber[662] = ppc_stwbrx; SubOpcode31Grabber[662] = ppc_stwbrx;
SubOpcode31Grabber[663] = ppc_stfsx; SubOpcode31Grabber[663] = ppc_stfsx;
+180 -381
View File
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// General opcodes for the processor - ppcopcodes.cpp // General opcodes for the processor - ppcopcodes.cpp
#include "ppcdefs.h"
#include "ppcemu.h" #include "ppcemu.h"
#include "ppcmmu.h" #include "ppcmmu.h"
#include <array> #include <array>
@@ -240,16 +241,25 @@ void dppc_interpreter::ppc_addis() {
} }
void dppc_interpreter::ppc_add() { void dppc_interpreter::ppc_add() {
/*
ppc_grab_regsdab(); ppc_grab_regsdab();
ppc_result_d = ppc_result_a + ppc_result_b; ppc_result_d = ppc_result_a + ppc_result_b;
if (oe_flag) if (oe_flag)
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d); ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
if (rc_flag) if (rc_flag)
ppc_changecrf0(ppc_result_d); ppc_changecrf0(ppc_result_d);
ppc_store_result_regd(); ppc_store_result_regd();*/
GET_rD_iA_iB(ppc_cur_instruction);
uint32_t result = imm_a + imm_b;
if (oe_flag)
ppc_setsoov(imm_a, ~imm_b, result);
if (rc_flag)
ppc_changecrf0(result);
SET_GPR(reg_d, result);
} }
void dppc_interpreter::ppc_addc() { void dppc_interpreter::ppc_addc() {
/*
ppc_grab_regsdab(); ppc_grab_regsdab();
ppc_result_d = ppc_result_a + ppc_result_b; ppc_result_d = ppc_result_a + ppc_result_b;
ppc_carry(ppc_result_a, ppc_result_d); ppc_carry(ppc_result_a, ppc_result_d);
@@ -259,7 +269,15 @@ void dppc_interpreter::ppc_addc() {
if (rc_flag) if (rc_flag)
ppc_changecrf0(ppc_result_d); ppc_changecrf0(ppc_result_d);
ppc_store_result_regd(); ppc_store_result_regd();*/
GET_rD_iA_iB(ppc_cur_instruction);
uint32_t result = imm_a + imm_b;
ppc_carry(imm_a, result);
if (oe_flag)
ppc_setsoov(imm_a, ~imm_b, result);
if (rc_flag)
ppc_changecrf0(result);
SET_GPR(reg_d, result);
} }
void dppc_interpreter::ppc_adde() { void dppc_interpreter::ppc_adde() {
@@ -746,6 +764,7 @@ void dppc_interpreter::ppc_rlwimi() {
} }
void dppc_interpreter::ppc_rlwinm() { void dppc_interpreter::ppc_rlwinm() {
/*
ppc_grab_regssa(); ppc_grab_regssa();
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31; unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31; unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
@@ -756,7 +775,19 @@ void dppc_interpreter::ppc_rlwinm() {
if ((ppc_cur_instruction & 0x01) == 1) { if ((ppc_cur_instruction & 0x01) == 1) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
} }
ppc_store_result_rega(); ppc_store_result_rega();*/
uint32_t opcode = ppc_cur_instruction;
GET_rA_iS(opcode);
unsigned rot_sh = (opcode >> 11) & 31;
unsigned rot_mb = (opcode >> 6) & 31;
unsigned rot_me = (opcode >> 1) & 31;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t r = ((imm_d << rot_sh) | (imm_d >> (32 - rot_sh)));
r &= mask;
SET_GPR(reg_a, r);
if (ppc_cur_instruction & 1) {
ppc_changecrf0(r);
}
} }
void dppc_interpreter::ppc_rlwnm() { void dppc_interpreter::ppc_rlwnm() {
@@ -1415,203 +1446,112 @@ void dppc_interpreter::ppc_dcbz() {
// Integer Load and Store Functions // Integer Load and Store Functions
void dppc_interpreter::ppc_stb() { template <class T>
void dppc_interpreter::ppc_st() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_stores++; num_int_stores++;
#endif #endif
ppc_grab_regssa(); GET_rS_rA_OFFS(ppc_cur_instruction);
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF)); uint32_t ea = offs + (reg_a ? GET_GPR(reg_a) : 0);
ppc_effective_address += reg_a ? ppc_result_a : 0; mmu_write_vmem<T>(ea, GET_GPR(reg_s));
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
//mem_write_byte(ppc_effective_address, ppc_result_d);
} }
void dppc_interpreter::ppc_stbx() { // explicitely instantiate all required ppc_st variants
#ifdef CPU_PROFILING template void dppc_interpreter::ppc_st<uint8_t>(void); // stb
num_int_stores++; template void dppc_interpreter::ppc_st<uint16_t>(void); // sth
#endif template void dppc_interpreter::ppc_st<uint32_t>(void); // stw
ppc_grab_regssab();
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
//mem_write_byte(ppc_effective_address, ppc_result_d);
}
void dppc_interpreter::ppc_stbu() { template <class T>
void dppc_interpreter::ppc_stu() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_stores++; num_int_stores++;
#endif #endif
ppc_grab_regssa(); GET_rS_rA_OFFS(ppc_cur_instruction);
if (reg_a != 0) { if (!reg_a) {
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += ppc_result_a;
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
//mem_write_byte(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
} }
uint32_t ea = offs + GET_GPR(reg_a);
mmu_write_vmem<T>(ea, GET_GPR(reg_s));
SET_GPR(reg_a, ea);
} }
void dppc_interpreter::ppc_stbux() { // explicitely instantiate all required ppc_stu variants
template void dppc_interpreter::ppc_stu<uint8_t>(void); // stbu
template void dppc_interpreter::ppc_stu<uint16_t>(void); // sthu
template void dppc_interpreter::ppc_stu<uint32_t>(void); // stwu
template <class T>
void dppc_interpreter::ppc_stx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_stores++; num_int_stores++;
#endif #endif
ppc_grab_regssab(); GET_rS_rA_iA_iB(ppc_cur_instruction);
if (reg_a != 0) { uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
ppc_effective_address = ppc_result_a + ppc_result_b; mmu_write_vmem<T>(ea, GET_GPR(reg_s));
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d); }
//mem_write_byte(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address; // explicitely instantiate all required ppc_stx variants
} else { template void dppc_interpreter::ppc_stx<uint8_t>(void); // stbx
template void dppc_interpreter::ppc_stx<uint16_t>(void); // sthx
template void dppc_interpreter::ppc_stx<uint32_t>(void); // stwx
template <class T>
void dppc_interpreter::ppc_stux() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
GET_rS_rA_iA_iB(ppc_cur_instruction);
if (!reg_a) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
} }
uint32_t ea = imm_a + imm_b;
mmu_write_vmem<T>(ea, GET_GPR(reg_s));
SET_GPR(reg_a, ea);
} }
void dppc_interpreter::ppc_sth() { // explicitely instantiate all required ppc_stux variants
#ifdef CPU_PROFILING template void dppc_interpreter::ppc_stux<uint8_t>(void); // stbux
num_int_stores++; template void dppc_interpreter::ppc_stux<uint16_t>(void); // sthux
#endif template void dppc_interpreter::ppc_stux<uint32_t>(void); // stwux
ppc_grab_regssa();
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
//mem_write_word(ppc_effective_address, ppc_result_d);
}
void dppc_interpreter::ppc_sthu() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssa();
if (reg_a != 0) {
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += ppc_result_a;
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
//mem_write_word(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_sthux() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssab();
if (reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
//mem_write_word(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_sthx() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssab();
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
//mem_write_word(ppc_effective_address, ppc_result_d);
}
void dppc_interpreter::ppc_sthbrx() { void dppc_interpreter::ppc_sthbrx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_stores++; num_int_stores++;
#endif #endif
ppc_grab_regssab(); GET_rS_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b); uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
ppc_result_d = (uint32_t)(BYTESWAP_16((uint16_t)ppc_result_d)); mmu_write_vmem<uint16_t>(ea, BYTESWAP_16((uint16_t)(GET_GPR(reg_s))));
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
//mem_write_word(ppc_effective_address, ppc_result_d);
}
void dppc_interpreter::ppc_stw() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssa();
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += reg_a ? ppc_result_a : 0;
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
}
void dppc_interpreter::ppc_stwx() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssab();
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
}
void dppc_interpreter::ppc_stwcx() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
// PLACEHOLDER CODE FOR STWCX - We need to check for reserve memory
if (rc_flag == 0) {
ppc_illegalop();
} else {
ppc_grab_regssab();
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
if (ppc_state.reserve) {
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x30000000 : 0x20000000;
ppc_state.reserve = false;
} else {
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x10000000 : 0;
}
}
}
void dppc_interpreter::ppc_stwu() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssa();
if (reg_a != 0) {
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += ppc_result_a;
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_stwux() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssab();
if (reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
} }
void dppc_interpreter::ppc_stwbrx() { void dppc_interpreter::ppc_stwbrx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_stores++; num_int_stores++;
#endif #endif
ppc_grab_regssab(); GET_rS_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b; uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
ppc_result_d = BYTESWAP_32(ppc_result_d); mmu_write_vmem<uint32_t>(ea, BYTESWAP_32(GET_GPR(reg_s)));
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d); }
//mem_write_dword(ppc_effective_address, ppc_result_d);
void dppc_interpreter::ppc_stwcx() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
if (rc_flag == 0) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
} else {
// TODO: We need to check for memory reservation
ppc_grab_regssab();
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
if (ppc_state.reserve) {
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x30000000 : 0x20000000;
ppc_state.reserve = false;
} else {
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x10000000 : 0;
}
}
} }
void dppc_interpreter::ppc_stmw() { void dppc_interpreter::ppc_stmw() {
@@ -1634,277 +1574,136 @@ void dppc_interpreter::ppc_stmw() {
} }
} }
void dppc_interpreter::ppc_lbz() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsda();
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
//ppc_result_d = mem_grab_byte(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
ppc_store_result_regd();
}
void dppc_interpreter::ppc_lbzu() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsda();
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
if ((reg_a != reg_d) || reg_a != 0) {
ppc_effective_address += ppc_result_a;
//ppc_result_d = mem_grab_byte(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
ppc_result_a = ppc_effective_address;
ppc_store_result_regd();
ppc_store_result_rega();
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_lbzx() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdab();
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
//ppc_result_d = mem_grab_byte(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
ppc_store_result_regd();
}
void dppc_interpreter::ppc_lbzux() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdab();
if ((reg_a != reg_d) || reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
//ppc_result_d = mem_grab_byte(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
ppc_result_a = ppc_effective_address;
ppc_store_result_regd();
ppc_store_result_rega();
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_lhz() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsda();
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += reg_a ? ppc_result_a : 0;
//ppc_result_d = mem_grab_word(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
ppc_store_result_regd();
}
void dppc_interpreter::ppc_lhzu() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsda();
if ((reg_a != reg_d) || reg_a != 0) {
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += ppc_result_a;
//ppc_result_d = mem_grab_word(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
ppc_result_a = ppc_effective_address;
ppc_store_result_regd();
ppc_store_result_rega();
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_lhzx() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdab();
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
//ppc_result_d = mem_grab_word(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
ppc_store_result_regd();
}
void dppc_interpreter::ppc_lhzux() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdab();
if ((reg_a != reg_d) || reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
//ppc_result_d = mem_grab_word(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
ppc_result_a = ppc_effective_address;
ppc_store_result_regd();
ppc_store_result_rega();
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_lha() { void dppc_interpreter::ppc_lha() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsda(); GET_rD_rA_OFFS(ppc_cur_instruction);
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF)); uint32_t ea = offs + ((reg_a) ? ppc_state.gpr[reg_a] : 0);
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0; SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
//uint16_t val = mem_grab_word(ppc_effective_address);
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
if (val & 0x8000) {
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
} else {
ppc_result_d = (uint32_t)val;
}
ppc_store_result_regd();
} }
void dppc_interpreter::ppc_lhau() { void dppc_interpreter::ppc_lhau() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsda(); GET_rD_rA_OFFS(ppc_cur_instruction);
if ((reg_a != reg_d) || reg_a != 0) { if ((reg_a == reg_d) || reg_a == 0) {
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += ppc_result_a;
//uint16_t val = mem_grab_word(ppc_effective_address);
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
if (val & 0x8000) {
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
} else {
ppc_result_d = (uint32_t)val;
}
ppc_store_result_regd();
ppc_result_a = ppc_effective_address;
ppc_store_result_rega();
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
} }
uint32_t ea = offs + ppc_state.gpr[reg_a];
SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
SET_GPR(reg_a, ea);
} }
void dppc_interpreter::ppc_lhaux() { void dppc_interpreter::ppc_lhaux() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsdab(); GET_rD_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b; if ((reg_a == reg_d) || reg_a == 0) {
//uint16_t val = mem_grab_word(ppc_effective_address); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
if (val & 0x8000) {
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
} else {
ppc_result_d = (uint32_t)val;
} }
ppc_store_result_regd(); uint32_t ea = imm_a + imm_b;
ppc_result_a = ppc_effective_address; SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
ppc_store_result_rega(); SET_GPR(reg_a, ea);
} }
void dppc_interpreter::ppc_lhax() { void dppc_interpreter::ppc_lhax() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsdab(); GET_rD_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b; uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
//uint16_t val = mem_grab_word(ppc_effective_address); SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
if (val & 0x8000) {
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
} else {
ppc_result_d = (uint32_t)val;
}
ppc_store_result_regd();
} }
void dppc_interpreter::ppc_lhbrx() { void dppc_interpreter::ppc_lhbrx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsdab(); GET_rD_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b; uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
//ppc_result_d = (uint32_t)(BYTESWAP_16(mem_grab_word(ppc_effective_address))); SET_GPR(reg_d, BYTESWAP_16(mmu_read_vmem<uint16_t>(ea)));
ppc_result_d = (uint32_t)(BYTESWAP_16(mmu_read_vmem<uint16_t>(ppc_effective_address)));
ppc_store_result_regd();
}
void dppc_interpreter::ppc_lwz() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsda();
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
//ppc_result_d = mem_grab_dword(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
ppc_store_result_regd();
} }
void dppc_interpreter::ppc_lwbrx() { void dppc_interpreter::ppc_lwbrx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsdab(); GET_rD_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b; uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
//ppc_result_d = BYTESWAP_32(mem_grab_dword(ppc_effective_address)); SET_GPR(reg_d, BYTESWAP_32(mmu_read_vmem<uint32_t>(ea)));
ppc_result_d = BYTESWAP_32(mmu_read_vmem<uint32_t>(ppc_effective_address));
ppc_store_result_regd();
} }
void dppc_interpreter::ppc_lwzu() { template <class T>
void dppc_interpreter::ppc_lz() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsda(); GET_rD_rA_OFFS(ppc_cur_instruction);
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF)); uint32_t ea = offs + ((reg_a) ? ppc_state.gpr[reg_a] : 0);
if ((reg_a != reg_d) || reg_a != 0) { SET_GPR(reg_d, mmu_read_vmem<T>(ea));
ppc_effective_address += ppc_result_a; }
//ppc_result_d = mem_grab_dword(ppc_effective_address);
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address); // explicitely instantiate all required ppc_lz variants
ppc_store_result_regd(); template void dppc_interpreter::ppc_lz<uint8_t>(void); // lbz
ppc_result_a = ppc_effective_address; template void dppc_interpreter::ppc_lz<uint16_t>(void); // lhz
ppc_store_result_rega(); template void dppc_interpreter::ppc_lz<uint32_t>(void); // lwz
} else {
template <class T>
void dppc_interpreter::ppc_lzu() {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
GET_rD_rA_OFFS(ppc_cur_instruction);
if ((reg_a == reg_d) || reg_a == 0) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
} }
uint32_t ea = offs + ppc_state.gpr[reg_a];
SET_GPR(reg_d, mmu_read_vmem<T>(ea));
SET_GPR(reg_a, ea);
} }
void dppc_interpreter::ppc_lwzx() { // explicitely instantiate all required ppc_lzu variants
template void dppc_interpreter::ppc_lzu<uint8_t>(void); // lbzu
template void dppc_interpreter::ppc_lzu<uint16_t>(void); // lhzu
template void dppc_interpreter::ppc_lzu<uint32_t>(void); // lwzu
template <class T>
void dppc_interpreter::ppc_lzx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsdab(); GET_rD_rA_iA_iB(ppc_cur_instruction);
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b; uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
//ppc_result_d = mem_grab_dword(ppc_effective_address); SET_GPR(reg_d, mmu_read_vmem<T>(ea));
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
ppc_store_result_regd();
} }
void dppc_interpreter::ppc_lwzux() { // explicitely instantiate all required ppc_lzx variants
template void dppc_interpreter::ppc_lzx<uint8_t>(void); // lbzx
template void dppc_interpreter::ppc_lzx<uint16_t>(void); // lhzx
template void dppc_interpreter::ppc_lzx<uint32_t>(void); // lwzx
template <class T>
void dppc_interpreter::ppc_lzux() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
#endif #endif
ppc_grab_regsdab(); GET_rD_rA_iA_iB(ppc_cur_instruction);
if ((reg_a != reg_d) || reg_a != 0) { if ((reg_a == reg_d) || reg_a == 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
} }
//ppc_result_d = mem_grab_dword(ppc_effective_address); uint32_t ea = imm_a + imm_b;
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address); SET_GPR(reg_d, mmu_read_vmem<T>(ea));
ppc_result_a = ppc_effective_address; SET_GPR(reg_a, ea);
ppc_store_result_regd();
ppc_store_result_rega();
} }
// explicitely instantiate all required ppc_lzux variants
template void dppc_interpreter::ppc_lzux<uint8_t>(void); // lbzux
template void dppc_interpreter::ppc_lzux<uint16_t>(void); // lhzux
template void dppc_interpreter::ppc_lzux<uint32_t>(void); // lwzux
void dppc_interpreter::ppc_lwarx() { void dppc_interpreter::ppc_lwarx() {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_int_loads++; num_int_loads++;
+5
View File
@@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <array> #include <array>
#include <chrono>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
@@ -499,7 +500,11 @@ void enter_debugger() {
exec_until_68k(addr); exec_until_68k(addr);
#endif #endif
} else { } else {
auto start_time = std::chrono::steady_clock::now();
ppc_exec_until(addr); ppc_exec_until(addr);
auto end_time = std::chrono::steady_clock::now();
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
LOG_F(INFO, "Time elapsed: %lld ns", time_elapsed.count());
} }
} catch (invalid_argument& exc) { } catch (invalid_argument& exc) {
cout << exc.what() << endl; cout << exc.what() << endl;