diff --git a/src/CP15.cpp b/src/CP15.cpp index 58137fdd..5e5b35ea 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -186,10 +186,14 @@ void ARMv5::UpdatePURegion(u32 n) return; } - u32 start = rgn >> 12; - u32 sz = 2 << ((rgn >> 1) & 0x1F); - u32 end = start + (sz >> 12); - // TODO: check alignment of start + // notes: + // * min size of a pu region is 4KiB (12 bits) + // * size is calculated as size + 1, but the 12 lsb of address space are ignored, therefore we need it as size + 1 - 12, or size - 11 + // * pu regions are aligned based on their size + u32 size = std::max((int)((rgn>>1) & 0x1F) - 11, 0); // obtain the size, subtract 11 and clamp to a min of 0. + u32 start = ((rgn >> 12) >> size) << size; // determine the start offset, and use shifts to force alignment with a multiple of the size. + u32 end = start + (1<> 4) & 0xF, val, val & 1 ? "enabled" : "disabled", val & 0xFFFFF000, - (val & 0xFFFFF000) + (2 << ((val & 0x3E) >> 1)) + (val & 0x3E) >> 1 ); Log(LogLevel::Debug, "%s", log_output); // Some implementations of Log imply a newline, so we build up the line before printing it