HARMcksL: ARM HAL toolbox (yet STM32 oriented) 1.6
SMFSW collection of HAL hacks for STM32
Loading...
Searching...
No Matches
stack_fill.s File Reference

Memory check utilities: stack filler. More...

Variables

syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type MemStackFill
syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type function adds r2
syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type function adds LoopFillHeapStack

Detailed Description

Memory check utilities: stack filler.

!

Author
SMFSW
Note
_Stack_Fill_Value has to be defined in linker script with 32b value to fill stack with (eg: _Stack_Fill_Value = 0xB00BFACE;)
MemStackFill has to be called by startup routine (after memory init steps, AND prior to any memory used on heap or stack), You may want to call stack fill routine:
1) for every build target, add:
syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type MemStackFill
Definition stack_fill.s:62
2) only for specific targets:
PREFERED METHOD
// Declare weak external symbol. If the linker finds a real definition elsewhere, it's used;
// if not, the symbol resolves to 0 (NULL) instead of causing a link error.
// Load the (possibly 0) address of external symbolinto r0. This is resolved by the linker,
// so it correctly reflects whether the symbol was ultimately defined anywhere in the final image.
ldr r0, =MemStackFill
// "Compare and Branch if Zero": if r0 == 0 (symbol was never defined, so it's NULL),
// skip the call and jump to label 1.
cbz r0, 1f
// Otherwise, branch-and-link to the address in r0, i.e. call optional_cb().
// "x" allows switching between ARM/Thumb state if needed.
blx r0
1: // Local label "1:" — landing point when there was nothing to call.
// `cbz .. 1f` is GNU assembler's **local label** syntax, not a special instruction field.
// **The rule:**
// - A label like `1:` (just a digit) is a *local/numeric label* — you can reuse the number `1` many times in the same file for different spots.
// - When you *reference* it, you must say which direction to search:
// - `1f` = search **f**orward from here for the next `1:` label.
// - `1b` = search **b**ackward from here for the nearest previous `1:` label.
CORES WITHOUT CBZ INSTRUCTION SUPPORT
...
//Call memory stack filler (following build target)
...
// Create weak MemStackFill routine (in startup file)
.section .text.MemStackFill
.type MemStackFill, %function
// Fill the user heap & stack.
bx lr

Variable Documentation

◆ LoopFillHeapStack

syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type function adds LoopFillHeapStack

◆ MemStackFill

syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type function adds r4 bcc FillHeapStack bx lr size MemStackFill

◆ r2

syntax unified thumb global MemStackFill word _Stack_Fill_Value word _sheap word _estack section text MemStackFill type function adds r2