Download MPLAB® Assembler, Linker and Utilities for PIC32 MCUs User's Guide
Transcript
Linker Processing
_bmxdupba_address = LENGTH(kseg1_data_mem) ;
/*
* The actual top of stack should include the gap between
* the stack section and the beginning of the .ramfunc
* section caused by the alignment of the .ramfunc
* section minus 1 word. If RAM functions do not exist,
* then the top of the stack should point to the end of
* the data memory.
*/
_stack = (_ramfunc_length > 0)
? _ramfunc_begin - 4
: ORIGIN(kseg1_data_mem) + LENGTH(kseg1_data_mem) ;
Notice that the linker script defines a required _stack symbol at the beginning of the
.ramfunc section. When RAM functions don’t exist, the _stack symbol points to the
end of data memory. This means that the effective stack is the entire space between
the heap and the .ramfunc section or the end of data memory.
The linker’s reported size of the .stack section is the minimum size required to avoid
a link error. The effective stack size is usually larger than the reported .stack section
size.
11.6
HEAP ALLOCATION
The C runtime heap is an uninitialized area of data memory that is used for dynamic
memory allocation using the standard C library dynamic memory-management functions, calloc, malloc, and realloc. If you do not use any of these functions (directly or
indirectly), then you do not need to allocate a heap. By default, the heap size is 0.
If you do want to use dynamic memory allocation, either directly, by calling one of the
memory allocation functions, or indirectly, by using a standard C library function that
uses one of these functions, then a heap must be created. A heap is created by specifying its size on the linker command line using the --defsym=_min_heap_size
linker command line option. An example of allocating a heap of 512 bytes using the
command line is:
pic32-gcc foo.c -Wl,--defsym=_min_heap_size=512
The linker allocates the heap immediately before the stack.
11.7
INTERRUPT VECTOR TABLES
The vector address of a given interrupt is calculated using Exception Base (EBASE
<31:12>) register, which provides a 4 KB page-aligned base address value located in
the kernel segment (kseg) address space. (EBASE is a CPU register.) The address is
calculated by using EBASE and VS (INTCTL <9:5>) values. The VS bits provide the
vector spacing between adjacent vector addresses.
The linker script creates the corresponding Interrupt Vector Table as follows:
PROVIDE(_vector_spacing = 0x00000001);
_ebase_address = 0x9FC01000;
SECTIONS
{
.app_excpt _GEN_EXCPT_ADDR :
{
KEEP(*(.gen_handler))
} > exception_mem
.vector_0 _ebase_address + 0x200 :
{
KEEP(*(.vector_0))
© 2009 Microchip Technology Inc.
DS51833A-page 137