void process_run(process_id_t pid) { context_t user_context; thread_table_t *my_thread = thread_get_current_thread_entry(); /* If my process is a zombie, that means initialisation failed. */ if (process_table[pid].state == PROCESS_ZOMBIE) { if (my_thread->pagetable) { vm_destroy_pagetable(my_thread->pagetable); my_thread->pagetable = NULL; } thread_finish(); } process_set_pagetable(my_thread->pagetable); my_thread->process_id = pid; my_thread->pagetable = my_thread->pagetable; /* Initialize the user context. (Status register is handled by thread_goto_userland) */ memoryset(&user_context, 0, sizeof(user_context)); _context_set_ip(&user_context, process_table[pid].entry_point); _context_set_sp(&user_context, process_table[pid].stack_top); thread_goto_userland(&user_context); }
/* Sets context for process */ void process_run(process_id_t pid) { context_t user_context; kprintf("vi er nu i process run\n"); process_set_pagetable(thread_get_thread_entry(thread_get_current_thread())->pagetable); /* Initialize the user context. (Status register is handled by thread_goto_userland) */ memoryset(&user_context, 0, sizeof(user_context)); _context_set_ip(&user_context, process_table[pid].entry_point); _context_set_sp(&user_context, process_table[pid].stack_top); kprintf("lige før thread goto"); thread_goto_userland(&user_context); }
/** Initializes the threading system. Does this by setting all thread * table entry states to THREAD_FREE. Called only once before any * threads are created. */ void thread_table_init(void) { int i; /* Thread table entry _must_ be 64 bytes long, because the context switching code in kernel/cswitch.S expects that. Let's make sure it is. If you hit this error, you have changed either context_t or thread_table_t, but have not changed padding in the end of thread_table_t definition in kernel/thread.h */ KERNEL_ASSERT(sizeof(thread_table_t) == 64); spinlock_reset(&thread_table_slock); /* Init all entries to 'NULL' */ for (i=0; i<CONFIG_MAX_THREADS; i++) { /* Set context pointers to the top of the stack*/ thread_table[i].context = (context_t *) (thread_stack_areas +CONFIG_THREAD_STACKSIZE*i + CONFIG_THREAD_STACKSIZE - sizeof(context_t)); thread_table[i].user_context = NULL; thread_table[i].state = THREAD_FREE; thread_table[i].sleeps_on = 0; thread_table[i].pagetable = NULL; thread_table[i].attribs = 0; thread_table[i].process_id = -1; thread_table[i].next = -1; } /* Setup Idle Thread */ _context_set_ip(thread_table[IDLE_THREAD_TID].context, (virtaddr_t)_idle_thread_wait_loop); _context_set_sp(thread_table[IDLE_THREAD_TID].context, (virtaddr_t) thread_stack_areas + CONFIG_THREAD_STACKSIZE - 4 - sizeof(context_t)); _context_enable_ints(thread_table[IDLE_THREAD_TID].context); thread_table[IDLE_THREAD_TID].state = THREAD_READY; thread_table[IDLE_THREAD_TID].context->prev_context = thread_table[IDLE_THREAD_TID].context; }