Microchip Technology SW006022-1N Data Sheet

Page of 338
MPLAB
®
 XC16 C Compiler User’s Guide
DS52071B-page 86
 2012 Microchip Technology Inc.
The -o command-line option names the output executable file, and the -T option gives 
the linker script name for the dsPIC30F2010 part. If p30f2010.gld is not found in the 
current directory, the linker searches in its known library paths. The default search path 
includes all locations of preinstalled libraries and linker scripts.
You should copy the appropriate linker script file (supplied with the compiler) into your 
project directory before any project-specific modifications are made.
4.4
STACK
The 16-bit devices use what is referred to in this user’s guide as a “software stack”. This 
is the typical stack arrangement employed by most computers and is ordinary data 
memory accessed by a push-and-pop type instruction and a stack pointer register. The 
term “hardware stack” is used to describe the stack employed by Microchip 8-bit 
devices, which is only used for storing function return addresses.
The 16-bit devices dedicate register W15 for use as a software Stack Pointer. All 
processor stack operations, including function calls, interrupts and exceptions, use the 
software stack. The stack grows upward, towards higher memory addresses.
The dsPIC DSC device also supports stack overflow detection. If the Stack Pointer 
Limit register, SPLIM, is initialized, the device will test for overflow on all stack opera-
tions. If an overflow should occur, the processor will initiate a stack error exception. By 
default, this will result in a processor Reset. Applications may also install a stack error 
exception handler by defining an interrupt function named _StackError. See Chap-
ter 11. “Interrupts”
 for details.
The C run-time startup module initializes the Stack Pointer (W15) and the Stack Pointer 
Limit register during the startup and initialization sequence. The initial values are 
normally provided by the linker, which allocates the largest stack possible from unused 
data memory. The location of the stack is reported in the link map output file. 
Applications can ensure that at least a minimum-sized stack is available with the 
--stack
 linker command-line option. See the MPLAB Assembler, Linker and Utilities 
for PIC24 MCUs and dsPIC DSCs User’s Guide (DS51317) for details.
Alternatively, a stack of specific size may be allocated with a user-defined section from 
an assembly source file. In the following example, 0x100 bytes of data memory are 
reserved for the stack:
  .section *,data,stack
  .space 0x100
The linker will allocate an appropriately sized section and initialize __SP_init and 
_ _SPLIM_init
 so that the run-time startup code can properly initialize the stack. Note 
that since this is a normal assembly code section, attributes such as address may be 
used to further define the stack. Please see the MPLAB Assembler, Linker and Utilities 
for PIC24 MCUs and dsPIC DSCs User’s Guide (DS51317)
 for more information.
4.5
CONFIGURATION BIT ACCESS
Microchip devices have several locations which contain the configuration bits or fuses. 
These bits specify fundamental device operation, such as the oscillator mode, watch-
dog timer, programming mode and code protection. Failure to correctly set these bits 
may result in code failure or a non-running device.
Configuration settings macros are provided that can be used to set configuration bits. 
For details, seAppendix G. “XC16 Configuration Settings”.