I/O & Interrupts

Module 3.8 — Interrupt handling, DMA transfers, device driver model

Speed:
Step 1 / 13
USER MODE
Running User Code

CPU executing user process instructions

CPUuser
PC: 0x4000
SP: 0x8000
IF: 1 (enabled)
CPL: 3 (ring 3)
Kernel Stack
(empty)
⌨️
Keyboard IRQ
Vector: 0x21 | Priority: 2
⏱️
Timer IRQ
Vector: 0x20 | Priority: 0

Interrupt Timeline

How It Works

Interrupt Flow
1. Device raises IRQ signal
2. CPU finishes current instruction
3. Save state (PC, flags) to kernel stack
4. Look up handler in IDT
5. Jump to handler (kernel mode)
6. IRET: restore state, return to user mode

User vs Kernel Mode

User (Ring 3)
Limited access
No I/O ports
No privileged ops
Kernel (Ring 0)
Full hardware access
I/O port access
Interrupt handling

Basic Interrupt Flow

A keyboard interrupt arrives while CPU executes user code. Watch the full interrupt dispatch cycle.