Passo intermediario, ainda falta um longo caminho
[pspdecompiler.git] / docs / eabi.txt
blob13910a96a28204d90b14268764f0835350bf3dee
1 This is it unfortunately... :)
3                         MIPS EABI
4                         =========
6 Sizes and alignments
7 --------------------
9         Type            Size (bytes)    Alignment (bytes)
11         char            1               1
12         short           2               2
13         int             4               4
14         unsigned        4               4
15         long            4               4 (32-bit mode)
16                         8               8 (64-bit mode)
17         long long       8               8
18         float           4               4
19         double          8               8
20         pointers        4               4 (32-bit mode)
21                         8               8 (64-bit mode)
23 * alignment within aggregates (structs and unions) is as above, with
24   padding added if needed
25 * aggregates have alignment equal to that of their most aligned
26   member
27 * aggregates have sizes which are a multiple of their alignment
30 Subroutine calls
31 ----------------
33 Parameter registers:
34     general-purpose     r4-r11
35     floating point      f12-f19
37 Register usage:
38     fixed 0 value       r0
39     volatile            r1-r15, r24, r25
40     non-volatile        r16-r23, r30
41     kernel reserved     r26, r27
42     gp (SDA base)       r28
43     stack pointer       r29
44     frame pointer       r30 (if needed)
45     return address      r31
47 Stack alignment         8 bytes
49 Parameter register allocation integer/floating independently (see below)
51 Structures passed       <= 32 bits as values, else as pointers
53 Homing area             none
56 Stack Frame
57 -----------
59         +-----------------------+
60         |    Saved Registers    |
61         +-----------------------+
62         |        ...            |
63         +-----------------------+
64         |    Local Variables    |
65         +-----------------------+
66         |        ...            |
67         +-----------------------+
68         |   Parameter Word 2    |
69         +-----------------------+
70 SP -->  |   Parameter Word 1    |
71         +-----------------------+
74 Parameter Assignment to Registers
75 ---------------------------------
77 Consider the parameters in a function call as ordered from left (first
78 parameter) to right.  In this algorithm, FR contains the number of the
79 next available floating-point register (or register pair for modes in
80 which floating-point registers hold only 32 bits).  GR contains the
81 number of the next available general-purpose register.  STARG is the
82 address of the next available stack parameter word.
84 INITIALIZE:
85         Set GR=r4, FR=f12, and STARG to point to parameter word 1.
87 SCAN:
88         If there are no more parameters, terminate.
89         Otherwise, select one of the following depending on the type
90         of the next parameter:
92     DOUBLE OR FLOAT:
94         If FR > f19, go to STACK.  Otherwise, load the parameter value
95         into floating-point register FR and advance FR to the next
96         floating-point register (or register pair in 32-bit mode).
97         Then go to SCAN.
99     SIMPLE ARG:
101         A SIMPLE ARG is one of the following:
103         * One of the simple integer types which will fit into a
104           general-purpose register,
105         * A pointer to an object of any type,
106         * A struct or union small enough to fit in a register
107           (<= 32 bits in 32-bit mode, <= 64 bits in 64-bit mode)
108         * A larger struct or union, which shall be treated as a
109           pointer to the object or to a copy of the object.
110           (See below for when copies are made.)
112         If GR > r11, go to STACK.  Otherwise, load the parameter
113         value into general-purpose register GR and advance GR
114         to the next general-purpose register.  Values shorter than
115         the register size are sign-extended or zero-extended depending
116         on whether they are signed or unsigned.  Then go to SCAN.
118     LONG LONG in 32-bit mode:
120         If GR > r10, go to STACK.  Otherwise, if GR is odd, advance
121         GR to the next register.  Load the 64-bit long long value into
122         register pair GR and GR+1.  Advance GR to GR+2 and go to SCAN.
124     STACK:
126         Parameters not otherwise handled above are passed in the
127         parameter words of the caller's stack frame.  SIMPLE ARGs,
128         as defined above, are considered to have size and alignment
129         equal to the size of a general-purpose register, with
130         simple argument types shorter than this sign- or zero-extended
131         to this width.  float arguments are considered to have size
132         and alignment equal to the size of a floating-point register.
133         In 64-bit mode, floats are stored in the low-order 32 bits
134         of the 64-bit space allocated to them.  double and long long
135         are considered to have 64-bit size and alignment.  Round
136         STARG up to a multiple of the alignment requirement of
137         the parameter and copy the argument byte-for-byte into
138         STARG, STARG+1, ... STARG+size-1.  Set STARG to STARG+size
139         and go to SCAN.
142 Structure passing
143 -----------------
145 As noted above, code which passes structures and unions by value is
146 implemented specially.  (In this section, "struct" will refer to
147 structs and unions inclusively.)  Structs small enough to fit in a
148 register are passed by value in a single register or in a stack frame
149 slot the size of a register.  Larger structs are handled by passing
150 the address of the structure.  In this case, a copy of the structure
151 will be made if necessary in order to preserve the pass-by-value
152 semantics.
154 Copies of large structs are made under the following rules:
156                         ANSI mode                       K&R Mode
157                         ---------                       --------
158 Normal param            Callee copies if needed         Caller copies
159 Varargs (...) param     Caller copies                   Caller copies
161 In the case of normal (non-varargs) large-struct parameters in ANSI
162 mode, the callee is responsible for producing the same effect as if a
163 copy of the structure were passed, preserving the pass-by-value
164 semantics.  This may be accomplished by having the callee make a copy,
165 but in some cases the callee may be able to determine that a copy is
166 not necessary in order to produce the same results.  In such cases,
167 the callee may choose to avoid making a copy of the parameter.
170 Varargs handling
171 ----------------
173 No special changes are needed for handling varargs parameters other
174 than the caller knowing that a copy is needed on struct parameters
175 larger than a register (see above).
177 The varargs macros set up a two-part register save area, one part for
178 the general-purpose registers and one part for floating-point
179 registers, and maintain separate pointers for these two areas and for
180 the stack parameter area.  The register save area lies between the
181 caller and callee stack frame areas.
183 In the case of software floating-point only the general-purpose
184 registers need to be saved.  Because the save area lies between the
185 two stack frames, the saved register parameters are contiguous with
186 parameters passed on the stack.  This allows the varargs macros to be
187 much simpler.  Only one pointer is needed, which advances from the
188 register save area into the caller's stack frame.
191 Function return values
192 ----------------------
194         Type            Register
195         ----            --------
196         int             r2
197         short           r2
198         long            r2
199         long long       r2-r3 (32-bit mode)
200                         r2    (64-bit mode)
201         float           f0
202         double          f0-f1 (32-bit mode)
203                         f0    (64-bit mode)
204         struct/union    see below
206 Structs/unions which will fit into two general-purpose registers are
207 returned in r2, or in r2-r3 if necessary.  They are aligned within the
208 register according to the endianness of the processor; e.g. on a
209 big-endian processor the first byte of the struct is returned in the
210 most significant byte of r2, while on a little-endian processor the
211 first byte is returned in the least significant byte of r2.  Larger
212 structs/unions are handled by the caller passing as a "hidden" first
213 argument a pointer to space allocated to receive the return value.
216 Software floating-point
217 -----------------------
219 For software floating-point implementations, floats shall be passed
220 and returned like ints, and doubles shall be passed and returned like
221 long longs.
223 This implies that, in 32-bit mode, floats will be passed in a single
224 integer register and doubles will be passed in an even/odd register
225 pair.  Similarly, floats will be returned in a single register, r2,
226 and doubles will be returned in register pair r2-r3.