Skip to content

Commit

Permalink
core: open-code thread_init_stack()
Browse files Browse the repository at this point in the history
The implementations of thread_init_stack() are identical and trivial for
both arm and riscv. So simplify code further and open-code it where it's
called from in core/kernel/thread.c.

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Alvin Chang <alvinga@andestech.com>
Tested-by: Alvin Chang <alvinga@andestech.com>
  • Loading branch information
jenswi-linaro authored and jforissier committed Sep 4, 2024
1 parent efcc90b commit 980d32c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 30 deletions.
8 changes: 0 additions & 8 deletions core/arch/arm/kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,6 @@ int thread_state_suspend(uint32_t flags, uint32_t cpsr, vaddr_t pc)
return ct;
}

bool thread_init_stack(uint32_t thread_id, vaddr_t sp)
{
if (thread_id >= CFG_NUM_THREADS)
return false;
threads[thread_id].stack_va_end = sp;
return true;
}

static void __maybe_unused
set_core_local_kcode_offset(struct thread_core_local *cls, long offset)
{
Expand Down
8 changes: 0 additions & 8 deletions core/arch/riscv/kernel/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,6 @@ int thread_state_suspend(uint32_t flags, unsigned long status, vaddr_t pc)
return ct;
}

bool thread_init_stack(uint32_t thread_id, vaddr_t sp)
{
if (thread_id >= CFG_NUM_THREADS)
return false;
threads[thread_id].stack_va_end = sp;
return true;
}

static void init_user_kcode(void)
{
}
Expand Down
8 changes: 0 additions & 8 deletions core/include/kernel/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ static inline void thread_update_canaries(void) { }

struct thread_core_local *thread_get_core_local(void);

/*
* Sets the stacks to be used by the different threads. Use THREAD_ID_0 for
* first stack, THREAD_ID_0 + 1 for the next and so on.
*
* Returns true on success and false on errors.
*/
bool thread_init_stack(uint32_t stack_id, vaddr_t sp);

/*
* Initializes thread contexts. Called in thread_init_boot_thread() if
* virtualization is disabled. Virtualization subsystem calls it for
Expand Down
9 changes: 3 additions & 6 deletions core/kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ static void init_thread_stacks(void)
/* init effective stack */
sp = tee_mm_get_smem(mm) + tee_mm_get_bytes(mm);
asan_tag_access((void *)tee_mm_get_smem(mm), (void *)sp);
if (!thread_init_stack(n, sp))
panic("init stack failed");
threads[n].stack_va_end = sp;
}
}
#else
Expand All @@ -455,10 +454,8 @@ static void init_thread_stacks(void)
size_t n;

/* Assign the thread stacks */
for (n = 0; n < CFG_NUM_THREADS; n++) {
if (!thread_init_stack(n, GET_STACK_BOTTOM(stack_thread, n)))
panic("thread_init_stack failed");
}
for (n = 0; n < CFG_NUM_THREADS; n++)
threads[n].stack_va_end = GET_STACK_BOTTOM(stack_thread, n);
}
#endif /*CFG_WITH_PAGER*/

Expand Down

0 comments on commit 980d32c

Please sign in to comment.