Skip to content

atmel-samd: Align stack on 8-byte boundary #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dhalbert opened this issue Jan 24, 2018 · 1 comment · Fixed by #551
Closed

atmel-samd: Align stack on 8-byte boundary #549

dhalbert opened this issue Jan 24, 2018 · 1 comment · Fixed by #551
Assignees
Milestone

Comments

@dhalbert
Copy link
Collaborator

dhalbert commented Jan 24, 2018

The stack should be aligned on an 8-byte boundary, according to the ARM procedure calling standard (AAPCS). A 4-byte boundary might work, but the interrupt controller expects an 8-byte-boundary, and compilers will also expect this.

Good discussion of several related points: https://community.arm.com/processors/f/discussions/6344/what-is-the-meaning-of-a-64-bit-aligned-stack-pointer-address

Right now _estack is on a 4-byte, but not an 8-byte boundary, due to the introduction of _bootloader_dbl_tap. This appears to have caused issue #521, which was fixed by PR #548, which avoids using alloca() in mp_import_from(). My guess is that gcc assumes an 8-byte boundary for alloca().

The fix is to adjust all the linker maps in ports/atmel-samd/boards/*.ld.Change:

_estack = ORIGIN(RAM) + LENGTH(RAM) - 4;

to

_estack = ORIGIN(RAM) + LENGTH(RAM) - 8;

The #548 changes should also be undone.

This appears to have caused a problem only on M4, not M0. But the NVIC supposedly expects an 8-byte boundary, so perhaps this should be backported to 2.x as well.

@dhalbert dhalbert added this to the 3.0 Beta milestone Jan 24, 2018
@dhalbert dhalbert self-assigned this Jan 24, 2018
@jerryneedell
Copy link
Collaborator

Nice! This makes a lot of sense. I suppose this is better than finding a compiler bug!! At least you can fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants