comparison doc/manual/callconvs/callconv_x86.tex @ 490:17287342e273

manual: - removed all API description and referred to manual instead, to avoid outdated and/or duplicated doc - cleanups and clarificaions
author Tassilo Philipp
date Sun, 20 Mar 2022 14:26:55 +0100
parents e5820b7a3fbc
children fc614cb865c6
comparison
equal deleted inserted replaced
489:63f623bff0b9 490:17287342e273
62 plan9call are supported.\\ 62 plan9call are supported.\\
63 \product{Dyncall} can also be used to issue syscalls on Linux and *BSD by using 63 \product{Dyncall} can also be used to issue syscalls on Linux and *BSD by using
64 the syscall number as target parameter and selecting the correct mode. 64 the syscall number as target parameter and selecting the correct mode.
65 65
66 66
67 \clearpage 67
68 68 \pagebreak
69 69
70 \subsubsection{cdecl} 70 \subsubsection{cdecl}
71 71
72 \paragraph{Registers and register usage} 72 \paragraph{Registers and register usage}
73 73
140 \end{tabular} 140 \end{tabular}
141 \caption{Stack layout on x86 cdecl calling convention} 141 \caption{Stack layout on x86 cdecl calling convention}
142 \end{figure} 142 \end{figure}
143 143
144 144
145 \clearpage 145 \pagebreak
146
147 146
148 \subsubsection{MS fastcall} 147 \subsubsection{MS fastcall}
149 148
150 \paragraph{Registers and register usage} 149 \paragraph{Registers and register usage}
151 150
178 \item arguments \textgreater\ 64 bits are pushed as a sequence of dwords 177 \item arguments \textgreater\ 64 bits are pushed as a sequence of dwords
179 \item aggregates (structs, unions) are pushed as a sequence of dwords, but are never split between registers and stack (if registers are still available and 178 \item aggregates (structs, unions) are pushed as a sequence of dwords, but are never split between registers and stack (if registers are still available and
180 aggregate doesn't fit entirely into ecx and edx, it is passed via the stack and remaining registers are free for subsequent arguments) 179 aggregate doesn't fit entirely into ecx and edx, it is passed via the stack and remaining registers are free for subsequent arguments)
181 \end{itemize} 180 \end{itemize}
182 181
182 \clearpage
183
183 \paragraph{Return values} 184 \paragraph{Return values}
184 185
185 \begin{itemize} 186 \begin{itemize}
186 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register 187 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
187 \item integers and aggregates (structs, unions) \textgreater\ 32 and \textless=\ 64 bits are returned via the eax and edx registers 188 \item integers and aggregates (structs, unions) \textgreater\ 32 and \textless=\ 64 bits are returned via the eax and edx registers
243 {\bf st1-st7} & scratch\\ 244 {\bf st1-st7} & scratch\\
244 \end{tabular*} 245 \end{tabular*}
245 \caption{Register usage on x86 fastcall (GNU) calling convention} 246 \caption{Register usage on x86 fastcall (GNU) calling convention}
246 \end{table} 247 \end{table}
247 248
249
250 \clearpage
251
248 \paragraph{Parameter passing} 252 \paragraph{Parameter passing}
249 253
250 \begin{itemize} 254 \begin{itemize}
251 \item stack parameter order: right-to-left 255 \item stack parameter order: right-to-left
252 \item called function cleans up the stack 256 \item called function cleans up the stack
266 \item aggregates (structs, unions) of any size are returned by the caller allocating the space and 270 \item aggregates (structs, unions) of any size are returned by the caller allocating the space and
267 passing a pointer to the callee as a new, implicit first parameter (always via ecx), that same pointer is returned in eax 271 passing a pointer to the callee as a new, implicit first parameter (always via ecx), that same pointer is returned in eax
268 \item floating point types are returned via the st0 272 \item floating point types are returned via the st0
269 \end{itemize} 273 \end{itemize}
270 274
271
272 \pagebreak
273 275
274 \paragraph{Stack layout} 276 \paragraph{Stack layout}
275 277
276 Stack directly after function prolog:\\ 278 Stack directly after function prolog:\\
277 279
298 & \vdots & & \\ 300 & \vdots & & \\
299 \end{tabular} 301 \end{tabular}
300 \caption{Stack layout on x86 fastcall (GNU) calling convention} 302 \caption{Stack layout on x86 fastcall (GNU) calling convention}
301 \end{figure} 303 \end{figure}
302 304
305
306 \pagebreak
303 307
304 \subsubsection{Borland fastcall} 308 \subsubsection{Borland fastcall}
305 309
306 Also called {\bf register convention} by Borland. 310 Also called {\bf register convention} by Borland.
307 311
338 \item all other parameters are pushed onto the stack 342 \item all other parameters are pushed onto the stack
339 \item the direction flag is clear on entry and must be returned clear % mention it first, above @@@ 343 \item the direction flag is clear on entry and must be returned clear % mention it first, above @@@
340 \end{itemize} 344 \end{itemize}
341 345
342 346
343 \pagebreak
344
345 \paragraph{Return values} 347 \paragraph{Return values}
346 348
347 \begin{itemize} 349 \begin{itemize}
348 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register 350 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
349 \item integers and aggregates (structs, unions) \textgreater\ 32 and \textless=\ 64 bits are returned via the eax and edx registers 351 \item integers and aggregates (structs, unions) \textgreater\ 32 and \textless=\ 64 bits are returned via the eax and edx registers
381 & \vdots & & \\ 383 & \vdots & & \\
382 \end{tabular} 384 \end{tabular}
383 \caption{Stack layout on x86 fastcall (Borland) calling convention} 385 \caption{Stack layout on x86 fastcall (Borland) calling convention}
384 \end{figure} 386 \end{figure}
385 387
388
389 \pagebreak
386 390
387 \subsubsection{Watcom fastcall} 391 \subsubsection{Watcom fastcall}
388 392
389 393
390 \paragraph{Registers and register usage} 394 \paragraph{Registers and register usage}
458 \end{tabular} 462 \end{tabular}
459 \caption{Stack layout on x86 fastcall (Watcom) calling convention} 463 \caption{Stack layout on x86 fastcall (Watcom) calling convention}
460 \end{figure} 464 \end{figure}
461 465
462 466
467 \pagebreak
463 468
464 \subsubsection{win32 stdcall} 469 \subsubsection{win32 stdcall}
465 470
466 \paragraph{Registers and register usage} 471 \paragraph{Registers and register usage}
467 472
535 & \vdots & & \\ 540 & \vdots & & \\
536 \end{tabular} 541 \end{tabular}
537 \caption{Stack layout on x86 stdcall calling convention} 542 \caption{Stack layout on x86 stdcall calling convention}
538 \end{figure} 543 \end{figure}
539 544
545
546 \pagebreak
547
540 \subsubsection{MS thiscall} 548 \subsubsection{MS thiscall}
541 549
542 \paragraph{Registers and register usage} 550 \paragraph{Registers and register usage}
543 551
544 \begin{table}[h] 552 \begin{table}[h]
556 {\bf st0} & scratch, floating point return value\\ 564 {\bf st0} & scratch, floating point return value\\
557 {\bf st1-st7} & scratch\\ 565 {\bf st1-st7} & scratch\\
558 \end{tabular*} 566 \end{tabular*}
559 \caption{Register usage on x86 thiscall (MS) calling convention} 567 \caption{Register usage on x86 thiscall (MS) calling convention}
560 \end{table} 568 \end{table}
561
562 \clearpage
563 569
564 570
565 \paragraph{Parameter passing} 571 \paragraph{Parameter passing}
566 572
567 \begin{itemize} 573 \begin{itemize}
697 Since this calling convention is for 16-bit APIs, it is not discussed in 703 Since this calling convention is for 16-bit APIs, it is not discussed in
698 further detail, here. 704 further detail, here.
699 705
700 706
701 707
702 \clearpage
703
704 \subsubsection{plan9call} 708 \subsubsection{plan9call}
705 709
706 \paragraph{Registers and register usage} 710 \paragraph{Registers and register usage}
707 711
708 \begin{table}[h] 712 \begin{table}[h]
732 \item all parameters are pushed onto the stack (as dwords) 736 \item all parameters are pushed onto the stack (as dwords)
733 \item arguments \textgreater\ 64 bits are pushed as a sequence of dwords 737 \item arguments \textgreater\ 64 bits are pushed as a sequence of dwords
734 \item aggregates (structs, unions) are pushed as a sequence of dwords 738 \item aggregates (structs, unions) are pushed as a sequence of dwords
735 \end{itemize} 739 \end{itemize}
736 740
737 \pagebreak
738 741
739 \paragraph{Return values} 742 \paragraph{Return values}
740 743
741 \begin{itemize} 744 \begin{itemize}
742 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register 745 \item return values of pointer or integral type (\textless=\ 32 bits) are returned via the eax register
770 & \vdots & & \\ 773 & \vdots & & \\
771 \end{tabular} 774 \end{tabular}
772 \caption{Stack layout on x86 plan9call calling convention} 775 \caption{Stack layout on x86 plan9call calling convention}
773 \end{figure} 776 \end{figure}
774 777
775
776 \clearpage
777 778
778 \subsubsection{Linux syscalls} 779 \subsubsection{Linux syscalls}
779 780
780 \paragraph{Parameter passing} 781 \paragraph{Parameter passing}
781 782
785 \item params are passed in the following registers in this order: ebx, ecx, edx, esi, edi, ebp 786 \item params are passed in the following registers in this order: ebx, ecx, edx, esi, edi, ebp
786 \item for more than six arguments, ebx points to the list of further arguments (not used in practice, as Linux syscalls use a maximum of 5 arguments) 787 \item for more than six arguments, ebx points to the list of further arguments (not used in practice, as Linux syscalls use a maximum of 5 arguments)
787 \item register eax holds the return value 788 \item register eax holds the return value
788 \end{itemize} 789 \end{itemize}
789 790
791
790 \subsubsection{*BSD syscalls} 792 \subsubsection{*BSD syscalls}
791 793
792 \paragraph{Parameter passing} 794 \paragraph{Parameter passing}
793 795
794 \begin{itemize} 796 \begin{itemize}