comparison doc/manual/callconvs/callconv_ppc32.tex @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children 7ca46969e0ad
comparison
equal deleted inserted replaced
-1:000000000000 0:3e629dc19168
1 %//////////////////////////////////////////////////////////////////////////////
2 %
3 % Copyright (c) 2007,2009 Daniel Adler <dadler@uni-goettingen.de>,
4 % Tassilo Philipp <tphilipp@potion-studios.com>
5 %
6 % Permission to use, copy, modify, and distribute this software for any
7 % purpose with or without fee is hereby granted, provided that the above
8 % copyright notice and this permission notice appear in all copies.
9 %
10 % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 %
18 %//////////////////////////////////////////////////////////////////////////////
19
20 % ==================================================
21 % PowerPC 32
22 % ==================================================
23 \subsection{PowerPC (32bit) Calling Convention}
24
25 \paragraph{Overview}
26
27 \begin{itemize}
28 \item Word size is 32 bits
29 \item Big endian (MSB) and litte endian (LSB) operating modes.
30 \item Processor operates on floats in double precision floating point arithmetc (IEEE-754) values directly (single precision is converted on the fly)
31 \item Apple Mac OS X/Darwin PPC is specified in "Mac OS X ABI Function Call Guide"\cite{ppcMacOSX}. It uses Big Endian (MSB).
32 \item Linux PPC 32-bit ABI is specified in "LSB for PPC"\cite{ppc32LSB} which is based on "System V ABI". It uses Big Endian (MSB).
33 \item PowerPC EABI is defined in the "PowerPC Embedded Application Binary Interface 32-Bit Implementation".
34 \end{itemize}
35
36
37 \paragraph{\product{dyncall} support}
38
39 \product{Dyncall} and \product{dyncallback} are supported for PowerPC (32bit) Big Endian (MSB) on Darwin (tested on Apple Mac OS X) and Linux, however, fail for *BSD.
40
41
42 \subsubsection{Mac OS X/Darwin}
43
44 \paragraph{Registers and register usage}
45
46 \begin{table}[h]
47 \begin{tabular}{3 B}
48 \hline
49 Name & Brief description\\
50 \hline
51 {\bf gpr0} & scratch\\
52 {\bf gpr1} & stack pointer\\
53 {\bf gpr2} & scratch\\
54 {\bf gpr3} & return value, parameter 0 if integer or pointer\\
55 {\bf gpr4-gpr10} & return value, parameter 1-7 for integer or pointer parameters\\
56 {\bf gpr11} & permanent\\
57 {\bf gpr12} & branch target for dynamic code generation\\
58 {\bf gpr13-31} & permanent\\
59 {\bf fpr0} & scratch\\
60 {\bf fpr1-fpr13} & parameter 0-12 for floating point (always double precision)\\
61 {\bf fpr14-fpr31} & permanent\\
62 {\bf v0-v1} & scratch\\
63 {\bf v2-v13} & vector parameters\\
64 {\bf v14-v19} & scratch\\
65 {\bf v20-v31} & permanent\\
66 {\bf lr} & scratch, link-register\\
67 {\bf ctr} & scratch, count-register\\
68 {\bf cr0-cr1} & scratch\\
69 {\bf cr2-cr4} & permanent\\
70 {\bf cr5-cr7} & scratch\\
71 \hline
72 \end{tabular}
73 \caption{Register usage on Darwin PowerPC 32-Bit}
74 \end{table}
75
76 \paragraph{Parameter passing}
77
78 \begin{itemize}
79 \item stack parameter order: right-to-left@@@?
80 \item caller cleans up the stack@@@?
81 \item the first 8 integer parameters are passed in registers gpr3-gpr10
82 \item the first 12 floating point parameters are passed in registers fpr1-fpr13
83 \item if a float parameter is passed via a register, gpr registers are skipped for subsequent integer parameters (based on the size of
84 the float - 1 register for single precision and 2 for double precision floating point values)
85 \item the caller pushes subsequent parameters onto the stack
86 \item for every parameter passed via a register, space is reserved in the stack parameter area (in order to spill the parameters if
87 needed - e.g. varargs)
88 \item ellipsis calls take floating point values in int and float registers (single precision floats are promoted to double precision
89 as defined for ellipsis calls)
90 \item all nonvector parameters are aligned on 4-byte boundaries
91 \item vector parameters are aligned on 16-byte boundaries
92 \item integer parameters \textless\ 32 bit occupy high-order bytes of their 4-byte area
93 \item composite parameters with size of 1 or 2 bytes occupy low-order bytes of their 4-byte area. INCONSISTENT with other 32-bit PPC
94 binary interfaces. In AIX and OS 9, padding bytes always follow the data structure
95 \item composite parameters 3 bytes or larger in size occupy high-order bytes
96 \end{itemize}
97
98
99 \paragraph{Return values}
100
101 \begin{itemize}
102 \item return values of integer \textless=\ 32bit or pointer type use gpr3
103 \item 64 bit integers use gpr3 and gpr4 (hiword in gpr3, loword in gpr4)
104 \item floating point values are returned via fpr1
105 \item structures \textless=\ 64 bits use gpr3 and gpr4
106 \item for types \textgreater\ 64 bits, a secret first parameter with an address to the return value is passed
107 \end{itemize}
108
109 \pagebreak
110
111 \paragraph{Stack layout}
112
113 Stack frame is always 16-byte aligned. Stack directly after function prolog:\\
114
115 \begin{figure}[h]
116 \begin{tabular}{5|3|1 1}
117 \hhline{~-~~}
118 & \vdots & & \\
119 \hhline{~=~~}
120 local data & & & \mrrbrace{13}{caller's frame} \\
121 \hhline{~-~~}
122 \mrlbrace{6}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
123 & \ldots & & \\
124 & \ldots & & \\
125 & \ldots & \mrrbrace{3}{spill area (as needed)} & \\
126 & \ldots & & \\
127 & gpr3 or fpr1 & & \\
128 \hhline{~-~~}
129 \mrlbrace{6}{linkage area} & reserved & & \\
130 & reserved & & \\
131 & reserved & & \\
132 & return address & & \\
133 & reserved for callee & & \\
134 & saved by callee & & \\
135 \hhline{~=~~}
136 local data & & & \mrrbrace{3}{current frame} \\
137 \hhline{~-~~}
138 parameter area & & & \\
139 \hhline{~-~~}
140 linkage area & \vdots & & \\
141 \hhline{~-~~}
142 \end{tabular}
143 \caption{Stack layout on ppc32 Darwin}
144 \end{figure}
145
146 \subsubsection{System V PPC 32-bit}
147
148 \paragraph{Status}
149
150 \begin{itemize}
151 \item C++ this calls do not work.
152 \item Callbacks don't work on *BSD.
153 \end{itemize}
154
155 \paragraph{Registers and register usage}
156
157 \begin{table}[h]
158 \begin{tabular}{3 B}
159 \hline
160 Name & Brief description\\
161 \hline
162 {\bf r0} & scratch\\
163 {\bf r1} & stack pointer\\
164 {\bf r2} & system-reserved\\
165 {\bf r3-r4} & parameter passing and return value\\
166 {\bf r5-r10} & parameter passing\\
167 {\bf r11-r12} & scratch\\
168 {\bf r13} & Small data area pointer register\\
169 {\bf r14-r30} & Local variables\\
170 {\bf r31} & Used for local variables or \emph{environment pointer}\\
171 {\bf f0} & scratch\\
172 {\bf f1} & parameter passing and return value\\
173 {\bf f2-f8} & parameter passing\\
174 {\bf f9-13} & scratch\\
175 {\bf f14-f31} & Local variables\\
176 {\bf cr0-cr7} & Conditional register fields, each 4-bit wide (cr0-cr1 and cr5-cr7 are scratch)\\
177 {\bf lr} & Link register (scratch)\\
178 {\bf ctr} & Count register (scratch) \\
179 {\bf xer} & Fixed-point exception register (scratch)\\
180 {\bf fpscr} & Floating-point Status and Control Register\\
181
182 % {\bf v0-v1} & scratch\\
183 % {\bf v2-v13} & vector parameters\\
184 % {\bf v14-v19} & scratch\\
185 % {\bf v20-v31} & permanent\\
186 % {\bf lr} & scratch, link-register\\
187 % {\bf ctr} & scratch, count-register\\
188 % {\bf cr0-cr1} & scratch\\
189 % {\bf cr2-cr4} & permanent\\
190 % {\bf cr5-cr7} & scratch\\
191 \hline
192 \end{tabular}
193 \caption{Register usage on System V ABI PowerPC Processor}
194 \end{table}
195
196 \paragraph{Parameter passing}
197
198 \begin{itemize}
199 \item Stack pointer (r1) is always 16-byte aligned. The EABI differs here - it is 8-byte alignment.
200 \item 8 general-purpose registers (r3-r10) for integer and pointer types.
201 \item 8 floating-pointer registers (f1-f8) for float (promoted to double) and double types.
202 \item Additional arguments are passed on the stack directly after the back-chain and saved return address (8 bytes structure) on the callers stack frame.
203 \item 64-bit integer data types are passed in general-purpose registers as a whole in two
204 32-bit general purpose registers (an odd and an even e.g. r3 and r4), probably skipping an even integer register.
205 or passed on the stack. They are never splitted into a register and stack part.
206 \item Ellipse calls set CR bit 6
207
208 \end{itemize}
209
210 \paragraph{Return values}
211
212 \begin{itemize}
213 \item 32-bit integers use register r3, 64-bit use registers r3 and r4 (hiword in r3, loword in r4).
214 \item floating-point values are returned using register f1.
215 \end{itemize}
216
217 \pagebreak
218
219 \paragraph{Stack layout}
220
221 Stack frame is always 16-byte aligned. Stack directly after function prolog:\\
222
223 \begin{figure}[h]
224 \begin{tabular}{5|3|1 1}
225 \hhline{~-~~}
226 & \vdots & & \\
227 \hhline{~=~~}
228 local data & & & \mrrbrace{6}{caller's frame} \\
229 \hhline{~-~~}
230 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
231 & \ldots & & \\
232 & \ldots & & \\
233 \hhline{~-~~}
234 & saved return address (for callee) & & \\
235 \hhline{~-~~}
236 & parent stack frame pointer & & \\
237 \hhline{~=~~}
238 local data & & & \mrrbrace{3}{current frame} \\
239 \hhline{~-~~}
240 parameter area & & & \\
241 \hhline{~-~~}
242 & \vdots & & \\
243 \hhline{~-~~}
244 \end{tabular}
245 \\
246 \\
247 \\
248 \caption{Stack layout on System V ABI for PowerPC 32-bit calling convention}
249 \end{figure}