ABC of Electronics cosycom.com
EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 52

Start-Up Code and the Linker

What runs before main().

After reset, a small start-up routine sets the stack pointer, copies initial values of global variables from flash into SRAM, zeroes uninitialised globals, and then calls main().

The linker places code, constants and data at the right addresses using a script that describes the chip's memory regions. A map file shows what ended up where and how much is left.

If a global has the wrong value at boot, suspect start-up or linker settings.