Re: Fork and Processes
Posted: Mon Mar 02, 2009 10:04 am
I think I am missing something here, but the way I understand how the scheduler should work is that it figures out what process to run next, saves the current context, and then restores the context of the process it wants to run, and when the iret is executed, you have set things up so that the eip of the processs you want to run is on the stack, so it smoothly transitions as if nothing happened but an interrupt occured and returned.Creature wrote:Schedule process is called when a timer interrupt occurs and switches processes all the time. Since I'm using JamesM's tutorials, I'm going to quote what James says (he explains best):yemista wrote:Why do you read the up? If schedule process is called doesnt that mean the process has switched?
This is what happens at the ReadEIP() in 'ScheduleProcess'.JamesM's Tutorials wrote: Read the instruction pointer. We do some cunning logic here:
One of two things could have happened when this function exits -
(a) We called the function and it returned the EIP as requested.
(b) We have just switched tasks, and because the saved EIP is essentially the instruction after read_eip(), it will seem as if read_eip has just returned.
In the second case we need to return immediately. To detect it we put a dummy
value in EAX further down at the end of this function. As C returns values in EAX,
it will look like the return value is this dummy value! (0x12345).