HP 3000 Manuals

Switch Subsystem [ Switch Programming User's Guide ] MPE/iX 5.0 Documentation


Switch Programming User's Guide

Switch Subsystem 

The Switch subsystem is an integral part of the MPE XL operating system.
Switch consists of a set of intrinsics that provide the following
services:

 *  Ability to call subsystem, intrinsic, or user-written CM SL
    procedures from NM system or user code

 *  Ability to call subsystem, intrinsic, or user-written NM XL
    procedures from CM system or user code


NOTE MPE V/E intrinsics (except for those no longer supported) are directly callable from both Compatibility Mode and Native Mode. You do not need to code any Switch calls to access these intrinsics.
Figure 1.8 and Figure 1.9 demonstrate the role of the Switch intrinsics in the process of carrying out mixed-mode procedure calls:
[]
Figure 1.8. Role of Switch Intrinsics in CM--> NM Switch
[]
Figure 1.9. Role of Switch Intrinsics in NM--> CM Switch Purpose Due to architectural differences between MPE V/E- and MPE XL-based systems, programs that switch between CM and NM execution may encounter differences in data representation. The primary purpose of Switch is to resolve this situation by providing mixed-mode execution access and parameter translation between Compatibility Mode and Native Mode. Invoking Switch One way to invoke Switch is to use an intermediate, user-written procedure that sets up variables and calls Switch to translate these data references whenever the program changes execution mode. This intermediate procedure is called a Switch stub. The primary purpose of a stub is to provide transparency to the calling procedure/program and thereby avoid source changes in the original code. To do this, the stub must have the same name as the original procedure. You can use the SWitch Assist Tool (SWAT) to automatically generate NM-to-CM stub procedures, or you can write your own Switch stubs. Refer to Chapter 2 for information on SWAT and to Chapters 3-5 for information on the Switch subsystem and the process of writing your own stubs. Another way to invoke Switch is to code the Switch call, and its attendant setting up of variables and error checking, directly in line in the calling procedure. Although this involves modification of your program, there are factors that may lead you to consider this alternative. For example, every time you call a procedure or function, the call and the entry and exit code add to execution overhead. This overhead could increase execution time if it occurred in a critical section of your program. In-line switch code may be appropriate for other-mode procedures that should execute quickly and/or are executed often (for example, in a loop). If an other-mode procedure is referenced in many places, then the convenience of the stub can justify the added overhead of a procedure call. Another factor influencing the choice between stubs and in-line switches is whether data setups can be reused. If not, the in-line switch is not justified. Finally, if backward source compatibility is important to you, you should use Switch stubs. To compile an application or module on an MPE V/E system, removing the stub from the compile procedures is all that is required. Switch to CM Overview Figure 1.10 represents the process of mixed-mode procedure calling in the NM--> CM direction.
[]
Figure 1.10. Mixed-mode Procedure Call: NM--> CM A mixed-mode procedure call in the direction NM--> CM involves the following steps, as indicated in Figure 1.10: 1. The NM code needing to access a CM routine calls a Switch intrinsic, either by means of in-line code or a Switch stub. 2. The in-line code or NM Switch stub sets up the data structures and parameters required by Switch and makes a call to the HPSWITCHTOCM intrinsic (call by name), or the HPLOADCMPROCEDURE and HPSWITCHTOCM intrinsics (call by plabel). 3. HPSWITCHTOCM calls the CM routine and passes the parameters, translating addresses and/or copying data to Compatibility Mode as required by their type, size, and location. 4. The CM routine executes using the passed parameters and returns its data values to HPSWITCHTOCM. 5. HPSWITCHTOCM receives the data values returned by the CM routine, back-translating addresses and recopying data as needed. 6. HPSWITCHTOCM returns the translated values to the caller. The stub or in-line code checks whether the Switch operation was successful and then control returns to the NM routine.
NOTE HPSWITCHTOCM is the system intrinsic that makes NM parameters addressable to Compatibility Mode, changes the execution mode, and invokes the CM routine. HPSWITCHTOCM and HPLOADCMPROCEDURE reside in the NM system library, NL.PUB.SYS.
Switch to NM Overview Figure 1.11 represents the process of mixed-mode procedure calling in the CM--> NM direction.
[]
Figure 1.11. Mixed-mode Procedure Call: CM--> NM A mixed-mode procedure call in the direction CM--> NM involves the following steps, as indicated in Figure 1.11: 1. The CM code needing to access an NM routine calls Switch, either by means of in-line code or a Switch stub. 2. The in-line code or CM Switch stub sets up the data structures and parameters required by Switch and makes a call to either the HPSWTONMNAME intrinsic or the HPLOADNMPROC and HPSWTONMPLABEL intrinsics. 3. HPSWTONMNAME or HPSWTONMPLABEL calls the NM routine, after preparing the NM registers as though the call was being made from Native Mode. 4. The NM routine executes as though called from Native Mode and returns the functional return value (if any) to the calling Switch intrinsic. Reference parameters are modified by the NM routine. 5. If the NM routine has a functional return value, HPSWTONMNAME or HPSWTONMPLABEL copies the value back to the CM stack. 6. The stub or in-line code checks whether the Switch operation was successful and then control returns to the CM routine.
NOTE HPSWTONMNAME or a combination of HPLOADNMPROC and HPSWTONMPLABEL are the system intrinsics called to pass CM values and parameters to Native Mode, to change the execution mode, and to invoke an NM routine. HPSWTONMNAME, HPLOADNMPROC, and HPSWTONMPLABEL reside in the CM system library, SL.PUB.SYS. The only difference between using HPSWTONMNAME and HPLOADNMPROC/HPSWTONMPLABEL is the manner in which the target routine is identified. For details on when and why to use names versus plabels, see Chapter 4.


MPE/iX 5.0 Documentation