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

3.6 Parameter Relocation

MPE documents

Complete PDF
Table of Contents

The procedure calling convention specifies that the first four words of the argument list and the function return value will be passed in registers: floating-point registers for floating-point values, general registers otherwise. However, some programming languages do not require type checking of parameters, which can lead to situations where the caller and the callee do not agree on the location of the parameters. Problems such as this occur frequently in the C language where, for example, formal and actual parameter types may be unmatched, due to the fact that no type checking occurs.

A parameter relocation mechanism alleviates this problem. The solution involves a short code sequence, called a relocation stub, which is inserted between the caller and the callee. When executed, the relocation stub moves any incorrectly located parameters to their expected location. If a procedure is called with more than one calling sequence, a relocation stub is needed for each non-matching calling sequence.

The compiler or assembler must communicate the location of the first four words of the parameter list and the location of the function return value to the linker and loader. To accomplish this, ten bits of argument location information have been added to the definitions of a symbol and a fix-up request. The following diagram shows the first word of a symbol definition record in the object file.

[Symbol definition record]

The argument location information is further broken down into five location values, corresponding to the first four argument words and the function return value, as shown below:
  • Bits 22-23 : define the location of parameter list word 0

  • Bits 24-25 : define the location of parameter list word 1

  • Bits 26-27 : define the location of parameter list word 2

  • Bits 28-29 : define the location of parameter list word 3

  • Bits 30-31 : define the location of the function value return

The value of an argument location is interpreted as follows:
00 Do not relocate
01 arg Argument register
10 fr Floating-point register (bits 0..31) *
11 frupper Floating-point register (bits 32..63) *
* For return values, '10' means a single precision floating-point value, and '11' means double precision floating-point value.

When the linker resolves a procedure call, it will generate a relocation stub if the argument location bits of the fixup request do not exactly match the relocation bits of the exported symbol. One exception is where either the caller or callee specifies "do not relocate". The relocation stub will essentially be part of the called procedure, and the linker can optionally add a symbol record for the stub so that it can be reused. The symbol record will be the same as the original export symbol record, except that the relocation bits will reflect the input of the stub. The type will be STUB and the symbol value will be the location of the relocation stub.

The execution of a relocation stub can be separated into the call path and the return path. During the call path, only the first four words of the parameter list will be relocated, while only the function return will be relocated during the return path. The control flow is shown in Figure 3-3.

Figure 3-3 Parameter Relocation Stub

[Figure 3-3]

If the function return does not need to be relocated, the return path can be omitted and the branch and link will be changed to a branch. The call path must always be executed, but if the first four words of the parameter list do not need to be relocated, it can be reduced to the code required to establish the return path (i.e save RP and branch and link to the callee).

When multiple stubs occur during a single call (e.g. calling stub and relocation stub), the stubs can be cascaded (i.e. used sequentially); in such a case, both RP' and RP" would be used. (The relocation stub uses RP".)

When the linker makes a load module executable, it will generate stubs for each procedure that can be called from another load module (i.e. called dynamically). In addition, a stub will be required for each possible calling sequence. Each of these stubs will contain the code for both relocation and external return, and will be required to contain a symbol definition record.

Both calling and called stubs use a standard interface: calling stubs always relocate arguments to general registers, and called stubs always assume general registers.

In order to optimize stub generation, the compilers should maximize the use of the argument location value 00 (do not relocate). A linker option may be provided, which will allow the user to turn stub generation on or off, depending on known conditions. Also, a linker option is provided to allow the user to inhibit the generation of stubs for run-time linking. In this case, if a mismatch occurs, it will be treated as a parameter type checking error (which is totally independent of parameter relocation).

Assembly programmers can specify argument relocation information in the .CALL and .EXPORT assembler directives.




3.5 Parameter Passing and Function Results


Chapter 4 The Actual Call