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>
56 lines
938 B
C
56 lines
938 B
C
/*
|
|
* Copyright (c) 2013-2014 Wind River Systems, Inc.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @brief Stack helpers for Cortex-M CPUs
|
|
*
|
|
* Stack helper functions.
|
|
*/
|
|
|
|
#ifndef _ARM_CORTEXM_STACK__H_
|
|
#define _ARM_CORTEXM_STACK__H_
|
|
|
|
#include <kernel_structs.h>
|
|
#include <asm_inline.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifdef _ASMLANGUAGE
|
|
|
|
/* nothing */
|
|
|
|
#else
|
|
|
|
extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
|
|
|
|
/**
|
|
*
|
|
* @brief Setup interrupt stack
|
|
*
|
|
* On Cortex-M, the interrupt stack is registered in the MSP (main stack
|
|
* pointer) register, and switched to automatically when taking an exception.
|
|
*
|
|
* @return N/A
|
|
*/
|
|
static ALWAYS_INLINE void _InterruptStackSetup(void)
|
|
{
|
|
u32_t msp = (u32_t)(K_THREAD_STACK_BUFFER(_interrupt_stack) +
|
|
CONFIG_ISR_STACK_SIZE);
|
|
|
|
_MspSet(msp);
|
|
}
|
|
|
|
#endif /* _ASMLANGUAGE */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _ARM_CORTEXM_STACK__H_ */
|