annotate doc/manual/callconvs/callconv_mips32.tex @ 499:fc614cb865c6

- doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
author Tassilo Philipp
date Mon, 04 Apr 2022 15:50:52 +0200
parents a55506bf924e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
1 %//////////////////////////////////////////////////////////////////////////////
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
2 %
478
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
3 % Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
4 % Tassilo Philipp <tphilipp@potion-studios.com>
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
5 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
6 % Permission to use, copy, modify, and distribute this software for any
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
7 % purpose with or without fee is hereby granted, provided that the above
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
8 % copyright notice and this permission notice appear in all copies.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
9 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
10 % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
11 % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
12 % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
13 % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
14 % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
15 % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
16 % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
17 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
18 %//////////////////////////////////////////////////////////////////////////////
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
19
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
20 \subsection{MIPS32 Calling Conventions}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
21
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
22 \paragraph{Overview}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
23
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
24 Multiple revisions of the MIPS Instruction set exist, namely MIPS I, MIPS II, MIPS III, MIPS IV, MIPS32 and MIPS64.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
25 Nowadays, MIPS32 and MIPS64 are the main ones used for 32-bit and 64-bit instruction sets, respectively.\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
26 Given MIPS processors are often used for embedded devices, several add-on extensions exist for the MIPS family, for example:
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
27
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
28 \begin{description}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
29 \item [MIPS-3D] simple floating-point SIMD instructions dedicated to common 3D tasks.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
30 \item [MDMX] (MaDMaX) more extensive integer SIMD instruction set using 64 bit floating-point registers.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
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).
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
32 \item [MIPS MT] multithreading additions to the system similar to HyperThreading.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
33 \end{description}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
34
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
35 Unfortunately, there is actually no such thing as "The MIPS Calling Convention". Many possible conventions are used
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
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}.\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
37
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
38 \paragraph{\product{dyncall} support}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
39
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
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),
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
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
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
42 (contrary to the like-minded ARM-THUMB, which is supported). Both, calls and callbacks are supported.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
43
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
44
467
b47168dacba6 manual:
Tassilo Philipp
parents: 328
diff changeset
45 \clearpage
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
46
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
47
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
48 \subsubsection{MIPS EABI 32-bit Calling Convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
49
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
50 % This is about hardware floating point targtes, there are also softfloat ones @@@
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
51
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
52 \paragraph{Register usage}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
53
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
54 \begin{table}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
55 \begin{tabular*}{0.95\textwidth}{lll}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
56 Name & Alias & Brief description\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
57 \hline
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
58 {\bf \$0} & {\bf \$zero} & hardware zero, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
59 {\bf \$1} & {\bf \$at} & assembler temporary, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
60 {\bf \$2-\$3} & {\bf \$v0-\$v1} & integer results, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
61 {\bf \$4-\$11} & {\bf \$a0-\$a7} & integer arguments, or double precision float arguments, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
62 {\bf \$12-\$15,\$24} & {\bf \$t4-\$t7,\$t8} & integer temporaries, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
63 {\bf \$25} & {\bf \$t9} & integer temporary, address of callee for PIC calls (by convention), scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
64 {\bf \$16-\$23} & {\bf \$s0-\$s7} & preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
65 {\bf \$26,\$27} & {\bf \$kt0,\$kt1} & reserved for kernel \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
66 {\bf \$28} & {\bf \$gp} & global pointer, preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
67 {\bf \$29} & {\bf \$sp} & stack pointer, preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
68 {\bf \$30} & {\bf \$s8/\$fp} & frame pointer (some assemblers name it \$fp), preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
69 {\bf \$31} & {\bf \$ra} & return address, preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
70 {\bf hi, lo} & & multiply/divide special registers \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
71 {\bf \$f0,\$f2} & & float results, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
72 {\bf \$f1,\$f3,\$f4-\$f11,\$f20-\$f23} & & float temporaries, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
73 {\bf \$f12-\$f19} & & single precision float arguments, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
74 \end{tabular*}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
75 \caption{Register usage on MIPS32 EABI calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
76 \end{table}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
77
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
78 \paragraph{Parameter passing}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
79
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
80 \begin{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
81 \item Stack grows down
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
82 \item Stack parameter order: right-to-left
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
83 \item Caller cleans up the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
84 \item first 8 integers (\textless=\ 32bit) are passed in registers \$a0-\$a7
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
85 \item first 8 single precision floating point arguments are passed in registers \$f12-\$f19
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
86 \item 64-bit stack arguments are always aligned to 8 bytes
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
87 \item 64-bit integers or double precision floats are passed in two general purpose registers starting at an even register number, skipping one odd register
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
88 \item if either integer or float registers are used up, the stack is used
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
89 \item if the callee takes the address of one of the parameters and uses it to address other unnamed parameters (e.g. varargs) it has to copy - in its prolog - the the argument registers to a reserved stack area adjacent to the other parameters on the stack (only the unnamed integer parameters require saving, though) % @@@ seems to *ONLY* spill with varargs, never for any other reason
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
90 \item float registers don't seem to ever need to be saved that way, because floats passed to an ellipsis function are promoted to doubles, which in turn are passed in a? register pairs, so only \$a0-\$a7 are need to be spilled
479
a55506bf924e - mips32/eabi doc: adding info about aggregates
Tassilo Philipp
parents: 478
diff changeset
91 \item aggregates (struct, union) \textless=\ 32bit are passed like an integer
499
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
92 \item {\it non-trivial} C++ aggregates (as defined by the language) of any size, are passed indirectly via a pointer to a copy of the aggregate
479
a55506bf924e - mips32/eabi doc: adding info about aggregates
Tassilo Philipp
parents: 478
diff changeset
93 \item all other aggregates (struct, union) are passed indirectly, as a pointer to a copy (if needed, and for vararg arguments required to be copied by the caller) of the struct
478
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
94 \end{itemize}
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
95
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
96 \paragraph{Return values}
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
97
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
98 \begin{itemize}
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
99 \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)
499
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
100 \item for {\it non-trivial} C++ aggregates, the caller allocates space, passes pointer to it to the callee as a hidden first param
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
101 (meaning in \%a0), and callee writes return value to this space; the ptr to the aggregate is returned in \%v0
479
a55506bf924e - mips32/eabi doc: adding info about aggregates
Tassilo Philipp
parents: 478
diff changeset
102 \item aggregates (struct, union) \textless=\ 64bit are returned like an integer (aligned within the register according to endianness)
a55506bf924e - mips32/eabi doc: adding info about aggregates
Tassilo Philipp
parents: 478
diff changeset
103 \item all other aggregates (struct, union) are returned in a space allocated by the caller, with a pointer to it
499
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
104 passed as first parameter to the function called (meaning in \%a0); the ptr to the aggregate is returned in \%v0
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
105 \end{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
106
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
107 \paragraph{Stack layout}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
108
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
109 % verified/amended: TP nov 2019 (see also doc/disas_examples/mips.eabi.disas)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
110 Stack directly after function prolog:\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
111
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
112 \begin{figure}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
113 \begin{tabular}{5|3|1 1}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
114 & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
115 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
116 register save area & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
117 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
118 local data & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
119 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
120 \mrlbrace{6}{parameter area} & last arg & \mrrbrace{3}{stack parameters} & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
121 & \ldots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
122 & first arg passed via stack & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
123 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
124 & \$a7 & \mrrbrace{3}{spill area (if needed)} & \mrrbrace{6}{current frame} \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
125 & \ldots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
126 & \$a? (first unnamed reg) & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
127 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
128 register save area (with return address) & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
129 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
130 local data & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
131 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
132 parameter area & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
133 \end{tabular}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
134 \caption{Stack layout on MIPS EABI 32-bit calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
135 \end{figure}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
136
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
137
467
b47168dacba6 manual:
Tassilo Philipp
parents: 328
diff changeset
138 \clearpage
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
139
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
140
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
141 \subsubsection{MIPS O32 32-bit Calling Convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
142
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
143 \paragraph{Register usage}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
144
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
145 \begin{table}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
146 \begin{tabular*}{0.95\textwidth}{lll}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
147 Name & Alias & Brief description\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
148 \hline
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
149 {\bf \$0} & {\bf \$zero} & hardware zero \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
150 {\bf \$1} & {\bf \$at} & assembler temporary \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
151 {\bf \$2-\$3} & {\bf \$v0-\$v1} & return value (only integer on hard-float targets), scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
152 {\bf \$4-\$7} & {\bf \$a0-\$a3} & first arguments (only integer on hard-float targets), scratch\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
153 {\bf \$8-\$15,\$24} & {\bf \$t0-\$t7,\$t8} & temporaries, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
154 {\bf \$25} & {\bf \$t9} & temporary, holds address of called function for PIC calls (by convention) \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
155 {\bf \$16-\$23} & {\bf \$s0-\$s7} & preserved \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
156 {\bf \$26,\$27} & {\bf \$k0,\$k1} & reserved for kernel \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
157 {\bf \$28} & {\bf \$gp} & global pointer, preserved by caller \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
158 {\bf \$29} & {\bf \$sp} & stack pointer, preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
159 {\bf \$30} & {\bf \$s8/\$fp} & frame pointer (some assemblers name it \$fp), preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
160 {\bf \$31} & {\bf \$ra} & return address, preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
161 {\bf hi, lo} & & multiply/divide special registers \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
162 {\bf \$f0-\$f3} & & only on hard-float targets: float return value, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
163 {\bf \$f4-\$f11,\$f16-\$f19} & & only on hard-float targets: float temporaries, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
164 {\bf \$f12-\$f15} & & only on hard-float targets: first floating point arguments, scratch \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
165 {\bf \$f20-\$f31} & & only on hard-float targets: preserved \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
166 \end{tabular*}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
167 \caption{Register usage on MIPS O32 calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
168 \end{table}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
169
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
170 \paragraph{Parameter passing}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
171
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
172 \begin{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
173 \item Stack grows down
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
174 \item Stack parameter order: right-to-left
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
175 \item Caller cleans up the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
176 \item Caller is required to always leave a 16-byte spill area for \$a0-\$a3 at the end of {\bf its} frame, to be used and spilled to by the callee, if needed
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
177 \item The different stack areas (local data, register save area, parameter area) are each aligned to 8 bytes
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
178 \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)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
179 \item subsequent parameters are passed vie the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
180 \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
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
181 \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
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
182 \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
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
183 \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
478
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
184 \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 % @@@ verify
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
185 \item aggregates (struct, union) are passed as a sequence of words like integers, no matter the fields or if hard-float target (splitting across registers and stack is allowed)
499
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
186 \item {\it non-trivial} C++ aggregates (as defined by the language) of any size, are passed indirectly via a pointer to a copy of the aggregate
478
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
187 \end{itemize}
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
188
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
189 \paragraph{Return values}
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
190
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 467
diff changeset
191 \begin{itemize}
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
192 \item results are returned in \$v0 and \$v1, with \$v0 for all values \textless\ 64bit (only integer on hard-float targets)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
193 \item only on hard-float targets: floating point results are returned in \$f0 (32-bit float), or \$f0 and \$f3 (64bit float)
499
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
194 \item aggregates (struct, union) are returned in a space allocated by the caller, with a pointer to it
fc614cb865c6 - doc and disasexample additions specific to non-trivial C++ aggregates as return values (incl. fixes to doc and additional LSB specific PPC32 section)
Tassilo Philipp
parents: 479
diff changeset
195 passed as first parameter to the function called (meaning in \%a0); the ptr to the aggregate is returned in \%v0
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
196 \end{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
197
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
198 \paragraph{Stack layout}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
199
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
200 % verified/amended: TP nov 2019 (see also doc/disas_examples/mips.o32.disas)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
201 Stack directly after function prolog:\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
202
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
203 \begin{figure}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
204 \begin{tabular}{5|3|1 1}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
205 & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
206 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
207 register save area (with return address) & \hspace{4cm} & & \mrrbrace{10}{caller's frame} \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
208 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
209 local data (and padding) & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
210 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
211 \mrlbrace{8}{parameter area} & padding (if needed) & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
212 & last arg & \mrrbrace{3}{stack parameters} & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
213 & \ldots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
214 & first arg passed via stack & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
215 & \$a3 & \mrrbrace{4}{spill area} & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
216 & \$a2 & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
217 & \$a1 & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
218 & \$a0 & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
219 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
220 register save area & & & \mrrbrace{3}{current frame} \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
221 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
222 local data & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
223 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
224 parameter area & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
225 \end{tabular}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
226 \caption{Stack layout on MIPS O32 calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
227 \end{figure}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 322
diff changeset
228