Device drivers
How an operating system talks to hardware it has never heard of: a driver translates for each device, usually from inside the kernel, which is why one bad driver can stop a whole machine.
In 30 seconds
Every piece of hardware speaks its own private language of numbers. A device driver is the software that translates between that language and the general requests an operating system makes.
Each kind of device needs its own driver, but all drivers of one type present the same face to the system, so programs never need to care what is plugged in.
Most drivers run inside the kernel with full privileges, so a bug in one can crash everything. Drivers that run as ordinary programs are slower but fail safely.
Device drivers, step by step
Simplified: a real USB keyboard sends an 8-byte report with the 0x04 inside it, and a user-space driver still relies on a small kernel part to reach the hardware.
- Step 1: Hardware speaks in numbers. Press A on a USB keyboard and what travels down the cable is a number, 0x04. Every device talks like this, in codes its designers chose. The kernel, the core of the operating system, cannot have every such scheme built in, so on its own it has no idea what 0x04 means.
- Step 2: The driver translates. A device driver is a piece of software that knows one device’s codes. It turns 0x04 into something the kernel understands whatever the hardware: the event “key A pressed”. The kernel passes that to the app in front, which simply receives the letter.
- Step 3: It works both ways. Drivers also carry orders down to the device. When the system wants the Caps Lock light on, the kernel makes a general request and the driver turns it into the byte this keyboard expects: 0x02, in which bit 1 stands for that light. The app never needs to know the byte.
- Step 4: One driver per kind of device. An older PS/2 keyboard reports the same key as 0x1C, over different wiring. It needs its own driver, yet both drivers hand the kernel the identical event. That is why new hardware needs a driver before it works, and why devices that follow a shared standard, as USB keyboards do, can all use one.
- Step 5: Most drivers run in the kernel. Ordinary programs run in user space, where each one is boxed in and cannot touch hardware or another program’s memory. The kernel runs in kernel space, with no such limits. Most drivers are loaded into the kernel itself, because they need direct, fast access to their device.
- Step 6: A driver bug stops everything. That power is the danger. If a kernel driver writes to the wrong address, it overwrites the kernel’s own data, and nothing stands in the way. The kernel can no longer trust its memory, so it stops on purpose: a kernel panic, or a blue screen on Windows. Every program stops with it.
- Step 7: User-space drivers. A driver can instead run as a normal boxed-in program, with the kernel passing the device’s data up to it. If it crashes, only it stops and it can be restarted. The price is speed: every request crosses the boundary more often. Printers, scanners and many USB gadgets are driven this way.
Try it yourself
Learn this first
Spotted a mistake on this page?