| |||
| Home > ARM Procedure Call Standard > APCS definition > The stack | |||
The APCS supports both contiguous and chunked stacks. The stack must be readable and writable by the executing program.
Chunked stacks have the following properties:
A chunked stack can be extended by allocating additional chunks anywhere in memory.
A chunked stack is a singly-linked list of activation records, linked through a stack backtrace data structure (see The stack backtrace data structure), stored at the high-address end of each activation record.
Each contiguous chunk of the stack must be allocated to activation records in descending address order. At all instants of execution, sp must point to the lowest used address of the most recently allocated activation record.
There are no constraints on the ordering of multiple stack chunks in the address space.
A chunked stack must be limit-checked. It can be extended only when a limit check fails.
Contiguous stacks have the following properties:
A contiguous stack can be extended at its low address only.
The activation records in a contiguous stack need not be linked together through a stack backtrace data structure.
Associated with sp is a possibly implicit stack chunk limit, below which sp must not be decremented.
At all instants of execution, the memory between sp and the stack chunk limit must contain nothing of value to the executing program. It may be modified unpredictably by the execution environment.
There are two types of stack chunk limit:
The stack chunk limit is said to be implicit if chunk overflow is detected and handled by the execution environment. If the stack chunk limit is implicit, sl may be used as v7, an additional callee-saved variable register.
The stack chunk limit is said to be explicit if chunk overflow is detected and handled by the program and its library support code.
If the conditions of the remainder of this subsection hold at all instants of execution, the program conforms strictly to the APCS. If they hold at, and during, external function calls (visible between compilation units), the program conforms to the APCS.
If the stack chunk limit is explicit, sl must:
point at least 256 bytes above it
identify the current stack chunk in a system-defined manner
at all times, identify the same chunk as sp points into.
The values of sl, fp and sp must be multiples of 4.
(sl >= stack_chunk_limit + 256 allows the
most common limit checks to be made very cheaply during function
entry.)
This final requirement implies that on changing stack chunks, registers sl and sp must be loaded simultaneously using:
LDM ..., {..., sl, sp}.
In general, this means that return from a function executing on an extension chunk to one executing on an earlier-allocated chunk should be through an intermediate function invocation, specially fabricated when the stack was extended.