annotate doc/manual/callconvs/callconv_mips32.tex @ 304:6869d834a847

- mips32 doc
author Tassilo Philipp
date Wed, 23 May 2018 11:39:40 +0200
parents d55f9d508074
children b104c5beec8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 %//////////////////////////////////////////////////////////////////////////////
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 % Copyright (c) 2007,2009 Daniel Adler <dadler@uni-goettingen.de>,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 % Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 % Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 % purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 % copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 %
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 %//////////////////////////////////////////////////////////////////////////////
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
20 \subsection{MIPS32 Calling Convention}
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 \paragraph{Overview}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 Multiple revisions of the MIPS Instruction set exist, namely MIPS I, MIPS II, MIPS III, MIPS IV, MIPS32 and MIPS64.
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
25 Nowadays, MIPS32 and MIPS64 are the main ones used for 32-bit and 64-bit instruction sets, respectively.\\
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
26 Given MIPS processors are often used for embedded devices, several add-on extensions exist for the MIPS family, for example:
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 \begin{description}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 \item [MIPS-3D] simple floating-point SIMD instructions dedicated to common 3D tasks.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 \item [MDMX] (MaDMaX) more extensive integer SIMD instruction set using 64 bit floating-point registers.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 \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).
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 \item [MIPS MT] multithreading additions to the system similar to HyperThreading.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 \end{description}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
35 Unfortunately, there is actually no such thing as "The MIPS Calling Convention". Many possible conventions are used
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
36 by many different environments such as \emph{O32}\cite{MIPSo32}, \emph{O64}\cite{MIPSo64}, \emph{N32}\cite{MIPSn32/n64}, \emph{N64}\cite{MIPSn32/n64}, \emph{EABI}\cite{MIPSeabi} and \emph{NUBI}\cite{MIPSnubi}.\\
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 \paragraph{\product{dyncall} support}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
40 Currently, dyncall supports for MIPS 32-bit architectures the widely-used O32 calling convention (for all four combinations of big/little-endian, and soft/hard-float targets),
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
41 as well as EABI (little-endian/hard-float, which is used on the Homebrew SDK for the Playstation Portable). \product{dyncall} currently does not support MIPS16e
139
5675d34f0a06 - mips64 doc about impl status
cslag
parents: 117
diff changeset
42 (contrary to the like-minded ARM-THUMB, which is supported). Both, calls and callbacks are supported.
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 \subsubsection{MIPS EABI 32-bit Calling Convention}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 \paragraph{Register usage}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 \begin{table}[h]
77
e441ef3ec782 - manual layout tweaks
cslag
parents: 76
diff changeset
49 \begin{tabular*}{0.95\textwidth}{lll}
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
50 Name & Alias & Brief description\\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
51 \hline
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
52 {\bf \$0} & {\bf \$zero} & Hardware zero \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
53 {\bf \$1} & {\bf \$at} & Assembler temporary \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
54 {\bf \$2-\$3} & {\bf \$v0-\$v1} & Integer results \\
110
9aa75a74614c - working mips32 eabi callbacks
cslag
parents: 108
diff changeset
55 {\bf \$4-\$11} & {\bf \$a0-\$a7} & Integer arguments, or double precision float arguments\\
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
56 {\bf \$12-\$15,\$24} & {\bf \$t4-\$t7,\$t8} & Integer temporaries \\
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
57 {\bf \$25} & {\bf \$t9} & Integer temporary, holds address of called function for PIC calls (by convention) \\
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
58 {\bf \$16-\$23} & {\bf \$s0-\$s7} & Preserved \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
59 {\bf \$26,\$27} & {\bf \$kt0,\$kt1} & Reserved for kernel \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
60 {\bf \$28} & {\bf \$gp} & Global pointer, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
61 {\bf \$29} & {\bf \$sp} & Stack pointer, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
62 {\bf \$30} & {\bf \$s8} & Frame pointer, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
63 {\bf \$31} & {\bf \$ra} & Return address, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
64 {\bf hi, lo} & & Multiply/divide special registers \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
65 {\bf \$f0,\$f2} & & Float results \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
66 {\bf \$f1,\$f3,\$f4-\$f11,\$f20-\$f23} & & Float temporaries \\
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
67 {\bf \$f12-\$f19} & & Single precision float arguments \\
76
7ca46969e0ad - tweaks in manual, mainly for html generation
cslag
parents: 0
diff changeset
68 \end{tabular*}
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
69 \caption{Register usage on MIPS32 EABI calling convention}
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 \end{table}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 \paragraph{Parameter passing}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 \begin{itemize}
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
75 \item Stack grows down
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 \item Stack parameter order: right-to-left
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 \item Caller cleans up the stack
190
06ee88ce4962 - doc and comment fixes
Tassilo Philipp
parents: 139
diff changeset
78 \item first 8 integers (\textless=\ 32bit) are passed in registers \$a0-\$a7
110
9aa75a74614c - working mips32 eabi callbacks
cslag
parents: 108
diff changeset
79 \item first 8 single precision floating point arguments are passed in registers \$f12-\$f19
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
80 \item if either integer or float registers are used up, the stack is used
111
6da2a7ee2a86 - doc updates for mips32
cslag
parents: 110
diff changeset
81 \item 64-bit stack arguments are always aligned to 8 bytes
110
9aa75a74614c - working mips32 eabi callbacks
cslag
parents: 108
diff changeset
82 \item 64-bit integers or double precision floats are passed on two general purpose registers starting at an even register number, skipping one odd register
9aa75a74614c - working mips32 eabi callbacks
cslag
parents: 108
diff changeset
83 \item \$a0-\$a7 and \$f12-\$f19 are not required to be preserved
9aa75a74614c - working mips32 eabi callbacks
cslag
parents: 108
diff changeset
84 \item results are returned in \$v0 (32-bit), \$v0 and \$v1 (64-bit), \$f0 or \$f0 and \$f2 (2 $\times$ 32 bit float e.g. complex)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 \end{itemize}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87 \paragraph{Stack layout}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 Stack directly after function prolog:\\
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 \begin{figure}[h]
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 \begin{tabular}{5|3|1 1}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 \hhline{~-~~}
92
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
94 & \vdots & & \\
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
95 \hhline{~=~~}
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
96 register save area & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
97 \hhline{~-~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
98 local data & & & \\
92
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
99 \hhline{~-~~}
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
100 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
101 & \ldots & & \\
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
102 & \ldots & & \\
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 \hhline{~=~~}
92
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
104 register save area (with return address) & & & \mrrbrace{5}{current frame} \\
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 \hhline{~-~~}
92
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
106 local data & & & \\
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 \hhline{~-~~}
92
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
108 parameter area & & & \\
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 \hhline{~-~~}
92
5c3fa8897e0e - manual work
cslag
parents: 90
diff changeset
110 & \vdots & & \\
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 \hhline{~-~~}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 \end{tabular}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 \caption{Stack layout on mips32 eabi calling convention}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 \end{figure}
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
116 \newpage
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
117
95
9e99918065e6 - doc fixes (mainly for html output)
cslag
parents: 92
diff changeset
118 \subsubsection{MIPS O32 32-bit Calling Convention}
9e99918065e6 - doc fixes (mainly for html output)
cslag
parents: 92
diff changeset
119
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
120 \paragraph{Register usage}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
121
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
122 \begin{table}[h]
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
123 \begin{tabular*}{0.95\textwidth}{lll}
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
124 Name & Alias & Brief description\\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
125 \hline
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
126 {\bf \$0} & {\bf \$zero} & hardware zero \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
127 {\bf \$1} & {\bf \$at} & assembler temporary \\
304
6869d834a847 - mips32 doc
Tassilo Philipp
parents: 302
diff changeset
128 {\bf \$2-\$3} & {\bf \$v0-\$v1} & return value (only integer on hard-float targets), scratch \\
6869d834a847 - mips32 doc
Tassilo Philipp
parents: 302
diff changeset
129 {\bf \$4-\$7} & {\bf \$a0-\$a3} & first arguments (only integer on hard-float targets), scratch\\
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
130 {\bf \$8-\$15,\$24} & {\bf \$t0-\$t7,\$t8} & temporaries, scratch \\
304
6869d834a847 - mips32 doc
Tassilo Philipp
parents: 302
diff changeset
131 {\bf \$25} & {\bf \$t9} & temporary, holds address of called function for PIC calls (by convention) \\
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
132 {\bf \$16-\$23} & {\bf \$s0-\$s7} & preserved \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
133 {\bf \$26,\$27} & {\bf \$k0,\$k1} & reserved for kernel \\
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
134 {\bf \$28} & {\bf \$gp} & global pointer, preserved by caller \\
108
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
135 {\bf \$29} & {\bf \$sp} & stack pointer, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
136 {\bf \$30} & {\bf \$fp} & frame pointer, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
137 {\bf \$31} & {\bf \$ra} & return address, preserve \\
bf8aef292216 - mips clarifications in doc
cslag
parents: 104
diff changeset
138 {\bf hi, lo} & & multiply/divide special registers \\
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
139 {\bf \$f0-\$f3} & & only on hard-float targets: float return value, scratch \\
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
140 {\bf \$f4-\$f11,\$f16-\$f19} & & only on hard-float targets: float temporaries, scratch \\
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
141 {\bf \$f12-\$f15} & & only on hard-float targets: first floating point arguments, scratch \\
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
142 {\bf \$f20-\$f31} & & only on hard-float targets: preserved \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
143 \end{tabular*}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
144 \caption{Register usage on MIPS O32 calling convention}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
145 \end{table}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
146
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
147 \paragraph{Parameter passing}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
148
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
149 \begin{itemize}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
150 \item Stack grows down
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
151 \item Stack parameter order: right-to-left
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
152 \item Caller cleans up the stack
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
153 \item Caller is required to always leave a 16-byte spill area for \$a0-\$a3 at the and of {\bf its} frame, to be used and spilled to by the callee, if needed
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
154 \item The different stack areas (local data, register save area, parameter area) are each aligned to 8 bytes
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
155 \item generally, first four 32bit arguments are passed in registers \$a0-\$a3, respectively (only on hard-float targets: see below for exceptions if first arg is a float)
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
156 \item subsequent parameters are passed vie the stack
104
dbca6763f2be - complete, working mips o32 callback (using hardware fp); fixes error from last commit, which ignored first 2 float args
cslag
parents: 101
diff changeset
157 \item 64-bit params passed via registers are passed using either two registers (starting at an even register number, skipping an odd one if necessary), or via the stack using an 8-byte alignment
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
158 \item only on hard-float targets: if the very first call argument is a float, up to 2 floats or doubles can be passed via \$f12 and \$f14, respectively, for first and second argument
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
159 \item only on hard-float targets: if any arguments are passed via float registers, skip \$a0-\$a3 for subsequent arguments as if the values were passed via them
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
160 \item only on hard-float targets: note that if the first argument is not a float, but the second, it'll get passed via the \$a? registers
304
6869d834a847 - mips32 doc
Tassilo Philipp
parents: 302
diff changeset
161 \item results are returned in \$v0 and \$v1, with \$v0 for all values < 64bit (only integer on hard-float targets)
302
d55f9d508074 - mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents: 200
diff changeset
162 \item only on hard-float targets: floating point results are returned in \$f0 (32-bit float), or \$f0 and \$f3 (64bit float)
304
6869d834a847 - mips32 doc
Tassilo Philipp
parents: 302
diff changeset
163 \item single precision float parameters (32 bit) are right-justified in their 8-byte slot on the stack on big endian targets, as they aren't promoted @@@
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
164 \end{itemize}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
165
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
166 \paragraph{Stack layout}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
167
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
168 Stack directly after function prolog:\\
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
169
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
170 \begin{figure}[h]
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
171 \begin{tabular}{5|3|1 1}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
172 \hhline{~-~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
173 & \vdots & & \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
174 \hhline{~=~~}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
175 local data & \hspace{4cm} & & \mrrbrace{12}{caller's frame} \\
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
176 \hhline{~-~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
177 register save area & return address & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
178 & s7 & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
179 & \vdots & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
180 & s0 & & \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
181 \hhline{~-~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
182 \mrlbrace{7}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
183 & \ldots & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
184 & \ldots & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
185 & a3 & \mrrbrace{4}{spill area} & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
186 & a2 & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
187 & a1 & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
188 & a0 & & \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
189 \hhline{~=~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
190 local data & & & \mrrbrace{5}{current frame} \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
191 \hhline{~-~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
192 register save area (with return address) & & & \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
193 \hhline{~-~~}
117
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
194 parameter area & & & \\
4a64b733dc76 - doc, added first version of mips64 callconv page
cslag
parents: 111
diff changeset
195 & \vdots & & \\
98
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
196 \hhline{~-~~}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
197 \end{tabular}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
198 \caption{Stack layout on MIPS O32 calling convention}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
199 \end{figure}
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
200
db0b2f19e165 - MIPS o32 manual appendix
cslag
parents: 95
diff changeset
201 \newpage
95
9e99918065e6 - doc fixes (mainly for html output)
cslag
parents: 92
diff changeset
202