cpu: added hardware breakpoints on execution

This commit is contained in:
Jakub Czekański 2019-09-03 20:53:27 +02:00
parent bb02ebff8f
commit 2b82089a20
5 changed files with 24 additions and 5 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto

View file

@ -32,6 +32,8 @@ struct COP0 {
uint32_t superMasterEnable2 : 1; // bits 24..29
};
inline bool codeBreakpointEnabled() { return masterEnableBreakpoints && superMasterEnable1 && superMasterEnable2 && breakOnCode; }
uint32_t _reg;
DCIC() : _reg(0) {}
};

View file

@ -54,7 +54,17 @@ void CPU::saveStateForException() {
branchTaken = false;
}
bool CPU::handleBreakpoints() {
void CPU::handleHardwareBreakpoints() {
if (cop0.dcic.codeBreakpointEnabled()) {
if (((PC ^ cop0.bpcm) & cop0.bpc) == 0) {
cop0.dcic.codeBreakpointHit = 1;
cop0.dcic.breakpointHit = 1;
instructions::exception(this, COP0::CAUSE::Exception::breakpoint);
}
}
}
bool CPU::handleSoftwareBreakpoints() {
if (!breakpoints.empty()) {
auto bp = breakpoints.find(PC);
if (bp != breakpoints.end() && bp->second.enabled) {
@ -83,10 +93,10 @@ bool CPU::executeInstructions(int count) {
if (maskedPc == 0xa0 || maskedPc == 0xb0 || maskedPc == 0xc0) sys->handleBiosFunction();
saveStateForException();
checkForInterrupts();
handleHardwareBreakpoints();
if (handleBreakpoints()) return false;
if (handleSoftwareBreakpoints()) return false;
_opcode = Opcode(sys->readMemory32(PC));
const auto& op = instructions::OpcodeTable[_opcode.op];

View file

@ -96,7 +96,8 @@ struct CPU {
}
void saveStateForException();
bool handleBreakpoints();
void handleHardwareBreakpoints();
bool handleSoftwareBreakpoints();
bool executeInstructions(int count);
struct Breakpoint {

View file

@ -201,7 +201,12 @@ void exception(CPU *cpu, COP0::CAUSE::Exception cause) {
cpu->cop0.tar = cpu->PC;
}
cpu->setPC(cpu->cop0.status.getHandlerAddress());
uint32_t handlerAddress = cpu->cop0.status.getHandlerAddress();
if (cause == Exception::breakpoint) {
handlerAddress -= 0x40;
}
cpu->setPC(handlerAddress);
}
void dummy(CPU *cpu, Opcode i) {