8259 Pic
8259 Pic
Lower priority interrupts need to wait for the higher priority interrupts to be completed
2
8088/8086 Interrupts
• An interrupt is an external event which informs the CPU that a
device needs service
• In the 8088 & 8086 there are are a total of 256 interrupts (or
interrupt types)
– INT 00
– INT 01
– …
– INT FF
• When an interrupt is executed, the microprocessor automatically
saves the flags register (FR), the instruction pointer (IP) and the
code segment register (CS) on the stack and goes to a fixed
memory location.
• In 80x86, the memory location to which an interrupt goes is always
four times the value of the interrupt number
• INT 03h goes to 000Ch
3
Interrupt Service Routine
• For every interrupt, there must be a program associated with it
• This program is called an Interrupt Service Routine (ISR)
• It is also called an interrupt handler
• When an interrupt occurs, CPU runs the interrupt handler but where
is the handler?
– In the interrupt Vector Table (IVT)
. . .
. . .
. . .
INT FF 003FCh IP255:CS255
4
Interrupt Vector Table
5
Interrupt Vector Table
6
Examples
7
Interrupt Instructions
8
Differences between INT and CALL
All the interrupts are serviced on priority basis. The higher priority
interrupt is served first and an active lower priority interrupt service is
interrupted by a higher priority one. Lower priority interrupts will have to
wait until their turns come.
The section of program to which the control is passed called
Interrupt-service routine (ISR)
10
Interrupt instructions
11
The Operation of Real Mode Interrupt
1. The contents of the FLAG REGİSTERS are pushed onto the stack
2. Both the interrupt (IF) and (TF) flags are cleared. This disables the
INTR pin and the trap or single-step feature. (Depending on the
nature of the interrupt, a programmer can unmask the INTR pin by
the STI instruction)
3. The contents of the code segment register (CS) is pushed onto the
stack.
4. The contents of the instruction pointer (IP) is pushed onto the stack.
5. The interrupt vector contents are fetched, and then placed into both
IP and CS so that the next instruction executes at the interrupt
service procedure addressed by the interrupt vector.
6. While returning from the interrupt-service routine by the instruction
IRET, flags return to their state prior to the interrupt and and
operation restarts at the prior IP address.
12
INT 00 (divide error)
MOV AL,92
SUB CL, CL
DIV CL ; 92/0 undefined
; Also invoked if the quotient is too large to fit into the assigned register
MOV AX,0FFFh
MOV BL,2
DIV BL
PUSHF
POP AX
OR AX,0000000100000000B
PUSH AX
POPF
14
Other Interrupts
• INT 02h
– Intel has set aside INT 02h for the NMI interrupt
– There is an NMI pin on the CPU
– If the NMI pin is activated by a H signal, the CPU jumps to
00008H to fetch the CS:IP of the ISR associated with NMI
• INT 03h (breakpoint)
• INT 04H (signed number overflow) or INTO
– If OF=0 goes to 00010h to get the address of the ISR
– Otherwise, it is equivalent to NOP
• Example: Use debug dump command to see the IVT
– D 0000:0000 0013
15
External Hardware Interrupt Interface
Minimum Mode
16
External hardware-interrupt Interface
• Minimum mode hardware-interrupt interface:
– 8088 samples INTR input during the last clock period of each
instruction execution cycle. INTR is a level triggered input;
therefore logic 1 input must be maintained there until it is
sampled. Moreover, it must be removed before it is sampled next
time. Otherwise, the same Interrupt Service is repeated twice.
– INTA goes to 0 in the first interrupt bus cycle to acknowledge
the interrupt after it was decided to respond to the interrupt.
– It goes to 0 again the second bus cycle too, to request for the
interrupt type number from the external device.
– The interrupt type number is read by the processor and the
corresponding int. CS and IP numbers are again read from the
memory.
17
External hardware-interrupt Sequence
18
Resident Programs
• Usually non-resident program is a file, loaded from disk by DOS.
Termination of such program is the passing control back to DOS.
DOS frees all memory, allocated for and by this program, and stays
idle to execute next program.
• Resident program passes control to DOS at the end of its execution,
but leaves itself in memory whole or partially.
• Such way of program termination was called TSR - Terminate-and-
Stay-Resident. So resident programs often called by this
abbreviations - TSR.
• For example, TSR can watch keypresses to get passwords, INT 13h
sectors operations to substitute info, INT 21h to watch and dispatch
file operations and so on.
• TSR stays in memory to have some control over the processes.
Usually, TSRs takes INTerrupt vectors to its code, so, when interrupt
occurs, vector directs execution to TSR code.
19
Storing an Interrupt Vector in the Vector Table
INT 21h
Initialization
AH = 25h Terminate and stay resident
Read the current vector
AL = interrupt AH = 31h
AH = 35h
type number AL = 00
AL = interrupt type
DS:DX = address DX = number of paragraphs
number
of new interrupt to reserve for the program
ES:BX = address
procedure
stored at vector
20
A virus!
21
Example-storing Interrupt Vector
22
Example-storing Interrupt Vector
23
Interrupt Sequence
27
Interrupt Example
Interrupts the microprocessor each time the interrupt request signal has a
transition from 0Æ 1. The corresponding interrupt number generated by
the hardware in response to INTA is 60H
28
Memory organization
29
Program
30
Using hardware interrupt
Using Tri-state buffers to Input vector
32
Description
• 8255 is decoded at 0500h, 0502h, 0504h, and 0506h
• 8255 is operated at Mode 1 (strobed input) B0 CONTROL WORD
• Whenever a key is typed , the INTR output (PC3) becomes a logic 1
and requests an interrupt thru the INTR pin on the microprocessor
• The INTR remains high until the ASCII data are read form port A.
• In other words, every time a key is typed the 8255 requests a type
40h interrupt thru the INTR pin
• The DAV signal from the keyboard causes data to be latched into
port A and causes INTR to become a logic 1
• Data are input from the keyboard and then stored in the FIFO (first
in first out) buffer
• FIFO in our example is 256 bytes
• The procedure first checks to see whether the FIFO is full.
• A full condition is indicated when the input pointer (INP) is one byte
below the output pointer (OUTP)
33
Remembering Mode 1 with Interrupts this time
34
Example: “Read from the Keyboard routine” into FIFO
35
Example contd: “Read from the FIFO into AH”
READ: PROC FAR USES BX DI DX
EMPTY: MOV BX, INP
MOV DI, OUTP
CMP BX,DI
JE EMPTY
MOV AH, CS:DI
MOV AL,9 ; enable 8255 intEa
MOV DX, CNTR
OUT DX,AL
INC BYTE PTR CS:OUTP
RET
READ : ENDP
36
Multiple Interrupts - Another Interrupt Structure
37
Multiple Interrupts - Interrupt Structures
40
8255 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
42
Block Diagram
43
82C59A Programmable Interrupt Controller
• Block diagram of 82C59A includes 8 blocks
– 8259 is treated by the host processor as a peripheral device.
– 8259 is configured by the host pocessor to select functions.
– Data bus buffer and read-write logic: are used to configure the
internal registers of the chip.
• A0 address selects different command words within the 8259
44
82C59A Programmable Interrupt Controller
– Control Logic INT and INTA¯ ared used as the handshaking interface.
• INT output connects to the INTR pin of the master and is connected to a
master IR pin on a slave. INTA¯ is sent as a reply.
• In a system with master and slaves, only the master INTA ¯ signal is
connected.
– Interrupt Registers and Priority Resolver: Interrupt inputs IR0 to IR7
can be configured as either level-sensitive or edge-triggered inputs.
Edge-triggered inputs become active on 0 to 1 transitions.
1. Interrupt request register (IRR): is used to indicate all interrupt
levels requesting service.
2. In service register (ISR): is used to store all interrupt levels which are
currently being serviced.
3. Interrupt mask register (IMR): is used to enable or mask out the
individual interrupt inputs through bits M0 to M7. 0= enable, 1=
masked out.
4. Priority resolver: This block determines the priorities of the bits set in
the IRR. The highest priority is selected and strobed into the
corresponding bit of the ISR during the INTA¯ sequence.
– The priority resolver examines these 3 registers and determines
whether INT should be sent to the MPU
45
82C59A Programmable Interrupt Controller
46
Interrupt Sequence
48
Content of the Interrupt Vector Byte
49
Two controllers wired in cascade
50
Fully Nested Mode
• It prioritizes the IR inputs such that IR0 has highest priority and IR7
has lowest priority
• This priority structure extends to interrupts currently in service as
well as simultaneous interrupt requests
• For example, if an interrupt on IR3 is being serviced (IS3 = 1) and a
request occurs on IR2, the controller will issue an interrupt request
because IR2 has higher priority.
• But if an IR4 is received (or any interrupt higher than IR2), the
controller will not issue the request
• Note however that the IR2 request will not be acknowledged unless
the processor has set IF within the IR3 service routine
• In all operating modes, the IS bit corresponding to the active routine
must be reset to allow other lower priority interrupts to be
acknowledged
• This can be done by outputting manually a special nonspecific EOI
instruction to the controller just before IRET
• Alternatively, the controller can be programmed to perform this
nonspecific EOI automatically when the second INTA pulse occurs
51
Interrupt Process Fully Nested Mode
52
End of Interrupt
¾The In Service (IS) bit can be reset automatically following the trailing edge
of the last in sequence INTA pulse (when AEOI bit in ICW4 is 1) or by a
command word that must be issued to the 8259 before returning from a service
routine (EOI command).
¾An EOI command must be issued twice in the Cascade mode, once for the
master and once for the corresponding slave.
¾There are two forms of (non-automatic) EOI command:
9Specific: When there is a mode which may disturb the fully nested
structure, the 8259 may not determine the last level acknowledged. In
this case a specific EOI must be issued, which includes the IS level to
be reset. (OCW2)
9Non Specific: When a Non Specific EOI issued the 8259 will
automatically reset the highest IS bit of those that are set, since in the
fully nested mode the highest level was necessarily the last level
acknowledged and serviced. (preserve the nested structure)
A non Specific EOI can be also issued at OCW2.
53
Initialization Sequence
Two types of command words are
provided to program the 8259:
1) The initialization command words
(ICW)
2) The operational command words
(OCW)
00011001b = 19h
55
ICW2
11110000b = F0h
Suppose IR6 is set to generate the value of 6E. Generate the addresses for
the other interrupts.
IR7 = 6F IR3 = 6B
IR6 = 6E IR2 = 6A
IR5 = 6D IR1 = 69
IR4 = 6C IR0 = 68 56
Master Slave Configuration
57
Master Slave Configuration
9When slave signals the master that an interrupt is active the master determines
whether or not its priority is higher than that of any already active interrupt.
9If the new interrupt is of higher priority the master controller switches INTR to
logic 1
58
Master Slave Configuration
9This signals MPU that external device needs to be serviced. If IF is set. As the first INTA is
sent out the master is signaled to output the 3 bit cascade code of the slave device whose whose
interrupt request is being acknowledged on the CAS bus. All slaves read this code and compare
internally
9The slave corresponding to the code is signaled to output the type number of its highest
priority active interrupt on the data bus during the second INTA cycle. 59
ICW3
61
ICW4
BUF when 1 selects buffer mode. The SP/EN pin becomes an output for the data
buffers.
When 0, the SP/EN pin becomes the input for the (MASTER/SLAVE)
functionality
M/S is used to set the function of the 8259 when operated in buffered mode.
If M/S is set the 8259 will function as the MASTER.
If cleared will function as SLAVE. 62
Masks and Other Mode selection
•Interrupt Masks
•Each Interrupt request can be masked individually
by the IMR programmed through OCW1. Each bit in
the IMR masks one interrupt channel if it is set (1).
Bit 0 masks IR0, Bit 1 masks IR1 and so forth,
Masking an IR channel does not affect the other
channels operation.
63
Special Fully Nested Mode
– Used in the case of a large system where cascading
is used, and the priority has to be conserved within
each slave.
– This mode is similar to the normal nested mode with
the following:
• When an interrupt request from a certain slave is in service
this slave is not locked out from the master’s priority logic
and further interrupt requests from higher priority IR’s within
the slave will be recognized by the master and will initiate
interrupts to the processor.
• When exiting the ISR the software has to check whether the
interrupt is the only interrupt that is serviced from the SLAVE.
This is done by sending an EOI command and check the In
service register in the SLAVE. If it is the only one, a non
specific EOI has to be sent to the MASTER, if it is not empty
no action performed.
64
Automatic Rotation
65
Automatic Rotation
interrupt requests
arrive on IR4 and IR6
66
Specific Rotation
67
OCW1 - OCW2
OCW1 is used to access the contents of the IMR. A READ operation can be performed
to the IMR to determine the present setting of the mask. Write operations can be
performed to mask or unmask certain bits.
What should be OCW1 if interrupt inputs IR0 through IR3 are to be masked
and IR4 through IR7 are to be unmasked?
D3D2D1D0 = 1111
D7..D4 = 0
Î 00001111 = 0F
What should be OCW2; if priority scheme rotate on non specific EOI issued
101 00000 (since it doesn’t have to be specific on certain bit
69
OCW3
Permits reading of the contents of the ISR or IRR registers through software
70
Example
Normally when an IR is acknowledged and EOI is not issued, lower priority
interrupts will be inhibited.
So the SPECIAL MASK MODE, when a mask bit is set in OCW1, it
inhibits further interrupts at that level and end enables from all other levels,
that are not masked.
71
IR7
• Controller does not remember interrupt requests that are not
acknowledged
• If an interrupt is requested but no IR bit is found during INTA that is
IR is removed before acknowledged, then controller will default to
an IR7
• If the IR7 input is used for a legitimate device, the service routine
should read the IS register and test to be sure that bit 7 is high
ISR7 PROC FAR
MOV AL, 00001011b
OUT 20h, AL
IN AL, 20h
TEST AL, 80h ; IS7 set
JZ FALSE
; process interrupt here
FALSE: IRET
ISR7 ENDP
72
Example
73
Example
• A0 not used
• Two I/O addresses are FF00h and FF02h
• FF00h: ICW1,
• FF02h: ICW2, ICW3, ICW4, OCW1
• ICW1 = 00010011b = 13h
• type number 72 will be used
– ICW2 = 01001000b = 48h
• ICW3 not needed
• nonbuffered and auto EOI
– ICW4 = 03h
• mask all other interrupts but IR0
– OCW1 = 11111110b = FEh
74
Main program and ISR
CLI
START: MOV AX, 0
MOV ES, AX
MOV AX, 100h
MOV DS, AX
MOV AX, 0FF0h; stack
MOV SS, AX
MOV SP, 100h
; interrupt install
MOV AX, OFFSET SRV72
MOV [ES:120h], AX
MOV AX, SEG SRV72
MOV [ES:122h]. AX
75
Example contd
; initialization
; service routine
MOV DX, 0FF00h
SRV72: PUSH AX
MOV AL, 13h
MOV AL, [COUNT]
OUT DX, AL
INC AL
MOV DX, 0FF02h
DAA
MOV AL, 48h
MOV [COUNT], AL
OUT DX, AL
POP AX
MOV AL, 03h
IRET
OUT DX, AL
MOV AL, 0FEh
OUT DX, AL
STI
; wait for interrupt
HERE: JMP HERE
76