rosco-m68k / rosco_m68k

Design, documentation and software for the Really Old School Computer (M68K)
https://rosco-m68k.com
Other
158 stars 35 forks source link

`start_serial` incorrectly handles `EFP_PROG_EXIT` vector #422

Closed roscopeco closed 7 months ago

roscopeco commented 7 months ago

Briefly:

The way the init code in start_serial uses the EFP_PROG_EXIT vector to handle program exit is flawed in two ways:

This is generally "fine" but breaks when user code does "weird things" like chaining to another user program (as is the case with sdfat_menu). In this case, the program variable is likely to be overwritten, and the original handler is likely to never be restored, leaving it as a dangling pointer to code that no longer exists when chained code (or anything run following warm boot) calls it.

Since user programs (like sdfat_menu) should be able to do this, this should be fixed in the libs. The obvious (and perhaps wrong) way to do this would be to make exit, atexit handlers and the init code itself work like it does in the new(lib) startup code: https://github.com/rosco-m68k/newlib-4.4.0.20231231/blob/062620702eccd78b1f19ea7f6d4a05bdbbfb0f14/libgloss/rosco/crt0.asm#L69

For full context, see this thread: https://discord.com/channels/698525682199822367/711035186170822727/1226460649673064449