1 / 63

第五章 中断和异常 Interrupt and Exception

第五章 中断和异常 Interrupt and Exception. 作业: P528 1,4,9,10,11,13,14,23,25,26,30,39,42,47,49,53,54,55. 12 .2 Types of Interrupts and Exceptions. Interrupt service routine :. Types of Interrupts and Exceptions. up to 256 Interrupts Interrupt types and their priority

karah
Download Presentation

第五章 中断和异常 Interrupt and Exception

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第五章中断和异常Interrupt and Exception 作业:P528 1,4,9,10,11,13,14,23,25,26,30,39,42,47,49,53,54,55

  2. 12.2 Types of Interrupts and Exceptions • Interrupt service routine :

  3. Types of Interrupts and Exceptions • up to 256 Interrupts • Interrupt types and their priority • External HW interrupts low • Non-maskable interrupt • SW interrupts • Internal Interrupts and exceptions high • Reset Increasing Priority

  4. 12.3 Interrupt Vector and Interrupt Vector Tables • Interrupt Vector Table: • In real-mode • In protect-mode

  5. 12.3.1 Interrupt Vector Tables • Interrupt Vector Table: • In a real-mode: • Ex 12.1

  6. 0000:0000 68 10 A7 00 BB 13 73 05-16 00 98 03 B1 13 73 05 0000:0010 8B 01 70 00 B9 06 0E 02-40 07 0E 02 FF 03 0E 02 0000:0020 46 07 0E 02 0A 04 0E 02-3A 00 98 03 54 00 98 03 0000:0030 6E 00 98 03 88 00 98 03-A2 00 98 03 FF 03 0E 02 INT 8H: 8*4=0020h 020E:0746 - u 020E:0746 020E:0746 E87000 CALL 07B9 020E:0749 06 PUSH ES 020E:074A 1E PUSH DS 020E:074B 50 PUSH AX 020E:074C 52 PUSH DX 020E:074D B84000 MOV AX,0040 020E:0750 8ED8 MOV DS,AX

  7. 23 16 15 8 7 0 31 24 DWORD COUNT 0 0 0 4 P DPL 0 111T OFFSET 31..16 7 3 OFFSET 15 .. 0 SELECTOR 0 12.3.2 Interrupt Descriptor Table • In a protected-mode: • Interrupt gate, trap gate, task gate descriptors T=0, Interrupt Gate, Type = 0Eh T=1, Trap Gate, Type = 0Fh P270, Fig 8.23

  8. 23 16 15 8 7 0 31 24 DWORD COUNT 0 0 0 4 P DPL 0 111T OFFSET 31..16 7 3 OFFSET 15 .. 0 SELECTOR 0 IDTbase=8003F400 Limit=07FF 0010:8003F400 B2 69 08 00 00 8E 4D 80-29 17 08 00 00 EE 54 F6 .i....M.).....T. 0010:8003F410 38 17 08 00 00 8E 54 F6-47 17 08 00 00 EE 54 F6 8.....T.G.....T. 0010:8003F420 96 6F 08 00 00 EE 4D 80-DE 70 08 00 00 8E 4D 80 .o....M..p....M. 0010:8003F430 56 17 08 00 00 8E 54 F6-1E 78 08 00 00 8E 4D 80 V.....T..x....M. 0010:8003F440 78 11 50 00 00 85 00 00-41 7C 08 00 00 8E 4D 80 x.P.....A|....M. 0010:8003F450 49 7D 08 00 00 8E 4D 80-65 17 08 00 00 8E 54 F6 I}....M.e.....T. 0010:8003F460 74 17 08 00 00 8E 54 F6-83 17 08 00 00 8E 54 F6 t.....T.......T. Int Type Sel:Offset Attributes 0000 IntG32 0008:804D69B2 DPL=0 P 0001 IntG32 0008:804D6B06 DPL=3 P 0002 IntG32 0008:0000111E DPL=0 P 0003 IntG32 0008:804D6E2E DPL=3 P 0004 IntG32 0008:804D6F96 DPL=3 P 0005 IntG32 0008:804D70DE DPL=0 P 0006 IntG32 0008:804D7242 DPL=0 P 0007 IntG32 0008:804D781E DPL=0 P 0008 TaskG 0050:00001178 DPL=0 P 0009 IntG32 0008:804D7C41 DPL=0 P 000A IntG32 0008:804D7D49 DPL=0 P 000B IntG32 0008:804D7E75 DPL=0 P 000C IntG32 0008:804D8042 DPL=0 P 000D IntG32 0008:804D8310 DPL=0 P

  9. Interrupt Procedures TSS Destination Code Segment Interrupt Vector Interrupt Vector Task Gate Offset Interrupt or Trap Gate TSS Descriptor Segment Descriptor

  10. Exceptions and Interrupts • Interrupts • Non-maskable interrupt • Maskable interrupts • Exceptions • Processor-detected exceptions • Programmed Exceptions : INTO, INT3, INT n, BOUND • Types of Exceptions • Faults: reported at the instruction boundary prior to the instruction in which the exception was detected • can be restarted • CS and EIP -> fault instruction • Traps: reported at the instruction boundary immediately after the instruction in which the exception was detected • CS and EIP -> next instruction • Aborts: does not always report the location of the faulted instruction • does not allow restart of the pgm • severe error

  11. 12.4 Interrupt Instructions

  12. 12.6 External Hardware-Interrupt Interface

  13. 12.7 Hardware-interrupt Sequence

  14. 12.7 Interrupt-acknowledge bus cycle

  15. 12.8 82C59A Programmable Interrupt Controller • Features • CMOS • Programmable • Level-sensitive or edge-triggered • cascaded to expand from 8 to 64 interrupt inputs • wide variety of priority schemes • Block Diagram of the 82C59A

  16. 12.8.1 Block Diagram of the 82C59A

  17. Internal Architecture of the 82C59A

  18. 8259A的内部结构 • IRR—Interrupt Request Register • PR---Priority Resolver • ISR---In-Service Register • IMR---Interrupt Mask Register • ICWs---Initialization Command Words • OCWs---Operation Command Words • 7个CPU可访问的寄存器,分两组: • 初始化命令字ICW1 ~ICW4---系统初启时设定。 • 操作命令字OCW1~OCW3—系统运行时,由应用程序设定(实现对中断处理的动态管理和控制). The OCWs can be written into the 8259A anytime after initialization.(手册P6-137)。

  19. Interface signals • D7-D0: host interface • RD: status of IRR, ISR, IMR of the Interrupt Level • WR:(ICWs and OCWs) Initialization Command Words, Operation Command Words • A0: RD, WR • INT: interrupt request: level-sensitive • INTA, CAS2-CAS0 • SP/EN: slave or master (input: cascaded mode)/enable(output: single mode or buffered mode) • IRR : interrupt request register : store all interrupt levels • ISR : store all the interrupt levels which are being served • Priority resolver: determine the priorities; the highest priority is selected and stored into the corresponding bit of the ISR during INTA pulse • IMR: 1: mask out 0: enable

  20. 片选 • 这是-个8位双向的三态缓冲器。当8259的片选有效时,接通内、外部数据线D7-D0,通过它传送命令,状态和中断类型码等信息。片选无效时高阻态,使内、外部数据线断开。带数据总线缓冲器的接口芯片是总线兼容的。

  21. 8259A的内部结构 • 8259A的处理部件: • 中断请求寄存器IRR-8位寄存器+控制逻辑 作用:接受并锁存来自IR0~IR7的中断请求信号 • 中断服务寄存器ISR 作用:保存当前正在处理的中断请求 • 优先级裁决器PR 作用:把新进入的中断请求和当前正在处理的中断进行比较,以决定哪一个优先级更高

  22. INTA 8259A的内部结构 • 处理过程: • IR0~IR7上出现某一中断请求信号-> • IRR对应位被置“1”-> • 由IMR的相应位决定是否将其屏蔽(屏蔽位=1,不通过;屏蔽位=0,通过)-> • 中断请求进PR-> • PR把新进入的中断请求和当前正在处理的中断进行优先级比较-> • 若新进入的中断优先级高,该中断请求被送到CPU。 • 若CPU的IF=1,CPU完成当前指令后,响应中断,在 引脚上发出两个 负脉冲(执行两个中断响应总线周期,参见P501图12.11):

  23. INTA INTA INTA INTA 8259A的内部结构 • 处理过程(续): • 8259A收到第一个 负脉冲后 • 使IRR锁存禁止,不予接受IR0~IR7上的中断请求信号;直到第二个负脉冲结束后,才又使IRR锁存允许(输入输出透明) • 使ISR的相应位置“1”,以便为优先级裁决器以后的裁决提供依据。 • 清除IRR的相应位。 • 8259A收到第二个 负脉冲后: • 中断类型码寄存器的内容(ICW2的内容)加上ISR的对应位送到D7-D0 • 如果ICW4的AEOI位为1,则在第二个 脉冲结束时,将ISR中被第一个 脉冲置“1”的位清除(自动结束);否则,要等到中断结束命令(EOI)发送后才能清除。 • The cascade bus lines are normally low and will contain the slave address code from the leading edge of the first INTA pulse to the trailing edge of the last INTA pulse.

  24. 三 8259A的工作方式 • 1 .设置优先级的方式 • (1) 全嵌套方式(FULLY NESTED MODE) 也称固定优先级方式。在这种方式下,由IRi引入的中断请求具有固定的优先级-IR0(最高)->IR7(最低). This mode is entered after initialization unless another mode is programmed. 当一个中断请求被响应时,ISR中的对应位ISn被置“1”,8259A把中断类型码放到数据总线上,然后,进入中断服务程序。一般情况下(除了“中断自动结束”方式外),在CPU发出中断结束命令(EOI)前,此对应位一直保持为“1”-封锁同级或低级的中断响应,但并不禁止比本级优先级高的中断响应-实现中断“嵌套”。

  25. 8259(主片) 8259(从片) IR0 IR0 CPU IR1 IR1 … … IR7 IR7 8259A的工作方式 • (2) 特殊全嵌套方式(SPECIAL FULLY NESTED MODE-SFNM) • 在处理某一级中断时,不但允许优先级更高的中断请求进入,也允许同级的中断请求进入。 • 用于主从结构的8259系统中,将主片设置为“特殊全嵌套方式”。 • 通过ICW4的“SFNM”位可以设置此种方式。(参见p513)

  26. 8259A工作方式 • (3) 优先级自动循环方式(AUTOMATIC ROTATION) • 优先级是循环变化的(不希望有固定的优先级差别)-一个设备的中断服务完成后,其优先级自动降为最低,而将最高优先级赋给原来比它低一级的中断请求。 • 开始时,优先级队列还是:IR0->IR7,若此时出现了IR0请求,响应IR0并处理完成后,队列变为: • IR1,IR2,IR3,IR4 ,IR5 ,IR6 ,IR7,IR0。 若又出现了IR4请求,处理完IR4后,队列变为: ???_____________________________ • 系统中是否采用“自动循环优先级”,由 操作命令字OCW2来设定。

  27. 8259A的工作方式 • (4)优先级特殊循环方式(SPECIFIC ROTATION) • 与“优先级自动循环方式”相比,只有一点不同,即可以设置开始的最低优先级。例如,设定IR4为最低优先级,那么IR5就是最高优先级,其余各级按循环方法类推。(OCW2:”110”)

  28. 输出OCW3(ESMM=1,SMM=1) 输出OCW1(使IMR对应于本级的位为“1”) …… …… 输出OCW1(使IMR对应于本级的位为“0”) 输出OCW3(ESMM=1,SMM=0) 设置 “中断级无效” 撤销 8259A的工作方式 • 2. 屏蔽中断源的方式(中断屏蔽方式) • 普通屏蔽方式 • 通过对中断屏蔽寄存器(IMR)的设定,实现对相应位为“1”的中断请求的屏蔽。 • 可通过OCW1使IMR的一位或几位置“1”。 • *特殊屏蔽方式(SPECIAL MASK MODE) • 实现:

  29. INTA 8259A工作方式 • 3. 中断结束方式(END OF INTERRUPT-EOI) • (1)中断自动结束方式(AUTOMATIC-AEOI方式) • 在第二个 后沿,即完成把对应的ISR位复位。 • 注意:AEOI方式是在中断响应后,而不是在中断处理程序结束后将ISR位清0。这样,在中断处理过程中,8259A中就没有“正在处理”的标识。此时,若有中断请求出现,且IF=1,则无论其优先级如何(比本级高、低或相同),都将得到响应。尤其是当某一中断请求信号被CPU响应后,如不及时撤销,就会再次被响应-“二次中断” • 所以,AEOI方式适合于中断请求信号的持续时间有一定限制以及不出现中断嵌套的场合。 • 通过ICW4可以设置AEOI方式(AEOI=1)

  30. 8259A工作方式 • (2)一般(常规)中断结束方式 • 适合于全嵌套方式。 • 实现:在中断服务程序结束时,向8259A发常规中断结束命令(OCW2:EOI=1,SL=0,R=0) • 例:MOV AL,20H; OCW2=20H OUT 20H,AL; 端口地址=20H(偶地址) • 在全嵌套方式下,ISR中最高优先级的置“1”位,正对应于当前正在处理的中断,将其清“0”,就完成了当前正在处理中断的结束操作。 IR0 IR7

  31. 8259A工作方式 • (3)特殊中断结束方式(SPECIFIC EOI-SEOI) • 在非全嵌套方式下,无固定的优先级序列(使用设置优先权命令或特殊屏蔽方式),此时,根据ISR的内容就无法确定刚刚所响应(处理)的中断。这种情况下,就不能用上述的EOI方式进行中断结束处理,而必须用特殊的中断结束命令SEOI--用OCW2:EOI=1,SL=1,R=0,L2~L0. • 由L2~L0指定清除ISR中的哪一位。

  32. 8259A工作方式 • 4. 中断触发方式 • 电平触发方式:由IRi上的有效电平来触发“中断请求触发器”。 • 边沿触发方式:由IRi上由低电平向高电平的跳变来触发“中断请求触发器”。 • 由ICW1的LTIM位可以设置中断触发方式。

  33. SP / EN SP / EN SP / EN EN SP 8259A工作方式 • 5. 连接系统总线的方式 • 缓冲方式(ICW4的BUF=1) • 8259A通过总线驱动器(如8286)和数据总线相连。 • 在缓冲方式下,8259A的 作为输出( 有效),此时,由ICW4的M/S位来定义(标识)本8259A是主片还是从片。 • 非缓冲方式(ICW4的BUF=0) • 即8259A直接与数据总线相连 • 在“非缓冲方式下”,8259A的 作为输入( 有效) 此时,由 端来标识本8259A是主片还是从片。 • 在“非缓冲方式下”,ICW4的BUF=0,M/S位无意义。

  34. 8259A工作方式 • *“中断查询”方式 • 特点:总的说,既有中断的特点,又有查询(Polling)的特点。 • 外设仍然向8259A发中断请求信号,要求CPU服务。 • CPU的IF=0,不响应外部的中断请求(对CPU的中断请求信号不起作用) • 此时,CPU需要用软件查询方法来确认中断源,从而实现对设备的服务 • 先向8259A发查询命令(poll command) • OCW3: P

  35. A0 D7 D0 0 IR - - - - W2 W1 W0 当前最高优先级的中断请求 1:有设备请求服务; 0:无设备请求服务。 RD INTA 8259A的工作方式 • 紧接着执行一条读指令(IN指令),读出专门的“中断状态字”: • 当8259A收到P=1的查询命令后,在下一个 信号将使ISR的相应位置“1”,就像收到了 一样,并把上述的“中断状态字”送到数据总线上,由CPU读入AL。

  36. 四 8259A的级联使用

  37. 五 8259A的控制字及编程使用 • 1 .初始化命令字ICW1~ICW4. • 8259A的初始化流程:

  38. 8259A的控制字及编程使用 • 8259A初始化编程举例 • 2. 8259A的操作命令字OCW1~OCW3(P132) • 3.关于8259A的读出操作,可以读四个方面的内容 • 读“中断状态字”(“查询字”): • 先写入P=1的OCW3查询命令字 • 用偶地址读(IN AL,20H) • 读IRR: • 先写入OCW3(RR=1,RIS=0) • 用偶地址读(IN AL,20H) • 读ISR: • 先写入OCW3(RR=1,RIS=1) • 用偶地址读(IN AL,20H) • 随时可用奇地址读IMR (IN AL,21H) 例1: IN AL,21H ; 读IMR AND AL,7FH ; 开放IR7中断 OUT 21H,AL 例2: IN AL,21H ; 读IMR OR AL,80H ; 关闭IR7中断 OUT 21H,AL

  39. 12.8.4 ICW • ICW Format

  40. ICW Format

  41. ICW Format • ICW4 format • master mode (SP=1 or in buffered mode when M/S=1 and BUF =1 in ICW4) • slave mode (SP =0 or if BUF=1 M/S=0 in ICW4) • IF BUF =1 the buffered mode is programmed. In buffered mode SP/EN becomes an enable output and the master/slave determination is by M/S • Special fully nested mode : only used in conjunction with the cascaded mode. • SP/EN: SLAVE PROGRAM/ENABLE BUFFER: This is a dual function pin. When in the Buffered Mode it can be used as an output to control buffer transceivers (EN). When not in the Buffered Mode it is used as an input to designate a master (SP = 1) or slave (SP = 0).

  42. 12.8.4 ICW • Ex 12.4 • Ex 12.5 • Ex 12.6

  43. 12.8.5 OCW1 & OCW2 Format x

  44. OCW3 Format

  45. 12.8.5 OCW • Ex 12.7 • Ex 12.8 • Ex 12.9

  46. OCW1:也用奇地址写入,但不紧跟ICW1 OCW2 也用偶地址写入,但D4=0 OCW3 8259A的内部结构 • 7个寄存器的寻址问题: 规定:A0 ICW1:用偶地址写入,且D4=1 ICW2 紧接着ICW1,用奇地址写入 ICW3 ICW4 即: • 采用了专门的“标识位,以节省输入地址的引脚数(仅用了A0) 0 0 0

More Related