Zalt Debugging Support

I have been busy on the Zim80 Z80 simulator software a lot lately. But recently I have been switching back to writing the Zalt bios (kernel/os – whatever you want to call it) and setting up basic facilities for further development.

One of these basic facilities is some kind of way to implement a debugger in the PSoC System Controller. As I have mentioned before I have chosen to use the Z80 Halt instruction as a signal from the Z80 to the System Controller it wishes to break into the debugger. The System Controller responds and an exchange of data follows.

  • Z80: Executes the Halt instruction and the HALT signal goes low (active).
  • PSoC: Has an interrupt on the HALT signal activation and executes its ISR:
    • Activates the NMI signal to the Z80
    • Wait for the HALT signal to become inactive – this means the Z80 has detected the NMI and is executing its NMI handler at address 66h.
    • Deactivate the NMI signal.
    • The Debugger starts the state-machine to indicate we have a debugger session.
  • Z80: The NMI handler calls a routine to save all registers into memory variables and calls the PSoC to ask if we’re in a debug session – executes an In (io) instruction on the debug-port (currently 00h – but that may change).
  • PSoC: detects the IO-In instruction and calls the Debugger (because the address is on the Debug-Port) and advances the state machine to the next state. Note that the PSoC will insert wait-states for all IO-operations to/from the Z80 – it just isn’t fast enough because software is involved.
  • Z80: It checks the result of the In-instruction and continues. For now I have hard -coded to dump all register values  (we previously saved) to the PSoC. At a later time a whole debug-monitor can be implemented here.
  • PSoC: all register values are intercepted and stored in memory. When done the statemachine engages its last state that signals the main-loop in the PSoC to print all the register values – remember we’re executing inside the Halt-ISR here (actually it’s the IO-ISR).
  • Z80: With all register values sent, the NMI handler returns (retn) and continues normal execution of the program.

Because I am currently writing most code in C I have made some debug marco’s that encapsulate this ‘breakpoint’ halt statement and make it easy to use.

As I go, I will add more functionality to the debug-monitor implementation to support more commands and interaction with the developer at the debug console.

You can follow along with the progress at the Zalt github repository.

Published in: on January 6, 2017 at 1:23 pm  Leave a Comment  

The URI to TrackBack this entry is:

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: