Stack frame mapping
The prolog of a function usually allocates space (referred to as
a frame
, Stack Frame
, or DSA
- dynamic storage
area) in the Language Environment-provided
stack segment for its own purposes and to support calls to other routines.
Figure 1 shows the stack frame layout. The stack register points to a location 2048 bytes before the stack frame for the currently active routine. It grows from numerically higher storage addresses to numerically lower ones, that is the stack frame for a called function is always at a lower address than the calling function. The stack frame is 32-byte-aligned.
![stack frame layout in a 64–bit environment](cee99064.gif)
Table 1 describes the contents of each area within the stack frame shown in Figure 1.
AMODE 64 stack frame area | Content |
---|---|
Save area | This area is always present when a stack frame
is required. It holds up to 12 registers. The first two doublewords
hold, optionally, GPRs 4 and 5, the registers containing the address
of the previous stack frame and the environment address passed into
the function. This is followed by the two doublewords containing
GPR6, which may or may not hold the actual entry point address depending
on the type of call, and GPR7, the return address. As many of the
8 non-volatile registers as are used by the called function are saved
in the following 64 bytes. Except when registers are saved in the prolog, this area may not be altered by compiled code. The PPA1 GPR Save Mask indicates which GPRs are saved in this area by the prolog. Stack overflow is detected by the STMG instruction used to save registers in this save area. Storage of the Backchain field in the save area is triggered by the optional XPLINK(BACKCHAIN) compiler option, or at the convenience of the compiler. The environment address is stored when the TEST compiler option or the optional XPLINK(STOREARGS) compiler option is specified, or at the convenience of the compiler. The third doubleword in the save area contains the value in GPR6 on entry to the routine. If the routine was called with a BASR instruction, the address is that of the function entry point. The fourth
doubleword contains the return address. The return point can be examined
to determine how the function was called:
|
Reserved | These areas are always present and are for the exclusive use of the runtime. It is uninitialized by compiled code. |
Debugger area | This area is always present and is for the exclusive use of the debugger. It is uninitialized by compiled code. |
Argument area | This area is at the fixed DSA offset of 128 bytes into the caller's stack frame. It contains the argument lists passed on function calls made by the function associated with this stack frame. The called function finds its parameters in the caller's stack frame. A minimum of four doublewords (32 bytes) must be always be allocated. |
Local storage | This is the space owned by the executing procedure and may be used for its local variables and temporaries. |