summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpthread/thread/thr_init.c')
-rw-r--r--lib/libpthread/thread/thr_init.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c
index 4dd356a..9f2f894 100644
--- a/lib/libpthread/thread/thr_init.c
+++ b/lib/libpthread/thread/thr_init.c
@@ -224,6 +224,9 @@ _thread_init(void)
/* Allocate memory for the scheduler stack: */
else if ((_thread_kern_sched_stack = malloc(sched_stack_size)) == NULL)
PANIC("Failed to allocate stack for scheduler");
+ /* Allocate memory for the idle stack: */
+ else if ((_idle_thr_stack = malloc(sched_stack_size)) == NULL)
+ PANIC("Failed to allocate stack for scheduler");
else {
/* Zero the global kernel thread structure: */
memset(&_thread_kern_thread, 0, sizeof(struct pthread));
@@ -273,6 +276,15 @@ _thread_init(void)
_thread_kern_kse_mailbox.km_func =
(void *)_thread_kern_scheduler;
+ /* Initialize the idle context. */
+ bzero(&_idle_thr_mailbox, sizeof(struct kse_thr_mailbox));
+ getcontext(&_idle_thr_mailbox.tm_context);
+ _idle_thr_mailbox.tm_context.uc_stack.ss_sp = _idle_thr_stack;
+ _idle_thr_mailbox.tm_context.uc_stack.ss_size =
+ sched_stack_size;
+ makecontext(&_idle_thr_mailbox.tm_context, _thread_kern_idle,
+ 1);
+
/*
* Write a magic value to the thread structure
* to help identify valid ones:
OpenPOWER on IntegriCloud