SPARC Assembly Language Reference Manual

Exit Print View

Updated: July 2014
 
 

6.3 Parameter Passing

On SPARC processors, arguments to C functions are passed as-if they were in a parameter array. The array elements are called slots. The slots are numbered from zero. For 32-bit code, the array has 32-bit elements (slots), and for 64-bit code the array has 64-bit elements (slots). Successive parameters to a routine are passed in successive slots of the parameter array.

There is space allocated on the stack for all the slots necessary for a function's parameters, but some slots may be promoted to registers and thus the stack location may contain no value.

For 32-bit code, the parameter array starts at %fp+68 (after a save instruction, %sp+68 before), and the stack and frame pointers are aligned on a 64-bit (8 Byte) boundary. For 64-bit code, the parameter array starts at %fp+BIAS+128 (after a save instruction), and the stack and frame pointers are aligned on a 128-bit (16 Byte) boundary. For 64-bit code, BIAS is 2047. Parameters that are passed in registers also have a (unused) memory location corresponding to their slot(s).

Integer data types smaller then a slot are passed in the lower part of that slot. For 64-bit code, where a smaller integer type (int, short, char) parameter is passed in a register, the caller must sign extend or zero extend the value to the full 64-bit slot width. Similarly, in 64-bit code where a smaller integer type is returned in a register, the callee must sign extend or zero extend the value to the full 64-bit slot width. In 32-bit code, there is no requirement for sign or zero extensions, and only the lower bits of the values should be used.

Data types that are larger than the slot size are passed in multiple slots. For 32-bit code, double and long long data types are passed in 2 slots, and they are not aligned, but packed next to the previous parameter slot. For 32-bit code, values longer than a double are passed like passing a structure by value. For 64-bit code, double and long long data types occupy just one slot, but long double and double complex data occupy two slots, and these slots are aligned (slot number modulo 2 equals 0), skipping a slot if necessary for alignment.

The first six slots of the parameter array are always passed in registers. For 32-bit code, these slots always go into the lower 32-bits of registers %o0 to %o5, regardless of whether they are integer or floating-point values. For 64-bit code, these 6 slots go into the full 64-bits of registers %o0 to %o5 if they are integer types. The float, double, long double types are passed in the double registers %d0 to %d10, corresponding to slots 0 to 5.

The float complex, double complex, and long double complex data types are passed as though there were just two parameters of their base type. The imaginary types are passed the same as the plain float types. For 64-bit code, float, double, and long double data in slots 6-31 are passed in registers %d12 to %d62.

Structure, union, or array parameters passed by value are passed by making a copy on the stack and passing a pointer to the copy. The details of this kind of parameter passing are complicated and beyond the scope of this manual. Similarly, for functions returning a structure, union, or array by value, the caller allocates space for the return value and passes a pointer for that area to the callee. The callee puts there returned value into the designated area before returning. The details of this kind of return value code are also complicated and beyond the scope of this manual.