Lesson 13
Lesson 13
Lesson 13
An introduction to reprogramming
of the 8259A Interrupt Controllers
Intel’s “reserved” interrupts
• Intel had reserved interrupt-numbers 0-31
for the processor’s various exceptions
• But only interrupts 0-4 were used by 8086
• Designers of the early IBM-PC ROM-BIOS
disregarded the “Intel reserved” warning
• So interrupts 5-31 got used by ROM-BIOS
code for its own various purposes
• This created interrupt-conflicts for 80286+
Exceptions in Protected-Mode
• The interrupt-conflicts seldom arise while
the processor is executing in Real-Mode
• PC BIOS uses interrupts 8-15 for devices
(such as timer, keyboard, printers, serial
communication ports, and diskette drives)
• CPU uses this range of interrupt-numbers
for various processor exceptions (such as
page-faults, stack-faults, protection-faults)
Handling these conflicts
• There are two ways we can ‘resolve’ these
interrupt-conflicts when we write ‘handlers’
for device-interrupts in the ‘overlap’ range
– We can design each ISR to query the system in
some way, to determine the ‘cause’ for the
interrupt-condition (i.e., a device or the CPU?)
– We can ‘reprogram’ the Interrupt Controllers to
use non-conflicting interrupt-numbers when the
peripheral devices trigger their interrupts
Learning to program the 8259A
• Either solution will require us to study how
the system’s two Programmable Interrupt
Controllers are programmed
• Of the two potential solutions, it is evident
that greater system efficiency will result if
we avoid complicating our interrupt service
routines with any “extra overhead” (i.e., to
see which component wished to interrupt)
Three internal registers
input-signals
8259A
IRR output-signal
IMR
ISR
1 S7 S6 S5 S4 S3 S2 S1 S0 (master)
A0 D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 1 0 0 0 1 ICW1=0x11
1 ICW2=baseID
1 0 0 0 0 0 1 0 0 ICW3=0x04
1 0 0 0 0 0 0 0 1 ICW4=0x01
Initializing the slave PIC
• Write a sequence of four command-bytes
• (Each command is comprised of 9-bits)
A0 D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 1 0 0 0 1 ICW1=0x11
1 ICW2=baseID
1 0 0 0 0 0 0 1 0 ICW3=0x02
1 0 0 0 0 0 0 0 1 ICW4=0x01
Unused real-mode ID-range
• We can use our ‘showivt.s’ demo to see
the “unused” real-mode interrupt-vectors
• One range of sixteen consecutive unused
interrupt-vectors is 0x90-0x9F
• We created a demo-program (‘reporter.s’)
to ‘reprogram’ the 8259s to use this range
• This could be done in protected-mode, too
• It would resolve the interrupt-conflict issue
Other ideas in the demo
• It uses an assembly language ‘macro’ to create
sixteen different ISR entry-points:
.macro isr id
pushf
pushw $\id
call action
.endm
• All the instances of this macro call to a common
interrupt-handling procedure (named ‘action’)
The Macro’s expansion
• If the macro-definition is invoked, with an
argument equal to, say, 0x08, like this:
isr 0x08
then the ‘as’ assembler will ‘expand’ that
macro-invocation, replacing it with:
pushf
pushw $0x08
call action
How ‘action’ works
• Upon entering the ‘action’ procedure, the system stack
has six words:
FLAGS
CS
IP
FLAGS
Interrupt-ID
return-from-action SS:SP
• The two “topmost” words (at bottom of picture) will get
replaced by the interrupt-vector corresponding to ‘int-ID’
The stack states
Stage 1 Stage 2 Stage 3 Stage 4
FLAGS FLAGS FLAGS FLAGS
CS CS CS CS
IP IP IP IP