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