annotate doc/manual/callconvs/callconv_mips64.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 75c19f11b86a
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: 305
diff changeset
1 %//////////////////////////////////////////////////////////////////////////////
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
2 %
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
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: 305
diff changeset
4 % Tassilo Philipp <tphilipp@potion-studios.com>
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
5 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
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: 305
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: 305
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: 305
diff changeset
9 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
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: 305
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: 305
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: 305
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: 305
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: 305
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: 305
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: 305
diff changeset
17 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
18 %//////////////////////////////////////////////////////////////////////////////
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
19
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
20 \subsection{MIPS64 Calling Conventions}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
21
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
22 \paragraph{Overview}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
23
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
24 There are two main ABIs in use for MIPS64 chips, \emph{N64}\cite{MIPSn32/n64}
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
25 and \emph{N32}\cite{MIPSn32/n64}. Both are basically the same, except that N32
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
26 uses ILP32 as programming model (32-bit pointers and long integers), whereas
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
27 N64 uses LP64 (64-bit pointers and long integers). All registers of a MIPS64
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
28 chip are considered to be 64-bit wide, even for the N32 calling convention.\\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
29 The word size is defined to be 32 bits, a dword 64 bits. Note that this is due
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
30 to historical reasons (terminology didn't change from MIPS32).\\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
31 Other than that there are correspoding 64-bit versions other MIPS32 ABIs, e.g.
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
32 the EABI\cite{MIPSeabi} and O64\cite{MIPSo64}.
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
33
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
34 \paragraph{\product{dyncall} support}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
35
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
36 For MIPS 64-bit machines, dyncall supports the N64 calling conventions for calls and callbacks (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: 305
diff changeset
37 The N32 calling convention might work - it used to, but hasn't been tested, recently.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
38
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
39 \subsubsection{MIPS N64 Calling Convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
40
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
41 \paragraph{Register usage}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
42
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
43 \begin{table}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
44 \begin{tabular*}{0.95\textwidth}{lll}
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
45 Name & Alias & Brief description\\
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
46 \hline
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
47 {\bf \$0} & {\bf \$zero} & hardware zero \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
48 {\bf \$1} & {\bf \$at} & assembler temporary, scratch \\
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
49 {\bf \$2-\$3} & {\bf \$v0-\$v1} & return value (only integers on hard-float targets), scratch \\
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
50 {\bf \$4-\$11} & {\bf \$a0-\$a7} & first arguments (only integers on hard-float targets), scratch \\
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
51 {\bf \$12-\$15,\$24} & {\bf \$t4-\$t7,\$t8} & temporaries, scratch \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
52 {\bf \$25} & {\bf \$t9} & temporary, address callee for all PIC calls (by convention), scratch \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
53 {\bf \$16-\$23} & {\bf \$s0-\$s7} & preserve \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
54 {\bf \$26,\$27} & {\bf \$kt0,\$kt1} & reserved for kernel \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
55 {\bf \$28} & {\bf \$gp} & global pointer, preserve \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
56 {\bf \$29} & {\bf \$sp} & stack pointer, preserve \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
57 {\bf \$30} & {\bf \$s8} & frame pointer, preserve \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
58 {\bf \$31} & {\bf \$ra} & return address, preserve \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
59 {\bf hi, lo} & & multiply/divide special registers \\
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
60 {\bf \$f0,\$f2} & & only on hard-float targets: float return values, scratch \\
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
61 {\bf \$f1,\$f3,\$f4-\$f11} & & only on hard-float targets: float temporaries, scratch \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
62 {\bf \$f12-\$f19} & & only on hard-float targets: float arguments, scratch \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
63 {\bf \$f20-\$f23} & & only on hard-float targets: float temporaries, scratch \\
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
64 {\bf \$f24-\$f31} & & only on hard-float targets: preserved \\
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
65 \end{tabular*}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
66 \caption{Register usage on MIPS N64 calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
67 \end{table}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
68
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
69 \paragraph{Parameter passing}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
70
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
71 \begin{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
72 \item Stack grows down
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
73 \item Stack parameter order: right-to-left
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
74 \item Caller cleans up the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
75 \item generally, first 8 params \textgreater=\ 64-bit are passed via registers
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
76 \item for hard-float targets: register arguments are passed via \$a0-\$a7 for integers and \$f12-\$f19 for floats - with mixed float and int parameters, some registers are left out (e.g. first parameter ends up in \$a0 or \$f12, second in \$a1 or \$f13, etc.)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
77 \item for soft-float targets: register arguments are passed via \$a0-\$a7
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
78 \item subsequent arguments are pushed onto the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
79 \item all stack entries are 64-bit aligned
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
80 \item all stack regions are 16-byte aligned
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
81 \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: 305
diff changeset
82 \item float arguments passed in the variable part of a vararg call are passed like integers, meaning float registers don't ever need to be saved that way, so only \$a0-\$a7 are need to be spilled
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
83 \item quad precision float arguments are passed in even-odd register pairs, skipping one register if needed
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
84 \item integer parameters \textless\ 64 bit are right-justified (meaning occupy higher-address bytes) in their 8-byte slot on the stack, requiring extra-care for big-endian targets
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
85 \item single precision float parameters (32 bit) are left-justified in their 8-byte slot on the stack, but are right justified in fp-registers on big endian targets, as they aren't promoted (actually, official docs says "undecided", but real world implementations seem to use what is described here)
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
86 \item aggregates (struct, union) are passed as a sequence of dwords in (integer registers and the stack), with the following particularities:
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: 477
diff changeset
87 \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
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
88 \begin{itemize}
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
89 \item if a dword happens to be a double precision floating point struct field, it is passed in a floating point register
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
90 \item array and union fields are always passed like integers (even if their type is float or double)
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
91 \item splitting an argument across registers and the stack is fine
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
92 \end{itemize}
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
93 %spec
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
94 %Structs, unions, or other composite types are treated as a sequence of doublewords,
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
95 %and are passed in integer or floating point registers as though they were simple
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
96 %scalar parameters to the extent that they fit, with any excess on the stack packed
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
97 %according to the normal memory layout of the object. More specifically:
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
98 %- Regardless of the struct field structure, it is treated as a sequence of 64-bit
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
99 %chunks. If a chunk consists solely of a double float field (but not a double,
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
100 %which is part of a union), it is passed in a floating point register. Any other
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
101 %chunk is passed in an integer register.
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
102 %- A union, either as the parameter itself or as a struct parameter field, is treated
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
103 %as a sequence of integer doublewords for purposes of assignment to integer
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
104 %parameter registers. No attempt is made to identify floating point components
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
105 %for passing in floating point registers.
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
106 %- Array fields of structs are passed like unions. Array parameters are passed by
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
107 %reference (unless the relevant language standard requires otherwise).
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
108 %- Right-justifying small scalar parameters in their save area slots
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
109 %notwithstanding, struct parameters are always left-justified. This applies both
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
110 %to the case of a struct smaller than 64 bits, and to the final chunk of a struct
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
111 %which is not an integral multiple of 64 bits in size. The implication of this rule is
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
112 %that the address of the first chunk’s save area slot is the address of the struct,
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
113 %and the struct is laid out in the save area memory exactly as if it were allocated
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
114 %normally (once any part in registers has been stored to the save area). [These
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
115 %rules are analogous to the o32-bit ABI treatment – only the chunk size and the
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
116 %ability to pass double fields in floating point registers are different.
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
117 \end{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
118 % maybe note somewhere that "prolog-based" spilling is neat for dyncall, as we don't have to care
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
119
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
120
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
121 \paragraph{Return values}
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
122
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
123 \begin{itemize}
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
124 \item results are returned in \$v0, and for a second one \$v1 is used
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
125 \item only on hard-float targets: floating point results are returned in \$f0 (and \$f2 if needed)
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
126 \item only on hard-float targets: structs with only one or two floating point fields are returned in \$f0 (and \$f2 if necessary), field-by-field
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: 477
diff changeset
127 \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: 477
diff changeset
128 (meaning in \%a0), and callee writes return value to this space; the ptr to the aggregate is returned in \%v0
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
129 \item any other aggregates (struct, union) \textless= 16 bytes are returned via registers \$v0 (and \$v1 if necessary), dword-by-dword
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
130 \item all other aggregates (struct, union) \textgreater 16 bytes 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: 477
diff changeset
131 passed as first parameter to the function called (meaning in \%a0); the ptr to the aggregate is returned in \%v0
477
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
132 %spec;
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
133 %Composite results (struct, union, or array) are returned in
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
134 %$2/$f0 and $3/$f2 according to the following rules:
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
135 %- A struct with only one or two floating point fields is returned in $f0 (and $f2 if
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
136 %necessary). This is a generalization of the Fortran COMPLEX case.
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
137 %- Any other struct or union results of at most 128 bits are returned in $2 (first 64
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
138 %bits) and $3 (remainder, if necessary).
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
139 %- Larger composite results are handled by converting the function to a procedure
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
140 %with an implicit first parameter, which is a pointer to an area reserved by the
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
141 %caller to receive the result. [The o32-bit ABI requires that all composite results
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
142 %be handled by conversion to implicit first parameters. The MIPS/SGI Fortran
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
143 %implementation has always made a specific exception to return COMPLEX
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
144 %results in the floating point registers.]
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
145 \end{itemize}
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
146
75c19f11b86a - mips64 doc and more disas examples (fbsd big endian w/ -mhard-float flag)
Tassilo Philipp
parents: 336
diff changeset
147
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
148 \paragraph{Stack layout}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
149
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
150 % verified/amended: TP nov 2019 (see also doc/disas_examples/mips64.n64.disas)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
151 Stack directly after function prolog:\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
152
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
153 \begin{figure}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
154 \begin{tabular}{5|3|1 1}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
155 & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
156 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
157 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: 305
diff changeset
158 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
159 local data & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
160 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
161 \mrlbrace{6}{parameter area} & arg n-1 & \mrrbrace{3}{stack parameters} & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
162 & \ldots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
163 & arg 8 & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
164 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
165 & \$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: 305
diff changeset
166 & \ldots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
167 & \$a? (first unnamed reg) & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
168 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
169 register save area (with return address) & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
170 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
171 local data & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
172 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
173 parameter area & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
174 \end{tabular}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
175 \caption{Stack layout on MIPS N64 calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
176 \end{figure}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
177
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
178
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
179 \subsubsection{MIPS N32 Calling Convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
180
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
181 Despite what one might think given the name, this is a MIPS 64-bit calling
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
182 convention. As mentioned in the overview of this chapter, it is nearly
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
183 identical to the N64 one, the differences being:
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 305
diff changeset
184
336
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
185 \begin{itemize}
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
186 \item uses ILP32 as programming model instead of LP64
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
187 \item floating point registers \$f20-\$f23 are to be preserved
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
188 \end{itemize}
3c6bc720bc1f - doc: added mips64/n32 stub
Tassilo Philipp
parents: 328
diff changeset
189