When the x86 processor is executing a sequence of instructions in privilege level 3, how do privilege-level-0 interrupts that are not in the sequence of instructions be inserted in the middle?
What are the steps of handling a non-programmed interrupt? For example, a divide by 0 in the user program will cause a divide error; what happens after executing the division? How the interrupt is called? Is the privilege level still checked?
I tried to use gdb to approach this question.
After a divide by 0 instruction,
cs:eip
is changed according to theIDT[0]
.cs
has privilege 0.ss:esp
is changed according to the current TSS.- User
cs:eip
andss:esp
are both saved on the TSS specified stack.
However, after an intentional call to int 0
, a general protection fault is generated. Similarly, cs:eip
and ss:esp
are changed according to IDT[13]
and current TSS, and user ones are saved.
Therefore, why a divide by 0 instruction in a user program, for example 1 / 0
in C, is able to cause an interrupt through IDT[0]
, but an intentional call of int 0
in the user program will cause an interrupt through IDT[13]
.