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 will perform the following tasks, which are discussed in the sections that follow.
- Switch to the selected instruction set (ISA) mode.
- Jump to NMI handler
(
_nmi_handler
) if an NMI occurred. - Initialize stack pointer and heap.
- Initialize global pointer in all register sets available on the selected target device.
- Call the application-provided “on
reset” routine (
_on_reset
). - Call the
__pic32_init_cache
routine to initialize the L1 cache on target devices that feature an L1 cache. - Call the
__pic32_tlb_init_ebi_sqi
routine to initialize the TLB on -target devices that use pre-mapped EBI and SQI external memory regions. - Clear uninitialized small bss sections.
- Initialize data using the linker-generated data-initialization template.
- If the target device that features a bus matrix and the application uses a RAM function, initialize the bus matrix for execution from data memory.
- Initialize the CP0 registers, including the enabling of the DSPr2 engine and Floating-Point Unit (FPU) for devices on which these are implemented.
- Call the “On Bootstrap” routine
(
_on_bootstrap
). - Change the location of exception vectors.
- For C++, call the C++ initialization code to invoke all constructors for file-scope static storage objects.
- Call
main()
. - On return from main(), call
exit()
if theCALL_EXIT
macro is defined; otherwise, enter an infinite loop.
The following provisions are made regarding the run-time model:
- Kernel mode only
- KSEG1 only
- RAM functions are attributed with
__ramfunc__
or__longramfunc__
, (defined insys/attribs.h
), meaning that all RAM functions end up in the .ramfunc
section and the function isramfunc
attributed.