Interrupt is usually defined as an event that changes the order of commands executed by the processor. Such events correspond to electrical signals generated by the internal and external hardware circuits of the CPU chip.
An interrupt is usually divided into a synchronous interrupt and an asynchronous interrupt:
Synchronization interruption is generated by the CPU control unit during command execution. It is called synchronization because the CPU is interrupted only after a command is terminated.
Asynchronous interruptions are randomly generated by other hardware devices according to the CPU clock signal.
In the Intel microprocessor manual, synchronous and asynchronous interrupts are called exceptions and interrupt ).
Interruptions are generated by interval timers and I/O devices, and exceptions are generated by program errors or exceptions that must be handled by the kernel.
Functions of Interrupt signals:
Interrupt signals provide a special way for the processor to execute code beyond the normal control flow. When an interrupt signal reaches, the CPU must stop what it is currently doing and switch to a new activity. To do this, you need to save the current value of the program counter in the kernel state stack, and put an address related to the interrupt type into the program counter.
There is a significant difference between Interrupt Processing and process switching: the code executed by the interrupt or exception handling program is not a process. More specifically, it is a kernel control path, indicates the execution of a running process when the interruption occurs. As a kernel control path, the interrupt processing program is lighter than a process, and the interrupt context is very small. It takes very little time to establish ignorance to stop the interrupt processing.
Interrupt Processing is one of the most sensitive tasks executed by the kernel because it must meet the following constraints:
When the kernel is planning to do something else, the interruption will come at any time. Therefore, the goal of the kernel is to finish the interrupt processing as quickly as possible and try its best to postpone more processing. The operations that need to be performed after the kernel response is interrupted are divided into two parts: the key and urgent part. The kernel is executed immediately; the other part is postponed and the kernel is executed subsequently.
As the interruption may come at any time, the kernel may be processing one of the interruptions, and the other may be interrupted again. Therefore, the interrupt handler must be compiled to make the corresponding kernel control path executable in nested mode. When the last kernel control path is terminated, the kernel must be able to resume the execution of the interrupted process. or, if the interrupted signal has led to rescheduling, the inner nuclear energy will switch to another process.
Although the kernel can accept a new interrupt when processing the previous interrupt, there are still some critical sections in the kernel code. In the critical section, the interrupt must be disabled. Such a critical section must be restricted as much as possible, because, according to previous requirements, the kernel, especially the interrupt processing program, should run in the open interrupt mode for most of the time.
Interruptions and exceptions:
Intel documents classify interruptions and exceptions into the following categories:
Interruption:
Maskable interrupt: If a blocked interrupt is still blocked, the control unit ignores it.
Nonmaskable interrupt: the unshielded interrupt is always identified by the CPU.
Exception:
Processor-detected exception: When the CPU executes a command, it detects an exception caused by an exception. The exception can be divided into three groups:
Fault: It can usually be corrected. Once corrected, the program can start again without interruption.
Trap: Mainly used to debug programs. Report immediately after the trap command is executed. After the kernel returns the control to the program, it can continue its execution without losing consistency.
Abort: a serious error occurs, and the Control Unit has a problem. You cannot store the exact location of the exception instruction in the eip register. An exception stop is used to report serious errors, such as hardware faults. The interrupt signal sent by the control unit is an emergency signal, which is used to switch control to the corresponding exception Stop handling program. This exception Stop handling program has no choice except to force the affected process to terminate.
Programming exception: occurs when the programmer sends a request. The control unit uses programming exceptions as traps. Programming exceptions are also called Soft Interrupt (software interrrupt ). Such exceptions have two purposes: to execute system calls and to notify the debugging program of a specific event.
Each interruption and exception is from 0 ~ A number between 255. Intel calls this 8-bit unsigned integer a vector ). The unshielded interrupt vectors and the abnormal vectors are fixed, while the blocked interrupt vectors can be changed by programming the interrupt controller.
Author: Crazy bird