Special Cases [ Switch Programming User's Guide ] MPE/iX 5.0 Documentation
Switch Programming User's Guide
Special Cases
There are certain situations that the Switch Assist Tool does not handle.
Other situations require special consideration before you decide to use
SWAT-generated Switch stubs.
NOTE The following information applies only to switches in the NM--> CM
direction. The Switch Assist Tool does not handle mixed-mode
procedure calls in the CM--> NM direction. Refer to Chapter 5 for
a discussion of how to code CM--> NM stubs manually.
Unsupported Cases
The Switch Assist Tool cannot handle the following:
* Value parameters that are larger than a single element (for example,
arrays passed by value) are not handled.
* No pointers of any kind are allowed.
* Plabels, and program labels in general, cannot be passed as
parameters.
* CM procedures that execute in split-stack mode cannot be accessed by
SWAT-generated stubs.
In Pascal, any size structure can be passed by value to another procedure
because a copy is placed on the top of the stack. SPL, on the other
hand, does not allow arrays to be passed by value. Because most CM
target procedures are written in SPL, the Switch Assist Tool does not
allow multi-element parameters, such as arrays, to be passed by value.
For a pointer to be valid, all its possible targets would also have to be
available to the called procedure. This is not possible since all
available storage within the NM process stack would have to be copied.
There may be some cases where an application dictates that a pointer
always points to a location within one of the other passed parameters,
but you must handle those instances manually.
Passing plabels across modes implies that you can transfer control across
modes without using Switch. Since that is not the case, you cannot pass
plabels as parameters.
CAUTION Programming a correct and reliable split-stack Switch stub
requires a very high level of knowledge about programming in
both modes on MPE XL. It also requires a strict coding
discipline in all of the procedures that the target procedure
calls, as well as special programming and debugging techniques
for error handling and recovery. In addition, all of the
warnings and restrictions about Privileged Mode programming
apply to split-stack stubs and their target procedures.
Therefore, Hewlett-Packard recommends that, if your application
needs access to split-stack target procedures, you should
request assistance from trained Hewlett-Packard support staff.
Special Case Considerations
There are some conditions that either are undetectable by the Switch
Assist Tool or make use of the SWAT-generated source code inadvisable.
These situations require modification of SWAT-generated Switch stubs:
* Use of unconverted variables of type real or long
* Overlapping reference parameters
* Specification of reference parameter data lengths at run time
* Option-variable procedures
Unconverted Real or Long Variables. Compatibility Mode has HP 3000 mode
floating-point format, while Native Mode supports both the HP 3000 mode
format and IEEE floating-point format. You can use the Switch Assist
Tool to generate Switch stubs for procedures that have variables of type
real or long. If you have not already coded their conversion, then, to
guarantee correct results, you must insert calls to the HPFPCONVERT
intrinsic into the SWAT-generated stub. You may have to perform the
conversion twice, once in preparation for the Switch and again upon
returning from it. No conversion is necessary if the calling procedure
has already done the conversion or if the caller used HP 3000 Mode
floating-point format. Refer to the MPE XL Intrinsics Reference Manual
(32650-90028) for information about HPFPCONVERT.
Overlapping Reference Parameters. If reference parameters overlap,
unpredictable results can occur. In Native Mode, the parameters will
overlap; in Compatibility Mode, however, the parameters are placed one
after the other on the CM stack. The Switch Assist Tool cannot detect
this situation. If you design calls to CM procedures via Switch, it is
your responsibility to deal with the consequences of overlapping
reference parameters.
Run-time Specification of Reference Parameter Data Lengths. Reference
parameter data lengths must be known at run time in the stub procedure.
It is not simply a matter of specifying the maximum length because the
length specified is copied to the CM stack and back again to the NM data
space. In many instances, it would not be practical, or even possible,
to use the maximum length. Such is the case with the target parameter
(buffer) for FREAD or FWRITE. For many situations, however, it is
possible to specify a maximum length. For example, the maximum length of
the formalfiledesignator parameter in an FOPEN call is never larger than
36 bytes.
If you use a maximum length, you should declare the parameter to Switch
as an input/output parameter, even if it is output only. If you declare
the parameter as output only, then part of your NM data area can be
altered when the CM data area of the declared length is copied back to
the NM data area. On the other hand, if you declare the parameter to be
input/output, then any portion of the data area that was not changed
during execution of the CM target is copied back unchanged to the NM data
area.
Several options are available to alleviate the reference parameter data
length problem. A discussion of two such options follows.
As one option, you can scan the buffer for a termination character to
determine the length. This method is applicable in many cases where the
data is terminated by a carriage return (for example, the COMMAND
intrinsic) or a binary zero (for example, the GENMESSAGE intrinsic).
Or, as another option (using SWAT), you can take the length of the buffer
from another parameter. In the case of FREAD/FWRITE, you specify the
length in the call. On the PARMINFO screen, you supply the name of the
parameter and then select the USE NEGATIVE = BYTES RULE option. SWAT
must do some additional processing to use the length value since the
length passed in the call is negative if specified in bytes or positive
if specified in words. The Switch call requires the length to be
specified in positive bytes. So, SWAT performs one of two conversions:
* Negative values (specifying byte lengths) are made positive.
* Positive values (specifying word lengths) are multiplied by two to
convert the word count to a byte count.
Option-variable Procedures. The problems involving calls to
option-variable procedures include the following:
* No direct HP Pascal/XL equivalent for the OPTION VARIABLE option
* Default value options for non-HP Pascal/XL programs
* Interference of EXTERNAL declarations with default value options
* Determining if a value parameter was included in the call
The OPTION VARIABLE option, as defined in the HP 3000/SPL environment, is
not supported in the HP Pascal/XL environment. Although the replacement
capability of HP Pascal/XL allows the specification of default values for
parameters left out of a procedure call, this capability does not provide
the functional equivalent of SPL option variable calls.
For the non-HP Pascal/XL program, the only way for the default values
options to function is through the use of an intrinsic file. The Switch
Assist Tool does not write the code necessary to place the declaration of
each option-variable stub into an intrinsic file.
Even if you manually place the stub's declaration in an intrinsic file,
the default values option does not function if there is an EXTERNAL
declaration for the stub procedure embedded within the calling program's
code.
Assuming there is no such EXTERNAL declaration and the default value
option works correctly, you can give reference parameters a default value
of NIL. Since NIL is never a valid value for reference parameters, this
provides an easy method for determining whether the parameter was passed.
However, parameters passed by value can have any value since, unlike
reference parameters, they do not have to be a valid address. This poses
a major problem in distinguishing value parameters included in the call.
A default value that will never be valid must somehow be assigned in
order to identify value parameters that were given default values versus
value parameters whose values were specified in the call.
User Options
Pointers are not allowed, and the Switch Assist Tool does not generate
them. However, if a pointer always points to an address within another
variable that is also being passed in the Switch call, then you can
manually code the statements needed to transfer the pointer.
MPE/iX 5.0 Documentation