Mehmet Ali
Mehmet Ali

Reputation: 101

What happens in the x86 architecture when an interrupt occurs?

I'm studying x86 and Real Time Systems, and I have a question, that is:

Which steps x86 follows to handle any interrupt ?

Upvotes: 10

Views: 4394

Answers (2)

ChrisW
ChrisW

Reputation: 56123

When an interrupt occurs, the CPU does the following:

  • Push the current address (contents of the Instruction Pointer) onto the stack; also, push the processor flags (but not all the other processor registers)
  • Jump to the address of the ISR (Interrupt Service Routine), which is specified in the Interrupt Descriptor Table.

The ISR should do the following:

  • Push any registers which it intends to alter (or, push all registers)
  • Handle the interrupt
  • Reenable interrupts
  • Pop any registers which it pushed
  • Use the IRET instructions, which pops the CPU flags and Instruction Pointer value from the stack (and thus returns to whatever was executing when the interrupt occured).

Upvotes: 15

Michael Dorgan
Michael Dorgan

Reputation: 12515

Start here with the Interrupt Descriptor Table. Basically, when an interrupt occurs, flow control jumps to this table and then on to whatever is in this table. Also, I believe all registers are pushed as soon as the interrupt occurs, but I'm not 100% certain of this as it's been a long, long time since I've dealt with this.

Upvotes: 1

Related Questions