Guardian Programmer's Guide

Table Of Contents
Debugging, Trap Handling, and Signal Handling
Guardian Programmer’s Guide 421922-014
25 - 12
Processing a Trap
Processing a Trap
The code for processing a trap depends on what you want to do for a given trap
condition. See Writing a Trap Handler: Examples at the end of this section for an
example of how to process a trap due to arithmetic overflow.
However, if you want to return to the application after processing the trap, then you
need to save the stack registers immediately on entering the trap-handling code.
When the trap-handling code is entered, the stack registers contain information at the
point that the trap occurred. Before the trap handler changes the register values, you
should save them so that you can restore them when you exit the trap handler.
To save the stack registers, you must push them onto the data stack using the PUSH
machine instruction as follows:
CODE (PUSH %777);
The parameter %777 causes all eight stack registers to be saved.
You must then allocate any storage you need for local variables by advancing the
S register by the number of words needed to save the local data. Use the ADDS
machine instruction as follows.
CODE (ADDS LOCALS);
Here, “LOCALS” specifies the number of two-byte words of local data.
The trap stack space now has data space allocated as shown in Figure 25-2.
Figure 25-1. Trap Handler Data Stack When Trap Occurs
VST115.VSD