Reputation: 49
When a process is being executed and an interrupt occurs, where is the current state of the process saved? Is the process control block updated or is the information just pushed onto the kernel stack?
Upvotes: 2
Views: 3300
Reputation: 21667
That depends on the hardware. Normally, there is a switch to a kernel mode stack pointer. Some systems have a dedicated stack pointer registers for each processor mode and an interrupt stack pointer. Accessing the SP accesses the register for the current mode. In that case, there is no need to save and restore the SP.
Interrupts are usually handled on a dedicated interrupt stack of some kind (that may be per processor, rather than per process).
There has to be some hardware mechanism of some kind to switch to a protected stack on an interrupt. That mechanism will usually save the program counter and processor status register automatically.
Because an interrupt does not cause a context switch, only a limited set of data needs to be saved. The interrupt handler usually saves the other registers that it will use on the stack.
Before returning, the interrupt handler restores the saved register.
Then the interrupt handler exits by executing a Return from Interrupt instruction of some kind that restores the PC, PS, and switches stacks.
Upvotes: 1