System V ABI: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
The latest SYSV i386 ABI changed the stack alignment from 4-byte to 16-byte
document correct stack alignment
Line 16:
=== i386 ===
 
This is a 32-bit platform. The stack grows downwards. Parameters to functions are passed on the stack in reverse order such that the first parameter is the last value pushed to the stack, which will then be the lowest value on the stack. Parameters passed on the stack may be modified by the called function. Functions are called using the <tt>call</tt> instruction that pushes the address of the next instruction to the stack and jumps to the operand. Functions return to the caller using the <tt>ret</tt> instruction that pops a value from the stack and jump to it. The stack is 4-byte aligned all the time, on older systems and those honouring the SYSV psABI. On some newer systems, the stack is additionally 16-byte aligned just before the call instruction is called (usually those that want to support SSE instructions); consult your manual (GNU/Linux on i386 has recently become such a system, but code mixing with 4-byte stack alignment-assuming code is possible).
 
Functions preserve the registers <tt>ebx</tt>, <tt>esi</tt>, <tt>edi</tt>, <tt>ebp</tt>, and <tt>esp</tt>; while <tt>eax</tt>, <tt>ecx</tt>, <tt>edx</tt> are scratch registers. The return value is stored in the <tt>eax</tt> register, or if it is a 64-bit value, then the higher 32-bits go in <tt>edx</tt>. Functions push <tt>ebp</tt> such that the <tt>caller-return-eip</tt> is 4 bytes above it, and set <tt>ebp</tt> to the address of the saved ebp. This allows iterating through the existing stack frames. This can be eliminated by specifying the <tt>-fomit-frame-pointer</tt> GCC option.