annotate doc/manual/callconvs/callconv_sparc64.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 6c72cb768099
children 9d0eefb0e0f0
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: 297
diff changeset
1 %//////////////////////////////////////////////////////////////////////////////
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
2 %
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
3 % Copyright (c) 2012-2022 Daniel Adler <dadler@uni-goettingen.de>,
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
4 % Tassilo Philipp <tphilipp@potion-studios.com>
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
5 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
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: 297
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: 297
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: 297
diff changeset
9 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
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: 297
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: 297
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: 297
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: 297
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: 297
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: 297
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: 297
diff changeset
17 %
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
18 %//////////////////////////////////////////////////////////////////////////////
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
19
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
20 \subsection{SPARC64 Calling Conventions}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
21
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
22 \paragraph{Overview}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
23
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
24 The SPARC family of processors is based on the SPARC instruction set architecture, which comes in basically three revisions,
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
25 V7, V8\cite{SPARCV8}\cite{SPARCSysV}\cite{SPARCCD} and V9\cite{SPARCV9}\cite{SPARCV9SysV}\cite{SPARCCD}. The former two are 32-bit (see previous chapter) whereas the latter refers to the 64-bit SPARC architecture.
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
26 SPARC uses big endian byte order, however, V9 supports also little endian byte order, but for data access only, not instruction access.\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
27 \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
28 There are two proposals, one from Sun and one from Hal, which disagree on how to handle some aspects of this calling convention.\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
29
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
30 \paragraph{\product{dyncall} support}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
31
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
32 \product{dyncall} fully supports the SPARC 64-bit instruction set (V9), for calls and callbacks.
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
33
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
34 \subsubsection{SPARC (64-bit) Calling Convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
35
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
36 \begin{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
37 \item 32 double precision floating point registers (d0,d2,d4,...,d62, usable as 16 quad precision ones q0,q4,q8,...g60, and also first half of them are usable as 32 single precision registers f0-f31)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
38 \item 32 64-bit integer/pointer registers out of a bigger (vendor/model dependent) number that are accessible at a time (8 are global ones (g*), whereas the remaining 24 form a register window with 8 input (i*), 8 output (o*) and 8 local (l*) ones)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
39 \item calling a function shifts the register window, the old output registers become the new input registers (old local and input ones are not accessible anymore)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
40 \item stack and frame pointer are offset by a BIAS of 2047 (see official doc for reasons)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
41 \end{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
42
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
43 \begin{table}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
44 \begin{tabular*}{0.95\textwidth}{lll}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
45 Name & Alias & Brief description\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
46 \hline
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
47 {\bf \%g0} & \%r0 & Read-only, hardwired to 0 \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
48 {\bf \%g1-\%g7} & \%r1-\%r7 & Global \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
49 {\bf \%o0-\%o3 and \%i0-\%i3} & \%r8-\%r11 and \%r24-\%r27 & Output and input argument registers, return value \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
50 {\bf \%o4,\%o5 and \%i4,\%i5} & \%r12,\%r13 and \%r28,\%r29 & Output and input argument registers \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
51 {\bf \%o6 and \%i6} & \%r14 and \%r30, \%sp and \%fp & Stack and frame pointer (NOTE, offset with a BIAS of 2047) \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
52 {\bf \%o7 and \%i7} & \%r15 and \%r31 & Return address (caller writes to o7, callee uses i7) \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
53 {\bf \%l0-\%l7} & \%r16-\%r23 & preserve \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
54 {\bf \%d0,\%d2,\%d4,\%d6} & & scratch, Floating point arguments, return value \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
55 {\bf \%d8,\%d10,...,\%d14} & & scratch, Floating point arguments \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
56 {\bf \%d16,\%d18,...,\%d30} & & scratch (preserve for Hal), Floating point arguments \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
57 {\bf \%d32,\%d34,...,\%d62} & & scratch (preserve for Hal) \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
58 \end{tabular*}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
59 \caption{Register usage on sparc64 calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
60 \end{table}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
61
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
62 \paragraph{Parameter passing}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
63 \begin{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
64 \item stack grows down
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
65 \item stack parameter order: right-to-left
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
66 \item caller cleans up the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
67 \item stack frame is always aligned to 16 bytes
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
68 \item first 6 integers are passed in registers using \%o0-\%o5
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
69 \item first 8 quad precision floating point args (or 16 double precision, or 32 single precision) are passed in floating point registers (\%q0,\%q4,...,\%q28 or \%d0,\%d2,...,\%d30 or \%f0-\%f31, respectively)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
70 \item for every other argument the stack is used
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
71 \item single precision floating point args are passed in odd \%f* registers, and are "right aligned" in their 8-byte space on the stack
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
72 \item for every argument passed, corresponding \%o*, \%f* register or stack space is skipped (e.g. passing a double as 3rd call argument, \%d4 is used and \%o2 is skipped)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
73 \item all arguments \textless=\ 64 bit are passed as 64 bit values
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
74 \item minimum stack size is 128 bytes, b/c stack pointer must always point at enough space to store all \%i* and \%l* registers, used when running out of register windows
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
75 \item if needed, register spill area (both, integer and float arguments are spilled in order) is adjacent to parameters
475
5be9f5ccdd35 - doc: ppc64 clarifications
Tassilo Philipp
parents: 474
diff changeset
76 \item structs with only one field are passed as if the param would be the field itself
5be9f5ccdd35 - doc: ppc64 clarifications
Tassilo Philipp
parents: 474
diff changeset
77 \item structs \textless=\ 16 bytes (which have more than one field) are passed field-by-field, {\bf however} evaluated as a sequence of 8-byte parameter slots
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
78 \begin{itemize}
475
5be9f5ccdd35 - doc: ppc64 clarifications
Tassilo Philipp
parents: 474
diff changeset
79 \item note that due to aggregate alignment rules, any floating point value is either the entire slot (for double precision) or exactly one half
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
80 \item fields are left justified in register or stack slots
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
81 \item integers in a slot are passed as such (either via \%o* registers or the stack)
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
82 \item single precision floats (using half of the slot) use even numbered \%f* registers when they occupy the left half, odd numbered ones otherwise (no register skipping logic applied within a slot)
475
5be9f5ccdd35 - doc: ppc64 clarifications
Tassilo Philipp
parents: 474
diff changeset
83 \item splitting struct fields between registers and stack is allowed
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
84 \end{itemize}
475
5be9f5ccdd35 - doc: ppc64 clarifications
Tassilo Philipp
parents: 474
diff changeset
85 \item unions \textless=\ 16 bytes passed by-value are passed like integers in left-justified 8-byte slots (either via \%o* registers or the stack)
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
86 \item aggregates (struct, union) and types \textgreater\ 16 bytes are passed indirectly, as a pointer to a correctly aligned copy of the data (that copy can be avoided under certain conditions)
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: 478
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
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
88 % from spec:
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
89 %Structure or union types up to eight bytes in size are assigned to one parameter array word, and align to eight-byte
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
90 %boundaries.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
91 %Structure or union types larger than eight bytes, and up to sixteen bytes in size are assigned to two consecutive
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
92 %parameter array words, and align according to the alignment requirements of the structure or at least to an eight-byte
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
93 %boundary.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
94 %Structure or union types are always left-justified, whether stored in registers or memory. The individual fields of a
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
95 %structure (or containing storage unit in the case of bit fields) are subject to promotion into registers based on their type
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
96 %using the same rules as apply to scalar values (with the addition that a single-precision floating-point number assigned
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
97 %to the left half of an argument slot will be promoted into the corresponding even-numbered float register.). Any union
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
98 %type being passed directly is subject to promotion into the appropriate integer register(s).
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
99 %Note that a sixteen-byte structure with all integral fields assigned to locations %sp+BIAS+168 and %sp+BIAS+176 will
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
100 %be “split,” as the contents of location %sp+BIAS+168 will be promoted to %o5.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
101 %Structures or unions larger than sixteen bytes are copied by the caller and passed indirectly; the caller will pass the
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
102 %address of a correctly aligned structure value. This sixty-four bit address will occupy one word in the parameter array,
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
103 %and may be promoted to an %o register like any other pointer value. The callee may modify the addressed structure.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
104 %The caller can omit the copy if such omission cannot be detected. That requires (at least) that:
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
105 %* the original aggregate is already properly aligned,
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
106 %* the original aggregate is not aliased,
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
107 %* the original aggregate is not used after the call, and
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
108 %* no language-specific semantics require the copy.
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
109 \end{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
110
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
111 \paragraph{Return values}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
112
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
113 \begin{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
114 \item results are expected by caller to be returned in \%o0-\%o3 (after reg window restore, meaning callee writes to \%i0-\%i3) for integers
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
115 \item \%d0,\%d2,\%d4,\%d6 are used for floating point values
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: 478
diff changeset
116 \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: 478
diff changeset
117 (meaning in \%o0), and callee writes return value to this space; the ptr to the aggregate is returned in the same register (after reg window restore)
478
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 475
diff changeset
118 \item the fields of aggregates (struct, union) \textless= 32 bytes are returned via registers mentioned above (which are
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
119 assigned following the same logic as when passing the aggregate as a first argument to a function)
478
6c72cb768099 callconv doc:
Tassilo Philipp
parents: 475
diff changeset
120 \item aggregates (struct, union) \textgreater 32 bytes are returned in a space allocated by the caller, with a pointer to it
474
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
121 passed as first parameter to the function called (meaning in \%o0)
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
122 % from spec:
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
123 %Structure and union return types up to thirty-two bytes in size are returned in registers. The registers are assigned as if
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
124 %the value was being passed as the first argument to a function with a known prototype.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
125 %For types with a larger size the caller allocates an area large enough and aligned properly to hold the return value, and
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
126 %passes a pointer to that area as an implicit first argument (of type pointer-to-data) to the callee. This implicit argument
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
127 %logically precedes the first actual argument, and is allocated according to normal argument passing rules (i.e. into %o0).
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
128 %The callee must store the function return value in the result area before control is returned to the caller and after the last
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
129 %use or definition of any variable that might overlap with the result area. If the callee is terminated through any means
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
130 %other than a normal function return (e.g., through a call to the longjmp function), the contents of the result area are
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
131 %undefined.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
132 %In the common case that the caller immediately assigns the returned value to a program variable, the caller may
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
133 %substitute the address of the assigned program variable in place of the allocated result area and omit the code to do the
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
134 %assignment, as long as this substitution does not change the program’s externally visible behavior.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
135 %Note also that the caller is required to provide the implicit argument and a properly sized and aligned receiving area
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
136 %even if it does not wish to use the callee’s function result. In that case, the caller may simply pass a pointer to a scratch
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
137 %area.
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
138 %So that compilers are not forced to emit in-line code for structure copy, Section 6.2 defines a set of routines optimized
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
139 %for this purpose. In the case of a routine which had kept its first argument in %i0 and was returning a value pointed to
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
140 %by %i1, epilogue code would take the form:
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
141 %
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
142 %mov %i0, %o0
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
143 %mov %i1, %o1
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
144 %call __align_cpy_n
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
145 %mov size, %o2
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
146 %ret
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
147 %restore %o0, %g0, %o0
c9e19249ecd3 - doc: sparc64 disas examples and doc additions regarding aggregates
Tassilo Philipp
parents: 330
diff changeset
148 %
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
149 \end{itemize}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
150
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
151 \paragraph{Stack layout}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
152
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
153 % verified/amended: TP nov 2019 (see also doc/disas_examples/sparc64.sparc64.disas)
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
154 Stack directly after function prolog:\\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
155
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
156 \begin{figure}[h]
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
157 \begin{tabular}{5|3|1 1}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
158 & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
159 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
160 local data (and padding) & \hspace{4cm} & & \mrrbrace{8}{caller's frame} \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
161 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
162 \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: 297
diff changeset
163 & \ldots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
164 & arg 6 & & \\
330
4e6f63b7020e - stack layout typo for sparc doc
Tassilo Philipp
parents: 328
diff changeset
165 & \%o5 & \mrrbrace{3}{spill area} & \\
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
166 & \ldots & & \\
330
4e6f63b7020e - stack layout typo for sparc doc
Tassilo Philipp
parents: 328
diff changeset
167 & \%o0 & & \\
328
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
168 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
169 register save area (\%i* and \%l*) & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
170 \hhline{~=~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
171 local data (and padding) & & & \mrrbrace{3}{current frame} \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
172 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
173 parameter area & & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
174 \hhline{~-~~}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
175 & \vdots & & \\
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
176 \end{tabular}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
177 \caption{Stack layout on sparc64 calling convention}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
178 \end{figure}
276eb8c87aa0 - review and fixes, cleanup, amendments to calling convention appendix of manual
Tassilo Philipp
parents: 297
diff changeset
179