Skip to content
Search

Interrupt

lastmod 2025-02-15created 2015-04-0412 edits

In a microprocessor, an interrupt (interrupt, {intercept}) is a mechanism by which, while the microprocessor (CPU) is executing a program, a device such as I/O hardware, or an exceptional situation, that needs handling notifies the microprocessor so that it can be handled. Whereas polling periodically monitors a target and runs the corresponding handling routine when a situation occurs, an interrupt is a means by which the other party asks the microprocessor to handle a task. It is therefore a concept contrasted with polling.

Whereas polling, overlapping with the microprocessor's other work, may lose data from high-speed hardware, with interrupts the hardware itself makes the request to the CPU, so as long as it is handled quickly the risk of data loss is small. Whereas polling can be problematic for real-time use, interrupts tend to be handled when needed, which gives them an advantage over polling.

When the microprocessor detects an interrupt, it suspends the machine code currently being executed, jumps to the handler program for that interrupt, and performs the task. The routine for handling an interrupt is called an interrupt service routine (ISR, Interrupt Service Routine). Interrupts are mostly input to the CPU core (CPU-core) in hardware, and are executed once the machine code currently in progress finishes. When an interrupt is received, whether it will be handled is selectively accepted through a bit mask in a special register of the CPU core.

When an interrupt fires, its service routine must run, but the program currently in progress must not be affected, so the ISR first saves the registers to the stack and then performs the task. The machine code must be structured so that the ISR does the register saving. When writing in C, each compiler provides its own way to define it differently from an ordinary function.

Interrupts are usually raised from outside the CPU core, but they can also be raised during execution inside the CPU. For example, cases such as dividing by 0 when executing a DIV instruction, or accessing an unallocated address space on the address bus, are called exceptions (exception) and undergo exception handling. Exception handling is also a type of interrupt, so it is handled the same way as interrupts.

A way to trigger interrupts in software is also provided. It is executed by an interrupt machine instruction. On x86, the INT instruction is the software interrupt instruction. Some microprocessors (Motorola 68000) also use the term trap.

A computer system usually has multiple sources that raise interrupts. A way to distinguish the types of interrupts is therefore needed.

Interrupt descriptor table

Hardware-generated exceptions

All INT_NUMbetween 0x0and 0x1F, inclusive, are reserved for exceptions; INT_NUM bigger than 0x1F are used for interrupt routines. (Note that the IBM PC did not always obey this rule, for instance using interrupt 5 to indicate the Print Screen key was pressed.)

INT_NUM

Short Description PM

0x00

Divide by 0

0x01

Debugger

0x02

Non-maskable interrupt

0x03

Breakpoint

0x04

Overflow

0x05

Bounds

0x06

Invalid Opcode

0x07

Coprocessor not available

0x08

Double fault

0x09

Coprocessor Segment Overrun (386 or earlier only)

0x0A

Invalid Task State Segment

0x0B

Segment not present

0x0C

Stack Fault

0x0D

General protection fault

0x0E

Page fault

0x0F

reserved

0x10

Math Fault

0x11

Alignment Check

0x12

Machine Check

0x13

SIMD Floating-Point Exception

Types of interrupts

External interrupts

Power fail interrupt (Power fail interrupt)
Literally a power outage, power failure, etc.
Machine check interrupt (Machine check interrupt)
Functional error of the CPU
External signal interrupt (External interrupt)
Interrupt by a timer - think of the Preemptive concept. When the time allotted to a resource has run out
When an interrupt key is pressed on the keyboard - typically Control + Alt + Delete
When there is an interrupt request from an external device - NOT an I/O interrupt!! It is a different concept
I/O interrupt (I/O Interrupt)
When an I/O device requests a data transfer, or a transfer has finished and the next operation must be performed
When there is a problem with I/O data

Internal interrupts

  • Occur when an invalid instruction or invalid data is used, and are called Trap.
  • Program check interrupt (Program check interrupt)
    • Division by zero
    • Overflow/Underflow
    • Other Exception
  • Software-like in content, but not interrupts by classification!

Software interrupt (SVC : SuperVisor Call)

  • When the user runs a program or performs an operation that calls the supervisor program (Supervisor)

Interrupt operation sequence

  1. Interrupt request
  2. Program execution suspended: completes up to the Micro operation currently being executed.
  3. Current program state saved: PCB (Process Control Block), PC (Program Counter), etc.
  4. Interrupt handling routine executed: identifies the device that requested the interrupt.
  5. Interrupt service routine executed: determines the cause of the interrupt and performs the actual work. Saves the processor register state. If a higher-priority interrupt occurs while the service routine is running, steps 1-5 are performed again recursively.
  6. State restoration: restores the PC (Program counter) saved when the interrupt occurred.
  7. Suspended program resumed: resumes the previously running program using the value of the PC.

Interrupt priority

When interrupts occur simultaneously from multiple devices, or an interrupt occurs while an interrupt service routine is running, they are handled according to priority.

  1. Power fail (Power fail)
  2. Machine check (Machine Check)
  3. External signal (External)
  4. I/O (I/O)
  5. Invalid instruction
  6. Program check (Program Check)
  7. SVC (SuperVisor Call)

In general, hardware interrupts have higher priority than software interrupts, and external interrupts have higher priority than internal interrupts.

Methods for determining interrupt priority

Software method (Polling)

  • Compares the interrupt request flags in turn to find the interrupt source with the highest priority, and runs the corresponding interrupt service routine.
  • Gives a higher rank to faster devices.
  • Priorities are easy to change.
  • With many interrupts, priority determination is slower than with the hardware method.
  • The circuit is simple and flexible, and no separate hardware is needed.

Hardware method (Vectored Interrupt)

  • Connects a bus that can identify device numbers, in serial/parallel, between the CPU and the devices that can request interrupts.
  • The interrupt vector is information about where the device that raised the interrupt should branch to.
  • Less economical than the software method.
  • The circuit is complex and inflexible, but it is fast because it is handled in hardware without any separate software.
  • The hardware method is divided into the following 2 types.
Daisy Chain
Connects all devices that raise interrupts with a single serial line.
Places the higher-priority devices upstream and arranges them in order of priority.
Parallel (Parallel) priority assignment
Connects all devices that raise interrupts with a single serial line.
Sets bits in the Mask register to determine the priority of each device.
While a higher-priority service routine is running, lower-priority bits in the Mask register can be disabled.
Conversely, a higher-priority interrupt is handled first even while a lower one is running.

Setting the interrupt flag (IF) to 1 while running an interrupt service routine prevents interrupts from occurring.

See also

Favorite site

author Zer0 sitemap