Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Interrupts

OS and Events

OS is event driven

i.e. executes only when there is an
interrupt, trap, or system call
Event Types
Events


Interrupts : raised by hardware or programs to
get OS attention.

Types

Hardware interrupts : raised by external
hardware devices

Software Interrupts : raised by user programs


Exceptions : due to illegal operations
Exception and Interrupt Vectors

Each interrupt/exception provided a number

Number used to index into an Interrupt descriptor table (IDT)

IDT provides the entry point into a interrupt/exception handler

0 to 255 vectors possible

0 to 31 used internally

Remaining can be defined by the OS
Exception and Interrupt Vectors
Exception and Interrupt Vectors
Hardware Interrupts

• Several devices connected to the CPU


– eg. Keyboards, mouse, network card, etc.

• These devices occasionally need to be serviced


by the CPU
– eg. Inform CPU that a key has been pressed

• These events are asynchronous i.e. we cannot


predict when they will happen.

• Need a way for the CPU to determine when a


device needs attention

(pooling?)
Hardware Interrupts
• Each device signals to the CPU that it wants to be serviced
• Generally CPUs have 2 pins
– INT : Interrupt
– NMI : Non maskable – for very critical signals
8259 Programmable Interrupt Controller
• 8259 (Programmable interrupt
controller) relays upto 8 interrupt to
CPU
• Devices raise interrupts by an
‘interrupt request’ (IRQ)
• CPU acknowledges and queries
the 8259 to determine which device
interrupted
• Priorities can be assigned to each
IRQ line
• 8259s can be cascaded to support
more interrupts
• 15 IRQs (IRQ0 to IRQ15), so 15
possible devices
• Interrupt types
– Edge
– Level
Interrupts: General Block Diagram
Interrupts: Cascade 8259
Interrupts
Interrupts: Events

1. Flag register value is pushed on to the stack.


2. CS value of the Return address and IP value of the Return address are
pushed on to the stack.
3. IP is loaded from the contents of the word location N x 4.
4. CS is loaded from the contents of the next word location.
5. Interrupt Flag and Trap Flag are reset to 0.

During the ISS, interrupt are disabled because the Interrupt flag is reset to 0

At the end of the ISS, there will be an IRET instruction.


This performs popping off from the stack top to IP, CS and Flag registers.

(RET vs IRET)
Interrupt Handler
Typical Interrupt Handler

Save additional CPU context (written in assembly)
(done by alltraps in xv6)

Process interrupt (communicate with I/O devices)

Invoke kernel scheduler

Restore CPU context and return (written in assembly)

• Do as little as possible in the interrupt handler


– Often just queue a work item or set a flag
• Defer non-critical actions till later
Example: Keyboard Interrupt

Keyboard connected to second interrupt line in 8259
master

Mapped to vector 33 : (T_IRQ0 + IRQ_KBD).

In function trap, invoke keyboard interrupt (kbdintr),
which is redirected to consleintr
Keyboard Interrupt Handler
Hardware vs Software Interrupt
Example: Write System Call
Exception Sources
Program-Error Exceptions

Eg. divide by zero

Software Generated Exceptions



Example INTO, INT 3, BOUND

INT 3 is a break point exception

INTO overflow instruction

BOUND, Bound range exceeded

Machine-Check Exceptions

Exception occurring due to a hardware error (eg. System bus error,
parity errors in memory, cache memory errors)

Microsoft Windows : Machine check exception


8259 Interrupt Controller
Initializing PIC
Initializing PIC
Initializing PIC
Initializing PIC
Initializing PIC
Controlling and Inquiry of PICs: OCWs
Controlling and Inquiry of PICs: OCWs
Controlling and Inquiry of PICs: OCWs
Controlling and Inquiry of PICs: OCWs
Ibm PC Compatible Controllers

DMA Controller
Serial Controller
Parallel Controller
Timer Controller
Keyboard Controller
HDD Controller
80X87 CoProcessor for arithmetic ops.
X486 and Pentium contains internal
...
Serial Ports
Serial Ports: Synchronous and Asychronous
Serial Ports: RS232 Standar
Logic Zero volt changes +3 to +15 volt
Logic One changes -3 to -15 volt
Serial Ports: Block diagram of UART chip
Serial Ports: UART internal registers
Serial Ports: Access to registers
Serial Ports: Initializing UART - LCR
Serial Ports: UART Status - LSR
Serial Ports: Control through interrupts
Serial Ports: Control through interrupts
Serial Ports: Send and Receive Buffers
Serial Ports: Send and Receive Buffers

You might also like