Presentation is loading. Please wait.

Presentation is loading. Please wait.

第五章 中断和异常 Interrupt and Exception

Similar presentations


Presentation on theme: "第五章 中断和异常 Interrupt and Exception"— Presentation transcript:

1 第五章 中断和异常 Interrupt and Exception
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
In real-mode In protect-mode

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

6 0000: A7 00 BB B 0000: B B9 06 0E E 02 FF 03 0E 02 0000: E 02 0A 04 0E 02-3A 0000: E A FF 03 0E 02 INT 8H: 8*4=0020h 020E:0746 - u 020E:0746 020E:0746 E CALL 07B9 020E: PUSH ES 020E:074A 1E PUSH DS 020E:074B PUSH AX 020E:074C PUSH DX 020E:074D B MOV AX,0040 020E:0750 8ED MOV DS,AX

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

8 Int Type Sel:Offset Attributes 0000 IntG32 0008:804D69B2 DPL=0 P
IDTbase=8003F400 Limit=07FF 0010:8003F400 B E 4D EE 54 F6 .i....M.).....T. 0010:8003F E 54 F EE 54 F T.G.....T. 0010:8003F F EE 4D 80-DE E 4D 80 .o....M..p....M. 0010:8003F E 54 F6-1E E 4D 80 V.....T..x....M. 0010:8003F C E 4D 80 x.P.....A|....M. 0010:8003F D E 4D E 54 F6 I}....M.e.....T. 0010:8003F E 54 F E 54 F6 t.....T T. Int Type Sel:Offset Attributes 0000 IntG :804D69B2 DPL=0 P 0001 IntG :804D6B06 DPL=3 P 0002 IntG : E DPL=0 P 0003 IntG :804D6E2E DPL=3 P 0004 IntG :804D6F96 DPL=3 P 0005 IntG :804D70DE DPL=0 P 0006 IntG :804D7242 DPL=0 P 0007 IntG :804D781E DPL=0 P 0008 TaskG : DPL=0 P 0009 IntG :804D7C41 DPL=0 P 000A IntG :804D7D49 DPL=0 P 000B IntG :804D7E75 DPL=0 P 000C IntG :804D8042 DPL=0 P 000D IntG :804D8310 DPL=0 P OFFSET SELECTOR DWORD COUNT OFFSET P DPL 111T 0 0 0 3 4 7 23 16 15 8 24 31

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

10 Exceptions and 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

13 12.6 External Hardware-Interrupt Interface

14

15 12.7 Hardware-interrupt Sequence

16 12.7 Interrupt-acknowledge bus cycle

17 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

18 Block Diagram of the 82C59A

19

20 Internal Architecture of the 82C59A

21 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)。

22 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 : enable

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

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

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

26 8259A的内部结构 处理过程(续): 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. INTA INTA INTA INTA

27

28 三 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”-封锁同级或低级的中断响应,但并不禁止比本级优先级高的中断响应-实现中断“嵌套”。

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

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

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

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

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

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

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

36 8259A工作方式 4. 中断触发方式 电平触发方式:由IRi上的有效电平来触发“中断请求触发器”。
由ICW1的LTIM位可以设置中断触发方式。

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

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

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

40 四 8259A的级联使用

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

42 8259A的控制字及编程使用 2. 8259A的操作命令字OCW1~OCW3(P132) 3.关于8259A的读出操作,可以读四个方面的内容
读“中断状态字”(“查询字”): 先写入P=1的OCW3查询命令字 用偶地址读(IN AL,20H) 读IRR: 先写入OCW3(RR=1,RIS=0) 读ISR: 先写入OCW3(RR=1,RIS=1) 随时可用奇地址读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

43 ICW ICW Format

44 ICW Format

45 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).

46 ICW Ex 12.4 Ex 12.5 Ex 12.6

47 OCW1 & OCW2 Format x

48 OCW3 Format

49 OCW Ex 12.7 Ex 12.8 Ex 12.9

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

51 82C59A Basic Operation A D D RD WR CS 1
4 3 1 IRR, ISR, Int. Level -> Data Bus * IRR(RIS=0), ISR(RIS=1) or Interrupt Level(P=0) is based on the content of OCW written before the READ op 3 1 1 IMR -> DataBus 1 DataBus -> OCW 2 1 1 DataBus -> OCW 3 1 x 1 DataBus -> ICW 1 1 x x 1 DataBus -> OCW , ICW , ICW , ICW 1 2 3 4

52 82C59A Basic Operation Special Mask Mode Buffered Mode Nested Mode
It inhibits further interrupts at that level and enables interrupts from all other levels(lower as well as higher) that are not masked Buffered Mode Bus buffers are required Nested Mode IR(priority from 0 to 7) -> ISR Cleared by EOI or if AEOI, INTA the same or lower priority are inhibited IR0 has the highest priority Special Fully Nested Mode Cascaded Mode

53 8259A的控制字及编程使用 (1)设置中断向量 (2)取中断向量 把由AL指定的中断类型的中断向量DS:DX放置在中断向量表的相应位置中。
AH=25H 执行:INT 21H AL=中断类型号 DS:DX=中断向量 (2)取中断向量 把由AL指定的中断类型的中断向量从中断向量表中取到ES:BX中 预置: AH=35H 执行:INT 21H 返回: ES:BX=中断向量

54 8259A的控制字及编程使用 MOV AL,N; type N Interrupt
例:使用DOS功能调用存取中断向量 …. MOV AL,N; type N Interrupt MOV AH,35H; get Interrupt vector INT 21H; PUSH ES; save the old base and PUSH BX; offset of interrupt N PUSH DS; MOV AX,SEG INTHAND; MOV DS,AX; base of INTHAND in DS MOV DX, Offset INTHAND; offset in DX MOV AL, N; MOV AH, 25H; Set Interrupt Vector POP DS;

55 8259A的控制字及编程使用 INTHAND: POP DX; restore the old offset
POP DS; and base of interrupt MOV AL,N; MOV AH,25H; set interrupt vector INT 21H; RET ; return INTHAND: … Interrupt Processing Routine IRET

56 12.8.3 82C59A Programmable Interrupt Controller
Programming the 82C59A Initialization Command Words(ICWs) 2 ~ 4 bytes Operational Command Words(OCWs) Fully Nested Mode Rotating Priority Mode Special Mask Mode Poll Mode Initialization Sequence

57

58 INITIALIZATION SEQUENCE

59 82C59A Basic Operation Poll Mode EOI(End of Interrupt)
disabling interrupt w2 w1 w0 W2 W1 W0 : binary code of the highest priority level requesting service EOI(End of Interrupt) IS bit : if AEOI bit in ICW4 is set, automatically reset the IS bit otherwise use OCW2 to reset the IS bit EOI must be issued twice in the cascaded system: one for master and one for slave Specific and Nonspecific EOI

60 AEOI Mode IS bit is cleared by INTA signal Rotating Priority Mode A (Automatic Rotation) for Equal Priority Devices Before Rotate “IS” priority non specific EOI; Automatic EOI(INTA) Rotating Priority Mode B (Rotation By Software) Programming the bottom priority specific EOI low high

61 12.9 Interrupt Interface Circuits using the 82C59A

62 Ex 12.10

63 Example


Download ppt "第五章 中断和异常 Interrupt and Exception"

Similar presentations


Ads by Google