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.
- 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.
- Call the On Reset routine (
_on_reset
). - Enable the Floating Point Unit (FPU) device if present and enabled by the compiler options.
- Enable the instruction and data caches, if present.
- Configure the instruction and/or data Tightly-Coupled Memory (TCM), if present and enabled. Also see 7.5 Tightly-Coupled Memories.
- Initialize the data, bss, and ramfunc sections using the linker-generated data-initialization template.
- If requested, relocate the stack to data TCM.
- For Cortex-M devices only, initialize the
VTOR
(Vector Table on Reset) register to the address of the interrupt vector table. - Perform the initialization for the standard C library.
- Call the On Bootstrap routine (
_on_bootstrap
). - Call the application
main()
function. - 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.