llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler
https://www.llvm-mos.org
Other
255 stars 52 forks source link

`commodore` family targets shouldn't both clobber BASIC ZP and return to BASIC #341

Closed mysterymath closed 1 week ago

mysterymath commented 1 week ago

This came up in https://github.com/llvm-mos/llvm-mos-sdk/pull/315, and it's discussed more thoroughly in the tail end of that discussion.

Summary: I think there's three aspects of the commodore family targets that come into conflict:

The easiest change we could make to make this consistent would be to change the commodore targets to exit-loop instead of exit-return; that's one line of CMake. It looks like cc65 doesn't use the BASIC ZP at all and returns. That's one possible configuration. Another is to save and restore BASIC ZP on entry/exit and use it, and another is to clobber it and never return. Ideally there would be a simple way to spell each of these for each commodore target in the SDK, and hopefully, without too much monkeying around in linker scripts. That's the part that needs designing; we've built out a huge degree of this kind of configuration in the NES targets, so it may be possible, but it can be tricky.

mysterymath commented 1 week ago

I think saving and restoring BASIC ZP makes sense as a library actually. We already have symbolic names for the BASIC ZP area, so we could register actions in early init/late fini to save and restore to a buffer. The buffer would need to be defined in a .s file per target (different sizes), but that's no major issue either.

So, for now I'm going to do the exit-loop change; it's easy, and it provides a safer version of what the SDK does already. I do think it's a good default; BASIC uses a ton of ZP, and doing something extra to save/restore seems largely better than disallowing use. I think some symbol work could make the ZP range used configurable, so we may need to just make sure that it's possible to link against -lexit-return directly (I think it should be?)

mysterymath commented 1 week ago

Closing this out with #342 and #343.