defined in x86_[32/64].S */
extern void _minios_entry_thread_starter(void);
-void run_idle_thread(void)
-{
- /* Switch stacks and run the thread */
-#if defined(__i386__)
- __asm__ __volatile__("mov %0,%%esp\n\t"
- "push %1\n\t"
- "ret"
- :"=m" (idle_tcb->btcb_sp)
- :"m" (idle_tcb->btcb_ip));
-#elif defined(__x86_64__)
- __asm__ __volatile__("mov %0,%%rsp\n\t"
- "push %1\n\t"
- "ret"
- :"=m" (idle_tcb->btcb_sp)
- :"m" (idle_tcb->btcb_ip));
-#endif
-}
-
void
bmk_cpu_switch(struct bmk_tcb *prev, struct bmk_tcb *next)
{
#ifndef __MINIOS_SCHED_H__
#define __MINIOS_SCHED_H__
-#include <mini-os/types.h>
-
-#include <bmk-core/sched.h>
-
-extern struct bmk_tcb *idle_tcb;
-void idle_thread_fn(void *unused);
-
-void run_idle_thread(void);
-
#endif /* __MINIOS_SCHED_H__ */
/* Init grant tables */
init_gnttab();
-
- /* Init scheduler. */
- bmk_sched_init(NULL, NULL);
/* Init XenBus */
init_xenbus();
- /* Call (possibly overridden) app_main() */
- bmk_sched_create("main", NULL, 0, _app_main, &start_info, NULL, 0);
-
- /* Everything initialised, start idle thread */
- run_idle_thread();
+ /* Init scheduler. */
+ bmk_sched_init(_app_main, &start_info);
+ bmk_platform_halt("unreachable");
}
void minios_stop_kernel(void)
TAILQ_ENTRY(bmk_thread) bt_entries;
};
-static struct bmk_thread *idle_thread = NULL;
-struct bmk_tcb *idle_tcb;
-
static TAILQ_HEAD(, bmk_thread) zombies = TAILQ_HEAD_INITIALIZER(zombies);
static TAILQ_HEAD(, bmk_thread) threads = TAILQ_HEAD_INITIALIZER(threads);
}
void
-idle_thread_fn(void *unused)
+bmk_sched_init(void (*mainfun)(void *), void *arg)
{
+ struct bmk_thread *mainthread;
+ struct bmk_thread initthread;
- for (;;) {
- bmk_sched_block(bmk_sched_current());
- bmk_sched();
- }
-}
+ mainthread = bmk_sched_create("main", NULL, 0, mainfun, arg, NULL, 0);
+ if (mainthread == NULL)
+ bmk_platform_halt("failed to create main thread");
-void
-bmk_sched_init(void (*notused)(void *), void *arg)
-{
- minios_printk("Initialising scheduler\n");
+ bmk_memset(&initthread, 0, sizeof(initthread));
+ bmk_strcpy(initthread.bt_name, "init");
+ sched_switch(&initthread, mainthread);
- idle_thread = bmk_sched_create("Idle", NULL, 0,
- idle_thread_fn, NULL, NULL, 0);
- idle_tcb = &idle_thread->bt_tcb;
+ bmk_platform_halt("bmk_sched_init unreachable");
}
void