Synergistic Processing Unit (SPU)

From PS3 Developer wiki
Revision as of 13:29, 25 February 2011 by 91.115.209.37 (talk) (Created page with "== SPU Application Binary Interface Specification == All the informations are taken from this [https://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/02E544E65760B0BF872570600...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SPU Application Binary Interface Specification

All the informations are taken from this PDF.

Function Calling Sequence

The standard calling sequence requirements apply only to global functions. Local functions that are not reachable from other compilation units may use different conventions; however, using non-standard calling sequences is not recommended.

Register Usage

Register Status Usage
R0 (LR) Dedicated Return Address / Link Register. This register contains the address to which a called function normally returns. It is volatile across function calls and must be saved by a non-leaf function.
R1 (SP) Dedicated Stack pointer information. Word element 0 of the SP register contains the current stack pointer. The stack pointer is always 16-byte aligned, and it must always point to the lowest allocated valid stack frame and grow towards low addresses. The contents of the word at the stack-frame address always point to the previous allocated stack frame. Word element 1 of the SP register contains the number of bytes of Available Stack Space.
R2 Volatile Environment pointer. This register is used as an environment pointer for languages that require one.
R3-R74 Volatile First 72 quadwords of a function’s argument list and its return value.
R75-R79 Volatile Scratch Registers.
R80-R127 Non-volatile Local variable registers. These must be preserved across function calls.

Stack Frame Layout

In addition to using registers, each function call may have a stack frame on the runtime stack. The runtime stack grows downward from high addresses.

     +-----------------------------+ High Address
+--->| Back Chain                  |
|    +-----------------------------+
|    | Register Argument Save Area |
|    +-----------------------------+
|    | General Register Save Area  |
|    | (max. 48 * 16 bytes)        |
|    +-----------------------------+
|    | Local Variable Space        |
|    +-----------------------------+
|    | Parameter List Area         |
|    +-----------------------------+
|    | Link Register Save Area     |
|    +-----------------------------+
+----| Back Chain                  |
     +-----------------------------+ Low Address <---- Stack Pointer (SP/R1)
     <--------- 128 bits ---------->

In the above figure, SP denotes the stack pointer (word element 0 of the general-purpose register R1) of the called function after it has executed the code that establishes its stack frame.

Argument Passing

For the SPU, up to 72 quadwords are passed in general-purpose registers, loaded sequentially into registers R3 through R74. If fewer than 72 argument registers are needed, the unneeded registers are not loaded, and any values that they contain when entering the called function are undefined. When arguments passed to a callee function will not fit into these 72 registers, the caller function must allocate additional space for these arguments in its Parameter List Area.

Program Initialization

When an SPU program is first entered, the contents of register R1 (SP) are initialized to the top of the stack. Generally, the top of the stack is a minimal stack located at the largest quadword address. A system with 256 KB of local storage initializes the stack pointer to 0x3FFD0. This address contains a Back Chain pointer to 0x3FFF0. The Back Chain pointer at 0x3FFF0 contains a NULL (0) pointer. Space is allocated for the entry function to save the Link Register (address 0x3FFE0). The contents of all other registers are unspecified. Thus, if a program requires registers to have specified values, it must explicitly set them.

     +----------------------------+
+--->| Back Chain Pointer 0x0     | 0x3FFF0
|    +----------------------------+
|    | Link Register Save Area    | 0x3FFE0
|    +----------------------------+
+----| Back Chain Pointer 0x3FFF0 | 0x3FFD0
     +----------------------------+ <------- Initial Stack Pointer
     |                            |
     ~                            ~

SPU Assembly Language Specification

[PDF]