Guardian Procedure Calls Reference Manual

where num-locals is a LITERAL defining the number of words of local storage needed (see
the next consideration).
Base-address equivalencing and declaring local variables
Any local variables in the application program's trap-handling procedure must be declared
relative to the L register by using base-address equivalencing. For example:
INT I='L' + 9;
STRING .EXT X(X_TEMPLATE)='L' + 12;
Assuming that the trap handler begins with the statement CODE ( PUSH %777 ), the first local
variable is placed at ‘L'+9.
For details on base-address equivalencing, see the TAL Reference Manual.
NOTE: Variables declared in this form cannot be initialized.
The trap-handling procedure must contain a statement that explicitly allocates storage for any
locally declared variables (see the preceding consideration).
Space ID, P register, and hardware ENV register
The space ID consists of a code space bit that signifies system or user space, a library space
bit that signifies code or library space, and a five-bit index to indicate which of the 32 possible
segments you are referring to. For more information about space IDs, see the appropriate
system description manual for your system.
At the time of a trap, the space ID of the calling procedure is placed in the stack at ‘L'[-5]; the
stack marker ENV register at ‘L'[-1] also contains the system code and library code bits but
not the index. When exiting the trap handler, execution resumes at the location identified by
the P register at ‘L'[-2], the space index in the stack at ‘L'[-5], and the library space and code
space bits of ‘L'[-1].
Value for the P register
The value for the P register at the time of the trap depends upon the trap condition. In this
table, I represents the address of the instruction being executed at the time of the trap, and ?
means undefined.
P RegisterTrap
I0
I1
I + 12
?3
I4
?5
I11
I12
?13
Terminating a trap handler
A trap handler can terminate in these ways on either a TNS or native system:
Clear the overflow (or trap) bit in the trap ENV variable and resume from a trap 2
(arithmetic overflow). See the “Resuming at the point of the trap” consideration below.
(If the overflow and trap bits of ENV are both set upon exit from the trap handler, then
72 Guardian Procedure Calls (A-B)