10.5 Stack Allocation
The MPLAB XC32 C compiler dedicates general-purpose register 29 (PIC32M devices) or 13 (PIC32C/SAM devices) as the software Stack Pointer. All processor stack operations, including function calls, interrupts, and exceptions use the software stack. The stack grows downward from high addresses to low addresses.
By default, 32-bit linker dynamically allocates the largest stack possible from unused data memory. Previous releases used output sections specified in the linker script to allocate the stack.
The location and size of the stack is reported in the link map output file
and the Memory-Usage Report, under the heading Dynamic Memory Usage. Applications can
ensure that at least a minimum sized stack is available by specifying the size on the
linker command line using the --defsym=_min_stack_size=size linker command
line option. An example of allocating a stack of 2048 bytes using the command line is:
xc32-gcc foo.c -Wl,--defsym=_min_stack_size=2048
The symbol _stack indicates the start of the stack and the end is indicated
by _splim.
