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

TNS Execution Modes
HP NonStop S-Series Server Description Manual520331-003
6-66
Example of an External Procedure Call
Example of an External Procedure Call
In this example, procedure Z in user code calls a READ procedure in system code.
The XCAL instruction that implements this call refers to an external entry point table in
its own segment and a procedure entry point table in the segment that contains the
called procedure. These references provide the entry point address.
The general flow applies to any allowable external call between any pair of segments
in any of the four code spaces—user code, user library, system code, and system
library.
With reference to the numbered callouts in Figure 6-36, the sequence of events is as
follows:
1. The callers environment is stored in a stack marker. The stored copy of the ENV
register contains the complete segment identification (LS and CS bits, plus the
space ID index) of the caller’s TNS code segment.
2. The C[0]-relative address of the procedure being called is obtained by a three-step
process. First, the XCAL instruction locates entry number 2 in the caller’s external
entry point (XEP) table. Second, that XEP table entry (formatted as shown upper
left) is used to locate the desired code segment (CS and LS specify the system
code space, in this example, and bits 2 through 6 specify a space ID index of 0)
and a particular procedure entry point number (41) as an index into the procedure
entry point (PEP) table. Third, the address in that PEP table entry (42037) is put in
the P register so that the next instruction executed will be the first instruction of the
system procedure.
3. If the calling procedure is not executing in privileged mode (assume it is not), the
callability attribute of the system procedure being called is checked. In this case,
the PEP number of 41 puts the call into the callable, privileged group. The call is
therefore permitted; the procedure will execute in privileged mode but will restore
the mode to nonprivileged on exit.
4. The S and L registers are set with the G-relative address of the new top-of-stack
location. The new L register setting defines the base of the stack frame for the
system procedure being called.
5. The new S register setting is tested for an address within the memory stack area,
G[0:32767]. If the value is greater than 32,767, control is transferred to the stack
overflow trap and the XCAL instruction is aborted.
6. The CS bit of the Environment register (not shown) is set to 1 and the LS bit is set
to 0 to indicate that further code area references will be in the system code space
(segment 0 in this example). Also, the register stack pointer, RP, is given an initial
value of 7 (stack empty).
When the system procedure finishes, the EXIT instruction is executed. The CS and LS
bits, plus the space ID index bits from the stored copy of the ENV register, are used to
reestablish the caller’s segment of the user code space as the currently selected code
space, so that the next instruction is executed from that segment.