Skip to content

Vertebrate: Introduction to Interrupts

Introduction to Interrupts

Interrupts are an alternative to polling.

Why do we require interrupts?

Basic setup of interrupts

Basic steps of Interrupt processing

For the following, we will take the keypad as an example device.

  1. Let somebody press the key of a keypad. The keypad will put the scancode for the pressed key into its data register and raises its INT pin.

  2. If one or more of its (unmasked) IRQ pins are raised, INT pin of the PIC is raised. Recall that PIC has a mask register which can mask the individual IRQ pins. PIC also sends out the vector corresponding to the highest priority IRQ that is raised.

  3. CPU receives the INT signal from the PIC. If its interrupt flag is set, CPU will wait till an instruction boundary, and then, rather than starting a new instruction, it starts interrupt processing.

  4. C_PU raises its INTACK signal to PIC to read the vector through its datain bus. At the same time, CPU disables all interrupts by making IF=_0,

  5. After receiving ACK, PIC sends the highest priority vector to CPU.

  6. C_PU receives the vector. It pushes PC and FLAGS registers to stack. Then it goes to IDT and retrieves the address of the ISR of the interrupting device, and jumps to that address.

  7. ISR is executed. Pushes all the registers that it plans to use. Then it masks its IRQ in PIC.

  8. ISR reads the keyboard data register. As its data register is read, keypad makes its INT pin zero.

  9. ISR executes a STI instruction and makes IF=0, enabling interrupts again.

  10. ISR processes data. At this stage, it can receive other interrupts.

  11. ISR pops all regs, unmasks the IRQ in PIC, and executes a RTI.

Note that here, for all intents and purposes, we are executing a multitasking program. Interrupt flag of the CPU and the mask register of PIC acts as semaphores. The rules are

  1. No two interrupts of the same kind (ie, with the same IRQ) can execute concurrently.
  2. Different interrupts can interrupt each other and can execute on top of each other.

Questions

Your email address will not be published. Required fields are marked *