Download PGI User's Guide

Transcript
Chapter 19. Run-time Environment
Position
Contents
Frame
...
16 (%rbp)
argument eightbyte 0
8 (%rbp)
return address
current
0 (%rbp)
caller's %rbp
current
-8 (%rbp)
unspecified
...
0 (%rsp)
variable size
-128 (%rsp)
red zone
Key points concerning the stack frame:
• The end of the input argument area is aligned on a 16-byte boundary.
• The 128-byte area beyond the location of %rsp is called the red zone and can be used for temporary local
data storage. This area is not modified by signal or interrupt handlers.
• A call instruction pushes the address of the next instruction (the return address) onto the stack. The return
instruction pops the address off the stack and effectively continues execution at the next instruction after
the call instruction. A function must preserve non-volatile registers, a register whose contents must be
preserved across subroutine calls. Additionally, the called function must remove the return address from the
stack, leaving the stack pointer (%rsp) with the value it had before the call instruction was executed.
All registers on an x64 system are global and thus visible to both a calling and a called function. Registers
%rbx, %rsp, %rbp, %r12, %r13, %r14, and %r15 are non-volatile across function calls. Therefore, a function
must preserve these registers’ values for its caller. Remaining registers are volatile (scratch) registers, that is a
register whose contents need not be preserved across subroutine calls. If a calling function wants to preserve
such a register value across a function call, it must save its value explicitly.
Registers are used extensively in the standard calling sequence. The first six integer and pointer arguments
are passed in these registers (listed in order): %rdi, %rsi, %rdx, %rcx, %r8, %r9. The first eight floating point
arguments are passed in the first eight XMM registers: %xmm0, %xmm1, …, %xmm7. The registers %rax
and %rdx are used to return integer and pointer values. The registers %xmm0 and %xmm1 are used to return
floating point values.
Additional registers with assigned roles in the standard calling sequence:
%rsp
The stack pointer holds the limit of the current stack frame, which is the address of the stack’s bottommost, valid word. The stack must be 16-byte aligned.
%rbp
The frame pointer holds a base address for the current stack frame. Consequently, a function has registers
pointing to both ends of its frame. Incoming arguments reside in the previous frame, referenced as
positive offsets from %rbp, while local variables reside in the current frame, referenced as negative offsets
from %rbp. A function must preserve this register value for its caller.
303