Startup Code
The linker script contains the addresses of the interrupt handlers and the reset handler. When a microcontroller is reset or an interrupt occurs, the microcontroller looks up the address of the corresponding handler function in the vector table and jumps to that address to execute the handler function.
Reset Handler
The Reset_Handler
function is the entry point of program after the system resets.
This location is typically specified in the reset vector, which is part of the vector table at
the start of the system memory. The reset vector points to the Reset_Handler function.
The Reset_Handler function typically performs the following tasks:
- Initializes the system’s RAM.
copying initial values for variables from non-volatile memory (like flash) to RAM.
- Calls system initialization functions.
setting up clocks
configuring peripherals
Calls the main function of the program.
Order of activities in Reset_Handler function:
Mask interrupts
Disable interrupts and clear pending flags
clear enable IRQ registers
ISR relocation
enable fpu
Init the rest of the registers
Initialize the stack pointer
c code call stack init
call boardInit function
Unmask interrupts
Init ECC RAM
Loop to copy data from read only memory to RAM
Loop to clear BSS section
call global constructors
call main function
__libc_init_array is a function which calls the constructors in the .preinit_array and .init_array sections.