NonStop S-Series Server Description Manual (G06.24+)

TNS Execution Modes
HP NonStop S-Series Server Description Manual520331-003
6-64
Calling External Procedures
Calling External Procedures
Procedures in another code segment can be called almost as efficiently as the current
segment’s own procedures. Two important features that make this possible are the
space ID (identification) convention and the XCAL (External Procedure Call)
instruction. The space ID convention provides a simple, one-step means to return to
the segment of the caller (only the Environment register needs to be examined), and
the XCAL instruction provides a two-table look-up sequence to get to the exact entry
point of the external procedure.
As is usual when any procedure is called, the first action of the calling instruction
(XCAL in this case) is to save the calling environment in a stack marker. The stored
copy of the Environment register contains the complete segment identification of the
caller’s segment. For procedure calls that are internal within a single code segment
(as performed by the PCAL instruction previously described), the segment
identification is not needed. However, the EXIT instruction always checks this
information so that it can return in exactly the same way regardless of which instruction
made the call.
For external calls, though, the complete segment identification is very important
because the call can be made to any one of four code spaces (user code, user library,
system code, or system library) and each of those code spaces can have multiple
segments. Thus, on return, the environment must switch quickly back to the specific
space and specific segment within that space.
The complete segment identification is in the saved copy of the Environment register,
shown in Figure 6-35. The complete identification consists of the LS and CS bits, to
select one of the four code spaces, plus a space ID index to select a specific segment
within that code space. The space ID index occupies bits 11 through 15. Normally, in
the Environment register itself, these bits are used to contain the condition code and
register pointer (CC and RP). However, because CC and RP do not need to be saved,
these bits are available to save the space ID index in the stack marker copy.
In the saved copy of the Environment register, in the stack marker, bits 4 through 10
contain exactly the same single-bit fields that exist in the Environment register itself.
LS, DS, and CS identify, respectively, library space (0 = no, 1 = yes), data space
(0 = process, 1 = interrupt), and code space (0 = user, 1 = system). PRIV, T, K, and V
indicate (if set = 1), privileged mode, traps enabled, carry, and overflow. Bits 11
through 15, the space ID index, identify one of 32 possible TNS code segments in the
space specified by the combination of LS and CS.
After the XCAL instruction has placed the three-word stack marker on the top of the
user stack, it then moves L and S in the same manner as a PCAL instruction (that is,
defines a new stack frame). However, instead of transferring control directly to a
procedure within the segment, control is transferred out of the segment. This transfer
of control is accomplished through two tables. The first, in the caller’s segment, is
called the external entry point table, or XEP table. The second, in the segment of
the called procedure, is that segment’s PEP, or procedure entry point table (previously
described for PCAL).