5.5.16 · D3Embedded Systems & Real-Time Software

Worked examples — Startup code — vector table, reset handler, stack initialization

2,715 words12 min readBack to topic

Everything here builds on the parent topic. When we touch how the linker hands us addresses, that's Linker scripts and memory sections (.text .data .bss); when we touch how the CPU stacks registers, that's the ARM Cortex-M exception and interrupt model.


Before we start: the three symbols every example uses

We keep meeting three families of names. Let's pin them to a picture so no symbol is ever a mystery.

Figure — Startup code — vector table, reset handler, stack initialization

The scenario matrix

Every case class this topic can throw at you, and which worked example covers it:

# Case class Concrete stimulus Example
A Normal load — both sections non-empty .data has 2 words, .bss has 1 word Ex 1
B Empty .data (degenerate copy) no initialized globals → _sdata == _edata Ex 2
C Empty .bss (degenerate zero) every global is initialized → _sbss == _ebss Ex 2
D Stack boundary / first push trace MSP after entry and first push Ex 3
E Sign / direction of growth full-descending SP, does it overflow up or down? Ex 3
F Collision limit — stack vs heap how much can the stack grow before it hits .bss? Ex 4
G Relocated table (VTOR ≠ 0) — bootloader case app's table at 0x0800_4000, what does hardware read? Ex 5
H Real-world word problem a sensor buffer as a global — where does its data come from? Ex 6
I Exam twist — the .bss-not-cleared heisenbug predict the bug's symptom Ex 7
J Exam twist — misaligned _estack _estack odd/not word-aligned, what faults? Ex 8

We now hit every cell.










Recall Did every matrix cell get hit?

Normal load (A) ::: Ex 1 Empty .data / empty .bss (B, C) ::: Ex 2 First push & growth direction (D, E) ::: Ex 3 Stack↔heap collision limit (F) ::: Ex 4 Relocated table via VTOR (G) ::: Ex 5 Real-world const-vs-bss (H) ::: Ex 6 .bss heisenbug symptom (I) ::: Ex 7 Misaligned _estack fault (J) ::: Ex 8


Connections used here

  • Linker scripts and memory sections (.text .data .bss) — source of every _s…/_e… symbol.
  • ARM Cortex-M exception and interrupt model — the auto-stacking and alignment rules in Ex 3 & Ex 8.
  • Stack vs Heap memory layout — the collision geometry in Ex 4.
  • Bootloaders and VTOR relocation — the relocated table in Ex 5.
  • Volatile, memory-mapped registers and hardware init — how VTOR itself is written.
  • The C runtime and crt0 — the bigger picture the reset handler slots into.