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 <ccaione@baylibre.com>
This commit is contained in:
Carlo Caione 2020-11-16 14:46:22 +01:00 committed by Anas Nashif
commit c559591380
2 changed files with 51 additions and 9 deletions

View file

@ -30,6 +30,7 @@
#include <arch/arm/aarch64/timer.h> #include <arch/arm/aarch64/timer.h>
#include <arch/arm/aarch64/error.h> #include <arch/arm/aarch64/error.h>
#include <arch/arm/aarch64/arm_mmu.h> #include <arch/arm/aarch64/arm_mmu.h>
#include <arch/arm/aarch64/thread_stack.h>
#include <arch/common/addr_types.h> #include <arch/common/addr_types.h>
#include <arch/common/sys_bitops.h> #include <arch/common/sys_bitops.h>
#include <arch/common/ffs.h> #include <arch/common/ffs.h>
@ -40,15 +41,6 @@ extern "C" {
#ifndef _ASMLANGUAGE #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 /* Kernel macros for memory attribution
* (access permissions and cache-ability). * (access permissions and cache-ability).
* *

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2020 Carlo Caione <ccaione@baylibre.com>
*
* 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_ */