hoglet67 / PiTubeDirect

Bare-metal Raspberry Pi project that attaches to the Acorn TUBE interface and emulates many BBC Micro Co Processors
GNU General Public License v3.0
188 stars 23 forks source link

Native ARM Co Pro: Implement X SWI Bit #210

Open hoglet67 opened 6 months ago

hoglet67 commented 6 months ago

See discussion here: https://stardot.org.uk/forums/viewtopic.php?p=424768#p424768

To correctly handle the X prefix, the SWI handler (in tube-swi.c) would need to install a temporary error handler. This would restore the original error handler, unwind the call and return to the caller with the V bit set. A non-error would also need to restore the original error handler and return with the V bit clear.

See #200 for how this was done in the RISC-V ECall Handler

hoglet67 commented 6 months ago

Started work on this, in the armnative_xbit branch

It's not currently working, because when generating an error the privilege level reduces to user mode . So the SWI handler ends up completing in user mode, and then hits a privileged instruction which causes an exception.

(Setjmp/Longjmp doesn't preserve the current privilege level)

There probably needs to be a way to specify that an error handler is run in supervisor mode.