10.4.3 Run-Time Library Support

In order to initialize variables in data memory, the data initialization template must be processed at start-up, before the application's main function takes control. For C programs, this task is performed by C start-up modules in the runtime library. Assembly language programs can also use the C start-up modules by linking with libpic32.a for PIC32M devices or libpic32c.a for PIC32C/SAM devices.

To utilize a start-up module, the application must allow the run-time library to take control at device Reset. This happens automatically for C programs. The application’s main() function is invoked after the start-up module has completed its work. Assembly language programs should use the following naming conventions to specify which routine takes control at device Reset.

Table 10-3. Table Main Entry Points
Main Entry Name Description
_reset Takes control immediately after device Reset.
main Takes control after the start-up module completes its work.

Note that the first entry name (_reset) includes one leading underscore characters. The second entry name (main) includes no leading underscore character. On device Reset, the startup module is called and it performs the following:

  1. Initialize Stack Pointer.
  2. The data initialization template in section .dinit is read, causing all uninitialized sections to be cleared and all initialized sections to be initialized with values read from program memory.
  3. Copy RAM functions from program flash to data memory an initialize bus matrix registers.
  4. The function main is called with no parameters.
  5. If main returns, the processor will reset.

The alternate start-up module is linked when the --no-data-init linker option is specified.

It performs the same operations, except for step (2), which is omitted. The alternate start-up module is smaller than the primary module and can be selected to conserve program memory, if data initialization is not required.

Source code for both modules is provided in the device family/lib directory of the MPLAB XC32 C compiler installation directory. The start-up modules may be modified if necessary. For example, if an application requires main to be called with parameters, a conditional assembly directive may be switched to provide this support.