arm: mpu: Account for stack guard size correctly

This patch fixes a couple of issues with the stack guard size and
properly constructs the STACK_ALIGN and STACK_ALIGN_SIZE definitions.

The ARM AAPCS requires that the stack pointers be 8 byte aligned.  The
STACK_ALIGN_SIZE definition is meant to contain the stack pointer
alignment requirements.  This is the required alignment at public API
boundaries (ie stack frames).

The STACK_ALIGN definition is the required alignment for the start
address for stack buffer storage.  STACK_ALIGN is used to validate
the allocation sizes for stack buffers.

The MPU_GUARD_ALIGN_AND_SIZE definition is the minimum alignment and
size for the MPU.  The minimum size and alignment just so happen to be
32 bytes for vanilla ARM MPU implementations.

When defining stack buffers, the stack guard alignment requirements
must be taken into consideration when allocating the stack memory.
The __align() must be filled in with either STACK_ALIGN_SIZE or the
align/size of the MPU stack guard.  The align/size for the guard region
will be 0 when CONFIG_MPU_STACK_GUARD is not set, and 32 bytes when it
is.

The _ARCH_THREAD_STACK_XXXXXX APIs need to know the minimum alignment
requirements for the stack buffer memory and the stack guard size to
correctly allocate and reference the stack memory.  This is reflected
in the macros with the use of the STACK_ALIGN definition and the
MPU_GUARD_ALIGN_AND_SIZE definition.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
This commit is contained in:
Andy Gross 2017-08-30 16:19:15 -05:00 committed by Kumar Gala
commit ecb0f3e159
3 changed files with 82 additions and 21 deletions

View file

@ -24,8 +24,8 @@ void configure_mpu_stack_guard(struct k_thread *thread)
{
arm_core_mpu_disable();
arm_core_mpu_configure(THREAD_STACK_GUARD_REGION,
thread->stack_info.start - STACK_ALIGN,
thread->stack_info.size);
thread->stack_info.start - MPU_GUARD_ALIGN_AND_SIZE,
thread->stack_info.size);
arm_core_mpu_enable();
}
#endif