Beispiel #1
0
/*
 * If the given thread has a User_Context,
 * switch to its memory space.
 *
 * Params:
 *   kthread - the thread that is about to execute
 *   state - saved processor registers describing the state when
 *      the thread was interrupted
 */
void Switch_To_User_Context(struct Kernel_Thread* kthread, struct Interrupt_State* state)
{
    /*
     * Hint: Before executing in user mode, you will need to call
     * the Set_Kernel_Stack_Pointer() and Switch_To_Address_Space()
     * functions.
     */
    //TODO("Switch to a new user address space, if necessary");
    	 Set_Kernel_Stack_Pointer((ulong_t)((kthread->stackPage)+PAGE_SIZE));
	// ERROR: only user thread need this function
	if(Interrupts_Enabled())
		Disable_Interrupts();
	if (kthread->userContext != 0)
	{
		//Print("SuC: %d ldt: %d\n", (int)(kthread->userContext), 
		//	(int)));
		//Set_Kernel_Stack_Pointer((ulong_t)(kthread->esp));
		Switch_To_Address_Space(kthread->userContext);
		//Print("Switch to Address Space!\n");
		//Print("jump to %d\n", (int)(kthread->userContext->entryAddr));
		//Dump_Interrupt_State(state);
		//KASSERT(0);
	}
	Enable_Interrupts();

}
Beispiel #2
0
/*
 * If the given thread has a User_Context,
 * switch to its memory space.
 *
 * Params:
 *   kthread - the thread that is about to execute
 *   state - saved processor registers describing the state when
 *      the thread was interrupted
 */
void Switch_To_User_Context(struct Kernel_Thread* kthread, struct Interrupt_State* state)
{
    /*
     * Hint: Before executing in user mode, you will need to call
     * the Set_Kernel_Stack_Pointer() and Switch_To_Address_Space()
     * functions.
     */
    if (kthread->userContext != NULL) {
        Switch_To_Address_Space(kthread->userContext);
        Set_Kernel_Stack_Pointer(((ulong_t) kthread->stackPage) + PAGE_SIZE);
    }
}
Beispiel #3
0
/*
 * If the given thread has a User_Context,
 * switch to its memory space.
 *
 * Params:
 *   kthread - the thread that is about to execute
 *   state - saved processor registers describing the state when
 *      the thread was interrupted
 */
void Switch_To_User_Context(struct Kernel_Thread* kthread, struct Interrupt_State* state)
{
    /*
     * Hint: Before executing in user mode, you will need to call
     * the Set_Kernel_Stack_Pointer() and Switch_To_Address_Space()
     * functions.
     */
    if(kthread->userContext == NULL)
		return;

	// very important
	Set_Kernel_Stack_Pointer(((ulong_t)kthread->stackPage) + PAGE_SIZE);
	//Print("Switch_To_User_Context %x\n", kthread->userContext->entryAddr);
	Switch_To_Address_Space(kthread->userContext);

}