DragonMinded / libdragon

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

joybus: fix race condition in SI interrupt that causes a crash at start #537

Closed rasky closed 2 months ago

rasky commented 2 months ago

entrypoint.S writes 0x8 to PIF-RAM to complete the PIF boot process (and avoid the PIF freezing the console after ~5 seconds). Like all writes to PIF-RAM, it takes a while to get through and when it's done, an interrupt is generated. If the interrupt triggers after the __joybus_init() constructor is run, the interrupt handler would get confused and assert it.

This commit fixes it by waiting for any pending SI transfers before enabling SI interrupts.

Notice that the same problem was fixed in preview by the new IPL3, which terminates the PIF boot correctly, including not leaving any pending interrupt when the application is booted.