当前位置:网站首页>x86 Exception Handling and Interrupt Mechanism (1) Overview of the source and handling of interrupts

x86 Exception Handling and Interrupt Mechanism (1) Overview of the source and handling of interrupts

2022-08-09 11:16:00 XV_

参考《计算机组成》(北京大学 MOOC)

1 The source of the exception and interrupt(为什么需要中断)

首先,说明一下异常中断这两个概念.

The only difference between these two,就是,没有什么区别.Just a different place different time different people call it is not the same,所以,Need not too care about the difference between,Later we referred to中断.

1.1 When the interrupt

一句话!CPUWhen she was working,Have something to disturb it,Don't let him continue to work,Need to deal with other things.
在这里插入图片描述

So what it is?It is divided into two classes

  • 内部的事情
  • 外部的事情

1.1.1 内部的事情

简而言之,就是执行指令的时候,Appeared the situation.

What the situation?举例说明

  1. After performing addition,The result is beyond the maximum range,发生了溢出(也就是overflow中断 int4)
  2. Perform division,被除数是0,The division zero interrupt(int 0)

在这里插入图片描述

关于这一点,在80386The manual is mentioned in the.

How are these interruptions judgment out of?

The hardware judgment!

我们知到,在CPU中有ALU,ALU的输出结果是有The results related signal的,对于x86体系,There will be all kinds of flags,The results of the sign bit,The hardware directly give,例如下图的ALU的输出结果(ZF SF CF OF)

在这里插入图片描述
The output signal,会作用到CPUThe other parts,从而能够让CPUPause the current work to deal with异常事件,至于具体发生了什么,We will back to mention.

About internal event named

Although just an internal event,About its name has a lot of,我们来解释一下,Can clear.

  1. 内部中断:这个不用解释,What happens inside,引起CPU中断The current,To deal with an emergency,Is the internal interrupt.
  2. 软件中断:We have just mentioned,内部发生的事情,是指令的执行结果The signal that generates hardware,触发中断,The essence of the software is指令序列,Therefore is a software interrupt.
  3. 异常:正在执行的指令,Performed after the found不正常,At the back of the instruction can not continue to perform,就是异常.

1.1.2 外部的事情

这个中断是CPU外部向CPU发出的中断信号,导致CPU不得不停下手头的工作.例如8259A芯片.

这里有一篇8259A芯片 详解.

外部中断Is from the external hardware,所以也叫硬件中断,It is interrupted by external signal directly,也被称为中断.


最后,Attach the figure,As the above content summary.
在这里插入图片描述

1.1.3 内部中断和外部中断的区别

Use a metaphor to solve:

  • 内部中断,Like do you work in a,Then accidentally touch the water and the,You have to stop work,Clean up the spill water first,再继续工作.
  • 外部中断:你在工作,And then inform you immediately the meeting your boss,You can only go to a meeting,Continue to work after the meeting.

在这里插入图片描述

1.1.4 Unresolved details

我们知到MIPS架构下,Interrupts are the execution of the judgment is interrupted after each instruction,那么,For internal interrupt and external interrupt(x86下),What is the details?When judging when execution?

下图是MIPS的:
在这里插入图片描述
x86也一样的,因为指令执行的切换,需要EIP的改变,EIPThe change will need to specify the clock cycle,因此来说,执行下一条指令orInterrupt service routine is the first instruction difference,EIPUpdated parts choose the value of the difference,In essence are updatedEIP的值.

1.2 What is interrupted after

好,现在CPUInterrupted by an event,然后,CPUHave to deal with this thing,那么What will you do it then?

假设现在进行了add指令,Add the result溢出了,Computation results stored more than,怎么办?

  1. 运算发生溢出,硬件电路检测The overflow,那么应该如何处理呢?If use hardware processing,This will be more troublesome,并且,If it is very difficult, later want to change,Because the fixed hardware can not change(当然,Hardware will soon,Hardware accelerators can be).
    在这里插入图片描述
  2. 使用软件方式处理溢出,也就是说,如果遇到溢出,Implement a program to deal with it,Is an instruction sequence.
    在这里插入图片描述
    We take a look at the first computer that can handle the exceptions,If detected in an overflow,Automatic steering address0,Performed in advance deposit good program,执行完之后,Go back to continue the original program,这个地址0The program is used to handle overflow,这也就是中断服务程序.

Thus to achieve the automatic computer to handle exceptions,The computer won't stop because of the abnormal,同时,The exception handling procedures,是软件,Subsequent can also be modified.

So here is the important point

  1. How to detect the overflow
  2. Detect the overflow after,How to enter the address0执行相应指令
  3. 执行完中断处理程序后,How to go back to execute programs before

对于问题1,设计一下ALUThe hardware circuit is easy to solve,前面也提到过,不再细说,在《计算机系统基础》(袁春风)The textbooks mentioned the details.

对于问题2,We are detected after operation result overflow,把它发送给EIPInstruction address update parts,一旦溢出,在下一个周期,就会EIP = 0,就能够执行0Programs for the unit.(这么一说,Here is the current instruction execution time to detect the abnormal,The next instruction to perform before switching to the interrupt service routine,因此和MIPSAs caught in the middle
在这里插入图片描述
对于问题3,我们需要在The interrupt handler before,Keep good should have normal execution instruction address,In order to switch back to,这也就涉及到了保护现场和恢复现场的工作.


Just talking about the encounter internal interrupt are,Now look at external interrupt.
在这里插入图片描述
对于80386来说,External interrupt by8259AInterrupt signal chip to send it,接收到中断信号之后,In the related processing,而8259AOn the other side of the connection of various peripherals(鼠标,键盘…)来,这样CPUWill be able to deal with the external interrupt request,Specific operation or

  • 保存现场
  • 执行中断处理程序
  • 恢复现场

这里是现场,Is general,Concrete contains the content of the follow-up.

1.2.1 小结

For the interruption发生以及处理过程,怎么解释呢?我们看一下:

Use a metaphor to solve:

  • 内部中断,Do you work in a(指令正常执行),Then accidentally touch the water and onto the computer(Met internal interrupt),You can not save the file you are editing and then turn it off(保存现场),Wipe off the spill of water(执行中断处理程序),再打开电脑,打开刚才保存的文件(恢复现场),之后继续工作(继续执行指令).
  • 外部中断:你在工作,And then inform you immediately the meeting your boss(外部中断),You can only save work in hand before,After going to the meeting,Save the file before opening when I come back,继续工作.

2 The whole article summary

这里仅仅以仅有一个Overflow exception handling为例子,To run through the whole process.

  1. 正在执行add指令,加完之后,Found that the results are too big,放不下,之后ALU产生了一个溢出信号
  2. The overflow signal is sent toEIP更新部件,Wait until the next clock cycle comes,EIP更新为0
  3. 开始执行中断处理程序
  4. The program to save the currentCPUAll the register values,Keep it under the normal execution of an instruction address
  5. Then execute overflow exception handler
  6. 之后恢复CPU寄存器的值,恢复EIP的值
  7. CPU继续执行add指令之后的指令

According to the northMOOCExample is given in the,In the current page after addition,发现放不下,Therefore turn to the first page to execute a program,执行完之后,Turn back to continue.

在这里插入图片描述

原网站

版权声明
本文为[XV_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091103199428.html