NonStop S-Series Server Description Manual (G06.27+)
Native Execution Mode
HP NonStop S-Series Server Description Manual—520331-004
7-14
Example of Enter_Priv Transition
Example of Enter_Priv Transition
Because privileged mode operation provides access to operating system elements,
transitions to privileged mode by nonprivileged procedures must be restricted to
callable procedures only. Transitions in the reverse direction, from privileged to
nonprivileged, occur while the code is running privileged (and therefore trusted), and
so this transition direction is accomplished simply by the Exit_Priv routine.
The transition to privileged mode, for a legitimate call to a callable procedure, is
accomplished by a set of short code sequences called gateways, which are located in
specific memory areas called gateway tables. Gateway tables are located all together
in region 7E. User code (UC, UCr) and user library (UL) seldom have such callable
procedures and so rarely have gateway tables. In fact, most callable procedures are in
the system library area. The example shown in Figure 7-7 illustrates the gateway table
for the RISC system library, which resides in user space.
Note the major elements of the example shown. These are the calling instructions in
the user code (on the left), the called procedure code in the native code part of the
system library (SLr in the 7C region), the gateway table, and a scratchpad page
(SPAD) in Kseg2. The example assumes the procedure being called is the READX
procedure.
Instead of jumping directly to the entry point of the called procedure, the caller goes to
the gateway for the called procedure (1). The gateway consists of a sequence of RISC
instructions, one of which is a load-byte instruction (2) that attempts to load a certain
byte of the scratchpad page (SPAD), which is located in privileged virtual memory
(Kseg2). Such a reference requires privileged mode. For the privileged caller, the load
occurs and the jump to the procedure entry point immediately follows. But for the
nonprivileged caller, an address error exception occurs. This invokes the exception
handler, which (recognizing that the address is special) checks the call for validity and
allows the process to proceed in privileged state.
The final instruction in the gateway is the jump to the entry point of the called
procedure (3). The called procedure now executes in privileged mode and performs
the requested operation.
An accelerated caller invokes the RISC part of a to-RISC shell by way of a very similar
gateway mechanism. The address of the load-byte instruction is different, to indicate
that the Enter_Priv transition is to a shell, so (a) it takes place in accelerated mode,
(b) zero instead of sp is stored in the special transition frame, and (c) the shell rather
than Enter_Priv moves sp to the privileged stack. The same sequence of steps
occurs, with the third jumping to the shell, which ultimately (4) calls the target RISC
procedure.
Essentially the same three-step sequence occurs when an accelerated TNS procedure
calls READX and is diverted to the gateway for $READX, the shell. (4) $READX calls
the same native READX procedure.