Cortex-M: initial stack alignment #2976
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The initial stack passed to the thread entry point was always anti-aligned to a 64 bit boundary (meaning the address is aligned to 32 bit, and never to 64 bits)
The cause is bit 9 in xPSR being set in the stacked xPSR when initializing the thread stack in
thread_arch_stack_init
.I have changed the initialization for Cortex-M3 and Cortex-M4 to clear the faulty bit and also cleaned up the comments a bit and added extra handling for aligning the stack on a 64-bit boundary.
Procedure Call Standard for the ARM® Architecture requires that the stack pointer is aligned on a 8 byte boundary upon function entry. Clang relies on this behaviour which caused problems in
auto_init_net_if
on mulle, but I am guessing this is not the only location where this caused problems. GCC does not seem to assume 64 bit alignment, at least not with-Os
and lower.