Assembler-level subroutine linkage conventions
The subroutine linkage convention specifies the machine state at subroutine entry and exit, allowing routines that are compiled separately in the same or different languages to be linked.
The information on subroutine linkage and system calls in the System V Application Binary Interface: PowerPC Processor Supplement and 64–bit PowerPC ELF Application Binary Interface Supplement are the base references on this topic. You should consult these for full details. This section summarizes the information needed to write mixed-language Fortran and assembler programs or to debug at the assembler level, where you need to be concerned with these kinds of low-level details.
The system linkage convention passes arguments in registers, taking full advantage of the large number of floating-point registers (FPRs), general-purpose registers (GPRs), vector registers (VRs and VSRs) and minimizing the saving and restoring of registers on subroutine entry and exit. The linkage convention allows for argument passing and return values to be in registers (FPRs, GPRs, VRs or multiple register types), memory, or both.
The following table lists floating-point registers and their functions. The floating-point registers are double precision (64 bits).
| Register | Preserved Across Calls | Use |
|---|---|---|
| 0 | no | |
| 1 | no | FP parameter 1, function return 1. |
| 2 | no | FP parameter 2, function return 2. |
| 3 | no | FP parameter 3, function return 3, function return complex *32. |
| 4 | no | FP parameter 4, function return 4 , function return complex *32. |
| 5 | no | FP parameter 5, function return 5. |
| ⋮ | ⋮ | ⋮ |
| 8 | no | FP parameter 8, function return 8. |
| 9 | no | FP parameter 9 |
| 10 | no | FP parameter 10 |
| 11 | no | FP parameter 11 |
| 12 | no | FP parameter 12 |
| 13 | no | FP parameter 13 |
| 14-31 | yes | local variables |
The following table lists general-purpose registers and their functions.
| Register | Preserved Across Calls | Use |
|---|---|---|
| 0 | no | |
| 1 | yes | Stack pointer. |
| 2 | yes | System-reserved TOC/GOT pointer. |
| 3 | no | 1st word of arg list; return value 1. |
| 4 | no | 2nd word of arg list; return value 2. |
| 5 | no | 3rd word of arg list |
| ⋮ | ⋮ | ⋮ |
| 10 | no | 8th word of arg list. |
| 11-12 | no | |
| 13 | yes | SDA (thread local storage) pointer. |
| 14-30 | no | Local variables. |
| 31 | yes | Local variables or environment pointers. |
| If a register is not designated as preserved, its contents may be changed during the call, and the caller is responsible for saving any registers whose values are needed later. Conversely, if a register is supposed to be preserved, the callee is responsible for preserving its contents across the call, and the caller does not need any special action. | ||
| Register | Preserved Across Calls | Use |
|---|---|---|
| 0 | no | Local variables |
| 1 | no | Local variables |
| 2 | no | Vector parameter 1, vector result 1 |
| 3 | no | Vector parameter 2, vector result 2 |
| 4 | no | Vector parameter 3, vector result 3 |
| 5 | no | Vector parameter 4, vector result 4 |
| 6 | no | Vector parameter 5, vector result 5 |
| 7 | no | Vector parameter 6, vector result 6 |
| 8 | no | Vector parameter 7, vector result 7 |
| 9 | no | Vector parameter 8, vector result 8 |
| 10 | no | Vector parameter 9 |
| 11 | no | Vector parameter 10 |
| 12 | no | Vector parameter 11 |
| 13 | no | Vector parameter 12 |
| 14-19 | no | Local variables |
| 20-31 | yes | Local variables |
| VMX vector registers VR0-31 correspond to VSX registers 32-63. FPR floating-point registers FP0-31 correspond to the upper halves of VSX registers 0-31. | ||
The following table lists special-purpose register conventions.
| Register | Preserved Across Calls |
|---|---|
| Condition register
Bits 0-7 (CR0,CR1) Bits 8-22 (CR2,CR3,CR4) Bits 23-31 (CR5,CR6,CR7) |
no yes no |
| Link register | no |
| Count register | no |
| XER register | no |
| FPSCR register | The control flags are preserved except for calls to functions whose purposes are to change them. The status flags are not preserved. |