Skip to content

Commit 011c420

Browse files
darcagnQuzarDC
authored andcommitted
Add arch_stk_setup function for setting up a new stack during thread creation
Some architectures, like PowerPC, need the stack to be adjusted before thread creation. This is unnecessary on Dreamcast, so the implementation added to Dreamcast is empty.
1 parent 4e79be9 commit 011c420

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

kernel/arch/dreamcast/include/arch/stack.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ static inline uintptr_t arch_fptr_next(uintptr_t fptr) {
100100
return arch_fptr_ret_addr(fptr + 4);
101101
}
102102

103+
/** \brief Set up new stack before running.
104+
105+
This function does nothing as it is unnecessary on Dreamcast.
106+
107+
\param nt A pointer to the new thread for which a stack
108+
is to be set up.
109+
*/
110+
void arch_stk_setup(kthread_t *nt);
111+
103112
/** \brief Do a stack trace from the current function.
104113
105114
This function does a stack trace from the current function, printing the

kernel/arch/dreamcast/kernel/stack.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ static uintptr_t arch_stack_32m_dft = 0x8e000000;
2020
extern uintptr_t arch_stack_16m __attribute__((weak,alias("arch_stack_16m_dft")));
2121
extern uintptr_t arch_stack_32m __attribute__((weak,alias("arch_stack_32m_dft")));
2222

23+
/* This function is unnecessary and does nothing on Dreamcast */
24+
void arch_stk_setup(kthread_t *nt) {
25+
(void)nt;
26+
}
27+
2328
/* Do a stack trace from the current function; leave off the first n frames
2429
(i.e., in assert()). */
2530
__noinline void arch_stk_trace(int n) {

kernel/thread/thread.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,11 @@ int thd_remove_from_runnable(kthread_t *thd) {
362362
}
363363

364364
/* New thread function; given a routine address, it will create a
365-
new kernel thread with the given attributes. When the routine
366-
returns, the thread will exit. Returns the new thread struct. */
365+
new thread with the given attributes. When the routine returns,
366+
the thread will exit. Returns the new thread struct.
367+
Note that this function is also used in thd_init() to add the
368+
already running kernel thread to the thread scheduler. This is
369+
the only circumstance in which routine should be NULL. */
367370
kthread_t *thd_create_ex(const kthread_attr_t *restrict attr,
368371
void *(*routine)(void *param), void *param) {
369372
kthread_t *nt = NULL;
@@ -431,6 +434,13 @@ kthread_t *thd_create_ex(const kthread_attr_t *restrict attr,
431434
((uint32_t)nt->stack) + nt->stack_size,
432435
(uint32_t)thd_birth, params, 0);
433436

437+
/* Some architectures require setting up a new stack before use.
438+
We won't do this if routine is NULL, however, as this means
439+
we are creating the kernel thread, which is already running. */
440+
if(routine) {
441+
arch_stk_setup(nt);
442+
}
443+
434444
/* Create static TLS data if the thread hasn't disabled it. */
435445
if(real_attr.disable_tls) {
436446
nt->flags |= THD_DISABLE_TLS;

0 commit comments

Comments
 (0)