第五章 中断和异常 Interrupt and Exception

63
1 第第第 第第第第第 Interrupt and Exception 第第P528 1,4,9,10,11,13,14,23,25,26,30,39, 42,47,49,53,54,55

description

第五章 中断和异常 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 - PowerPoint PPT Presentation

Transcript of 第五章 中断和异常 Interrupt and Exception

Page 1: 第五章 中断和异常 Interrupt and Exception

1

第五章中断和异常Interrupt and Exception

作业: P528

1,4,9,10,11,13,14,23,25,26,30,39,42,47,49,53,54,55

Page 2: 第五章 中断和异常 Interrupt and Exception

2

12.2 Types of Interrupts and Exceptions

Interrupt service routine :

Page 3: 第五章 中断和异常 Interrupt and Exception

3

Types of Interrupts and Exceptions

up to 256 Interrupts Interrupt types and their priority

1. External HW interrupts low2. Non-maskable interrupt3. SW interrupts4. Internal Interrupts and exceptions high5. Reset Increasing Priority

Page 4: 第五章 中断和异常 Interrupt and Exception

412.3 Interrupt Vector and Interrupt Vector Tables

Interrupt Vector Table: In real-mode In protect-mode

Page 5: 第五章 中断和异常 Interrupt and Exception

5

12.3.1 Interrupt Vector Tables

Interrupt Vector Table: In a real-mode:

Ex 12.1

Page 6: 第五章 中断和异常 Interrupt and Exception

6

0000:0000 68 10 A7 00 BB 13 73 05-16 00 98 03 B1 13 73 050000:0010 8B 01 70 00 B9 06 0E 02-40 07 0E 02 FF 03 0E 020000:0020 46 07 0E 02 0A 04 0E 02-3A 00 98 03 54 00 98 030000: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:0746020E:0746 E87000 CALL 07B9020E:0749 06 PUSH ES020E:074A 1E PUSH DS020E:074B 50 PUSH AX020E:074C 52 PUSH DX020E:074D B84000 MOV AX,0040020E:0750 8ED8 MOV DS,AX

Page 7: 第五章 中断和异常 Interrupt and Exception

7

12.3.2 Interrupt Descriptor Table

In a protected-mode: Interrupt gate, trap gate, task gate descriptors

OFFSET 15 .. 0SELECTOR

DWORDCOUNT

OFFSET 31..16 P DPL 0 111T 0 0 0

03

47

023 16 15 8 72431

T=0, Interrupt Gate, Type = 0Eh

T=1, Trap Gate, Type = 0Fh

P270, Fig 8.23

Page 8: 第五章 中断和异常 Interrupt and Exception

8IDTbase=8003F400 Limit=07FF0010: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 P0003 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 P0009 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

OFFSET 15 .. 0SELECTOR

DWORDCOUNT

OFFSET 31..16 P DPL 0 111T 0 0 0

3

7

023 16 15 8 72431

Page 9: 第五章 中断和异常 Interrupt and Exception

9

Interrupt Procedures

Interrupt or TrapGate

SegmentDescriptor

Interrupt VectorOffset

Destination CodeSegment

Task Gate

TSSDescriptor

TSS

Interrupt Vector

Page 10: 第五章 中断和异常 Interrupt and Exception

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

Page 11: 第五章 中断和异常 Interrupt and Exception

11

12.4 Interrupt Instructions

Page 12: 第五章 中断和异常 Interrupt and Exception

12

Page 13: 第五章 中断和异常 Interrupt and Exception

1312.6 External Hardware-Interrupt Interface

Page 14: 第五章 中断和异常 Interrupt and Exception

14

74LS245x2

8284AClock

Generator

RDY

Vcc

8086CPU

CLK

READY

RESET

MN/MX#

S0#S1#S2#

8288Bus

Controller

MRDC#

MWTC#

AMWC#

IORC#

IOWC#

AIOWC#

INTA#

CLK

74LS373x3

ADDR/DATA

LEOE#

ALE

DENDT/R#

BHE#

AD15:AD0

A19:A16

74LS245x2

EN#DIR

D15:D0

A19:A0,BHE#

ADDR/Data

IRQ0

