call swtch
1) to save the current context in proc->context
2) switch to the scheduler context previously saved in cpu->scheduler
The flow of swtch
1) copying old's arguments from the stack to the caller-saved registers %eax and %edx
(swtch must to this before it changes the stack pointer (2969-2970) and can no longer access the arguments via %esp)
2) pushing the register state
3) creating a context structure on the current stack
4) calle saved registers : %ebp, %ebx, %esi, %edi, and %esp registers
5) pushing the %ebp, %ebx, %esi, %edi
- it saves the last implicitly as the context* written to *old
6) %eip : the program counter ; it has already been saved on the stack by the call instruction that invoked swtch
7) moving the pointer to the new context into the stack pointer
8) swtch can invert the sequence to restore new context
9) popping the values for %edi, %esi, %ebx, %ebp
10) the instruction addresss is from new context because the stack pointer is changed
In this example, the context had been saved by scheduler's call to /swtch/.
It returns not to sched but to scheduler
stack pointer points at the current CPU's scheduler stack, not initproc's kernel stack
Scheduling
A process that wants to give up the CPU
must acquire the process table lock ptable (for sync of ptable)