18.2 Runtime Start-up Code

A C/C++ program requires certain objects to be initialized and the processor to be in a particular state before it can begin execution of its function main(). It is the job of the runtime start-up code to perform these tasks before the execution of main().

If you require any additional initialization to be performed, you typically do not need to modify the default runtime startup code provided by the compiler. That would only be required if any of the existing actions taken by the startup code needed to be changed. The special On Reset and On Bootstrap hooks allow the startup code to be customized at various places in the startup sequence.

The PIC32 start-up code calls a function called Reset_Handler()to perform the following tasks, which are discussed in the sections that follow.

  1. For Cortex-M devices, ensure the stack pointer register is initialized to point to the top of the system stack; for Cortex-A devices, ensure the stack pointer registers are initialized to point to the top of the appropriate stack.
  2. Call the On Reset routine (_on_reset).
  3. Enable the Floating Point Unit (FPU) device if present and enabled by the compiler options.
  4. Enable the instruction and data caches, if present.
  5. Configure the instruction and/or data Tightly-Coupled Memory (TCM), if present and enabled. Also see 7.5 Tightly-Coupled Memories.
  6. Initialize the data, bss, and ramfunc sections using the linker-generated data-initialization template.
  7. If requested, relocate the stack to data TCM.
  8. For Cortex-M devices only, initialize the VTOR (Vector Table on Reset) register to the address of the interrupt vector table.
  9. Perform the initialization for the standard C library.
  10. Call the On Bootstrap routine (_on_bootstrap).
  11. Call the application main() function.
  12. On return from main(), optionally call _on_exit() or enter an infinite loop.

Each step will be described in further detail in the following sections.