1
$\begingroup$

In response to a clock interrupt, the OS saves the PC and user stack pointer of the currently executing process, and transfers control to the kernel clock interrupt handler.

Then the clock interrupt handler saves the rest of the registers, as well as other machine state, such as the state of the floating point registers, in the process PCB.

Why these information are saved in 2 separate moments ? And what is the purpose of "PC and user stack pointer" ?

$\endgroup$
1
$\begingroup$

the OS saves the PC and user stack pointer of the currently executing process, and transfers control to the kernel clock interrupt handler.

This is not done by the OS, since the PC is still pointing to the process code. It is the CPU that performs this step, just before jumping to the kernel interrupt handler (hence modifying PC and SP), which can then save the rest of the state in the PCB.

Since the first step is implemented at a lower level (in the CPU hardware / firmware) it should be simple so that the CPU design does not require too much effort.

Saving registers is much simpler (cheap) when done at the assembly (OS) level, which requires less effort to design/code with respect to the CPU level. Hence, usually the CPU is made to save just enough to allow the OS to save the rest.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.