arch: arm: utilize Kconfig option for min ARM MPU region size

The commit enforces the use of ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
in include/arch/arm/arch.h, instead of using 32 as a hard-coded
value. The symbol is also used in arm/thread.c to truncate the
thread stack size to satisfy MPU granularity. The commit does
not introduce behavioral changes.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2018-11-20 09:58:15 +01:00 committed by Carles Cufí
commit 80d38788fc
2 changed files with 18 additions and 15 deletions

View file

@ -122,11 +122,9 @@ FUNC_NORETURN void _arch_user_mode_enter(k_thread_entry_t user_entry,
_current->arch.priv_stack_size =
(u32_t)CONFIG_PRIVILEGED_STACK_SIZE;
/* FIXME: Need a general API for aligning stacks so that the initial
* user thread stack pointer doesn't overshoot the granularity of MPU
* regions, that works for ARM/NXP/QEMU.
*/
_current->stack_info.size &= ~0x1f;
/* Truncate the stack size with the MPU region granularity. */
_current->stack_info.size &=
~(CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE - 1);
_arm_userspace_enter(user_entry, p1, p2, p3,
(u32_t)_current->stack_info.start,

View file

@ -92,7 +92,7 @@ extern "C" {
*
*/
#if defined(CONFIG_MPU_STACK_GUARD)
#define MPU_GUARD_ALIGN_AND_SIZE 32
#define MPU_GUARD_ALIGN_AND_SIZE CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
#else
#define MPU_GUARD_ALIGN_AND_SIZE 0
#endif
@ -107,7 +107,7 @@ extern "C" {
*
*/
#if defined(CONFIG_USERSPACE)
#define STACK_ALIGN 32
#define STACK_ALIGN CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
#else
#define STACK_ALIGN max(STACK_ALIGN_SIZE, MPU_GUARD_ALIGN_AND_SIZE)
#endif
@ -258,10 +258,11 @@ extern "C" {
#include <arch/arm/cortex_m/mpu/arm_mpu.h>
#endif /* _ASMLANGUAGE */
#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
BUILD_ASSERT_MSG(!(((size) & ((size) - 1))) && (size) >= 32 && \
BUILD_ASSERT_MSG(!(((size) & ((size) - 1))) && \
(size) >= CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE && \
!((u32_t)(start) & ((size) - 1)), \
"the size of the partition must be power of 2" \
" and greater than or equal to 32." \
" and greater than or equal to the minimum MPU region size." \
"start address of the partition must align with size.")
#endif /* CONFIG_CPU_HAS_ARM_MPU */
#ifdef CONFIG_CPU_HAS_NXP_MPU
@ -313,11 +314,15 @@ extern "C" {
#endif /* _ASMLANGUAGE */
#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
BUILD_ASSERT_MSG((size) % 32 == 0 && (size) >= 32 && \
(u32_t)(start) % 32 == 0, \
"the size of the partition must align with 32" \
" and greater than or equal to 32." \
"start address of the partition must align with 32.")
BUILD_ASSERT_MSG((size) % \
CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE == 0 && \
(size) >= CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE && \
(u32_t)(start) % CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE == 0, \
"the size of the partition must align with minimum MPU \
region size" \
" and greater than or equal to minimum MPU region size." \
"start address of the partition must align with minimum MPU \
region size.")
#endif /* CONFIG_CPU_HAS_ARM_MPU */
#endif /* CONFIG_USERSPACE */