breakintoprogram / agon-mos

Official AGON QUARK Firmware: eZ80 MOS
MIT License
73 stars 16 forks source link

Concerns about available stack space for MOS commands #9

Open breakintoprogram opened 1 year ago

breakintoprogram commented 1 year ago

This issue was raised by Reinhard Schu on Facebook:

I have written a stacktest program that runs as a MOS command. Please see the output in the attached screenshot. My init.inc code automatically detects when its running as a MOS command and re-adjusts the SPS to $7FFE. Without this adjustment, if you study the output of my stacktest program, you will see that a MOS command that pushes more than 256 bytes onto the SPS with PUSH and POP instructions in Z80 (16-bit) mode will conflict with the SPL, as the top of both SPL and SPS will be at $08FFFF.

I have written my own init.inc code to correct this, but I would suggest it is best to fix the MOS to set the SPS to $7FFE when spawning a MOS ccommand, otherwise MOS commands could have unpredictable results due to SPS/SPL stack conflict.

Image

breakintoprogram commented 1 year ago

This only affects 16-bit MOS commands like Hello_16 or Memdump. The solution is to adjust the stack pointer to &8000 in the initialisation code, restoring the stack before returning to MOS. This has been implemented in Memdump and Hello_16.

breakintoprogram commented 1 year ago

Keeping this card open as there is a further consideration with regards to MOS and SPS, as the MOS CALL.LIS may potentially overwrite the topmost entry.