HPlogo PA-RISC Procedure Calling Conventions Reference Manual > Chapter 3 Register Usage and Parameter Passing

3.5 Parameter Passing and Function Results

MPE documents

Complete PDF
Table of Contents

3.5.1 Value Parameters


Value parameters are mapped to a sequential list of argument words with successive parameters mapping to successive argument words, except 64-bit parameters, which must be aligned on 64-bit boundaries. Irregularly sized data items should be extended to 32 or 64 bits. (The practice that has been adopted is to right-justify the value itself, and then left-extend it.) Non-standard length parameters that are signed integers are sign-extended to the left to 32 or 64 bits. This convention does not specify how 1-31, 33-63-bit data items are passed by value (except single ASCII characters).

Table 3-2 lists the sizes for recognized inter-language parameter data types. The form column indicates which of the forms (space ID), nonfloating-point, floating-point, or any) the data type is considered to be.

3.5.2 Inter-Language Parameter Data Types and Sizes


Table 3-4 Parameter Data Types and Sizes

Type Size (bits) Form
ASCII character (in low order 8 bits)32Nonfloating-Pt.
Integer32Nonfloating-Pt. or Space ID
Short Pointer32Nonfloating-Pt.
Long Pointer64Nonfloating-Pt.
Routine Reference (see below for details of Routine Reference) 32 or 64Routine Reference
Long Integer64Nonfloating-Pt.
Real (single-precision)32Floating-Pt.
Long Real (double-precision)64Floating-Pt.
Quad Precision128Any

Space Identifier (SID) (32 Bits): One arg word, callee cannot assume a valid SID.

Non-Floating-Point (32 Bits): One arg word.

Non-Floating-Point (64 Bits): Two words, double word aligned, high order word in an odd arg word. This may create a void in the argument list (i.e. an unused register and/or an unused word on the stack.)

Floating-Point (32 Bits, single-precision): One word, callee cannot assume a valid floating-point number.

Floating-Point (64 Bits, double-precision): Two words, double word aligned (high order word in odd arg word). This may create a void in the argument list. 64-bit floating-point value parameters mapped to the first and second double-words of the argument list should be passed in fargl and farg3, respectively. farg0 and farg2 are never used for 64-bit floating-point parameters. Callee cannot assume a valid floating-point number.


NOTE: The point is made that the callee "cannot assume a valid" value in these cases because no specifications are made in this convention that would ensure such validity.

Any Larger Than 64 Bits: A short pointer (using sr5 - sr7) to the high-order byte of the value is passed as a nonfloating-point 32-bit value parameter. The callee must copy the accessed portion of the value parameter into a temporary area before any modification can be made to the (caller's) data. The callee may assume that this address will be aligned to the natural boundary for a data item of the parameter's type. It should be noted that some compilers support options which allow data structures to be aligned on non-natural boundaries. The instruction sequence used to copy the value should be consistent with the data alignment assumptions made by potential callers of that routine.


NOTE: The natural boundaries for data types on PA-RISC are documented in the Programmer's Guide that is available for each supported programming language.

3.5.3 Reference Parameters


A short pointer to the referenced data item (using sr4 - sr7) is passed as a nonfloating-point 32-bit value parameter. The alignment requirements for the short pointer are the same as those mentioned for value parameters larger than 64 bits. Note that sr4 can only be used if the call is known to be local, because an external call will modify sr4. (See Chapter 5 for further details.)

3.5.4 Value-Result and Result Parameters


It is intended that language processors can use either the reference or value parameter mechanisms for value-result and result parameters. In particular, Ada uses the argument registers/parameters as output registers/parameters.

3.5.5 Routine References


This convention requires that routine references (i.e. procedure parameters, function pointers, external subroutines) be passed as 32-bit nonfloating-point values.

It is expected that language processors that require a static link to be passed with a routine reference (i.e. Pascal passing level 2 procedures) will pass that static link as a separate 32-bit nonfloating-point value parameter. A language processor is free to maximize the efficiency of static scope linking within the requirements, without impacting other language processors. (Pascal passes routine references as either two separate 32-bit values or as one 64-bit value.) See Chapter 5 for further details on Routine References.

3.5.6 Argument Register Usage Conventions


Parameters to routines are logically located in the argument list. When a call is made, the first four words of the argument list are passed in registers, depending on the usage and number of the argument. The first four words of the actual argument list on the stack are reserved as spill locations for the argument registers. These requirements imply that the minimum argument list size is 16 bytes; this space must be allocated in the frame for non-leaf procedures, but it may remain unused.

The standard argument register use conventions are shown in Table 3-3.

Table 3-5 Argument Register Use

void SID nonFP FP32 FP64
arg word 0no regsargarg0farg0farg0 {32..63}
arg word 1no regarg1arg1farg1farg1 {0..31}
arg word 2no regarg2arg2farg2farg2 {32..63}
arg word 3no regarg3arg3farg3farg3 {0..31}

definitions:
void - arg word not used in this call
SID - space identifier value
nonFP- any 32-bit or 64-bit nonfloating-point
FP32 - 32-bit floating-point (single-precision)
FP64 - 64-bit floating-point (double-precision)

3.5.7 Function Return Values


Function result values are placed in registers as described in Table 3-4. As with value parameters, irregularly sized function results should be extended to 32 or 64 bits. (The practice that has been adopted is to right-justify the value itself, and then left-extend it.) Non-standard length function results that are signed integers are sign-extended to the left to 32 or 64 bits. This convention does not specify how 1 - 31 or 33 - 63-bit data items are returned (except single ASCII characters).

When calling functions that return results larger than 64 bits, the caller passes a short pointer (using sr5 - sr7) in gr28 (ret0) which describes the memory location for the function result. The address given should be the address for the high-order byte of the result. The function may assume that the result address will be aligned to the natural boundary for a data item of the result's type. It should be noted that some compilers support options which allow data structures to be aligned on non-natural boundaries. The instruction sequence used to store a function result should be consistent with the data alignment assumptions made by potential callers of that function.

Table 3-6 Return Values
Type of Return Value Return Register
ASCII character ret0 (gr28) - low order 8 bits
Nonfloating-Pt. (32-bit) ret0 (gr28)
Nonfloating-Pt. (64-bit) ret0 (gr28) - high order word
ret1 (gr29) - low order word
Floating-Pt. (32-bit) fret (fr4) *
Floating-Pt. (64-bit) fret (fr4) *
Space Identifier (32-bit) sret (srl)
Any Larger Than 64-bit result is stored to memory at location described by a short pointer passed by caller in gr28**
* Although not common, it is possible to return floating-point values in general registers, as long as the argument relocation bits in the symbol record are set correctly. (Refer to Parameter Relocation for more details.)

** The caller may not assume that the result's address is still in gr28 on return from the function.

3.5.8 Parameter Type Checking


Some compilers may place argument descriptors in the object file which contain information about the type of each parameter passed and each formal argument expected. These descriptors are then checked by the linker for compatibility. If they do not match, a warning is generated. There is currently no mechanism available in the PA-RISC assembler to generate these argument descriptors.




3.4 Summary of Dedicated Register Usage


3.6 Parameter Relocation