0
|
1 %//////////////////////////////////////////////////////////////////////////////
|
|
2 %
|
|
3 % Copyright (c) 2007,2009 Daniel Adler <dadler@uni-goettingen.de>,
|
|
4 % Tassilo Philipp <tphilipp@potion-studios.com>
|
|
5 %
|
|
6 % Permission to use, copy, modify, and distribute this software for any
|
|
7 % purpose with or without fee is hereby granted, provided that the above
|
|
8 % copyright notice and this permission notice appear in all copies.
|
|
9 %
|
|
10 % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
11 % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12 % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
13 % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
14 % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
15 % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
16 % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
17 %
|
|
18 %//////////////////////////////////////////////////////////////////////////////
|
|
19
|
|
20 \subsection{MIPS Calling Convention}
|
|
21
|
|
22 \paragraph{Overview}
|
|
23
|
|
24 The MIPS family of processors is based on the MIPS processor architecture.
|
|
25 Multiple revisions of the MIPS Instruction set exist, namely MIPS I, MIPS II, MIPS III, MIPS IV, MIPS32 and MIPS64.
|
|
26 Today, MIPS32 and MIPS64 for 32-bit and 64-bit respectively.\\
|
|
27 Several add-on extensions exist for the MIPS family:
|
|
28
|
|
29 \begin{description}
|
|
30 \item [MIPS-3D] simple floating-point SIMD instructions dedicated to common 3D tasks.
|
|
31 \item [MDMX] (MaDMaX) more extensive integer SIMD instruction set using 64 bit floating-point registers.
|
|
32 \item [MIPS16e] adds compression to the instruction stream to make programs take up less room (allegedly a response to the THUMB instruction set of the ARM architecture).
|
|
33 \item [MIPS MT] multithreading additions to the system similar to HyperThreading.
|
|
34 \end{description}
|
|
35
|
|
36 Unfortunately, there is actually no such thing as "The MIPS Calling Convention". Many possible conventions are used
|
98
|
37 by many different environments such as \emph{O32}\cite{MIPSo32}, \emph{O64}, \emph{N32}, \emph{N64} and \emph{EABI}.\\
|
0
|
38
|
|
39 \paragraph{\product{dyncall} support}
|
|
40
|
|
41 Currently, dyncall supports the EABI calling convention which is used on the Homebrew SDK for the Playstation Portable.
|
95
|
42 As documentation for this EABI is unofficial, this port is currently experimental. It also supports O32, N32 and N64.
|
0
|
43
|
|
44 \subsubsection{MIPS EABI 32-bit Calling Convention}
|
|
45
|
|
46 \paragraph{Register usage}
|
|
47
|
|
48 \begin{table}[h]
|
77
|
49 \begin{tabular*}{0.95\textwidth}{lll}
|
0
|
50 Name & Alias & Brief description\\
|
|
51 \hline
|
|
52 {\bf \$0} & {\bf \$zero} & Hardware zero \\
|
|
53 {\bf \$1} & {\bf \$at} & Assembler temporary \\
|
|
54 {\bf \$2-\$3} & {\bf \$v0-\$v1} & Integer results \\
|
|
55 {\bf \$4-\$11} & {\bf \$a0-\$a7} & Integer arguments\\
|
|
56 {\bf \$12-\$15,\$24,\$25} & {\bf \$t4-\$t7,\$t8,\$t9} & Integer temporaries \\
|
|
57 {\bf \$25} & {\bf \$t9} & Integer temporary, hold the address of the called function for all PIC calls (by convention) \\
|
|
58 {\bf \$16-\$23} & {\bf \$s0-\$s7} & Preserved \\
|
|
59 {\bf \$26,\$27} & {\bf \$kt0,\$kt1} & Reserved for kernel \\
|
|
60 {\bf \$28} & {\bf \$gp} & Global pointer \\
|
|
61 {\bf \$29} & {\bf \$sp} & Stack pointer \\
|
|
62 {\bf \$30} & {\bf \$s8} & Frame pointer \\
|
|
63 {\bf \$31} & {\bf \$ra} & Return address \\
|
|
64 {\bf hi, lo} & & Multiply/divide special registers \\
|
|
65 {\bf \$f0,\$f2} & & Float results \\
|
|
66 {\bf \$f1,\$f3,\$f4-\$f11,\$f20-\$f23} & & Float temporaries \\
|
|
67 {\bf \$f12-\$f19} & & Float arguments \\
|
76
|
68 \end{tabular*}
|
98
|
69 \caption{Register usage on MIPS32 EABI calling convention}
|
0
|
70 \end{table}
|
|
71
|
|
72 \paragraph{Parameter passing}
|
|
73
|
|
74 \begin{itemize}
|
98
|
75 \item Stack grows down
|
0
|
76 \item Stack parameter order: right-to-left
|
|
77 \item Caller cleans up the stack
|
|
78 \item Stack always aligned to 8 bytes.
|
|
79 \item first 8 integers and floats are passed independently in registers using \$a0-\$a7 and \$f12-\$f19, respectively.
|
|
80 \item if either integer or float registers are consumed up, the stack is used.
|
|
81 \item 64-bit floats and integers are passed on two integer registers starting at an even register number, probably skipping one odd register.
|
|
82 \item \$a0-\$a7 and \$f12-\$f19 are not required to be preserved.
|
98
|
83 \item results are returned in \$v0 (32-bit), \$v0 and \$v1 (64-bit), \$f0 (32 bit float) and \$f0 and \$f2 (2 $\times$ 32 bit float e.g. complex).
|
0
|
84 \end{itemize}
|
|
85
|
|
86 \paragraph{Stack layout}
|
|
87
|
|
88 Stack directly after function prolog:\\
|
|
89
|
|
90 \begin{figure}[h]
|
|
91 \begin{tabular}{5|3|1 1}
|
|
92 \hhline{~-~~}
|
92
|
93 & \vdots & & \\
|
|
94 \hhline{~=~~}
|
|
95 register save area & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
|
96 \hhline{~-~~}
|
|
97 local data & & & \\
|
|
98 \hhline{~-~~}
|
|
99 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
100 & \ldots & & \\
|
|
101 & \ldots & & \\
|
0
|
102 \hhline{~=~~}
|
92
|
103 register save area (with return address) & & & \mrrbrace{5}{current frame} \\
|
0
|
104 \hhline{~-~~}
|
92
|
105 local data & & & \\
|
0
|
106 \hhline{~-~~}
|
92
|
107 parameter area & & & \\
|
0
|
108 \hhline{~-~~}
|
92
|
109 & \vdots & & \\
|
0
|
110 \hhline{~-~~}
|
|
111 \end{tabular}
|
|
112 \caption{Stack layout on mips32 eabi calling convention}
|
|
113 \end{figure}
|
|
114
|
98
|
115 \newpage
|
|
116
|
95
|
117 \subsubsection{MIPS O32 32-bit Calling Convention}
|
|
118
|
98
|
119 \paragraph{Register usage}
|
|
120
|
|
121 \begin{table}[h]
|
|
122 \begin{tabular*}{0.95\textwidth}{lll}
|
|
123 Name & Alias & Brief description\\
|
|
124 \hline
|
|
125 {\bf \$0} & {\bf \$zero} & Hardware zero \\
|
|
126 {\bf \$1} & {\bf \$at} & Assembler temporary \\
|
|
127 {\bf \$2-\$3} & {\bf \$v0-\$v1} & Integer results, scratch \\
|
|
128 {\bf \$4-\$7} & {\bf \$a0-\$a3} & Integer arguments, scratch\\
|
|
129 {\bf \$8-\$15,\$24,\$25} & {\bf \$t0-\$t7,\$t8,\$t9} & Integer temporaries, scratch \\
|
|
130 {\bf \$16-\$23} & {\bf \$s0-\$s7} & Preserved \\
|
|
131 {\bf \$26,\$27} & {\bf \$k0,\$k1} & Reserved for kernel \\
|
|
132 {\bf \$28} & {\bf \$gp} & Global pointer, preserve \\
|
|
133 {\bf \$29} & {\bf \$sp} & Stack pointer, preserve \\
|
|
134 {\bf \$30} & {\bf \$fp} & Frame pointer, preserve \\
|
|
135 {\bf \$31} & {\bf \$ra} & Return address \\
|
|
136
|
|
137
|
|
138 \end{tabular*}
|
|
139 \caption{Register usage on MIPS O32 calling convention}
|
|
140 \end{table}
|
|
141
|
|
142 \paragraph{Parameter passing}
|
|
143
|
|
144 \begin{itemize}
|
|
145 \item Stack grows down
|
|
146 \item Stack parameter order: right-to-left
|
|
147 \item Caller cleans up the stack
|
|
148 \item The different stack areas (e.g. parameter area, register save area, ...) are always aligned to 8 bytes.
|
|
149 \item first 4 32bit arguments are passed in registers \$a0-\$a3, respectively
|
|
150 \item subsequent parameters are passed vie the stack
|
|
151 \item @@@unsure... 64-bit floats and integers are passed on two integer registers starting at an even register number, probably skipping one odd register.
|
|
152 \item results are returned in \$v0 (32-bit integer), \$v0 and \$v1 (64-bit integer/float)
|
99
|
153 \item note that only s? registers that are modified by the function are required to be preserved on save area
|
98
|
154 \end{itemize}
|
|
155
|
|
156 \paragraph{Stack layout}
|
|
157
|
|
158 Stack directly after function prolog:\\
|
|
159
|
|
160 \begin{figure}[h]
|
|
161 \begin{tabular}{5|3|1 1}
|
|
162 \hhline{~-~~}
|
|
163 & \vdots & & \\
|
|
164 \hhline{~=~~}
|
|
165 local data & \hspace{4cm} & & \mrrbrace{12}{caller's frame} \\
|
|
166 \hhline{~-~~}
|
|
167 register save area & return address & & \\
|
|
168 & s7 & & \\
|
|
169 & \vdots & & \\
|
|
170 & s0 & & \\
|
|
171 \hhline{~-~~}
|
|
172 \mrlbrace{7}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
173 & \ldots & & \\
|
|
174 & \ldots & & \\
|
|
175 & a3 & \mrrbrace{4}{spill area} & \\
|
|
176 & a2 & & \\
|
|
177 & a1 & & \\
|
|
178 & a0 & & \\
|
|
179 \hhline{~=~~}
|
|
180 local data & & & \mrrbrace{5}{current frame} \\
|
|
181 \hhline{~-~~}
|
|
182 register save area (with return address) & & & \\
|
|
183 \hhline{~-~~}
|
|
184 parameter area & & & \\
|
|
185 & \vdots & & \\
|
|
186 \hhline{~-~~}
|
|
187 \end{tabular}
|
|
188 \caption{Stack layout on MIPS O32 calling convention}
|
|
189 \end{figure}
|
|
190
|
|
191 \newpage
|
95
|
192
|
|
193 \subsubsection{MIPS N32 32-bit Calling Convention}
|
|
194
|
|
195 @@@
|
|
196
|