07.04.2013 Views

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

16-Bit C <strong>Compiler</strong> User’s Guide<br />

4.4 STARTUP AND INITIALIZATION<br />

Two C run-time startup modules are included in the libpic30.a archive/library. The<br />

entry point <strong>for</strong> both startup modules is __reset. The linker scripts construct a GOTO<br />

__reset instruction at location 0 in program memory, which transfers control upon<br />

device reset.<br />

The primary startup module (crt0.o) is linked by default <strong>and</strong> per<strong>for</strong>ms the following:<br />

1. The Stack Pointer (W15) <strong>and</strong> Stack Pointer Limit register (SPLIM) are initialized,<br />

using values provided by the linker or a custom linker script. For more<br />

in<strong>for</strong>mation, see Section 4.8 “Software Stack”.<br />

2. If a .const section is defined, it is mapped into the program space visibility<br />

window by initializing the PSVPAG <strong>and</strong> CORCON registers. Note that a .const<br />

section is defined when the “Constants in code space” option is selected in<br />

<strong>MPLAB</strong> IDE, or the default -mconst-in-code option is specified on the<br />

compiler comm<strong>and</strong> line.<br />

3. The data initialization template in section .dinit is read, causing all<br />

uninitialized sections to be cleared, <strong>and</strong> all initialized sections to be initialized<br />

with values read from program memory. The data initialization template is<br />

created by the linker, <strong>and</strong> supports the st<strong>and</strong>ard sections listed in<br />

Section 4.3 “Address Spaces”, as well as the user-defined sections.<br />

Note: The persistent data section .pbss is never cleared or initialized.<br />

4. If the application has defined user_init functions, these are invoked. The<br />

order of execution depends on link order.<br />

5. The function main is called with no parameters.<br />

6. If main returns, the processor will reset.<br />

The alternate startup module (crt1.o) is linked when the -Wl, --no-data-init<br />

option is specified. It per<strong>for</strong>ms the same operations, except <strong>for</strong> step (3), which is<br />

omitted. The alternate startup module is smaller than the primary module, <strong>and</strong> can be<br />

selected to conserve program memory if data initialization is not required.<br />

Source code (in <strong>dsPIC</strong> DSC assembly language) <strong>for</strong> both modules is provided in the<br />

c:\Program Files\<strong>Microchip</strong>\<strong>MPLAB</strong> C30\src directory. The startup modules<br />

may be modified if necessary. For example, if an application requires main to be called<br />

with parameters, a conditional assembly directive may be changed to provide this<br />

support.<br />

DS51284H-page 64 © 2008 <strong>Microchip</strong> Technology Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!