What is a device driver
Up to lesson 10, the operating system managed the CPU and memory from the inside. But a computer also has to talk to outside devices: the keyboard, mouse, screen, disk, printer, and even a new device you bought yesterday that didn't exist when the operating system was made. Every device speaks differently, so how can it understand them all?
There are so many devices
The devices that can attach to a computer are endless: keyboards, mice, screens, disks, printers, cameras, and new ones keep pouring out every year.
Each device exchanges different signals, too.
The operating system can't possibly memorize them all.
Press a device: each speaks in its own signals, so the operating system alone can hardly understand them.
With every device speaking differently, it seems hopeless. And you can't rewrite the operating system for each and every device either, because new devices keep coming.
So someone is placed between the two: an interpreter.
A driver is an interpreter
The operating system uses only one standard language: simple requests like "read," "write," and "open."
The driver that comes with each device interprets those words. It turns the operating system's "read" into signals only that device understands, and translates the device's reply back into the standard language.
Send the standard command "read," and the drivers interpret it into each device's signals.
The operating system only ever has to speak the same standard language, and the drivers take on all the fussy details of each device.
So how can a brand-new device, one the operating system has never seen, be used?
A new device? Just install the driver
The operating system talks only to drivers, not to devices. So even when a device it has never seen arrives, the solution is simple: just install that device's driver, its own personal interpreter.
Without changing a single thing in the operating system itself, the driver bridges the gap and the device works right away.
Connect a new device: at first they can't understand each other, but once the driver is installed, they connect right away.
With a single driver, even a new device is taken in without trouble. Now they can talk, but one thing remains.
Devices are usually much slower than the CPU. How should the operating system wait for such a slow device?
Don't keep asking; let it tap you on the shoulder
If the operating system waits next to a slow device asking "Done yet? Done yet?" over and over, the fast CPU sits idle the whole time.
That's far too wasteful. So it makes the request and goes off to do other work. When the device finishes, it taps the operating system on the shoulder with an interrupt: "Done!"
Only then does the operating system come back to take care of it.
Compare the two approaches: asking over and over leaves the CPU idle, while a tap on the shoulder lets the CPU do other work.
With a tap on the shoulder, the CPU never sits idle for a moment. It makes a request, does other work, and takes care of it when the signal comes.
This interrupt is the key technique for working with outside devices. So what happens when the interpreter and the tap on the shoulder come together?
Getting along with the outside world through interpreters and taps
The operating system handles an ever-growing range of devices with two techniques: drivers that interpret for each device, and interrupts that announce when work is done.
Thanks to them, it can handle even devices it has never seen, without waste.
Among all those devices, one is especially important: the disk, where files live. How does the operating system organize the disk?
Put the operating system in the middle, and you can see the drivers interpreting and the devices tapping it on the shoulder with interrupts.
To sum up, there are two secrets to getting along with outside devices: the driver, the interpreter that translates for each device, and the interrupt, the tap on the shoulder when a slow device finishes.
With these two, the operating system can join hands with any device in the world. In the next lesson, we'll see how one of those devices, the disk, is organized into files and folders.