Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MPU regions instead of hardcoded RAM information to better distinguish data and prefetch aborts #225

Open
Jaklyy opened this issue Nov 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Jaklyy
Copy link

Jaklyy commented Nov 8, 2024

currently when a data/prefetch abort occurs the "defaultExceptionHandler" will assume a data abort occurred and try to read and decode an instruction only if the pc was within normal main ram or itcm bounds.
It would make the exception handler smarter and more flexible to instead check for a prefetch abort first by manually calculating the region bounds from the mpu region sizing regs and checking against the region's code read perms to determine if the pc was within an executable region, and then try to decode the instruction if so. (though you might also want to ensure it's a readable region as well? though maybe that's overengineering a debug tool)

Some example sorta pseudo-code:

bool prefetchabort = true;
for (int i = 7; i >= 0; i--) // higher number regions have higher priority
{
if (!(MPURegionSize[i] & 1)) continue; // check if region is enabled
int size = 1 << std::max(12, ((MPURegionSize[i] & 0x3E) >> 1) + 1); // get the size of the region, minimum size is 12.

u32 startaddr = MPURegionSize[i] & ~(size-1); // start address is size aligned
u32 endaddr = startaddr + size-1;
if ((PC > startaddr) && (PC < endaddr))
{
prefetchabort = !RegionCodeRead[i]; // ngl idk what the proper way to check for region access perms is? you'd probably have to use a switch statement to look it up? and it'd also be different if the exception occurred in user mode (idk why you'd want to be in user mode tho)
break;
}
}

@asiekierka
Copy link
Contributor

Does the NTR BIOS not have any other way of distinguishing between a data and prefetch abort? That's honestly a little disappointing.

@asiekierka asiekierka changed the title Prefetch Aborts and the default exception handler Use MPU regions instead of hardcoded RAM information to better distinguish data and prefetch aborts Nov 8, 2024
@asiekierka asiekierka added the enhancement New feature or request label Nov 8, 2024
@Jaklyy
Copy link
Author

Jaklyy commented Nov 9, 2024

There are separate exception vector offsets for prefetch and data aborts, but annoyingly the (ds and dsi) arm9 bios makes no efforts to distinguish them by immediately redirecting them to the same handler, with no clarifying info preserved. So only with the low exception vector can you distinguish them.

@asiekierka
Copy link
Contributor

Yeah, I'm not 100% on throwing out the BIOS handler just yet; especially as we can't do that on ARM7. Let's stick to using MPU region information instead, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants