From c559591380db14db841c76fd2cee5254a67865e4 Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Mon, 16 Nov 2020 14:46:22 +0100 Subject: [PATCH] aarch64: stack: Rework memory stack allocations Introduce the necessary macros and defines to have the stack regions correctly aligned and sized. Signed-off-by: Carlo Caione --- include/arch/arm/aarch64/arch.h | 10 +---- include/arch/arm/aarch64/thread_stack.h | 50 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 include/arch/arm/aarch64/thread_stack.h diff --git a/include/arch/arm/aarch64/arch.h b/include/arch/arm/aarch64/arch.h index a765daaff70..4e1ccbfd962 100644 --- a/include/arch/arm/aarch64/arch.h +++ b/include/arch/arm/aarch64/arch.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -40,15 +41,6 @@ extern "C" { #ifndef _ASMLANGUAGE -/** - * @brief Declare the ARCH_STACK_PTR_ALIGN - * - * Denotes the required alignment of the stack pointer on public API - * boundaries - * - */ -#define ARCH_STACK_PTR_ALIGN 16 - /* Kernel macros for memory attribution * (access permissions and cache-ability). * diff --git a/include/arch/arm/aarch64/thread_stack.h b/include/arch/arm/aarch64/thread_stack.h new file mode 100644 index 00000000000..65967d6a049 --- /dev/null +++ b/include/arch/arm/aarch64/thread_stack.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Carlo Caione + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_AARCH64_THREAD_STACK_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_AARCH64_THREAD_STACK_H_ + +#define ARCH_STACK_PTR_ALIGN 16 + +#if CONFIG_USERSPACE +#define Z_ARM64_STACK_BASE_ALIGN CONFIG_MMU_PAGE_SIZE +#define Z_ARM64_STACK_SIZE_ALIGN CONFIG_MMU_PAGE_SIZE +#else +#define Z_ARM64_STACK_BASE_ALIGN ARCH_STACK_PTR_ALIGN +#define Z_ARM64_STACK_SIZE_ALIGN ARCH_STACK_PTR_ALIGN +#endif + +/* + * High memory addresses + * + * +-------------------+ <- thread.stack_info.start + thread.stack_info.size + * | TLS | + * +-------------------+ <- initial sp (computable with thread.stack_info.delta) + * | | + * | Used stack | + * | | + * +...................+ <- thread's current stack pointer + * | | + * | Unused stack | + * | | + * +-------------------+ <- thread.stack_info.start + * | Reserved memory | } K_(THREAD|KERNEL)_STACK_RESERVED + * +-------------------+ <- thread.stack_obj + * + * Low Memory addresses + */ + +/* thread stack */ +#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_ARM64_STACK_BASE_ALIGN +#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \ + ROUND_UP((size), Z_ARM64_STACK_SIZE_ALIGN) +#define ARCH_THREAD_STACK_RESERVED CONFIG_PRIVILEGED_STACK_SIZE + +/* kernel stack */ +#define ARCH_KERNEL_STACK_RESERVED 0 +#define ARCH_KERNEL_STACK_OBJ_ALIGN ARCH_STACK_PTR_ALIGN + +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH64_THREAD_STACK_H_ */