
86 Chapter 7: Peripherals
it is the data pointed to that is subject to change without notice. This is a very sub-
tle point, and it is easy to confuse yourself by thinking about it too much. Just
remember that the location of a register is fixed, though its contents might not be.
And if you use the volatile keyword, the compiler will assume the same.
The primary disadvantage of the other type of device registers, I/O-mapped regis-
ters, is that there is no standard way to access them from C or C++. Such registers
are accessible only with the help of special machine-language instructions. And
these processor-specific instructions are not supported by the C or C++ language
standards. So it is necessary to use special library routines or inline assembly (as
we did in Chapter 2) to read and write the registers of an I/O–mapped device.
The Device Driver Philosophy
When it comes to designing device drivers, you should always focus on one eas-
ily stated goal: hide the hardware completely. When you’re finished, you want the
device driver module to be the only piece of software in the entire system that
reads or writes that particular device’s control and status registers directly. In addi-
tion, if the device generates any interrupts, the interrupt service routine that
responds to them should be an integral part of the device driver. In this section,
I’ll explain why I recommend this philosophy and how ...