Mercurial > pub > dyncall > dyncall
annotate doc/manual/callconvs/callconv_mips64.tex @ 336:3c6bc720bc1f r1.1-RC1
- doc: added mips64/n32 stub
author | Tassilo Philipp |
---|---|
date | Sat, 30 Nov 2019 15:57:28 +0100 |
parents | 276eb8c87aa0 |
children | 75c19f11b86a |
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 % |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
3 % Copyright (c) 2007-2019 Daniel Adler <dadler@uni-goettingen.de>, |
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 | 24 There are two main ABIs in use for MIPS64 chips, \emph{N64}\cite{MIPSn32/n64} |
25 and \emph{N32}\cite{MIPSn32/n64}. Both are basically the same, except that N32 | |
26 uses ILP32 as programming model (32-bit pointers and long integers), whereas | |
27 N64 uses LP64 (64-bit pointers and long integers). All registers of a MIPS64 | |
28 chip are considered to be 64-bit wide, even for the N32 calling convention.\\ | |
29 The word size is defined to be 32 bits, a dword 64 bits. Note that this is due | |
30 to historical reasons (terminology didn't change from MIPS32).\\ | |
31 Other than that there are correspoding 64-bit versions other MIPS32 ABIs, e.g. | |
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 | 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 | 47 {\bf \$0} & {\bf \$zero} & hardware zero \\ |
48 {\bf \$1} & {\bf \$at} & assembler temporary, scratch \\ | |
49 {\bf \$2-\$3} & {\bf \$v0-\$v1} & return value (only integer on hard-float targets), scratch \\ | |
50 {\bf \$4-\$11} & {\bf \$a0-\$a7} & first arguments (only integer on hard-float targets), scratch \\ | |
51 {\bf \$12-\$15,\$24} & {\bf \$t4-\$t7,\$t8} & temporaries, scratch \\ | |
52 {\bf \$25} & {\bf \$t9} & temporary, address callee for all PIC calls (by convention), scratch \\ | |
53 {\bf \$16-\$23} & {\bf \$s0-\$s7} & preserve \\ | |
54 {\bf \$26,\$27} & {\bf \$kt0,\$kt1} & reserved for kernel \\ | |
55 {\bf \$28} & {\bf \$gp} & global pointer, preserve \\ | |
56 {\bf \$29} & {\bf \$sp} & stack pointer, preserve \\ | |
57 {\bf \$30} & {\bf \$s8} & frame pointer, preserve \\ | |
58 {\bf \$31} & {\bf \$ra} & return address, preserve \\ | |
59 {\bf hi, lo} & & multiply/divide special registers \\ | |
60 {\bf \$f0,\$f2} & & only on hard-float targets: float results, scratch \\ | |
61 {\bf \$f1,\$f3,\$f4-\$f11} & & only on hard-float targets: float temporaries, scratch \\ | |
62 {\bf \$f12-\$f19} & & only on hard-float targets: float arguments, scratch \\ | |
63 {\bf \$f20-\$f23} & & only on hard-float targets: float temporaries, scratch \\ | |
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 results are returned in \$v0, and for a second one \$v1 is used |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
82 \item only on hard-float targets: floating point results are returned in \$f0 |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
83 \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
|
84 \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
|
85 \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
|
86 \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 | 87 \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) |
328
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
88 \end{itemize} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
89 % 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
|
90 |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
91 \paragraph{Stack layout} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
92 |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
93 % 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
|
94 Stack directly after function prolog:\\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
95 |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
96 \begin{figure}[h] |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
97 \begin{tabular}{5|3|1 1} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
98 & \vdots & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
99 \hhline{~=~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
100 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
|
101 \hhline{~-~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
102 local data & & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
103 \hhline{~-~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
104 \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
|
105 & \ldots & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
106 & arg 8 & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
107 \hhline{~=~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
108 & \$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
|
109 & \ldots & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
110 & \$a? (first unnamed reg) & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
111 \hhline{~-~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
112 register save area (with return address) & & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
113 \hhline{~-~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
114 local data & & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
115 \hhline{~-~~} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
116 parameter area & \vdots & & \\ |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
117 \end{tabular} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
118 \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
|
119 \end{figure} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
120 |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
121 |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
122 \subsubsection{MIPS N32 Calling Convention} |
276eb8c87aa0
- review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents:
305
diff
changeset
|
123 |
336 | 124 Despite what one might think given the name, this is a MIPS 64-bit calling |
125 convention. As mentioned in the overview of this chapter, it is nearly | |
126 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
|
127 |
336 | 128 \begin{itemize} |
129 \item uses ILP32 as programming model instead of LP64 | |
130 \item floating point registers \$f20-\$f23 are to be preserved | |
131 \end{itemize} | |
132 |