Interrupts
Interrupts
Interrupts
Interrupt Types
Hardware Interrupts: External event
Software Interrupts: Internal event (Software generated)
Maskable and non-maskable interrupts
Interrupt priority
Main Program
Main Program
Printer Interrupt
Main Program
Modem Interrupt
Main Program
Modem Interrupt
Interrupt vector: Code loaded on the bus by the interrupting device that contains the
Address (segment and offset) of specific interrupt service routine
Interrupt Masking: Ignoring (disabling) an interrupt
Non-Maskable Interrupt: Interrupt that cannot be ignored (power-down)
Interrupt Vectors
The processor uses the interrupt vector to determine the address of the
ISR of the interrupting device.
In the 8088/8086 processor as well as in the 80386/80486/Pentium
processors operating in Real Mode (16-bit operation), the interrupt vector
is a pointer to the Interrupt Vector Table.
The Interrupt Vector Table occupies the address range from 00000H to
003FFH (the first 1024 bytes in the memory map).
Each entry in the Interrupt Vector Table is 4 bytes long:
The first two represent the offset address and the last two the
segment address of the ISR.
The first 5 vectors are reserved by Intel to be used by the processor.
The vectors 5 to 255 are free to be used by the user.
5 PF
01110
00H
Segment Selector
The processor reads the data bus to get the interrupt vector
8088 System
D7
Peripheral
Device
D0
A0
Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
E2
INTR
LS244
A19
E1
I7 I6 I5 I4 I3 I2 I1 I0
INTA
4C = 0 1 0 0 1 1 0 0
INTR
+5V
00000
00010
.........
00100
00110
.........
00250
3C 22 10 38 6F 13 2C 2A 33
11 3C 32 88 90 16 44 32 14
... ... ... ... ... ... ... ... ...
4A 33 3C 4A AA 1A 1B A2 2A
C1 58 4E C1 4F 11 66 F4 C5
... ... ... ... ... ... ... ... ...
00 10 10 20 3F 26 33 3C 20
22
30
...
33
58
...
26
21 67 EE F1
42 58 30 36
... ... ... ...
3C 4A AA 1A
4E 20 4F 11
... ... ... ...
20 C1 3F 10
32
34
...
3E
F0
...
28
25
66
...
77
F4
...
32
00260
.........
003E0
20
...
3A
4E
...
10
00
...
45
10
...
2F
50
...
4E
88
...
33
22
...
6F
38
...
90
10
...
3A
5A
...
44
38
...
37
10
...
43
4C
...
3A
55
...
54
14
...
54
54
...
7F
003F0
22
3C
80
01
3C
4F
4E
88
22
3C
50
21
49
3F
F4
65
Get the offset address of the ISR using the Offset directive
Get the segment address of the ISR using the Segment directive
ax
Save registers in the stack
ds
ax,0
Set ds to 0 to point to the interrupt vector table
ds,ax
ax,offset isr40
Get the offset address of the ISR and store
it in the address 0100h (4X40h = 100h)
[0100h],ax
ax,segment isr40
Get the segment address of the ISR
[0102h],ax
and store it in the address 0102h
ds
Restore registers from the stack
ax
IR1
IR2
IR3
IR4
IR5
IR6
Vector
FEH
FDH
FBH
F7H
EFH
DFH
BFH
Software Polling,
Daisy-Chained Interrupt
Each device is connected to
the same interrupt request
line, but there is only a
single interrupt vector.
The device that sent the
request will respond.
Interrupt Masking
The processor can inhibit certain types of interrupts by use of a special interrupt mask
bit.
This mask bit is part of the flags/condition code register, or a special interrupt register.
If this bit is clear, and an interrupt request occurs on the Interrupt Request input, it is
ignored.
NMI cannot be masked
Software Interrupts
Traps: (self-interrupt!)
Single step mode
Calls to Operating System (INT 21H - x86, SC PPC)
Exceptions:
Divide by zero
Memory protection fault
Interrupt Processing
Save state
Disable interrupts for the duration of the ISR or allow it to be interrupted too?
Save program counter
Save flags
Save register values?
Process interrupt
Restore state
Load PC, flags, registers etc.
ICW1/ICW2
ICW1 Programs the basic operation of the 8259A
Initialization Control Word (ICW1) Bits
7:5 (Interrupt Vector Addresses for MCS-80/85 Mode, dont cares for x86.)
4 (Must be set to 1 for ICW1)
3 (1: Level Triggered Interrupts, 0: Edge Triggered Interrupts)
2 (1: Call Address Interval of 4, 0: Call Address Interval of 8)
1 (1: Single 8259A, 0: Cascaded 8259A)
0 (1: Will be Sending ICW4, 0: Don't need ICW4)
ICW2 specifies the vector number used with the interrupt request inputs
Example: for vectors 08H-0FH, write 08H in ICW2
Example: for vectors 70H-77H, write 70H in ICW2
ICW3/ICW4
ICW3 only used in cascade mode, indicating where the slave is connected to the
master.
Example: If slave is connected in IR3, we write 00001000 = 04H in ICW3
ICW4 bits
7-5: Always 0
4: When 1 a IR request from a slave is recognized by the master while processing
another slave interrupt
3: 1- Buffered operation, 0 Non-buffered operation
2: 1- 8259A is master, 0 8259A is slave
1: 1- Automatic end of interrupt (preferable), 0 normal end of interrupt
0: Always 1 in 8088/8086 mode
OCW1/OCW2
Operation Control Word 1 (OCW1) bits: Sets the mask register
OCW3
OCW3 is used to read internal 8259A registers, specify the operation of the special
mask register, and the poll command
Status registers:
Interrupt Request Register (IRR): indicates which IR inputs are active
In-Service Register (ISR): contains the level of the interrupt being serviced
Interrupt Mask Register (IMR): Holds the interrupt mask bits
IRR and ISR are read by programming OCW3, IMR is read through OCW1
Example
Use an 8259A PIC to connect the I/O device in the example of slide 8
Interrupt Vectors
The Interrupt Vector contains the address of the interrupt service routine
The Interrupt Vector Table is located in the first 1024 bytes of memory at address
000000H-0003FFH.
It contains 256 different 4-byte interrupt vectors, grouped in 18 types
Interrupt Types
Instruction executions
Single-step
NMI
Coprocessor segment overrun
INTR
INT instruction
The contents of the flag register are pushed onto the stack
IF and TF are cleared, disabling the INTR pin
CS is pushed to the stack
IP is pushed onto the stack
Interrupt Vector contents are fetched and placed into IP and CS, so the next instruction is the
Interrupt Service Routine indicated by the Interrupt Vector