A stack frame procedure is one that allocates space for and saves its caller's context on the stack. This type of procedure is sometimes called a heavyweight procedure, referring to the cost of storing this context in memory.
Such a procedure can save and restore registers and may make standard calls to other procedures.
The stack frame of this type of procedure consists of a fixed part (the size of which is known at compile time) and an optional variable part. Certain optimizations can be done if the optional variable part is not present. Compilers must be careful to recognize situations that can effectively cause a variable part of the stack to exist in nonintuitive ways, such as:
If any such situation exists a compiler must choose to use a variable-size stack frame procedure when compiling the caller so that an unwind operation can be done correctly.
Although the compiler determines the exact contents of a stack frame, certain properties are common to all stack frames. The two basic flavors of stack frames are described below.
The following figure illustrates the format of the stack frame for a procedure with a fixed amount of stack that uses the SP as the stack base register (i.e., BASE_REG_IS_FP is 0). In this case, R15 is simply another saved register and otherwise has no special significance.
Some parts of the stack frame are optional and occur only as required by the particular procedure. Brackets surrounding a field's name indicate the field is optional.
Figure 3-1 Fixed Size Stack Frame Format
octaword-aligned
+---------------+---------------+---------------+---------------+
| | :0
| |(From SP)
| |
| [fixed temporary locations] |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| [argument home area] |
| |
+---------------+---------------+---------------+---------------+
| | :FRAME_SIZE
| |(From SP)
| [arguments passed in memory] |
| |
| |
+---------------+---------------+---------------+---------------+
The following figure illustrates the format of the stack frame for procedures with a varying amount of stack that uses the FP as the stack base register (i.e., BASE_REG_IS_FP is 1).
Some parts of the stack frame are optional and occur only as required by the particular procedure. Brackets surrounding a field's name indicate the field is optional.
Figure 3-2 Variable Size Stack Frame Format
octaword-aligned
+---------------+---------------+---------------+---------------+
| | :0
| |(From SP)
: [stack temporary area] :
: :
: :
| |
| |
+---------------+---------------+---------------+---------------+
| | :0
| |(From FP)
| [fixed temporary locations] |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| [argument home area] |
| |
+---------------+---------------+---------------+---------------+
| | :FRAME_SIZE
| [arguments passed in memory] |(From FP)
| |
| |
+---------------+---------------+---------------+---------------+
In either case the portion of the stack frame designated by FRAME_SIZE must be allocated and initialized by the entry code sequence of a called procedure with a stack frame.
Fixed temporary locations are optional sections of the stack frame that contain language-specific locations required by the procedure context of some high-level languages. This may include, for example, register spill area, language-specific exception-handling context (such as language dynamic exception-handling information), fixed temporaries, etc.
If a compiler chooses, the fixed temporary locations adjacent to the area pointed to by the frame base register plus FRAME_SIZE can be used for a special purpose termed the argument home area. The argument home area is a region of memory used by the called procedure for the purpose of assembling in contiguous memory the arguments passed in registers, adjacent to the arguments passed in memory, so that all arguments can be addressed as a contiguous array. This area may also be used to store arguments that are passed in registers if an address for such an argument must be generated. Generally, either 6 or 12 contiguous quadwords of stack storage will be allocated by the called procedure for this purpose.
A compiler may use the stack temporary area for fixed local variables, such as constant-sized data items and program state, as well as for dynamically sized local variables. The stack temporary area may also be used for dynamically sized items with a limited lifetime; for example, a dynamically sized function result or string concatenation that can't be directly stored in a target variable. When a procedure uses this area, the compiler must keep track of its base and reset SP to the base to reclaim storage used by temporaries.
The high-address end of the stack frame is defined by the value stored in FRAME_SIZE plus the contents of SP or FP, as indicated by BASE_REG_IS_FP. The high-address end is used to determine the value of SP for the predecessor procedure in the calling chain.
Note Floating registers saved in the stack are stored as a 64-bit exact image of the register; i.e., no reordering of bits is done on the way to or from memory. Compilers must use an STT instruction to store the register regardless of floating-point type.