7 Type Size (bytes) Alignment (bytes)
19 * alignment within aggregates (structs and unions) is as above, with
20 padding added if needed
21 * aggregates have alignment equal to that of their most aligned
23 * aggregates have sizes which are a multiple of their alignment
29 All emulated using IEEE floating point conventions.
38 %4 argument register 1
39 %5 argument register 2
40 %6 argument register 3
41 %7 argument register 4
42 %8 argument register 5
43 %9 argument register 6
44 %10 argument register 7
45 %11 argument register 8
67 Stack alignment 8 bytes
69 Structures passed <= 32 bits as values, else as pointers
74 Space is allocated as needed in the stack frame for the following at compile
77 * Outgoing parameters beyond the eighth
79 * All automatic arrays, automatic data aggregates, automatic
80 scalars which must be addressable, and automatic scalars for
81 which there is no room in registers
83 * Compiler-generated temporary values (typically when there are
84 too many for the compiler to keep them all in registers)
86 Space can be allocated dynamically (at runtime) in the stack frame for the
89 * Memory allocated using the alloca() function of the C library
91 Addressable automatic variables on the stack are addressed with positive
92 offsets relative to %27; dynamically allocated space is addressed with positive
93 offsets from the pointer returned by alloca().
98 +-----------------------+
99 | Caller memory args |
100 +-----------------------+ <-sp
102 +-----------------------+
104 +-----------------------+
106 +-----------------------+
108 +-----------------------+
110 +-----------------------+ <-fp
112 +-----------------------+
114 +-----------------------+
116 +-----------------------+
118 +-----------------------+ <-sp
121 Parameter Assignment to Registers
122 ---------------------------------
124 Consider the parameters in a function call as ordered from left (first
125 parameter) to right. GR contains the number of the next available
126 general-purpose register. STARG is the address of the next available stack
130 Set GR=r4 and STARG to point to parameter word 1.
133 If there are no more parameters, terminate.
134 Otherwise, select one of the following depending on the type
135 of the next parameter:
139 A SIMPLE ARG is one of the following:
141 * One of the simple integer types which will fit into a
142 general-purpose register,
143 * A pointer to an object of any type,
144 * A struct or union small enough to fit in a register (<= 32 bits)
145 * A larger struct or union, which shall be treated as a
146 pointer to the object or to a copy of the object.
147 (See below for when copies are made.)
149 If GR > r11, go to STACK. Otherwise, load the parameter value into
150 general-purpose register GR and advance GR to the next general-purpose
151 register. Values shorter than the register size are sign-extended or
152 zero-extended depending on whether they are signed or unsigned. Then
157 If GR > r10, go to STACK. Otherwise, if GR is odd, advance GR to the
158 next register. Load the 64-bit long long or double value into register
159 pair GR and GR+1. Advance GR to GR+2 and go to SCAN.
163 Parameters not otherwise handled above are passed in the parameter
164 words of the caller's stack frame. SIMPLE ARGs, as defined above, are
165 considered to have size and alignment equal to the size of a
166 general-purpose register, with simple argument types shorter than this
167 sign- or zero-extended to this width. Round STARG up to a multiple of
168 the alignment requirement of the parameter and copy the argument
169 byte-for-byte into STARG, STARG+1, ... STARG+size-1. Set STARG to
170 STARG+size and go to SCAN.
176 As noted above, code which passes structures and unions by value is implemented
177 specially. (In this section, "struct" will refer to structs and unions
178 inclusively.) Structs small enough to fit in a register are passed by value in
179 a single register or in a stack frame slot the size of a register. Structs
180 containing a single double or long long component are passed by value in two
181 registers or in a stack frame slot the size of two registers. Other structs
182 are handled by passing the address of the structure. In this case, a copy of
183 the structure will be made if necessary in order to preserve the pass-by-value
186 Copies of large structs are made under the following rules:
190 Normal param Callee copies if needed Caller copies
191 Varargs (...) param Caller copies Caller copies
193 In the case of normal (non-varargs) large-struct parameters in ANSI mode, the
194 callee is responsible for producing the same effect as if a copy of the
195 structure were passed, preserving the pass-by-value semantics. This may be
196 accomplished by having the callee make a copy, but in some cases the callee may
197 be able to determine that a copy is not necessary in order to produce the same
198 results. In such cases, the callee may choose to avoid making a copy of the
205 No special changes are needed for handling varargs parameters other than the
206 caller knowing that a copy is needed on struct parameters larger than a
207 register (see above).
209 The varargs macros set up a register save area for the general-purpose
210 registers to be saved. Because the save area lies between the caller and
211 callee stack frames, the saved register parameters are contiguous with
212 parameters passed on the stack. A pointer advances from the register save area
213 into the caller's stack frame.
216 Function return values
217 ----------------------
227 struct/union see below
229 Structs/unions which will fit into two general-purpose registers are returned
230 in r2, or in r2-r3 if necessary. Larger structs/unions are handled by the
231 caller passing as a "hidden" first argument a pointer to space allocated to
232 receive the return value.