Reapply "Improve accuracy of prefetch aborts"

This reverts commit 0dc619d615.
This commit is contained in:
Jaklyy 2024-08-05 12:37:42 -04:00
parent 0dc619d615
commit eedd2806f9
2 changed files with 32 additions and 35 deletions

View File

@ -343,12 +343,6 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr)
CPSR &= ~0x20; CPSR &= ~0x20;
} }
if (!(PU_Map[addr>>12] & 0x04))
{
PrefetchAbort();
return;
}
NDS.MonitorARM9Jump(addr); NDS.MonitorARM9Jump(addr);
} }
@ -575,15 +569,6 @@ void ARMv5::PrefetchAbort()
CPSR |= 0x97; CPSR |= 0x97;
UpdateMode(oldcpsr, CPSR); UpdateMode(oldcpsr, CPSR);
// this shouldn't happen, but if it does, we're stuck in some nasty endless loop
// so better take care of it
if (!(PU_Map[ExceptionBase>>12] & 0x04))
{
Log(LogLevel::Error, "!!!!! EXCEPTION REGION NOT EXECUTABLE. THIS IS VERY BAD!!\n");
NDS.Stop(Platform::StopReason::BadExceptionRegion);
return;
}
R_ABT[2] = oldcpsr; R_ABT[2] = oldcpsr;
R[14] = R[15] + (oldcpsr & 0x20 ? 2 : 0); R[14] = R[15] + (oldcpsr & 0x20 ? 2 : 0);
JumpTo(ExceptionBase + 0x0C); JumpTo(ExceptionBase + 0x0C);
@ -686,10 +671,18 @@ void ARMv5::Execute()
if (R[15] & 0x2) { NextInstr[1] >>= 16; CodeCycles = 0; } if (R[15] & 0x2) { NextInstr[1] >>= 16; CodeCycles = 0; }
else NextInstr[1] = CodeRead32(R[15], false); else NextInstr[1] = CodeRead32(R[15], false);
// handle aborted instructions
if (!(PU_Map[(R[15]-4)>>12] & 0x04)) [[unlikely]]
{
PrefetchAbort();
}
// actually execute // actually execute
else [[likely]]
{
u32 icode = (CurInstr >> 6) & 0x3FF; u32 icode = (CurInstr >> 6) & 0x3FF;
ARMInterpreter::THUMBInstrTable[icode](this); ARMInterpreter::THUMBInstrTable[icode](this);
} }
}
else else
{ {
if constexpr (mode == CPUExecuteMode::InterpreterGDB) if constexpr (mode == CPUExecuteMode::InterpreterGDB)
@ -701,8 +694,13 @@ void ARMv5::Execute()
NextInstr[0] = NextInstr[1]; NextInstr[0] = NextInstr[1];
NextInstr[1] = CodeRead32(R[15], false); NextInstr[1] = CodeRead32(R[15], false);
// handle aborted instructions
if (!(PU_Map[(R[15]-8)>>12] & 0x04)) [[unlikely]] // todo: check for bkpt instruction?
{
PrefetchAbort();
}
// actually execute // actually execute
if (CheckCondition(CurInstr >> 28)) else if (CheckCondition(CurInstr >> 28)) [[likely]]
{ {
u32 icode = ((CurInstr >> 4) & 0xF) | ((CurInstr >> 16) & 0xFF0); u32 icode = ((CurInstr >> 4) & 0xF) | ((CurInstr >> 16) & 0xFF0);
ARMInterpreter::ARMInstrTable[icode](this); ARMInterpreter::ARMInstrTable[icode](this);

View File

@ -773,14 +773,13 @@ u32 ARMv5::CP15Read(u32 id) const
u32 ARMv5::CodeRead32(u32 addr, bool branch) u32 ARMv5::CodeRead32(u32 addr, bool branch)
{ {
/*if (branch || (!(addr & 0xFFF))) // prefetch abort
// the actual exception is not raised until the aborted instruction is executed
if (!(PU_Map[addr>>12] & 0x04)) [[unlikely]]
{ {
if (!(PU_Map[addr>>12] & 0x04)) CodeCycles = 1;
{
PrefetchAbort();
return 0; return 0;
} }
}*/
if (addr < ITCMSize) if (addr < ITCMSize)
{ {
@ -807,7 +806,7 @@ u32 ARMv5::CodeRead32(u32 addr, bool branch)
bool ARMv5::DataRead8(u32 addr, u32* val) bool ARMv5::DataRead8(u32 addr, u32* val)
{ {
if (!(PU_Map[addr>>12] & 0x01)) if (!(PU_Map[addr>>12] & 0x01)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -833,7 +832,7 @@ bool ARMv5::DataRead8(u32 addr, u32* val)
bool ARMv5::DataRead16(u32 addr, u32* val) bool ARMv5::DataRead16(u32 addr, u32* val)
{ {
if (!(PU_Map[addr>>12] & 0x01)) if (!(PU_Map[addr>>12] & 0x01)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -861,7 +860,7 @@ bool ARMv5::DataRead16(u32 addr, u32* val)
bool ARMv5::DataRead32(u32 addr, u32* val) bool ARMv5::DataRead32(u32 addr, u32* val)
{ {
if (!(PU_Map[addr>>12] & 0x01)) if (!(PU_Map[addr>>12] & 0x01)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -889,7 +888,7 @@ bool ARMv5::DataRead32(u32 addr, u32* val)
bool ARMv5::DataRead32S(u32 addr, u32* val) bool ARMv5::DataRead32S(u32 addr, u32* val)
{ {
if (!(PU_Map[addr>>12] & 0x01)) if (!(PU_Map[addr>>12] & 0x01)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -917,7 +916,7 @@ bool ARMv5::DataRead32S(u32 addr, u32* val)
bool ARMv5::DataWrite8(u32 addr, u8 val) bool ARMv5::DataWrite8(u32 addr, u8 val)
{ {
if (!(PU_Map[addr>>12] & 0x02)) if (!(PU_Map[addr>>12] & 0x02)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -944,7 +943,7 @@ bool ARMv5::DataWrite8(u32 addr, u8 val)
bool ARMv5::DataWrite16(u32 addr, u16 val) bool ARMv5::DataWrite16(u32 addr, u16 val)
{ {
if (!(PU_Map[addr>>12] & 0x02)) if (!(PU_Map[addr>>12] & 0x02)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -973,7 +972,7 @@ bool ARMv5::DataWrite16(u32 addr, u16 val)
bool ARMv5::DataWrite32(u32 addr, u32 val) bool ARMv5::DataWrite32(u32 addr, u32 val)
{ {
if (!(PU_Map[addr>>12] & 0x02)) if (!(PU_Map[addr>>12] & 0x02)) [[unlikely]]
{ {
DataAbort(); DataAbort();
return false; return false;
@ -1002,7 +1001,7 @@ bool ARMv5::DataWrite32(u32 addr, u32 val)
bool ARMv5::DataWrite32S(u32 addr, u32 val, bool dataabort) bool ARMv5::DataWrite32S(u32 addr, u32 val, bool dataabort)
{ {
if (!(PU_Map[addr>>12] & 0x02)) if (!(PU_Map[addr>>12] & 0x02)) [[unlikely]]
{ {
if (!dataabort) DataAbort(); if (!dataabort) DataAbort();
return false; return false;