diff --git a/arch/arm64/core/userspace.S b/arch/arm64/core/userspace.S index 1c60ebb76bf..7155ef79c67 100644 --- a/arch/arm64/core/userspace.S +++ b/arch/arm64/core/userspace.S @@ -9,6 +9,7 @@ #include #include #include +#include #include "macro_priv.inc" _ASM_FILE_PROLOGUE @@ -66,7 +67,7 @@ abv_loop: b 2f 1: at S1E0W, x0 -2: orr x0, x0, #(CONFIG_MMU_PAGE_SIZE - 1) +2: orr x0, x0, #(MEM_DOMAIN_ALIGN_AND_SIZE - 1) add x0, x0, #1 isb diff --git a/include/arch/arm64/mm.h b/include/arch/arm64/mm.h index 373e0627cab..7b269b1d110 100644 --- a/include/arch/arm64/mm.h +++ b/include/arch/arm64/mm.h @@ -8,8 +8,19 @@ #if defined(CONFIG_ARM_MMU) #include +/* + * When mmu enabled, some section addresses need to be aligned with + * page size which is CONFIG_MMU_PAGE_SIZE + */ +#define MEM_DOMAIN_ALIGN_AND_SIZE CONFIG_MMU_PAGE_SIZE #elif defined(CONFIG_ARM_MPU) #include +/* + * When mpu enabled, some section addresses need to be aligned with + * mpu region min align size which is + * CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE + */ +#define MEM_DOMAIN_ALIGN_AND_SIZE CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE #endif #ifndef _ASMLANGUAGE diff --git a/include/arch/arm64/thread.h b/include/arch/arm64/thread.h index 9b542abcc68..3227d451d44 100644 --- a/include/arch/arm64/thread.h +++ b/include/arch/arm64/thread.h @@ -49,7 +49,7 @@ struct z_arm64_fp_context { }; struct _thread_arch { -#ifdef CONFIG_USERSPACE +#if defined(CONFIG_USERSPACE) && defined(CONFIG_ARM_MMU) struct arm_mmu_ptables *ptables; #endif #ifdef CONFIG_FPU_SHARING diff --git a/include/arch/arm64/thread_stack.h b/include/arch/arm64/thread_stack.h index 422a0dcf966..22f0a1e5d39 100644 --- a/include/arch/arm64/thread_stack.h +++ b/include/arch/arm64/thread_stack.h @@ -7,11 +7,13 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM64_THREAD_STACK_H_ #define ZEPHYR_INCLUDE_ARCH_ARM64_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 +#include +#define Z_ARM64_STACK_BASE_ALIGN MEM_DOMAIN_ALIGN_AND_SIZE +#define Z_ARM64_STACK_SIZE_ALIGN MEM_DOMAIN_ALIGN_AND_SIZE #else #define Z_ARM64_STACK_BASE_ALIGN ARCH_STACK_PTR_ALIGN #define Z_ARM64_STACK_SIZE_ALIGN ARCH_STACK_PTR_ALIGN