0
|
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 \paragraph{\product{dyncall} support}
|
|
37
|
|
38 \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.
|
|
39
|
|
40
|
|
41 \subsubsection{Mac OS X/Darwin}
|
|
42
|
|
43 \paragraph{Registers and register usage}
|
|
44
|
|
45 \begin{table}[h]
|
77
|
46 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
47 Name & Brief description\\
|
|
48 \hline
|
|
49 {\bf gpr0} & scratch\\
|
|
50 {\bf gpr1} & stack pointer\\
|
|
51 {\bf gpr2} & scratch\\
|
238
|
52 {\bf gpr3,gpr4} & return value, parameter 0 and 1 for integer or pointer\\
|
|
53 {\bf gpr5-gpr10} & parameter 2-7 for integer or pointer parameters\\
|
0
|
54 {\bf gpr11} & permanent\\
|
|
55 {\bf gpr12} & branch target for dynamic code generation\\
|
|
56 {\bf gpr13-31} & permanent\\
|
|
57 {\bf fpr0} & scratch\\
|
238
|
58 {\bf fpr1} & floating point return value, floating point parameter 0 (always double precision)\\
|
|
59 {\bf fpr2-fpr13} & floating point parameters 1-12 (always double precision)\\
|
0
|
60 {\bf fpr14-fpr31} & permanent\\
|
|
61 {\bf v0-v1} & scratch\\
|
|
62 {\bf v2-v13} & vector parameters\\
|
|
63 {\bf v14-v19} & scratch\\
|
|
64 {\bf v20-v31} & permanent\\
|
|
65 {\bf lr} & scratch, link-register\\
|
|
66 {\bf ctr} & scratch, count-register\\
|
|
67 {\bf cr0-cr1} & scratch\\
|
|
68 {\bf cr2-cr4} & permanent\\
|
|
69 {\bf cr5-cr7} & scratch\\
|
76
|
70 \end{tabular*}
|
0
|
71 \caption{Register usage on Darwin PowerPC 32-Bit}
|
|
72 \end{table}
|
|
73
|
|
74 \paragraph{Parameter passing}
|
|
75
|
|
76 \begin{itemize}
|
238
|
77 \item stack parameter order: right-to-left
|
|
78 \item caller cleans up the stack
|
0
|
79 \item the first 8 integer parameters are passed in registers gpr3-gpr10
|
|
80 \item the first 12 floating point parameters are passed in registers fpr1-fpr13
|
|
81 \item if a float parameter is passed via a register, gpr registers are skipped for subsequent integer parameters (based on the size of
|
|
82 the float - 1 register for single precision and 2 for double precision floating point values)
|
|
83 \item the caller pushes subsequent parameters onto the stack
|
|
84 \item for every parameter passed via a register, space is reserved in the stack parameter area (in order to spill the parameters if
|
|
85 needed - e.g. varargs)
|
|
86 \item ellipsis calls take floating point values in int and float registers (single precision floats are promoted to double precision
|
|
87 as defined for ellipsis calls)
|
|
88 \item all nonvector parameters are aligned on 4-byte boundaries
|
|
89 \item vector parameters are aligned on 16-byte boundaries
|
|
90 \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
|
|
91 binary interfaces. In AIX and OS 9, padding bytes always follow the data structure
|
|
92 \item composite parameters 3 bytes or larger in size occupy high-order bytes
|
125
|
93 \item integer parameters \textless\ 32 bit are right-justified (meaning occupy higher-address bytes) in their 4-byte slot on the stack, requiring extra-care for big-endian targets
|
0
|
94 \end{itemize}
|
|
95
|
|
96
|
|
97 \paragraph{Return values}
|
|
98
|
|
99 \begin{itemize}
|
|
100 \item return values of integer \textless=\ 32bit or pointer type use gpr3
|
|
101 \item 64 bit integers use gpr3 and gpr4 (hiword in gpr3, loword in gpr4)
|
|
102 \item floating point values are returned via fpr1
|
|
103 \item structures \textless=\ 64 bits use gpr3 and gpr4
|
|
104 \item for types \textgreater\ 64 bits, a secret first parameter with an address to the return value is passed
|
|
105 \end{itemize}
|
|
106
|
|
107 \pagebreak
|
|
108
|
|
109 \paragraph{Stack layout}
|
|
110
|
|
111 Stack frame is always 16-byte aligned. Stack directly after function prolog:\\
|
|
112
|
|
113 \begin{figure}[h]
|
|
114 \begin{tabular}{5|3|1 1}
|
|
115 \hhline{~-~~}
|
|
116 & \vdots & & \\
|
|
117 \hhline{~=~~}
|
92
|
118 local data & \hspace{4cm} & & \mrrbrace{13}{caller's frame} \\
|
0
|
119 \hhline{~-~~}
|
|
120 \mrlbrace{6}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
121 & \ldots & & \\
|
|
122 & \ldots & & \\
|
|
123 & \ldots & \mrrbrace{3}{spill area (as needed)} & \\
|
|
124 & \ldots & & \\
|
|
125 & gpr3 or fpr1 & & \\
|
|
126 \hhline{~-~~}
|
|
127 \mrlbrace{6}{linkage area} & reserved & & \\
|
|
128 & reserved & & \\
|
|
129 & reserved & & \\
|
|
130 & return address & & \\
|
|
131 & reserved for callee & & \\
|
|
132 & saved by callee & & \\
|
|
133 \hhline{~=~~}
|
|
134 local data & & & \mrrbrace{3}{current frame} \\
|
|
135 \hhline{~-~~}
|
|
136 parameter area & & & \\
|
|
137 \hhline{~-~~}
|
|
138 linkage area & \vdots & & \\
|
|
139 \hhline{~-~~}
|
|
140 \end{tabular}
|
|
141 \caption{Stack layout on ppc32 Darwin}
|
|
142 \end{figure}
|
|
143
|
|
144 \subsubsection{System V PPC 32-bit}
|
|
145
|
|
146 \paragraph{Status}
|
|
147
|
|
148 \begin{itemize}
|
|
149 \item C++ this calls do not work.
|
|
150 \item Callbacks don't work on *BSD.
|
|
151 \end{itemize}
|
|
152
|
|
153 \paragraph{Registers and register usage}
|
|
154
|
|
155 \begin{table}[h]
|
77
|
156 \begin{tabular*}{0.95\textwidth}{3 B}
|
76
|
157 Name & Brief description\\
|
0
|
158 \hline
|
|
159 {\bf r0} & scratch\\
|
|
160 {\bf r1} & stack pointer\\
|
|
161 {\bf r2} & system-reserved\\
|
|
162 {\bf r3-r4} & parameter passing and return value\\
|
|
163 {\bf r5-r10} & parameter passing\\
|
|
164 {\bf r11-r12} & scratch\\
|
|
165 {\bf r13} & Small data area pointer register\\
|
|
166 {\bf r14-r30} & Local variables\\
|
|
167 {\bf r31} & Used for local variables or \emph{environment pointer}\\
|
|
168 {\bf f0} & scratch\\
|
|
169 {\bf f1} & parameter passing and return value\\
|
|
170 {\bf f2-f8} & parameter passing\\
|
|
171 {\bf f9-13} & scratch\\
|
|
172 {\bf f14-f31} & Local variables\\
|
|
173 {\bf cr0-cr7} & Conditional register fields, each 4-bit wide (cr0-cr1 and cr5-cr7 are scratch)\\
|
|
174 {\bf lr} & Link register (scratch)\\
|
|
175 {\bf ctr} & Count register (scratch) \\
|
|
176 {\bf xer} & Fixed-point exception register (scratch)\\
|
|
177 {\bf fpscr} & Floating-point Status and Control Register\\
|
|
178 % {\bf v0-v1} & scratch\\
|
|
179 % {\bf v2-v13} & vector parameters\\
|
|
180 % {\bf v14-v19} & scratch\\
|
|
181 % {\bf v20-v31} & permanent\\
|
|
182 % {\bf lr} & scratch, link-register\\
|
|
183 % {\bf ctr} & scratch, count-register\\
|
|
184 % {\bf cr0-cr1} & scratch\\
|
|
185 % {\bf cr2-cr4} & permanent\\
|
|
186 % {\bf cr5-cr7} & scratch\\
|
76
|
187 \end{tabular*}
|
0
|
188 \caption{Register usage on System V ABI PowerPC Processor}
|
|
189 \end{table}
|
|
190
|
|
191 \paragraph{Parameter passing}
|
|
192
|
|
193 \begin{itemize}
|
|
194 \item Stack pointer (r1) is always 16-byte aligned. The EABI differs here - it is 8-byte alignment.
|
|
195 \item 8 general-purpose registers (r3-r10) for integer and pointer types.
|
|
196 \item 8 floating-pointer registers (f1-f8) for float (promoted to double) and double types.
|
|
197 \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.
|
|
198 \item 64-bit integer data types are passed in general-purpose registers as a whole in two
|
|
199 32-bit general purpose registers (an odd and an even e.g. r3 and r4), probably skipping an even integer register.
|
|
200 or passed on the stack. They are never splitted into a register and stack part.
|
|
201 \item Ellipse calls set CR bit 6
|
123
|
202 \item integer parameters \textless\ 32 bit are right-justified (meaning occupy high-order bytes) in their 4-byte area, requiring extra-care for big-endian targets
|
0
|
203 \end{itemize}
|
|
204
|
|
205 \paragraph{Return values}
|
|
206
|
|
207 \begin{itemize}
|
|
208 \item 32-bit integers use register r3, 64-bit use registers r3 and r4 (hiword in r3, loword in r4).
|
|
209 \item floating-point values are returned using register f1.
|
|
210 \end{itemize}
|
|
211
|
|
212 \pagebreak
|
|
213
|
|
214 \paragraph{Stack layout}
|
|
215
|
|
216 Stack frame is always 16-byte aligned. Stack directly after function prolog:\\
|
|
217
|
|
218 \begin{figure}[h]
|
|
219 \begin{tabular}{5|3|1 1}
|
|
220 \hhline{~-~~}
|
|
221 & \vdots & & \\
|
|
222 \hhline{~=~~}
|
92
|
223 local data & \hspace{4cm} & & \mrrbrace{6}{caller's frame} \\
|
0
|
224 \hhline{~-~~}
|
|
225 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
226 & \ldots & & \\
|
|
227 & \ldots & & \\
|
|
228 \hhline{~-~~}
|
|
229 & saved return address (for callee) & & \\
|
|
230 \hhline{~-~~}
|
|
231 & parent stack frame pointer & & \\
|
|
232 \hhline{~=~~}
|
|
233 local data & & & \mrrbrace{3}{current frame} \\
|
|
234 \hhline{~-~~}
|
|
235 parameter area & & & \\
|
|
236 \hhline{~-~~}
|
|
237 & \vdots & & \\
|
|
238 \hhline{~-~~}
|
|
239 \end{tabular}
|
|
240 \\
|
|
241 \\
|
|
242 \\
|
|
243 \caption{Stack layout on System V ABI for PowerPC 32-bit calling convention}
|
|
244 \end{figure}
|