Home >Common Problem >What are the five stages of interrupt handling?

What are the five stages of interrupt handling?

青灯夜游
青灯夜游Original
2021-04-14 16:06:2038151browse

The five stages of the interrupt processing process: 1. Interrupt request stage; 2. Interrupt arbitration stage, there are two methods of hardware arbitration and software arbitration; 3. Interrupt response stage, the CPU sends a message to the interrupt source Interrupt response signal; 4. Interrupt service phase; 5. Interrupt return phase, return to the breakpoint of the original program, restore the hardware site, and continue executing the original program.

What are the five stages of interrupt handling?

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

The basic process of interrupt processing includes five stages: interrupt request, interrupt arbitration, interrupt response, interrupt service and interrupt return.

1. Interrupt request phase


1) Interrupts that occur inside the CPU (Internal interrupt) do not require interrupt requests. The interrupt control logic inside the CPU directly receives and processes it.

2)External interruptThe request is made by the interrupt source. The external interrupt source uses the interrupt input pin of the CPU to input the interrupt request signal. Generally, the CPU has two interrupt request input pins: a maskable interrupt request input pin and a non-maskable interrupt request input pin.

1.1 Interrupt request trigger

The time when each interrupt source sends an interrupt request signal is uncertain, and when the CPU responds to the interrupt is also uncertain. definite. Therefore, each interrupt source has an interrupt request flip-flop, which latches its own interrupt request signal and holds it until the CPU responds to the interrupt request before clearing it.

1.2 Interrupt enable flip-flop

There is an interrupt enable flip-flop inside the CPU. When it is "1", the CPU is allowed to respond to interrupts, which is called Open interrupt. If it is "0", the CPU is not allowed to respond to interrupts and the interrupts are masked, which is called off interrupt.

%%Normally, when the CPU is reset, the interrupt enable flip-flop is also reset to "0", which means interrupts are turned off. When the CPU interrupt responds, the CPU automatically turns off the interrupt and is prohibited from accepting another new interrupt.
%%The status of the interrupt enable flip-flop can be set using the interrupt on or off instruction.

2. Interrupt arbitration stage


The CPU can only accept a request from one interrupt source at a time. When multiple interrupt sources make interrupt requests to the CPU at the same time, , the CPU must find the interrupt source with the highest interrupt priority. This process is called interrupt arbitration.

Interrupt arbitration can use hardware methods or software methods.

2.1 Software Arbitration

After the CPU detects an interrupt request, it first reads the contents of the interrupt request register, detects their status bit by bit, and detects If a certain bit is 1, it is determined that the corresponding interrupt source has an interrupt request, and its interrupt service routine is executed.

Whichever one is detected first will have a higher priority, whichever one is detected later will have a lower priority. The order of detection is the priority order of each interrupt source.

What are the five stages of interrupt handling?
Assume that the input port address in the above figure is 87FFH. There is the following query program:

MOV DX, 87FFH
IN AL, DX; Read the contents of the interrupt request register
SHR AL, 1
JC IR0; If there is a request for IRQ0, transfer to IR0
SHR AL,1
JC IR1 ;If there is a request on IRQ1, forward to IR1
SHR AL,1
JC IR2 ;If there is a request on IRQ2, forward to IR2
… …
Software The decision-making process takes a long time. If there are many interrupt sources, the real-time performance of interrupts will be poor, but the software priority arrangement is flexible.

2.2 Hardware Arbitration

Use specialized hardware circuits to determine the priority of interrupt sources. There are two common ways: daisy chain arbitration Optimization circuit and interrupt controller arbitration.

2.2.1 Daisy chain arbitration circuit

Design idea: Each interrupt source has an interrupt logic circuit, all interrupt logic The circuits form a chain, like a daisy chain. The interrupt source at the front of the chain has the highest priority, and the further back the device is, the lower the priority.
What are the five stages of interrupt handling?
Implementation process: The CPU receives an interrupt request. If the interrupt is allowed, the CPU sends an interrupt response signal. The interrupt response signal first reaches the front end of the daisy chain. If interrupt source 1 makes an interrupt request, it will intercept the interrupt response signal and block it so that it cannot be transmitted to the next interrupt source. Regardless of whether the following interrupt sources have raised interrupt requests, it is impossible to receive interrupt response signals, so their interrupt requests cannot be responded to.

2.2.2 Interrupt controller arbitration

Interrupt controllers, such as Intel8259A, can set the interrupt priority of interrupt sources in a variety of ways. There is an interrupt priority discriminator in the interrupt controller, which automatically determines the highest priority interrupt source currently requesting an interrupt, and sends its interrupt vector code to the data bus. The CPU receives the interrupt vector code and finds it accordingly. interrupt service routine.

What are the five stages of interrupt handling?

3. Interrupt response phase


After interrupt arbitration, interrupt processing enters the interrupt response phase. When responding to an interrupt, the CPU sends an interrupt response signal to the interrupt source, and at the same time:

① Protect the hardware site;

② Turn off interrupts;

③ Protect breakpoints;

④ Obtain the entry address of the interrupt service routine.

4. Interrupt service phase


The general structure of the interrupt service program is:

1)Protect the scene . Arrange several push instructions at the beginning of the interrupt service routine to push the contents of each register onto the stack for storage.

2)Enable interrupt. During the execution of the interrupt service routine, higher level interrupt requests are allowed to interrupt the current interrupt service routine to implement interrupt nesting.

3)Interrupt service. Complete the specific requirements of the interrupt source.

4)Restore the scene. Before the interrupt service routine ends, the interrupt scene of the main program must be restored. Usually the local information saved in the stack is popped into the original register.

5)Interrupt return. Return to the breakpoint of the original program and continue executing the original program.

5. Interrupt return phase


Return to the breakpoint of the original program, restore the hardware site, and continue executing the original program.

The interrupt return operation is the reverse process of the interrupt response operation.

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of What are the five stages of interrupt handling?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn