yonigo
yonigo

Reputation: 1087

What happens to lost interrupts after cli on x86?

What happens to interrupts that are sent to the processor after i use cli command and before i use sti to enable them again?

Upvotes: 7

Views: 1888

Answers (1)

rkapl
rkapl

Reputation: 990

As several people in your comments have said, interrupts do not get lost. The interrupt that has happened between the CLI and STI gets serviced as soon as you re-enable the interrupts using the STI instruction.

To understand the behaviour, you must know, how interrupts are delivered to the processor. To quote Intel Developer Manual:

Asserting the INTR pin signals the processor that an external interrupt has occurred. The processor reads from the system bus the interrupt vector number provided by an external interrupt controller, such as an 8259A

The key is that INTR pin is asserted by the 8259A PIC until you, in the interrupt service routine, acknowladge the interrupt. Thus, when you disable interrupts, you are just instructing the processor to ignore the INTR pin. When you re-enable the interrupts, you stop ignoring the INTR pin and processor starts handling the interrupt right away.

Disclaimer: this is a legacy behaviour, but sufficient for explanation.

Upvotes: 7

Related Questions