2.4.7. Runtime memory models

Two runtime memory models are provided:

In both runtime memory models, the stack grows unchecked.

Note

Both these examples are suitable for the Integrator system.

One-region model

In the default, one-region model, the application stack and heap grow towards each other in the same region of memory. In this case, the heap is checked against the value of the stack pointer when new heap space is allocated (for example, when malloc() is called).

Figure 2.10 and Example 2.5 show an example of __user_initial_stackheap() implementing a simple one-region model, where the stack grows downwards from address 0x40000, and the heap grows upwards from 0x20000.

The routine loads the appropriate values into the registers r0 and r1, and then returns. Register r2 remains unchanged, because a heap limit is not used in a one-region model. Register r3 is not used.

Figure 2.10. One-region model

Example 2.5. One-region model routine

    EXPORT __user_initial_stackheap

__user_initial_stackheap
    LDR r0, =0x20000 ;HB
    LDR r1, =0x40000 ;SB
    ; r2 not used (HL)
    ; r3 not used
    MOV pc, lr

Two-region model

Your system design might require the stack and heap to be placed in separate regions of memory.

For example, you might have a small block of fast RAM that you want to reserve for stack use only. To inform the linker that you want to use a two-region model, you must import the symbol __use_two_region_memory using the assembler IMPORT directive. The heap is then checked against a dedicated heap limit, that is set up by __user_initial_stackheap().

Figure 2.11 and Example 2.6 show an example of implementing a two-region model.

In this example, the heap grows upwards from 0x28000000 to 0x28080000, and the stack grow downwards from 0x40000.

Figure 2.11. Two-region model

Example 2.6. Two-region model routine

    IMPORT __use_two_region_memory
    EXPORT __user_initial_stackheap

__user_initial_stackheap
    LDR r0, =0x28000000 ;HB
    LDR r1, =0x40000 ;SB
    LDR r2, =0x28080000 ;HL
	; r3 not used
    MOV pc, lr
Copyright © 2002-2006 ARM Limited. All rights reserved.ARM DUI 0203G
Non-Confidential