/* * Done by Dietmar Hahn #include #include #include #include /* The function is implemented in fw.S */ extern void thread_starter(void); void stack_walk(void) { /* TODO */ } struct thread* arch_create_thread(char *name, void (*function)(void *), void *data) { struct thread* _thread; _thread = (struct thread*)_xmalloc(sizeof(struct thread), 16); /* Allocate pages for stack, stack will be aligned */ _thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER); _thread->name = name; memset((void*)&(_thread->regs), 0, sizeof(_thread->regs)); _thread->regs.sp = ((uint64_t)_thread->stack) + STACK_SIZE - 16; _thread->regs.bsp = ((uint64_t)_thread->stack) + 0x10; _thread->regs.rp = FDESC_FUNC(thread_starter); _thread->regs.pfs = 0x82; _thread->regs.r4 = FDESC_FUNC(function); _thread->regs.r6 = (uint64_t)data; return _thread; } extern void restore_context(struct thread*); extern int switch_context(struct thread*, struct thread*); void arch_switch_threads(struct thread* prev, struct thread* next) { ia64_set_r13((uint64_t)next); switch_context(prev, next); } /* Everything initialised, start idle thread */ void run_idle_thread(void) { //do_busy_loop(); ia64_set_r13((uint64_t)idle_thread); restore_context(idle_thread); printk("%s: restore_context() returned - bad!\n", __func__); }