Microchip Technology SW006023-1N Data Sheet
MPLAB
®
XC32 C/C++ Compiler User’s Guide
DS51686E-page 144
2012 Microchip Technology Inc.
12.3.1
Jump to NMI Handler if an NMI Occurred
If an NMI caused entry to the Reset vector, a jump to an NMI handler procedure
(_nmi_handler) occurs. A weak version of the NMI handler procedure is provided
that performs an ERET. The _nmi_handler function must be attributed with
nomips16
(_nmi_handler) occurs. A weak version of the NMI handler procedure is provided
that performs an ERET. The _nmi_handler function must be attributed with
nomips16
[e.g., __attribute__((nomips16))] since the start-up code jumps to
this function.
12.3.2
Initialize Stack Pointer and Heap
The Stack Pointer (sp) register must be initialized in the start-up code. To enable the
start-up code to initialize the sp register, the linker script must initialize a variable which
points to the end of KSEG1 data memory
start-up code to initialize the sp register, the linker script must initialize a variable which
points to the end of KSEG1 data memory
1
. This variable is named _stack. The user
can change the minimum amount of stack space allocated by providing the command
line option --defsym _min_stack_size=N to the linker. _min_stack_size is
provided by the linker script with a default value of 1024.
line option --defsym _min_stack_size=N to the linker. _min_stack_size is
provided by the linker script with a default value of 1024.
On a similar note, the user may wish to utilize a heap with their application. While the
start-up code does not need to initialize the heap, the standard C libraries (sbrk) must
be made aware of the heap location and its size. The linker script creates a variable to
identify the beginning of the heap. The location of the heap is the end of the utilized
KSEG1 data memory. This variable is named _heap. The user can change the
minimum amount of heap space allocated by providing the command line option
--defsym _min_heap_size=M
start-up code does not need to initialize the heap, the standard C libraries (sbrk) must
be made aware of the heap location and its size. The linker script creates a variable to
identify the beginning of the heap. The location of the heap is the end of the utilized
KSEG1 data memory. This variable is named _heap. The user can change the
minimum amount of heap space allocated by providing the command line option
--defsym _min_heap_size=M
to the linker. _min_heap_size is provided by the
linker script with a default value of 0. If the heap is used when the heap size is set to
zero, the behavior is the same as when the heap usage exceeds the minimum heap
size. Namely, it overflows into the space allocated for the stack.
zero, the behavior is the same as when the heap usage exceeds the minimum heap
size. Namely, it overflows into the space allocated for the stack.
The heap and the stack use the unallocated KSEG1 data memory, with the heap
starting from a low address in KSEG1 data memory, and growing upwards towards the
stack while the stack starts at a higher address in KSEG1 data memory and grows
downwards towards the heap. The linker attempt to allocate the heap and stack
together in the largest gap of memory available in the KSEG1 data memory region. If
enough space is not available based on the minimum amount of heap size and stack
size requested, the linker issues an error.
starting from a low address in KSEG1 data memory, and growing upwards towards the
stack while the stack starts at a higher address in KSEG1 data memory and grows
downwards towards the heap. The linker attempt to allocate the heap and stack
together in the largest gap of memory available in the KSEG1 data memory region. If
enough space is not available based on the minimum amount of heap size and stack
size requested, the linker issues an error.
1. The end of data memory is different based on whether RAM functions exist. If RAM functions exist, then
part of the DRM must be configured for the kernel program to contain the RAM functions, and the Stack
Pointer is located one word prior to the beginning of the DRM kernel program boundary address. If RAM
functions do not exist, then the Stack Pointer is located at the true end of DRM.
Pointer is located one word prior to the beginning of the DRM kernel program boundary address. If RAM
functions do not exist, then the Stack Pointer is located at the true end of DRM.