_platform_pre_stackheap_init()
If defined, _platform_pre_stackheap_init
is called by __rt_entry
before stack and heap initialization. Define this function to perform hardware initialization after scatter-loading but before stack and heap initialization.
Because _platform_pre_stackheap_init
is called before the stack
initialization, either it must not use the stack or the SP must already be
valid.
Invalidating the ARMv8 instruction cache
To invalidate the ARMv8 instruction cache after scatter-loading and before initialization of the stack and heap, you must:
- Implement instruction cache invalidation code in
_platform_pre_stackheap_init
. - Ensure that all code that is executed from the program entry, up to and
including
_platform_pre_stackheap_init
, is located in a root region.
Where a processor starts in AArch64 state, then switches to AArch32 state, it is possible that addresses are speculatively prefetched, and therefore cached, while in AArch64 state. If the MMU has remained off while in AArch64 state, a processor is allowed to speculatively prefetch from any address either within:
- The same page as an architecturally executed instruction.
- The following page, where
page
is the smallest supported granulesizeof
for the processor.
If you have AArch64 startup code that switches to AArch32 state to run __main
and then run C/C++ applications, then the cache invalidation
must be done in AArch32 state.
Example
Invalidate caches in AArch64 as follows:
_platform_pre_stackheap_init: dsb ish // ensure all previous stores have completed // before invalidating ic ialluis // I cache invalidate all inner shareable to PoU // (which includes secondary cores) dsb ish // ensure completion on inner shareable domain // (which includes secondary cores) isb b InvalidateUDCaches // only needed if the MMU is on at this point
Note
b
is a tail-call to avoid saving the return address.