Calling Conventions: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Add table of calling conventions |
|||
Line 7:
== Cheat Sheets ==
Here is a quick overview of common calling conventions. Note that the calling conventions are usually more complex than represented here (for instance, how is a large struct returned? How about a struct that fits in two registers? How about va_list's?). Look up the specifications if you want to be certain. It may be useful to write a test function and use gcc -S to see how the compiler generates code, which may give a hint of how the calling convention specification should be interpreted.
{| {{wikitable}}
Line 16 ⟶ 18:
! Scratch Registers
! Preserved Registers
! Call List
|-
| System V i386 || eax, edx || none || stack (right to left) || || eax, ecx, edx || ebx, esi, edi, ebp, esp || ebp
|-
| System V X86_64<sup>[[#Note1|1]]</sup> || rax, rdx || rdi, rsi, rdx, rcx, r8, r9 || stack (right to left) || 16-byte at call<sup>[[#
|-
| ARM || r0, r1 || r0, r1, r2, r3 || stack || 8 byte<sup>[[#
|}
<small id="Note1">Note 1: There is a 128 byte area below the stack called the 'red zone', which may be used by leaf functions without increasing %rsp. This requires the kernel to increase %rsp by an additional 128 bytes upon signals in user-space. This is <em>not</em> done by the CPU - if interrupts use the current stack (as with kernel code), and the red zone is enabled (default), then interrupts will silently corrupt the stack. Always pass -mno-red-zone to kernel code (even support libraries such as libc's embedded in the kernel) if interrupts don't respect the red zone.</small>
<small id="Note1">Note 1: Stack is 16 byte aligned at time of call. The call pushes %rip, so the stack is 16-byte aligned again if the callee pushes %rbp.</small>▼
▲<small id="
<small id="
==External References==
|