1 Copyright (C) 2005 Free Software Foundation, Inc.
3 Copying and distribution of this file, with or without modification,
4 are permitted in any medium without royalty provided the copyright
5 notice and this notice are preserved.
7 --------------------------------------------------------------------------
15 Type Size (bytes) Alignment (bytes)
27 * alignment within aggregates (structs and unions) is as above, with
28 padding added if needed
29 * aggregates have alignment equal to that of their most aligned
31 * aggregates have sizes which are a multiple of their alignment
37 All emulated using IEEE floating point conventions.
43 r1 argument register 1
44 r2 argument register 2
45 r3 argument register 3
46 r4 argument register 4
53 r11 function return value
59 Stack alignment 8 bytes
61 Structures passed <= 32 bits as values, else as pointers
66 Space is allocated as needed in the stack frame for the following at compile
69 * Outgoing parameters beyond the fourth
71 * All automatic arrays, automatic data aggregates, automatic
72 scalars which must be addressable, and automatic scalars for
73 which there is no room in registers
75 * Compiler-generated temporary values (typically when there are
76 too many for the compiler to keep them all in registers)
78 Space can be allocated dynamically (at runtime) in the stack frame for the
81 * Memory allocated using the alloca() function of the C library
83 Addressable automatic variables on the stack are addressed with positive
84 offsets relative to r12; dynamically allocated space is addressed with positive
85 offsets from the pointer returned by alloca().
90 +-----------------------+
92 +-----------------------+ <-sp
94 +-----------------------+
96 +-----------------------+
98 +-----------------------+
100 +-----------------------+
102 +-----------------------+ <-fp
104 +-----------------------+
106 +-----------------------+
108 +-----------------------+
110 +-----------------------+ <-sp
113 Parameter Assignment to Registers
114 ---------------------------------
116 Consider the parameters in a function call as ordered from left (first
117 parameter) to right. GR contains the number of the next available
118 general-purpose register. STARG is the address of the next available stack
122 Set GR=r1 and STARG to point to parameter word 1.
125 If there are no more parameters, terminate.
126 Otherwise, select one of the following depending on the type
127 of the next parameter:
131 A SIMPLE ARG is one of the following:
133 * One of the simple integer types which will fit into a
134 general-purpose register,
135 * A pointer to an object of any type,
136 * A struct or union small enough to fit in a register (<= 32 bits)
137 * A larger struct or union, which shall be treated as a
138 pointer to the object or to a copy of the object.
139 (See below for when copies are made.)
141 If GR > r4, go to STACK. Otherwise, load the parameter value into
142 general-purpose register GR and advance GR to the next general-purpose
143 register. Values shorter than the register size are sign-extended or
144 zero-extended depending on whether they are signed or unsigned. Then
149 If GR > r3, go to STACK. Otherwise, if GR is odd, advance GR to the
150 next register. Load the 64-bit long long or double value into register
151 pair GR and GR+1. Advance GR to GR+2 and go to SCAN.
155 Parameters not otherwise handled above are passed in the parameter
156 words of the caller's stack frame. SIMPLE ARGs, as defined above, are
157 considered to have size and alignment equal to the size of a
158 general-purpose register, with simple argument types shorter than this
159 sign- or zero-extended to this width. Round STARG up to a multiple of
160 the alignment requirement of the parameter and copy the argument
161 byte-for-byte into STARG, STARG+1, ... STARG+size-1. Set STARG to
162 STARG+size and go to SCAN.
168 As noted above, code which passes structures and unions by value is implemented
169 specially. (In this section, "struct" will refer to structs and unions
170 inclusively.) Structs small enough to fit in a register are passed by value in
171 a single register or in a stack frame slot the size of a register. Structs
172 containing a single double or long long component are passed by value in two
173 registers or in a stack frame slot the size of two registers. Other structs
174 are handled by passing the address of the structure. In this case, a copy of
175 the structure will be made if necessary in order to preserve the pass-by-value
178 Copies of large structs are made under the following rules:
182 Normal param Callee copies if needed Caller copies
183 Varargs (...) param Caller copies Caller copies
185 In the case of normal (non-varargs) large-struct parameters in ANSI mode, the
186 callee is responsible for producing the same effect as if a copy of the
187 structure were passed, preserving the pass-by-value semantics. This may be
188 accomplished by having the callee make a copy, but in some cases the callee may
189 be able to determine that a copy is not necessary in order to produce the same
190 results. In such cases, the callee may choose to avoid making a copy of the
197 No special changes are needed for handling varargs parameters other than the
198 caller knowing that a copy is needed on struct parameters larger than a
199 register (see above).
201 The varargs macros set up a register save area for the general-purpose
202 registers to be saved. Because the save area lies between the caller and
203 callee stack frames, the saved register parameters are contiguous with
204 parameters passed on the stack. A pointer advances from the register save area
205 into the caller's stack frame.
208 Function return values
209 ----------------------