I'm reading OSTEP for my Operating Systems course, and I have a question from Chp.6.3:
Note that there are two types of register saves/restores that happen during this protocol. The first is when the timer interrupt occurs; in this case, the user registers of the running process are implicitly saved by the hardware, using the kernel stack of that process. The second is when the OS decides to switch from A to B; in this case, the kernel registers are explicitly saved by the software (i.e., the OS), but this time into memory in the process structure of the process. The latter action moves the system from running as if it just trapped into the kernel from A to as if it just trapped into the kernel from B.
I don't really understand what's going on in this following text-segment and the associated diagram:
Specifically:
- What is going on with the registers during the context switch? It mentions that there are "kernel registers" and "user registers"? Why are both saved, and why are each of them saved where they are? In class, I learned that the user registers are saved into the associated PCB whenever a context-switch occurs, but this seems to suggest that the user registers are saved into the k-stack and the kernel registers onto the PCB? What is the difference between these and what exactly is going on here? Details are appreciated. I really enjoy this stuff.
To be clear: to me, it seems like there is redundancy here, as from the diagram alone, it seems that user registers are being saved into PCB and k-stack and being restored from both.