Skip to content
Permalink
Browse files

kernel: init: use K_THREAD_STACK_SIZEOF when switching to main thread

For architectures with custom swap to main, currently:
- arm
- posix
we are now using K_THREAD_STACK_SIZEOF macro to pass the
main thread stack size to z_arch_switch_to_main_thread().

This does not introduce any behavioral changes for posix;
the K_THREAD_STACK_SIZEOF() simply returns the sizeof()
the stack object. For Arm, this allows us to clean-up one
more occurence of CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
in kernel_arch_func.h.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and nashif committed May 24, 2019
1 parent 9e96df3 commit 5a709f5dc9f58dd28923cd3cc4f05fbf4746c5c7
Showing with 3 additions and 8 deletions.
  1. +1 −7 arch/arm/include/kernel_arch_func.h
  2. +2 −1 kernel/init.c
@@ -74,15 +74,9 @@ z_arch_switch_to_main_thread(struct k_thread *main_thread,
/* get high address of the stack, i.e. its start (stack grows down) */
char *start_of_main_stack;

#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) && \
defined(CONFIG_USERSPACE)
start_of_main_stack =
Z_THREAD_STACK_BUFFER(main_stack) + main_stack_size -
MPU_GUARD_ALIGN_AND_SIZE;
#else
start_of_main_stack =
Z_THREAD_STACK_BUFFER(main_stack) + main_stack_size;
#endif

start_of_main_stack = (char *)STACK_ROUND_DOWN(start_of_main_stack);

#ifdef CONFIG_TRACING
@@ -411,7 +411,8 @@ static void prepare_multithreading(struct k_thread *dummy_thread)
static void switch_to_main_thread(void)
{
#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN
z_arch_switch_to_main_thread(_main_thread, _main_stack, MAIN_STACK_SIZE,
z_arch_switch_to_main_thread(_main_thread, _main_stack,
K_THREAD_STACK_SIZEOF(_main_stack),
bg_thread_main);
#else
/*

0 comments on commit 5a709f5

Please sign in to comment.
You can’t perform that action at this time.