This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM stack alignment on exception entry

Note: This was originally posted on 8th November 2011 at http://forums.arm.com

Hello everybody,

The Application Binary Interface (ABI) for the ARM architecture requires that the stack must be eight-byte aligned on exception entry. The default stack alignment for Cortex-M3 is 4 byte and not 8 byte, why this ambiguity?

Why is it required anyway to configure the 8 byte stack alignment if it also works with 4 byte? Is there any reason?

Regards,
affonpign
Parents
  • Note: This was originally posted on 8th November 2011 at http://forums.arm.com

    Starting in revision 1 of the Cortex-M3, the Configuration Control Register (address 0xE000ED14) has a STKALIGN control bit to control this behavior.  When this bit is set, the exception stack frame is double word aligned.

    From revision 2, this bit is set by default.

    There are some cases where double word stack alignment is essential - dependent on the application code.
    For example, when the interrupt handler or the functions that the interrupt handler accesses has pointer arithmetic that assumed the stack was double word aligned, the code might not work.

    If you are using  Cortex-M3 r1p0/r1p1, it is recommended to add
      SCB->CCR |= SCB_CCR_STKALIGN_Msk;
    in the beginning of the application.
Reply
  • Note: This was originally posted on 8th November 2011 at http://forums.arm.com

    Starting in revision 1 of the Cortex-M3, the Configuration Control Register (address 0xE000ED14) has a STKALIGN control bit to control this behavior.  When this bit is set, the exception stack frame is double word aligned.

    From revision 2, this bit is set by default.

    There are some cases where double word stack alignment is essential - dependent on the application code.
    For example, when the interrupt handler or the functions that the interrupt handler accesses has pointer arithmetic that assumed the stack was double word aligned, the code might not work.

    If you are using  Cortex-M3 r1p0/r1p1, it is recommended to add
      SCB->CCR |= SCB_CCR_STKALIGN_Msk;
    in the beginning of the application.
Children
No data