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

What is the meaning of a 64 bit aligned stack pointer address?

According to ARM Architecture Procedure Call Standard (AAPCS) on the ARMv6-M, and ARMv7-M architecture in  it says:

"Although the processor hardware allows SP to be at any word aligned address at function boundaries, standard programming practice requires C program code to ensure that the SP is at a 64-bit (doubleword) aligned address."

What does it mean that the Stack pointer has to be at a 64 bit aligned address?

Parents
  • Hello,

    as far as my memory is correct, the 8-byte alignment of the exception stack frame would be required only for Cortex-M7.

    The other Cortex-M core would be enough with 4-byte alignment.
    The reason of 8-byte alignment of Cortex-M7 would be guessed as that the internal AXI bus width is 64 bit.

    According to "ARM®v7-M Architecture Reference Manual [ARM DDI 0403E.b (ID120114)]", B1.5.7 describes as the following.

    B1.5.7 Stack alignment on exception entry

    The ARMv7-M architecture guarantees that stack pointer values are at least 4-byte aligned.

    However, some software standards require the stack pointer to be 8-byte aligned, and the architecture can enforce this alignment.
    The CCR.STKALIGN bit indicates whether, as part of an exception entry, the processor aligns the SP to 4 bytes, or
    to 8 bytes. It is IMPLEMENTATION DEFINED whether this bit is:
    - RW, in which case its reset value is IMPLEMENTATION DEFINED.
    - RO, in which case it is RAO, indicating 8-byte SP alignment

    Also, according to the Cortex-M4 TRM, CCR.STKALIGN is R/W although the initial value is 1 (i.e. 8-byte align).
    According to the Coetex-M7 TRM, CCR.STKALIGN is R/O and the initial value is 1 (i.e. 8-byte align).
    As for Cortex-M0+ and Cortex-M3 TRMs, it is uncertain whether CCR.STKALIGN can be modified or not, but the initial value is 1. I think they can be modified.

    Best regards,

    Yasuhiko Koumoto.

Reply
  • Hello,

    as far as my memory is correct, the 8-byte alignment of the exception stack frame would be required only for Cortex-M7.

    The other Cortex-M core would be enough with 4-byte alignment.
    The reason of 8-byte alignment of Cortex-M7 would be guessed as that the internal AXI bus width is 64 bit.

    According to "ARM®v7-M Architecture Reference Manual [ARM DDI 0403E.b (ID120114)]", B1.5.7 describes as the following.

    B1.5.7 Stack alignment on exception entry

    The ARMv7-M architecture guarantees that stack pointer values are at least 4-byte aligned.

    However, some software standards require the stack pointer to be 8-byte aligned, and the architecture can enforce this alignment.
    The CCR.STKALIGN bit indicates whether, as part of an exception entry, the processor aligns the SP to 4 bytes, or
    to 8 bytes. It is IMPLEMENTATION DEFINED whether this bit is:
    - RW, in which case its reset value is IMPLEMENTATION DEFINED.
    - RO, in which case it is RAO, indicating 8-byte SP alignment

    Also, according to the Cortex-M4 TRM, CCR.STKALIGN is R/W although the initial value is 1 (i.e. 8-byte align).
    According to the Coetex-M7 TRM, CCR.STKALIGN is R/O and the initial value is 1 (i.e. 8-byte align).
    As for Cortex-M0+ and Cortex-M3 TRMs, it is uncertain whether CCR.STKALIGN can be modified or not, but the initial value is 1. I think they can be modified.

    Best regards,

    Yasuhiko Koumoto.

Children