IRQ1

IRQ2

IRQ3

IRQ4

IRQ5

IRQ6

IRQ7

IRQ0

IRQ1

IRQ2

IRQ3

IRQ4

IRQ5

IRQ6

IRQ7

D0

D1

D2

D3

D4

D5

D6

D7

INT

INTR

INTA# From 8288

A0WR#RD#CS#

From I/O DecodeLogic

IOR# From 8288

IOW# From 8288

A0 from 74LS373

Page 15: 第五章 中断和异常 Interrupt and Exception

15

12.7 Hardware-interrupt Sequence

Page 16: 第五章 中断和异常 Interrupt and Exception

1612.7 Interrupt-acknowledge bus cycle

Page 17: 第五章 中断和异常 Interrupt and Exception

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

Page 18: 第五章 中断和异常 Interrupt and Exception

18

12.8.1 Block Diagram of the 82C59A

Page 19: 第五章 中断和异常 Interrupt and Exception

19

Page 20: 第五章 中断和异常 Interrupt and Exception

20

Internal Architecture of the 82C59A

Page 21: 第五章 中断和异常 Interrupt and Exception

21

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

8259A 的内部结构

Page 22: 第五章 中断和异常 Interrupt and Exception

22

Interface signals

D7-D0: host interface RD: status of IRR, ISR, IMR of the Interrupt Level WR:(ICWs and OCWs) Initialization Command Words, Operatio

