DragonMinded / libdragon

Open source library for N64 development.
https://libdragon.dev
The Unlicense
746 stars 108 forks source link

Restore execution mode to kernel in interrupt handler #598

Closed Dillonb closed 3 months ago

Dillonb commented 3 months ago

Consider when an exception is thrown from user mode: image

The exception handler will save all registers, then mask out EXL and IE, then write the masked value back to $Status. Because the code was running in user mode, this will dump us back to user mode in the middle of the exception handler in KSEG0, which will throw a TLB exception immediately. image

This PR is a simple change to mask out KSU as well. I validated that it works with my custom exception handler, and even puts me back into my original user mode code with KSU set properly.