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.

  1. Switch to the selected instruction set (ISA) mode.
  2. Jump to NMI handler (_nmi_handler) if an NMI occurred.
  3. Initialize stack pointer and heap.
  4. Initialize global pointer in all register sets available on the selected target device.
  5. Call the application-provided “on reset” routine (_on_reset).
  6. Call the __pic32_init_cache routine to initialize the L1 cache on target devices that feature an L1 cache.
  7. 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.
  8. Clear uninitialized small bss sections.
  9. Initialize data using the linker-generated data-initialization template.
  10. 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.
  11. Initialize the CP0 registers, including the enabling of the DSPr2 engine and Floating-Point Unit (FPU) for devices on which these are implemented.
  12. Call the “On Bootstrap” routine (_on_bootstrap).
  13. Change the location of exception vectors.
  14. For C++, call the C++ initialization code to invoke all constructors for file-scope static storage objects.
  15. Call main().
  16. On return from main(), call exit() if the CALL_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 in sys/attribs.h), meaning that all RAM functions end up in the .ramfunc section and the function is ramfunc attributed.