n Command Words A0: RD, WR INT: interrupt request: level-sensitive INTA, CAS2-CAS0 SP/EN: slave or master (input: cascaded mode)/enable(outp

ut: 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 i

s selected and stored into the corresponding bit of the ISR during INTA pulse

IMR: 1: mask out 0: enable

Page 23: 第五章 中断和异常 Interrupt and Exception

23

片选

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

Page 24: 第五章 中断和异常 Interrupt and Exception

24

8259A 的内部结构

8259A 的处理部件: 中断请求寄存器 IRR - 8 位寄存器+控制逻辑

作用:接受并锁存来自 IR0 ~ IR7 的中断请求信号 中断服务寄存器 ISR

作用:保存当前正在处理的中断请求 优先级裁决器 PR

作用:把新进入的中断请求和当前正在处理的中断进行比较,以决定哪一个优先级更高

Page 25: 第五章 中断和异常 Interrupt and Exception

25

8259A 的内部结构

处理过程: IR0 ~ IR7 上出现某一中断请求信号 -> IRR 对应位被置“ 1”-> 由 IMR 的相应位决定是否将其屏蔽 ( 屏蔽位 =1 ,不

通过;屏蔽位 =0 ,通过 )-> 中断请求进 PR-> PR 把新进入的中断请求和当前正在处理的中断进行

优先级比较 -> 若新进入的中断优先级高,该中断请求被送到

CPU 。 若 CPU 的 IF=1 , CPU 完成当前指令后,响应中断,

在 引脚上发出两个 负脉冲 ( 执行两个中断响应总线周期,参见 P501 图 12.11) :

INTA

Page 26: 第五章 中断和异常 Interrupt and Exception

26

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.

INTAINTA

INTA

INTA

Page 27: 第五章 中断和异常 Interrupt and Exception

27

Page 28: 第五章 中断和异常 Interrupt and Exception

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

Page 29: 第五章 中断和异常 Interrupt and Exception

29

8259A 的工作方式 (2) 特殊全嵌套方式 (SPECIAL FULLY NESTED MODE - SFNM)

在处理某一级中断时,不但允许优先级更高的中断请求进入,也允许同级的中断请求进入。

用于主从结构的 8259 系统中,将主片设置为“特殊全嵌套方式”。 通过 ICW4 的“ SFNM”位可以设置此种方式。 ( 参见 p513)

CPU

IR0

IR1

IR7

IR0

IR1

IR7

8259(主片 ) 8259(从片 )

Page 30: 第五章 中断和异常 Interrupt and Exception

30

8259A 工作方式

(3) 优先级自动循环方式 (AUTOMATIC ROTATION) 优先级是循环变化的 ( 不希望有固定的优先级差别 ) -一个

设备的中断服务完成后,其优先级自动降为最低,而将最高优先级赋给原来比它低一级的中断请求。

开始时,优先级队列还是: IR0->IR7 ,若此时出现了 IR0 请求,响应 IR0 并处理完成后,队列变为:

IR1 , IR2 , IR3 , IR4 , IR5 , IR6 , IR7 , IR0

。若又出现了 IR4 请求,处理完 IR4 后,队列变为:??? _____________________________

系统中是否采用“自动循环优先级”,由操作命令字 OCW2 来设定。

IR0

IR1

IR2

IR3

IR4

IR5

IR6

IR7

Page 31: 第五章 中断和异常 Interrupt and Exception

31

8259A 的工作方式

(4) 优先级特殊循环方式 (SPECIFIC ROTATION) 与“优先级自动循环方式”相比,只有一点不同,即

可以设置开始的最低优先级。例如,设定 IR4 为最低优先级,那么 IR5就是最高优先级,其余各级按循环方法类推。 (OCW2:”110”)

Page 32: 第五章 中断和异常 Interrupt and Exception

32

8259A 的工作方式 2. 屏蔽中断源的方式 ( 中断屏蔽方式 )

普通屏蔽方式 通过对中断屏蔽寄存器 (IMR) 的设定,实现对相应位为“ 1” 的中断请

求的屏蔽。 可通过 OCW1 使 IMR 的一位或几位置“ 1” 。

*特殊屏蔽方式 (SPECIAL MASK MODE) 实现:

输出 OCW3(ESMM=1,SMM=1)

输出 OCW1( 使 IMR 对应于本级的位为“ 1”)

……

……

输出 OCW1( 使 IMR 对应于本级的位为“ 0”)

输出 OCW3(ESMM=1 , SMM=0)

“ 中断级无效”

设置

撤销

Page 33: 第五章 中断和异常 Interrupt and Exception

33

8259A 工作方式

3. 中断结束方式 (END OF INTERRUPT - EOI) (1) 中断自动结束方式 (AUTOMATIC - AEOI 方式 )

在第二个 后沿,即完成把对应的 ISR 位复位。 注意: AEOI 方式是在中断响应后,而不是在中断处理程序结

束后将 ISR 位清 0 。这样,在中断处理过程中, 8259A 中就没有“正在处理”的标识。此时,若有中断请求出现,且 IF= 1 ,则无论其优先级如何 ( 比本级高、低或相同 ) ,都将得到响应。尤其是当某一中断请求信号被 CPU 响应后,如不及时撤销,就会再次被响应-“二次中断”

所以, AEOI 方式适合于中断请求信号的持续时间有一定限制以及不出现中断嵌套的场合。

通过 ICW4 可以设置 AEOI 方式 (AEOI=1)

INTA

Page 34: 第五章 中断和异常 Interrupt and Exception

34

8259A 工作方式

(2) 一般 ( 常规 ) 中断结束方式 适合于全嵌套方式。 实现:在中断服务程序结束时,向 8259A 发常规中断结束命令

(OCW2:EOI=1,SL=0,R=0) 例: MOV AL,20H; OCW2=20H

OUT 20H,AL; 端口地址 =20H(偶地址 ) 在全嵌套方式下, ISR 中最高优先级的置“ 1” 位,正对应于

当前正在处理的中断,将其清“ 0” ,就完成了当前正在处理中断的结束操作。

1 1 0 1 …IR0 IR7

Page 35: 第五章 中断和异常 Interrupt and Exception

35

8259A 工作方式

(3) 特殊中断结束方式 (SPECIFIC EOI - SEOI) 在非全嵌套方式下,无固定的优先级序列 ( 使用设置

优先权命令或特殊屏蔽方式 ) ,此时,根据 ISR 的内容就无法确定刚刚所响应 ( 处理 ) 的中断。这种情况下,就不能用上述的 EOI 方式进行中断结束处理,而必须用特殊的中断结束命令 SEOI --用OCW2:EOI=1,SL=1,R=0,L2 ~ L0.

由 L2 ~ L0 指定清除 ISR 中的哪一位。

Page 36: 第五章 中断和异常 Interrupt and Exception

36

8259A 工作方式

4. 中断触发方式 电平触发方式:由 IRi 上的有效电平来触发“中断请

求触发器”。

边沿触发方式:由 IRi 上由低电平向高电平的跳变来触发“中断请求触发器”。

由 ICW1 的 LTIM 位可以设置中断触发方式。

Page 37: 第五章 中断和异常 Interrupt and Exception

37

8259A 工作方式

5. 连接系统总线的方式 缓冲方式 (ICW4 的 BUF=1)

8259A 通过总线驱动器 ( 如 8286) 和数据总线相连。 在缓冲方式下, 8259A 的 作为输出 ( 有效 ) ,此

时,由 ICW4 的 M/S 位来定义 (标识 ) 本 8259A 是主片还是从片。

非缓冲方式 (ICW4 的 BUF=0) 即 8259A 直接与数据总线相连 在“非缓冲方式下”, 8259A 的 作为输入 ( 有

效 ) 此时,由 端来标识本 8259A 是主片还是从片。 在“非缓冲方式下”, ICW4 的 BUF = 0 , M/S 位无意义。

SP / EN EN

SP / EN SP

SP / EN

Page 38: 第五章 中断和异常 Interrupt and Exception

38

8259A 工作方式 *“ 中断查询”方式 特点:总的说,既有中断的特点,又有查询 (Polling) 的特点。

外设仍然向 8259A 发中断请求信号,要求 CPU 服务。 CPU 的 IF=0 ,不响应外部的中断请求 ( 对 CPU 的中断请求信

号不起作用 ) 此时, CPU需要用软件查询方法来确认中断源,从而实现对设备的服务

先向 8259A 发查询命令 (poll command) OCW3:

0 0 0 0 1 1 0 0

P

Page 39: 第五章 中断和异常 Interrupt and Exception

39

8259A 的工作方式

紧接着执行一条读指令 (IN 指令 ) ,读出专门的“中断状态字”:

当 8259A 收到 P=1 的查询命令后,在下一个 信号将使 ISR 的相应位置“ 1” ,就像收到了 一样,并把上述的“中断状态字”送到数据总线上,由 CPU读入 AL 。

0A0

IR - - - - W2 W1 W0

D7 D0

1: 有设备请求服务;

0 :无设备请求服务。

当前最高优先级的中断请求

RDINTA

Page 40: 第五章 中断和异常 Interrupt and Exception

40

四 8259A 的级联使用

Page 41: 第五章 中断和异常 Interrupt and Exception

41

五 8259A 的控制字及编程使用

1 . 初始化命令字ICW1~ICW4.

8259A 的初始化流程: ICW1

ICW2

级联方式?

ICW3

I CW需 4?

ICW4

准备接受中断请求

YES(IC4=1)

YES(SNGL=0)

NO(SNGL=1)

NO(IC4=0)

Page 42: 第五章 中断和异常 Interrupt and Exception

42

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 ; 读 IMROR AL,80H ; 关闭 IR7 中断OUT 21H,AL

Page 43: 第五章 中断和异常 Interrupt and Exception

43

ICW Format

12.8.4 ICW

Page 44: 第五章 中断和异常 Interrupt and Exception

44ICW Format

Page 45: 第五章 中断和异常 Interrupt and Exception

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

Page 46: 第五章 中断和异常 Interrupt and Exception

46

Ex 12.4 Ex 12.5 Ex 12.6

12.8.4 ICW

Page 47: 第五章 中断和异常 Interrupt and Exception

47

12.8.5 OCW1 & OCW2 Format

x

Page 48: 第五章 中断和异常 Interrupt and Exception

48

OCW3 Format

Page 49: 第五章 中断和异常 Interrupt and Exception

49

Ex 12.7 Ex 12.8 Ex 12.9

12.8.5 OCW

Page 50: 第五章 中断和异常 Interrupt and Exception

50

8259A 的内部结构

7 个寄存器的寻址问题 :规定: A0

0

11

1

ICW1: 用偶地址写入,且 D4=1

ICW2

ICW3

ICW4

紧接着 ICW1 ,用奇地址写入

1

0

0

OCW1: 也用奇地址写入,但不紧跟ICW1OCW2OCW3

也用偶地址写入,但 D4=0

即: 0 1

0 0

0 1

D4 D3

ICW1

OCW2

OCW3

0

0

•采用了专门的“标识位,以节省输入地址的引脚数 (仅用了 A0)

Page 51: 第五章 中断和异常 Interrupt and Exception

51

82C59A Basic Operation

A0 D4 D3 RD WR CS

0

1

0

0

1

1

0

0

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

IMR -> DataBus

0001

001x

01xx

1111

0000

0000

DataBus -> OCW2

DataBus -> OCW3

DataBus -> ICW1

DataBus -> OCW1 , ICW2 , ICW3 , ICW4

Page 52: 第五章 中断和异常 Interrupt and Exception

52

Special Mask Mode It inhibits further interrupts at that level and enables interru

pts 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

82C59A Basic Operation

Page 53: 第五章 中断和异常 Interrupt and Exception

53

8259A 的控制字及编程使用 (1) 设置中断向量

把由 AL 指定的中断类型的中断向量 DS:DX 放置在中断向量表的相应位置中。

AH=25H 执行: INT 21H AL= 中断类型号 DS:DX= 中断向量

(2)取中断向量 把由 AL 指定的中断类型的中断向量从中断向量表中取到

ES:BX 中 预置: AH=35H 执行: INT 21H AL= 中断类型号 返回: ES:BX= 中断向量

Page 54: 第五章 中断和异常 Interrupt and Exception

54

8259A 的控制字及编程使用 例:使用 DOS功能调用存取中断向量

….MOV AL,N; type N InterruptMOV AH,35H; get Interrupt vectorINT 21H;PUSH ES; save the old base andPUSH BX; offset of interrupt NPUSH DS;MOV AX,SEG INTHAND;MOV DS,AX; base of INTHAND in DSMOV DX, Offset INTHAND; offset in DXMOV AL, N;MOV AH, 25H; Set Interrupt VectorINT 21H;POP DS;…

Page 55: 第五章 中断和异常 Interrupt and Exception

55

8259A 的控制字及编程使用POP DX; restore the old offsetPOP DS; and base of interruptMOV AL,N;MOV AH,25H; set interrupt vectorINT 21H;RET ; return

INTHAND:…. Interrupt Processing RoutineIRET

Page 56: 第五章 中断和异常 Interrupt and Exception

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

Page 57: 第五章 中断和异常 Interrupt and Exception

57

D0D1D2D3D4D5D6D7

IR0IR1IR2IR3IR4IR5IR6IR7

IRQ0IRQ1IRQ2IRQ3IRQ4IRQ5IRQ6IRQ7

INT

INTA

8259A

D0D1D2D3D4D5D6D7

IR0IR1IR2IR3IR4IR5IR6IR7

IRQ8IRQ9IRQ10IRQ11IRQ12IRQ13IRQ14IRQ15

INT

INTA

8259A

CAS0CAS1

CAS2

Master

Slave

INTA

INTR

SP/EN

SP/ENHi

Lo

Cascaded i8259As

Page 58: 第五章 中断和异常 Interrupt and Exception

58

INITIALIZATION SEQUENCE

Page 59: 第五章 中断和异常 Interrupt and Exception

59

Poll Mode disabling interrupt

1 - - - - 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 bitotherwise 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

82C59A Basic Operation

Page 60: 第五章 中断和异常 Interrupt and Exception

60

AEOI Mode IS bit is cleared by INTA signal

Rotating Priority Mode A (Automatic Rotation) for Equal Priority Devices

Before Rotate“IS” 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0

priority 7 6 5 4 3 2 1 0 2 1 0 7 6 5 4 3

non specific EOI; Automatic EOI(INTA) Rotating Priority Mode B (Rotation By Software)

Programming the bottom priority specific EOI

low lowhigh high

Page 61: 第五章 中断和异常 Interrupt and Exception

6112.9 Interrupt Interface Circuits using the 82C59A

Page 62: 第五章 中断和异常 Interrupt and Exception

62

Ex 12.10

Page 63: 第五章 中断和异常 Interrupt and Exception

63

Example