// // Context switch from curenv to env e. // Note: if this is the first call to env_run, curenv is NULL. // (This function does not return.) // void env_run(struct Env *e) { //panic("env_run not yet implemented"); // Step 1: If this is a context switch (a new environment is running), // then set 'curenv' to the new environment, // update its 'env_runs' counter, and // and use lcr3() to switch to its address space. // Step 2: Use env_pop_tf() to restore the environment's // registers and drop into user mode in the // environment. // Hint: This function loads the new environment's state from // e->env_tf. Go back through the code you wrote above // and make sure you have set the relevant parts of // e->env_tf to sensible values. // LAB 3: Your code here. if(curenv == NULL) { curenv = &envs[0]; curenv->env_runs++; lcr3(curenv->env_cr3); env_pop_tf(&(curenv->env_tf)); } else { curenv = e; e->env_runs++; lcr3(e->env_cr3); env_pop_tf(&(e->env_tf)); } panic("env_run not yet implemented"); }
// // Context switch from curenv to env e. // Note: if this is the first call to env_run, curenv is NULL. // (This function does not return.) // void env_run(struct Env *e) { // Step 1: If this is a context switch (a new environment is running), // then set 'curenv' to the new environment, // update its 'env_runs' counter, and // and use lcr3() to switch to its address space. // Step 2: Use env_pop_tf() to restore the environment's // registers and drop into user mode in the // environment. // Hint: This function loads the new environment's state from // e->env_tf. Go back through the code you wrote above // and make sure you have set the relevant parts of // e->env_tf to sensible values. // LAB 3: Your code here. //panic("env_run not yet implemented"); //cprintf("the PADDR of env is %x\n",e->env_cr3); //cprintf("env %d father %d : the KADDR of env is %x, the PADDR of env is %x\n", e->env_id, e->env_parent_id, e->env_pgdir, e->env_cr3); if(curenv != e){ curenv = e; curenv->env_runs++;//run again lcr3(curenv->env_cr3); } env_pop_tf(&curenv->env_tf); }
// // Context switch from curenv to env e. // Note: if this is the first call to env_run, curenv is NULL. // (This function does not return.) // void env_run(struct Env *e) { // Step 1: If this is a context switch (a new environment is running), // then set 'curenv' to the new environment, // update its 'env_runs' counter, and // and use lcr3() to switch to its address space. // Step 2: Use env_pop_tf() to restore the environment's // registers and drop into user mode in the // environment. // Hint: This function loads the new environment's state from // e->env_tf. Go back through the code you wrote above // and make sure you have set the relevant parts of // e->env_tf to sensible values. // LAB 3: Your code here. // During the switch of env, it will first trap into the kernel. // During the trap, the state of the registers have been stored. // So we don't need to store the registers in env_run(). // The kernel will schedule which env to run next, then do context switching. // At last, it will execute the next env curenv = e; curenv->env_runs++; lcr3(curenv->env_cr3); env_pop_tf(&(e->env_tf)); }
// Used to run the given environment "e", simply by // context switch from curenv to env e. // (This function does not return.) // void env_run(struct Env *e) { if(curenv != e) { curenv = e ; curenv->env_runs++ ; lcr3(curenv->env_cr3) ; } env_pop_tf(&(curenv->env_tf)); }
void syscall_helper(struct Trapframe *tf) { lock_kernel(); tf->tf_eflags |= FL_IF; //Enable interrupts while in user mode. curenv->env_tf = *tf; curenv->env_tf.tf_regs.reg_eax = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx,tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, 0); unlock_kernel(); env_pop_tf(&curenv->env_tf); }
void proc_run(struct ProcStruct *proc) { if(curproc && curproc->status!=FREE &&curproc->status!=WAITING) curproc->status =RUNNABLE; proc->status = RUNNING; lcr3(proc->cr3); tss.rsp0 =(uint64_t) &proc->kstack[511]; curproc = proc; printf("\nRUN:%d",curproc->proc_id); env_pop_tf(&(proc->tf)); }
// // Context switch from curenv to env e. // Note: if this is the first call to env_run, curenv is NULL. // (This function does not return.) // void env_run(struct Env *e) { // Step 1: If this is a context switch (a new environment is running), if (curenv != e) { // then set 'curenv' to the new environment, curenv = e; // update its 'env_runs' counter, and e->env_runs++; // and use lcr3() to switch to its address space. lcr3(e->env_cr3); } // Step 2: Use env_pop_tf() to restore the environment's // registers and drop into user mode in the // environment. env_pop_tf(&e->env_tf); }