aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ARM.cpp13
-rw-r--r--src/CP15.cpp54
2 files changed, 51 insertions, 16 deletions
diff --git a/src/ARM.cpp b/src/ARM.cpp
index 9b114f2..ab13e7d 100644
--- a/src/ARM.cpp
+++ b/src/ARM.cpp
@@ -335,12 +335,11 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr)
CPSR &= ~0x20;
}
- /*if (!(PU_Map[addr>>12] & 0x04))
+ if (!(PU_Map[addr>>12] & 0x04))
{
- printf("jumped to %08X. very bad\n", addr);
PrefetchAbort();
return;
- }*/
+ }
NDS::MonitorARM9Jump(addr);
}
@@ -535,7 +534,7 @@ void ARM::TriggerIRQ()
void ARMv5::PrefetchAbort()
{
- printf("prefetch abort\n");
+ printf("ARM9: prefetch abort (%08X)\n", R[15]);
u32 oldcpsr = CPSR;
CPSR &= ~0xBF;
@@ -546,7 +545,7 @@ void ARMv5::PrefetchAbort()
// so better take care of it
if (!(PU_Map[ExceptionBase>>12] & 0x04))
{
- printf("!!!!! EXCEPTION REGION NOT READABLE. THIS IS VERY BAD!!\n");
+ printf("!!!!! EXCEPTION REGION NOT EXECUTABLE. THIS IS VERY BAD!!\n");
NDS::Stop();
return;
}
@@ -558,7 +557,7 @@ void ARMv5::PrefetchAbort()
void ARMv5::DataAbort()
{
- printf("data abort\n");
+ printf("ARM9: data abort (%08X)\n", R[15]);
u32 oldcpsr = CPSR;
CPSR &= ~0xBF;
@@ -566,7 +565,7 @@ void ARMv5::DataAbort()
UpdateMode(oldcpsr, CPSR);
R_ABT[2] = oldcpsr;
- R[14] = R[15] + (oldcpsr & 0x20 ? 6 : 4);
+ R[14] = R[15] + (oldcpsr & 0x20 ? 4 : 0);
JumpTo(ExceptionBase + 0x10);
}
diff --git a/src/CP15.cpp b/src/CP15.cpp
index c258478..69551de 100644
--- a/src/CP15.cpp
+++ b/src/CP15.cpp
@@ -136,12 +136,10 @@ void ARMv5::UpdateITCMSetting()
if (CP15Control & (1<<18))
{
ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F);
- //printf("ITCM [%08X] enabled at %08X, size %X\n", ITCMSetting, 0, ITCMSize);
}
else
{
ITCMSize = 0;
- //printf("ITCM disabled\n");
}
}
@@ -150,6 +148,9 @@ void ARMv5::UpdateITCMSetting()
// (not to the region range/enabled status)
void ARMv5::UpdatePURegion(u32 n)
{
+ if (!(CP15Control & (1<<0)))
+ return;
+
u32 coderw = (PU_CodeRW >> (4*n)) & 0xF;
u32 datarw = (PU_DataRW >> (4*n)) & 0xF;
@@ -274,6 +275,8 @@ void ARMv5::UpdatePURegions(bool update_all)
// TODO: this is way unoptimized
// should be okay unless the game keeps changing shit, tho
if (update_all) UpdateRegionTimings(0x00000, 0x100000);
+
+ // TODO: throw exception if the region we're running in has become non-executable, I guess
}
void ARMv5::UpdateRegionTimings(u32 addrstart, u32 addrend)
@@ -522,7 +525,7 @@ void ARMv5::CP15Write(u32 id, u32 val)
return;
case 0x502: // data permissions
- {printf("SET DATAPERM %08X (%08X %08X)\n", val,PU_DataRW,PU_DataRW ^ val);
+ {
u32 diff = PU_DataRW ^ val;
PU_DataRW = val;
for (u32 i = 0; i < 8; i++)
@@ -747,6 +750,15 @@ u32 ARMv5::CP15Read(u32 id)
u32 ARMv5::CodeRead32(u32 addr, bool branch)
{
+ /*if (branch || (!(addr & 0xFFF)))
+ {
+ if (!(PU_Map[addr>>12] & 0x04))
+ {
+ PrefetchAbort();
+ return 0;
+ }
+ }*/
+
if (addr < ITCMSize)
{
CodeCycles = 1;
@@ -772,6 +784,12 @@ u32 ARMv5::CodeRead32(u32 addr, bool branch)
void ARMv5::DataRead8(u32 addr, u32* val)
{
+ if (!(PU_Map[addr>>12] & 0x01))
+ {
+ DataAbort();
+ return;
+ }
+
DataRegion = addr;
if (addr < ITCMSize)
@@ -793,6 +811,12 @@ void ARMv5::DataRead8(u32 addr, u32* val)
void ARMv5::DataRead16(u32 addr, u32* val)
{
+ if (!(PU_Map[addr>>12] & 0x01))
+ {
+ DataAbort();
+ return;
+ }
+
DataRegion = addr;
addr &= ~1;
@@ -816,11 +840,11 @@ void ARMv5::DataRead16(u32 addr, u32* val)
void ARMv5::DataRead32(u32 addr, u32* val)
{
- /*if (!(PU_Map[addr>>12] & 0x01))
- {printf("addr %08X very bad\n", addr);
+ if (!(PU_Map[addr>>12] & 0x01))
+ {
DataAbort();
return;
- }*/
+ }
DataRegion = addr;
@@ -866,6 +890,12 @@ void ARMv5::DataRead32S(u32 addr, u32* val)
void ARMv5::DataWrite8(u32 addr, u8 val)
{
+ if (!(PU_Map[addr>>12] & 0x02))
+ {
+ DataAbort();
+ return;
+ }
+
DataRegion = addr;
if (addr < ITCMSize)
@@ -890,6 +920,12 @@ void ARMv5::DataWrite8(u32 addr, u8 val)
void ARMv5::DataWrite16(u32 addr, u16 val)
{
+ if (!(PU_Map[addr>>12] & 0x02))
+ {
+ DataAbort();
+ return;
+ }
+
DataRegion = addr;
addr &= ~1;
@@ -916,11 +952,11 @@ void ARMv5::DataWrite16(u32 addr, u16 val)
void ARMv5::DataWrite32(u32 addr, u32 val)
{
- /*if (!(PU_Map[addr>>12] & 0x02))
- {printf("addr %08X wr very bad\n", addr);
+ if (!(PU_Map[addr>>12] & 0x02))
+ {
DataAbort();
return;
- }*/
+ }
DataRegion = addr;