Based on my understanding, when an interrupt is fired, the CPU will switch to kernel mode, and when the interrupt is handled, the operating system will switch the CPU back to user mode.
Now my questions are:
How did the operating system switch the CPU to user mode (what is the assembly instruction used?).
Processors have special return from interrupt instructions. The name of the instruction varies among processors but they all do roughly the same thing. REI, IRET are examples.
Is there an assembly instruction that switches the CPU to kernel mode, or does the switch to kernel mode only happens when an interrupt is fired?
There are two ways for a process to get into kernel mode: (1) trigger an exception or (2) execute a special instruction. E.g.,
DIVL2 #0, R0
Will get you into kernel mode as will
int a = b / 0 ;
The instruction for getting into kernel mode varies by processors but examples include CHMK, INT. The i86 family has multiple ways of doing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With