| |||

Home > The C and C++ Libraries > Tailoring the runtime memory model > __user_initial_stackheap() |

Returns the locations of the initial stack and heap.

`__value_in_regs struct `

unsigned**__initial_stackheap__user_initial_stackheap** (` R0`, unsigned `SP`, unsigned` R2`, unsigned` SL``)`

;

If you are using scatter-loading files with the linker, you
must reimplement this function. The default implementation uses
the value of the symbol `Image$$ZI$$Limit`

. This
symbol is not defined if the linker uses a scatter-loading file
(`-scatter`

command-line option).

If this function is redefined, it must:

use no more than 96 bytes of stack

not corrupt registers other than r12 (ip)

return in r0-r3 respectively the heap base, stack base, heap limit, and stack limit

maintain 8-byte alignment of the heap.

For the default single region model, the values in r2 and r3 are ignored and all memory between r0 and r1 is available for the heap. For a two region model, the heap limit is set by r2 and the stack limit is set by r3.

The values of sp and sl inherited from the environment are
passed as arguments in r1 and r3, respectively. The default implementation
of `__user_initial_stackheap()`

that uses the
semihosting SWI SYS_HEAPINFO is given by the library in module `sys_stackheap.o`

.

To create a version of `__user_initial_stack_heap()`

that
inherits sp and sl from the execution environment and does not have
a heap, set r0 and r2 to the value of r3 and return.

The definition of __initial_stackheap in `rt_misc.h`

is:

struct __initial_stackheap{ unsigned heap_base, stack_base, heap_limit, stack_limit;}

See also the re-implementation of this function in `\Examples\Embedded\embed\retarget.c`

.

The values returned in r0 to r3 depend on whether you are using the one or two region model:

- One region
(r0,r1) is the single stack and heap region. r1 is greater than r0. r2 and r3 are ignored.

- Two regions
(r0, r2) is the initial heap and (r3, r1) is the initial stack. r2 is greater than or equal to r0. r3 is less than r1.