Ora

What are vectored and non-vectored interrupts?

Published in Computer Architecture Interrupts 4 mins read

Vectored and non-vectored interrupts are two fundamental mechanisms by which a computer processor handles external events or requests from peripheral devices, differing primarily in how the processor determines the address of the Interrupt Service Routine (ISR) it needs to execute.

Understanding Interrupts

An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention. When an interrupt occurs, the processor temporarily suspends its current task, saves its current state, and jumps to a specific routine designed to handle that event. This routine is known as an Interrupt Service Routine (ISR), or interrupt handler.

Interrupts are crucial for efficient system operation, allowing the CPU to manage multiple devices and tasks without constantly polling them, thus improving responsiveness and performance. For more on the basics, see how interrupts work.

Vectored Interrupts

In vectored interrupts, the processor automatically branches to the specific address in response to an interrupt. This means the hardware itself provides, or points to, the starting address of the appropriate ISR.

How Vectored Interrupts Work:

  • Direct Jump: When a device raises an interrupt, it also sends an interrupt vector to the processor. This vector is typically a small, unique number.
  • Vector Table: The processor uses this vector as an index into a predefined data structure called an interrupt vector table (or dispatch table). This table contains the memory addresses of all the ISRs for different interrupt types.
  • Automatic Branching: Based on the vector, the processor fetches the corresponding ISR address from the table and immediately jumps to that location to begin executing the interrupt handler.

Key Characteristics:

  • Automatic ISR Discovery: The processor knows where to go without needing additional information from the device beyond the vector itself.
  • Faster Response: Generally offers faster interrupt response times because the processor doesn't need to query the device for the ISR address.
  • Hardware Support: Requires dedicated hardware logic to generate and transmit the interrupt vector.

Examples and Applications:

  • Modern Processors: Most modern CPUs (like those based on ARM or x86 architectures) extensively use vectored interrupts.
  • Interrupt Controllers: Dedicated hardware components like a Programmable Interrupt Controller (PIC) manage multiple interrupt lines and provide the correct vector to the CPU.
  • Device-Specific Handlers: Each peripheral (e.g., keyboard, mouse, network card, disk controller) typically has a unique vector pointing to its specific ISR.

Non-Vectored Interrupts

In contrast, with non-vectored interrupts, the interrupted device should give the address of the Interrupt Service Routine (ISR). This means the processor does not automatically know which ISR to execute and must explicitly ask the interrupting device for more information or determine it through other means.

How Non-Vectored Interrupts Work:

  • Generic Interrupt Signal: When a device raises an interrupt, it sends a generic interrupt signal to the processor without providing an ISR address or a vector.
  • Processor Inquiry (Polling): The processor, upon receiving a non-vectored interrupt, must then determine the source of the interrupt. This is typically done through a process called polling, where the processor queries each potential interrupting device to find out which one requested the interrupt.
  • Address Provision: Once the interrupting device is identified, it then provides the address of its ISR, or the processor deduces it based on the identified device.

Key Characteristics:

  • Device-Provided Address: The responsibility for identifying the ISR address lies more heavily with the device or through a software-driven discovery process.
  • Slower Response: Polling multiple devices can introduce latency, making the interrupt response slower compared to vectored interrupts.
  • Simpler Hardware: Can be implemented with simpler hardware as the devices don't need to generate specific vectors.

Examples and Applications:

  • Older Systems: Some older or simpler microcontroller architectures might use non-vectored interrupts, especially if the number of devices is small.
  • Software-Driven Identification: In scenarios where a single interrupt line is shared by multiple devices, and the system relies on software to poll each device.
  • Complex Handshaking: Sometimes, a sequence of data transfers (handshaking) is required between the CPU and the device to determine the ISR address.

Comparison Table: Vectored vs. Non-Vectored Interrupts

To summarize the key distinctions:

Feature Vectored Interrupts Non-Vectored Interrupts
ISR Address Discovery Processor automatically branches using a vector. Interrupted device provides the ISR address.
Speed/Latency Faster, direct jump. Slower, involves polling or inquiry.
Hardware Complexity More complex (requires vector table, vector generation). Simpler (generic interrupt signal, polling mechanism).
Processor Action Uses vector as an index to the vector table. Queries devices (polls) to identify the source.
Responsibility Hardware points to ISR. Device or software determines ISR.
Implementation Common in modern CPUs and complex systems. Found in older or simpler microcontrollers.

Choosing between vectored and non-vectored interrupts depends on the specific requirements of the system, balancing factors like performance, hardware complexity, and design flexibility. Modern systems predominantly favor vectored interrupts due to their efficiency and speed.