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 % x86
|
|
22 % ==================================================
|
|
23 \subsection{x86 Calling Conventions}
|
|
24
|
|
25
|
|
26 \paragraph{Overview}
|
|
27
|
|
28 There are numerous different calling conventions on the x86 processor
|
|
29 architecture, like cdecl \cite{x86cdecl}, MS fastcall \cite{x86Winfastcall}, GNU
|
|
30 fastcall \cite{x86GNUfastcall}, Borland fastcall \cite{x86Borlandfastcall}, Watcom
|
|
31 fastcall \cite{x86Watcomfastcall}, Win32 stdcall \cite{x86Winstdcall}, MS thiscall
|
|
32 \cite{x86Winthiscall}, GNU thiscall \cite{x86GNUthiscall}, the pascal calling
|
|
33 convention \cite{x86Pascal} and a cdecl-like version for Plan9 \cite{x86Plan9}
|
95
|
34 (dubbed plan9call by us), etc.\\
|
0
|
35
|
|
36
|
|
37 \paragraph{\product{dyncall} support}
|
|
38
|
|
39 Currently cdecl, stdcall, fastcall (MS and GNU), thiscall (MS and GNU) and
|
|
40 plan9call are supported.\\
|
|
41 \\
|
|
42
|
|
43
|
|
44 \subsubsection{cdecl}
|
|
45
|
|
46 \paragraph{Registers and register usage}
|
|
47
|
|
48 \begin{table}[h]
|
77
|
49 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
50 Name & Brief description\\
|
|
51 \hline
|
|
52 {\bf eax} & scratch, return value\\
|
|
53 {\bf ebx} & permanent\\
|
|
54 {\bf ecx} & scratch\\
|
|
55 {\bf edx} & scratch, return value\\
|
|
56 {\bf esi} & permanent\\
|
|
57 {\bf edi} & permanent\\
|
|
58 {\bf ebp} & permanent\\
|
|
59 {\bf esp} & stack pointer\\
|
|
60 {\bf st0} & scratch, floating point return value\\
|
|
61 {\bf st1-st7} & scratch\\
|
76
|
62 \end{tabular*}
|
0
|
63 \caption{Register usage on x86 cdecl calling convention}
|
|
64 \end{table}
|
|
65
|
|
66
|
|
67 \pagebreak
|
|
68
|
|
69 \paragraph{Parameter passing}
|
|
70
|
|
71 \begin{itemize}
|
|
72 \item stack parameter order: right-to-left
|
|
73 \item caller cleans up the stack
|
|
74 \item all arguments are pushed onto the stack
|
|
75 \end{itemize}
|
|
76
|
|
77 \paragraph{Return values}
|
|
78
|
|
79 \begin{itemize}
|
|
80 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
81 \item integers \textgreater\ 32 bits are returned via the eax and edx registers
|
|
82 \item floating point types are returned via the st0 register
|
|
83 \end{itemize}
|
|
84
|
|
85
|
|
86 \paragraph{Stack layout}
|
|
87
|
|
88 Stack directly after function prolog:\\
|
|
89
|
|
90 \begin{figure}[h]
|
|
91 \begin{tabular}{5|3|1 1}
|
|
92 \hhline{~-~~}
|
92
|
93 & \vdots & & \\
|
0
|
94 \hhline{~=~~}
|
92
|
95 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
96 \hhline{~-~~}
|
92
|
97 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
98 & \ldots & & \\
|
|
99 & \ldots & & \\
|
0
|
100 \hhline{~-~~}
|
92
|
101 & return address & & \\
|
0
|
102 \hhline{~=~~}
|
92
|
103 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
104 \hhline{~-~~}
|
92
|
105 parameter area & & & \\
|
0
|
106 \hhline{~-~~}
|
92
|
107 & \vdots & & \\
|
0
|
108 \hhline{~-~~}
|
|
109 \end{tabular}
|
|
110 \caption{Stack layout on x86 cdecl calling convention}
|
|
111 \end{figure}
|
|
112
|
|
113
|
|
114 \pagebreak
|
|
115
|
|
116 \subsubsection{MS fastcall}
|
|
117
|
|
118 \paragraph{Registers and register usage}
|
|
119
|
|
120 \begin{table}[h]
|
77
|
121 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
122 Name & Brief description\\
|
|
123 \hline
|
|
124 {\bf eax} & scratch, return value\\
|
|
125 {\bf ebx} & permanent\\
|
|
126 {\bf ecx} & scratch, parameter 0\\
|
|
127 {\bf edx} & scratch, parameter 1, return value\\
|
|
128 {\bf esi} & permanent\\
|
|
129 {\bf edi} & permanent\\
|
|
130 {\bf ebp} & permanent\\
|
|
131 {\bf esp} & stack pointer\\
|
|
132 {\bf st0} & scratch, floating point return value\\
|
|
133 {\bf st1-st7} & scratch\\
|
76
|
134 \end{tabular*}
|
0
|
135 \caption{Register usage on x86 fastcall (MS) calling convention}
|
|
136 \end{table}
|
|
137
|
|
138
|
|
139 \pagebreak
|
|
140
|
|
141 \paragraph{Parameter passing}
|
|
142
|
|
143 \begin{itemize}
|
|
144 \item stack parameter order: right-to-left
|
|
145 \item called function cleans up the stack
|
|
146 \item first two integers/pointers (\textless=\ 32bit) are passed via ecx and edx (even if preceded by other arguments)
|
|
147 \item integer types 64 bits in size @@@ ? first in edx:eax ?
|
|
148 \item if first argument is a 64 bit integer, it is passed via ecx and edx
|
|
149 \item all other parameters are pushed onto the stack
|
|
150 \end{itemize}
|
|
151
|
|
152 \paragraph{Return values}
|
|
153
|
|
154 \begin{itemize}
|
|
155 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
156 \item integers \textgreater\ 32 bits are returned via the eax and edx registers@@@verify
|
|
157 \item floating point types are returned via the st0 register@@@ really ?
|
|
158 \end{itemize}
|
|
159
|
|
160
|
|
161 \paragraph{Stack layout}
|
|
162
|
|
163 Stack directly after function prolog:\\
|
|
164
|
|
165 \begin{figure}[h]
|
|
166 \begin{tabular}{5|3|1 1}
|
|
167 \hhline{~-~~}
|
92
|
168 & \vdots & & \\
|
0
|
169 \hhline{~=~~}
|
92
|
170 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
171 \hhline{~-~~}
|
92
|
172 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
173 & \ldots & & \\
|
|
174 & \ldots & & \\
|
0
|
175 \hhline{~-~~}
|
92
|
176 & return address & & \\
|
0
|
177 \hhline{~=~~}
|
92
|
178 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
179 \hhline{~-~~}
|
92
|
180 parameter area & & & \\
|
0
|
181 \hhline{~-~~}
|
92
|
182 & \vdots & & \\
|
0
|
183 \hhline{~-~~}
|
|
184 \end{tabular}
|
|
185 \caption{Stack layout on x86 fastcall (MS) calling convention}
|
|
186 \end{figure}
|
|
187
|
|
188
|
|
189 \pagebreak
|
|
190
|
|
191 \subsubsection{GNU fastcall}
|
|
192
|
|
193 \paragraph{Registers and register usage}
|
|
194
|
|
195 \begin{table}[h]
|
77
|
196 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
197 Name & Brief description\\
|
|
198 \hline
|
|
199 {\bf eax} & scratch, return value\\
|
|
200 {\bf ebx} & permanent\\
|
|
201 {\bf ecx} & scratch, parameter 0\\
|
|
202 {\bf edx} & scratch, parameter 1, return value\\
|
|
203 {\bf esi} & permanent\\
|
|
204 {\bf edi} & permanent\\
|
|
205 {\bf ebp} & permanent\\
|
|
206 {\bf esp} & stack pointer\\
|
|
207 {\bf st0} & scratch, floating point return value\\
|
|
208 {\bf st1-st7} & scratch\\
|
76
|
209 \end{tabular*}
|
0
|
210 \caption{Register usage on x86 fastcall (GNU) calling convention}
|
|
211 \end{table}
|
|
212
|
|
213 \paragraph{Parameter passing}
|
|
214
|
|
215 \begin{itemize}
|
|
216 \item stack parameter order: right-to-left
|
|
217 \item called function cleans up the stack
|
|
218 \item first two integers/pointers (\textless=\ 32bit) are passed via ecx and edx (even if preceded by other arguments)
|
|
219 \item if first argument is a 64 bit integer, it is pushed on the stack and the two registers are skipped
|
|
220 \item all other parameters are pushed onto the stack
|
|
221 \end{itemize}
|
|
222
|
|
223
|
|
224 \paragraph{Return values}
|
|
225
|
|
226 \begin{itemize}
|
|
227 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register.
|
|
228 \item integers \textgreater\ 32 bits are returned via the eax and edx registers.
|
|
229 \item floating point types are returned via the st0.
|
|
230 \end{itemize}
|
|
231
|
|
232
|
|
233 \pagebreak
|
|
234
|
|
235 \paragraph{Stack layout}
|
|
236
|
|
237 Stack directly after function prolog:\\
|
|
238
|
|
239 \begin{figure}[h]
|
|
240 \begin{tabular}{5|3|1 1}
|
|
241 \hhline{~-~~}
|
92
|
242 & \vdots & & \\
|
0
|
243 \hhline{~=~~}
|
92
|
244 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
245 \hhline{~-~~}
|
92
|
246 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
247 & \ldots & & \\
|
|
248 & \ldots & & \\
|
0
|
249 \hhline{~-~~}
|
92
|
250 & return address & & \\
|
0
|
251 \hhline{~=~~}
|
92
|
252 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
253 \hhline{~-~~}
|
92
|
254 parameter area & & & \\
|
0
|
255 \hhline{~-~~}
|
92
|
256 & \vdots & & \\
|
0
|
257 \hhline{~-~~}
|
|
258 \end{tabular}
|
|
259 \caption{Stack layout on x86 fastcall (GNU) calling convention}
|
|
260 \end{figure}
|
|
261
|
|
262
|
|
263 \subsubsection{Borland fastcall}
|
|
264
|
|
265 \paragraph{Registers and register usage}
|
|
266
|
|
267 \begin{table}[h]
|
77
|
268 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
269 Name & Brief description\\
|
|
270 \hline
|
|
271 {\bf eax} & scratch, parameter 0, return value\\
|
|
272 {\bf ebx} & permanent\\
|
|
273 {\bf ecx} & scratch, parameter 2\\
|
|
274 {\bf edx} & scratch, parameter 1, return value\\
|
|
275 {\bf esi} & permanent\\
|
|
276 {\bf edi} & permanent\\
|
|
277 {\bf ebp} & permanent\\
|
|
278 {\bf esp} & stack pointer\\
|
|
279 {\bf st0} & scratch, floating point return value\\
|
|
280 {\bf st1-st7} & scratch\\
|
76
|
281 \end{tabular*}
|
0
|
282 \caption{Register usage on x86 fastcall (Borland) calling convention}
|
|
283 \end{table}
|
|
284
|
|
285 \paragraph{Parameter passing}
|
|
286
|
|
287 \begin{itemize}
|
|
288 \item stack parameter order: left-to-right
|
|
289 \item called function cleans up the stack
|
|
290 \item first three integers/pointers (\textless=\ 32bit) are passed via eax, ecx and edx (even if preceded by other arguments@@@?)
|
|
291 \item integer types 64 bits in size @@@ ?
|
|
292 \item all other parameters are pushed onto the stack
|
|
293 \end{itemize}
|
|
294
|
|
295
|
|
296 \pagebreak
|
|
297
|
|
298 \paragraph{Return values}
|
|
299
|
|
300 \begin{itemize}
|
|
301 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
302 \item integers \textgreater\ 32 bits are returned via the eax and edx registers@@@ verify
|
|
303 \item floating point types are returned via the st0 register@@@ really ?
|
|
304 \end{itemize}
|
|
305
|
|
306
|
|
307
|
|
308 \paragraph{Stack layout}
|
|
309
|
|
310 Stack directly after function prolog:\\
|
|
311
|
|
312 \begin{figure}[h]
|
|
313 \begin{tabular}{5|3|1 1}
|
|
314 \hhline{~-~~}
|
92
|
315 & \vdots & & \\
|
0
|
316 \hhline{~=~~}
|
92
|
317 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
318 \hhline{~-~~}
|
92
|
319 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
320 & \ldots & & \\
|
|
321 & \ldots & & \\
|
0
|
322 \hhline{~-~~}
|
92
|
323 & return address & & \\
|
0
|
324 \hhline{~=~~}
|
92
|
325 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
326 \hhline{~-~~}
|
92
|
327 parameter area & & & \\
|
0
|
328 \hhline{~-~~}
|
92
|
329 & \vdots & & \\
|
0
|
330 \hhline{~-~~}
|
|
331 \end{tabular}
|
|
332 \caption{Stack layout on x86 fastcall (Borland) calling convention}
|
|
333 \end{figure}
|
|
334
|
|
335
|
|
336 \subsubsection{Watcom fastcall}
|
|
337
|
|
338
|
|
339 \paragraph{Registers and register usage}
|
|
340
|
|
341 \begin{table}[h]
|
77
|
342 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
343 Name & Brief description\\
|
|
344 \hline
|
|
345 {\bf eax} & scratch, parameter 0, return value@@@\\
|
|
346 {\bf ebx} & scratch when used for parameter, parameter 2\\
|
|
347 {\bf ecx} & scratch when used for parameter, parameter 3\\
|
|
348 {\bf edx} & scratch when used for parameter, parameter 1, return value@@@\\
|
|
349 {\bf esi} & scratch when used for return pointer @@@??\\
|
|
350 {\bf edi} & permanent\\
|
|
351 {\bf ebp} & permanent\\
|
|
352 {\bf esp} & stack pointer\\
|
|
353 {\bf st0} & scratch, floating point return value\\
|
|
354 {\bf st1-st7} & scratch\\
|
76
|
355 \end{tabular*}
|
0
|
356 \caption{Register usage on x86 fastcall (Watcom) calling convention}
|
|
357 \end{table}
|
|
358
|
|
359 \paragraph{Parameter passing}
|
|
360
|
|
361 \begin{itemize}
|
|
362 \item stack parameter order: right-to-left
|
|
363 \item called function cleans up the stack
|
|
364 \item first four integers/pointers (\textless=\ 32bit) are passed via eax, edx, ebx and ecx (even if preceded by other arguments@@@?)
|
|
365 \item integer types 64 bits in size @@@ ?
|
|
366 \item all other parameters are pushed onto the stack
|
|
367 \end{itemize}
|
|
368
|
|
369
|
|
370 \paragraph{Return values}
|
|
371
|
|
372 \begin{itemize}
|
|
373 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register@@@verify, I thnik its esi?
|
|
374 \item integers \textgreater\ 32 bits are returned via the eax and edx registers@@@ verify
|
|
375 \item floating point types are returned via the st0 register@@@ really ?
|
|
376 \end{itemize}
|
|
377
|
|
378
|
|
379 \paragraph{Stack layout}
|
|
380
|
|
381 Stack directly after function prolog:\\
|
|
382
|
|
383 \begin{figure}[h]
|
|
384 \begin{tabular}{5|3|1 1}
|
|
385 \hhline{~-~~}
|
92
|
386 & \vdots & & \\
|
0
|
387 \hhline{~=~~}
|
92
|
388 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
389 \hhline{~-~~}
|
92
|
390 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
391 & \ldots & & \\
|
|
392 & \ldots & & \\
|
0
|
393 \hhline{~-~~}
|
92
|
394 & return address & & \\
|
0
|
395 \hhline{~=~~}
|
92
|
396 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
397 \hhline{~-~~}
|
92
|
398 parameter area & & & \\
|
0
|
399 \hhline{~-~~}
|
92
|
400 & \vdots & & \\
|
0
|
401 \hhline{~-~~}
|
|
402 \end{tabular}
|
|
403 \caption{Stack layout on x86 fastcall (Watcom) calling convention}
|
|
404 \end{figure}
|
|
405
|
|
406
|
|
407
|
|
408 \subsubsection{win32 stdcall}
|
|
409
|
|
410 \paragraph{Registers and register usage}
|
|
411
|
|
412 \begin{table}[h]
|
77
|
413 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
414 Name & Brief description\\
|
|
415 \hline
|
|
416 {\bf eax} & scratch, return value\\
|
|
417 {\bf ebx} & permanent\\
|
|
418 {\bf ecx} & scratch\\
|
|
419 {\bf edx} & scratch, return value\\
|
|
420 {\bf esi} & permanent\\
|
|
421 {\bf edi} & permanent\\
|
|
422 {\bf ebp} & permanent\\
|
|
423 {\bf esp} & stack pointer\\
|
|
424 {\bf st0} & scratch, floating point return value\\
|
|
425 {\bf st1-st7} & scratch\\
|
76
|
426 \end{tabular*}
|
0
|
427 \caption{Register usage on x86 stdcall calling convention}
|
|
428 \end{table}
|
|
429
|
|
430 \paragraph{Parameter passing}
|
|
431
|
|
432 \begin{itemize}
|
|
433 \item Stack parameter order: right-to-left
|
|
434 \item Called function cleans up the stack
|
|
435 \item All parameters are pushed onto the stack
|
|
436 \item Stack is usually 4 byte aligned (GCC \textgreater=\ 3.x seems to use a 16byte alignement@@@)
|
|
437 \item Function name is decorated by prepending an underscore character and appending a '@' character and the number of bytes of stack space required
|
|
438 \end{itemize}
|
|
439
|
|
440
|
|
441 \paragraph{Return values}
|
|
442
|
|
443 \begin{itemize}
|
|
444 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
445 \item integers \textgreater\ 32 bits are returned via the eax and edx registers
|
|
446 \item floating point types are returned via the st0 register
|
|
447 \end{itemize}
|
|
448
|
|
449
|
|
450 \paragraph{Stack layout}
|
|
451
|
|
452 Stack directly after function prolog:\\
|
|
453
|
|
454 \begin{figure}[h]
|
|
455 \begin{tabular}{5|3|1 1}
|
|
456 \hhline{~-~~}
|
92
|
457 & \vdots & & \\
|
0
|
458 \hhline{~=~~}
|
92
|
459 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
460 \hhline{~-~~}
|
92
|
461 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
462 & \ldots & & \\
|
|
463 & \ldots & & \\
|
0
|
464 \hhline{~-~~}
|
92
|
465 & return address & & \\
|
0
|
466 \hhline{~=~~}
|
92
|
467 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
468 \hhline{~-~~}
|
92
|
469 parameter area & & & \\
|
0
|
470 \hhline{~-~~}
|
92
|
471 & \vdots & & \\
|
0
|
472 \hhline{~-~~}
|
|
473 \end{tabular}
|
|
474 \caption{Stack layout on x86 stdcall calling convention}
|
|
475 \end{figure}
|
|
476
|
|
477 \subsubsection{MS thiscall}
|
|
478
|
|
479 \paragraph{Registers and register usage}
|
|
480
|
|
481 \begin{table}[h]
|
77
|
482 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
483 Name & Brief description\\
|
|
484 \hline
|
|
485 {\bf eax} & scratch, return value\\
|
|
486 {\bf ebx} & permanent\\
|
|
487 {\bf ecx} & scratch, parameter 0\\
|
|
488 {\bf edx} & scratch, return value\\
|
|
489 {\bf esi} & permanent\\
|
|
490 {\bf edi} & permanent\\
|
|
491 {\bf ebp} & permanent\\
|
|
492 {\bf esp} & stack pointer\\
|
|
493 {\bf st0} & scratch, floating point return value\\
|
|
494 {\bf st1-st7} & scratch\\
|
76
|
495 \end{tabular*}
|
0
|
496 \caption{Register usage on x86 thiscall (MS) calling convention}
|
|
497 \end{table}
|
|
498
|
|
499 \newpage
|
|
500
|
|
501
|
|
502 \paragraph{Parameter passing}
|
|
503
|
|
504 \begin{itemize}
|
|
505 \item stack parameter order: right-to-left
|
|
506 \item called function cleans up the stack
|
|
507 \item first parameter (this pointer) is passed via ecx
|
|
508 \item all other parameters are pushed onto the stack
|
|
509 \item Function name is decorated by prepending a '@' character and appending a '@' character and the number of bytes (decimal) of stack space required
|
|
510 \end{itemize}
|
|
511
|
|
512
|
|
513 \paragraph{Return values}
|
|
514
|
|
515 \begin{itemize}
|
|
516 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
517 \item integers \textgreater\ 32 bits are returned via the eax and edx registers@@@verify
|
|
518 \item floating point types are returned via the st0 register@@@ really ?
|
|
519 \end{itemize}
|
|
520
|
|
521
|
|
522 \paragraph{Stack layout}
|
|
523
|
|
524 Stack directly after function prolog:\\
|
|
525
|
|
526 \begin{figure}[h]
|
|
527 \begin{tabular}{5|3|1 1}
|
|
528 \hhline{~-~~}
|
92
|
529 & \vdots & & \\
|
0
|
530 \hhline{~=~~}
|
92
|
531 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
532 \hhline{~-~~}
|
92
|
533 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
534 & \ldots & & \\
|
|
535 & \ldots & & \\
|
0
|
536 \hhline{~-~~}
|
92
|
537 & return address & & \\
|
0
|
538 \hhline{~=~~}
|
92
|
539 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
540 \hhline{~-~~}
|
92
|
541 parameter area & & & \\
|
0
|
542 \hhline{~-~~}
|
92
|
543 & \vdots & & \\
|
0
|
544 \hhline{~-~~}
|
|
545 \end{tabular}
|
|
546 \caption{Stack layout on x86 thiscall (MS) calling convention}
|
|
547 \end{figure}
|
|
548
|
|
549
|
|
550
|
|
551 \subsubsection{GNU thiscall}
|
|
552
|
|
553 \paragraph{Registers and register usage}
|
|
554
|
|
555 \begin{table}[h]
|
77
|
556 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
557 Name & Brief description\\
|
|
558 \hline
|
|
559 {\bf eax} & scratch, return value\\
|
|
560 {\bf ebx} & permanent\\
|
|
561 {\bf ecx} & scratch\\
|
|
562 {\bf edx} & scratch, return value\\
|
|
563 {\bf esi} & permanent\\
|
|
564 {\bf edi} & permanent\\
|
|
565 {\bf ebp} & permanent\\
|
|
566 {\bf esp} & stack pointer\\
|
|
567 {\bf st0} & scratch, floating point return value\\
|
|
568 {\bf st1-st7} & scratch\\
|
76
|
569 \end{tabular*}
|
0
|
570 \caption{Register usage on x86 thiscall (GNU) calling convention}
|
|
571 \end{table}
|
|
572
|
|
573 \paragraph{Parameter passing}
|
|
574
|
|
575 \begin{itemize}
|
|
576 \item stack parameter order: right-to-left
|
|
577 \item caller cleans up the stack
|
|
578 \item all parameters are pushed onto the stack
|
|
579 \end{itemize}
|
|
580
|
|
581
|
|
582 \paragraph{Return values}
|
|
583
|
|
584 \begin{itemize}
|
|
585 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
586 \item integers \textgreater\ 32 bits are returned via the eax and edx registers@@@verify
|
|
587 \item floating point types are returned via the st0 register@@@ really ?
|
|
588 \end{itemize}
|
|
589
|
|
590
|
|
591 \paragraph{Stack layout}
|
|
592
|
|
593 Stack directly after function prolog:\\
|
|
594
|
|
595 \begin{figure}[h]
|
|
596 \begin{tabular}{5|3|1 1}
|
|
597 \hhline{~-~~}
|
92
|
598 & \vdots & & \\
|
0
|
599 \hhline{~=~~}
|
92
|
600 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
601 \hhline{~-~~}
|
92
|
602 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
603 & \ldots & & \\
|
|
604 & \ldots & & \\
|
0
|
605 \hhline{~-~~}
|
92
|
606 & return address & & \\
|
0
|
607 \hhline{~=~~}
|
92
|
608 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
609 \hhline{~-~~}
|
92
|
610 parameter area & & & \\
|
0
|
611 \hhline{~-~~}
|
92
|
612 & \vdots & & \\
|
0
|
613 \hhline{~-~~}
|
|
614 \end{tabular}
|
|
615 \caption{Stack layout on x86 thiscall (GNU) calling convention}
|
|
616 \end{figure}
|
|
617
|
|
618
|
|
619
|
|
620 \subsubsection{pascal}
|
|
621
|
|
622 The best known uses of the pascal calling convention are the 16 bit OS/2 APIs, Microsoft Windows 3.x and Borland Delphi 1.x.
|
|
623
|
|
624 \paragraph{Registers and register usage}
|
|
625
|
|
626 \begin{table}[h]
|
77
|
627 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
628 Name & Brief description\\
|
|
629 \hline
|
|
630 {\bf eax} & scratch, return value\\
|
|
631 {\bf ebx} & permanent\\
|
|
632 {\bf ecx} & scratch\\
|
|
633 {\bf edx} & scratch, return value\\
|
|
634 {\bf esi} & permanent\\
|
|
635 {\bf edi} & permanent\\
|
|
636 {\bf ebp} & permanent\\
|
|
637 {\bf esp} & stack pointer\\
|
|
638 {\bf st0} & scratch, floating point return value\\
|
|
639 {\bf st1-st7} & scratch\\
|
76
|
640 \end{tabular*}
|
0
|
641 \caption{Register usage on x86 pascal calling convention}
|
|
642 \end{table}
|
|
643
|
|
644 \paragraph{Parameter passing}
|
|
645
|
|
646 \begin{itemize}
|
|
647 \item stack parameter order: left-to-right
|
|
648 \item called function cleans up the stack
|
|
649 \item all parameters are pushed onto the stack
|
|
650 \end{itemize}
|
|
651
|
|
652
|
|
653 \paragraph{Return values}
|
|
654
|
|
655 \begin{itemize}
|
|
656 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
657 \item integers \textgreater\ 32 bits are returned via the eax and edx registers
|
|
658 \item floating point types are returned via the st0 register
|
|
659 \end{itemize}
|
|
660
|
|
661
|
|
662 \paragraph{Stack layout}
|
|
663
|
|
664 Stack directly after function prolog:\\
|
|
665
|
|
666 \begin{figure}[h]
|
|
667 \begin{tabular}{5|3|1 1}
|
|
668 \hhline{~-~~}
|
92
|
669 & \vdots & & \\
|
0
|
670 \hhline{~=~~}
|
92
|
671 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
672 \hhline{~-~~}
|
92
|
673 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
674 & \ldots & & \\
|
|
675 & \ldots & & \\
|
0
|
676 \hhline{~-~~}
|
92
|
677 & return address & & \\
|
0
|
678 \hhline{~=~~}
|
92
|
679 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
680 \hhline{~-~~}
|
92
|
681 parameter area & & & \\
|
0
|
682 \hhline{~-~~}
|
92
|
683 & \vdots & & \\
|
0
|
684 \hhline{~-~~}
|
|
685 \end{tabular}
|
|
686 \caption{Stack layout on x86 pascal calling convention}
|
|
687 \end{figure}
|
|
688
|
|
689
|
|
690 \newpage
|
|
691
|
|
692 \subsubsection{plan9call}
|
|
693
|
|
694 \paragraph{Registers and register usage}
|
|
695
|
|
696 \begin{table}[h]
|
77
|
697 \begin{tabular*}{0.95\textwidth}{3 B}
|
0
|
698 Name & Brief description\\
|
|
699 \hline
|
|
700 {\bf eax} & scratch, return value\\
|
|
701 {\bf ebx} & scratch\\
|
|
702 {\bf ecx} & scratch\\
|
|
703 {\bf edx} & scratch\\
|
|
704 {\bf esi} & scratch\\
|
|
705 {\bf edi} & scratch\\
|
|
706 {\bf ebp} & scratch\\
|
|
707 {\bf esp} & stack pointer\\
|
|
708 {\bf st0} & scratch, floating point return value\\
|
|
709 {\bf st1-st7} & scratch\\
|
76
|
710 \end{tabular*}
|
0
|
711 \caption{Register usage on x86 plan9call calling convention}
|
|
712 \end{table}
|
|
713
|
|
714 \paragraph{Parameter passing}
|
|
715
|
|
716 \begin{itemize}
|
|
717 \item stack parameter order: right-to-left
|
|
718 \item caller cleans up the stack%@@@ doesn't belong to "parameter passing"
|
|
719 \item all parameters are pushed onto the stack
|
|
720 \end{itemize}
|
|
721
|
|
722 \pagebreak
|
|
723
|
|
724 \paragraph{Return values}
|
|
725
|
|
726 \begin{itemize}
|
|
727 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
|
|
728 \item integers \textgreater\ 32 bits or structures are returned by the caller allocating the space and
|
|
729 passing a pointer to the callee as a new, implicit first parameter (this means, on the stack)
|
|
730 \item floating point types are returned via the st0 register (called F0 in plan9 8a's terms)
|
|
731 \end{itemize}
|
|
732
|
|
733
|
|
734 \paragraph{Stack layout}
|
|
735
|
|
736 Stack directly after function prolog:\\
|
|
737
|
|
738 \begin{figure}[h]
|
|
739 \begin{tabular}{5|3|1 1}
|
|
740 \hhline{~-~~}
|
92
|
741 & \vdots & & \\
|
0
|
742 \hhline{~=~~}
|
92
|
743 local data & \hspace{4cm} & & \mrrbrace{5}{caller's frame} \\
|
0
|
744 \hhline{~-~~}
|
92
|
745 \mrlbrace{3}{parameter area} & \ldots & \mrrbrace{3}{stack parameters} & \\
|
|
746 & \ldots & & \\
|
|
747 & \ldots & & \\
|
0
|
748 \hhline{~-~~}
|
92
|
749 & return address & & \\
|
0
|
750 \hhline{~=~~}
|
92
|
751 local data & & & \mrrbrace{3}{current frame} \\
|
0
|
752 \hhline{~-~~}
|
92
|
753 parameter area & & & \\
|
0
|
754 \hhline{~-~~}
|
92
|
755 & \vdots & & \\
|
0
|
756 \hhline{~-~~}
|
|
757 \end{tabular}
|
|
758 \\
|
|
759 \\
|
|
760 \\
|
|
761 \caption{Stack layout on x86 plan9call calling convention}
|
|
762 \end{figure}
|