College of Engineering & CS
Wright State University
Dayton, Ohio 45435-0001

EGR 199: Fundamentals of Engineering

Device Drivers

Prabhaker Mateti

   

Table of Contents

   

Executive Summary

This article is about software components known as device drivers. This is third in a series of modules on computer hardware related topics for a class on freshman engineering. It assumes that the student is already familiar with the internals of a PC, local area network setup, Web, and HTML authoring.
   

Background Information

http://thetech.pcwebopedia.com/TERM/d/driver.html defines a device driver as

"a program that controls a device. Every device, whether it be a printer, disk drive, or keyboard, must have a driver program. Many drivers, such as the keyboard driver, come with the operating system. For other devices, you may need to load a new driver when you connect the device to your computer. In DOS systems, drivers are files with a.SYS extension. In Windows environments, drivers often have a.DRV extension.

A driver acts like a translator between the device and programs that use the device. Each device has its own set of specialized commands that only its driver knows. In contrast, most programs access devices by using generic commands. The driver, therefore, accepts generic commands from a program and then translates them into specialized commands for the device."

But, this is a sloppy definition.  It is our goal to explain what a device driver is in a more precise manner.  In order to do that, we need to understand the following.

PC Architecture

The architecture of a computer system is the combination of the architectures for the hardware and systems software.  By hardware we mean the motherboard, the plug in cards, the devices connected to these, etc.  By systems software we mean the BIOS, and the operating system;  we exclude all applications such as MS Word, and Netscape.

A modern motherboard has several PCI bus slots, one or two ISA bus slots, and one AGP slot.  A card plugged into one of these slots is generally a device card.  Each device communicates with the CPU on the motherboard via the bus.  Some devices can communicate with CPUs in a very speedy manner using Direct Memory Access. Such a communication uses "resources." 

A resource is defined, in this context, as an IRQ channel, an I/O port, a memory block, or a DMA channel.

There are 16 IRQ lines used to signal the CPU that a peripheral event has started or terminated. Except for PCI devices, two devices cannot use the same line.  However, IRQ 2 is lost because it is used to connect to the second interrupt controller chip making IRQ 9 and IRQ 2 are the same. All the IRQs except for 10, 11, 12 and 15 are pre-assigned.  If a second parallel port is not used, IRQ 5 is available. IRQ 9 is also often available as most VGA cards do not require an IRQ. Thus IRQs 5, 9, 10, 11, 12 and 15 are arbitrarily used for scanners, SCSI boards, CD-ROM controllers, sound boards and any other peripheral that can be attached to a PC.

Direct Memory Access is a specialized circuitry or a dedicated microprocessor that transfers data from memory to memory without using the CPU. In the PIO mode, data is first transferred from device to CPU, and then to memory.  Although DMA may periodically steal cycles from the CPU, data is transferred much faster than using the CPU for every byte of transfer.




DMA Disk Transfers
DMA  Used for
   0      8-bit transfer
   1      8-bit transfer
   2      Floppy disk controller
   3      8-bit transfer
   4      Cascaded from 0-3
   5      16-bit transfer
   6      16-bit transfer
   7      16-bit transfer
On PCs, there are eight DMA channels commonly used as follows. Most sound cards are set to use DMA channel 1.

There are various modes of data transfer on IDE disk drives. The PIO (programmed IO) modes use the CPU, and the DMA modes bypass the CPU.

The operating system (OS) of a computer manages the hardware resources and provides an environment that allows the users' applications to run. The operating system is divided into the routines that make up the kernel and the programs that make up a broad set of utilities. At the center of the operating system is the kernel which performs the following low-level functions:

Programs request operating system services such as input and output by invoking an appropriate system call, for example, a request for action from the kernel, such as 'read n bytes from a file from the current position'. A system call is an entry point directly into the kernel. (The terms "operating system" and "kernel" are sometimes used interchangeably.) The set of entry points into the kernel code that allow programs to make use of facilities such as device access, is known as the system call interface.

Plug and Play

Hardware devices are called plug-n-play (PnP) if they meet certain conditions.

  1. The device must be entirely (re-)configurable by software; no mechanical switches or jumpers are allowed.
  2. The device must be able to uniquely identify itself to any inquiring software.
  3. The device must be able to report to the system on the resources it requires to operate,  indicating 'preferred' and 'alternate' sets of resources.

A legacy device is a device requiring a certain resource setup to maintain 1980s PC compatibility.   Devices like Floppy controllers, Real Time Clocks, Keyboard Controllers, DMA controllers, Timers, etc. have inherited fixed sets of resources from the original IBM standards.

Ideally, a modern PC should have a PnP BIOS on the motherboard, no non-PnP devices, and a PnP aware Operating System.  A modern BIOS has a setup option called "PnP Aware OS Installed (Yes/No)". When set to Yes, the BIOS only does the bare minimum setting up work to get the OS booted up. All devices not required for the boot process are deliberately left in their unconfigured, inactive state. The OS is expected to 'finish' the job of getting the devices configured into a conflict-free state. Windows 95, 98 and 2000 are capable of this;  DOS, Windows NT and Linux are not.

Most PnP BIOS's have an extra CMOS memory - usually between 4k and 16k long. This is referred to as the ESCD and it holds the complete record of how the system was configured the last time it was booted. The ESCD can also contain information about non-PnP devices.  This can be inserted by a PnP aware Operating System, or the PnP BIOS can discover these devices manually.  The message "Updating ESCD" you see when most modern systems boot is simply the BIOS's way of telling you it's finished sorting out the PnP configuration and is saving it to the ESCD CMOS memory. It takes a second or two simply because of the way the ESCD CMOS is designed.

Dynamic-Link Libraries

Dynamic linking provides a mechanism for linking applications to libraries of functions at run time. The libraries reside in their own executable files and are not copied into an application's executable file as with static linking. These libraries are "dynamically linked" because they are linked to an application when it is loaded and executed rather than when it is linked. When an application uses a DLL, the operating system loads the DLL into memory, resolves references to functions in the DLL so that they can be called by the application, and unloads the DLL when it is no longer needed. Dynamic linking can be performed explicitly by applications or implicitly by the operating system.

DLLs are designed to provide resources to applications. Many applications can use the code in a DLL, meaning that only one copy of the code is resident in the system. Also, it is possible to update a DLL without changing applications that use the DLL, as long as the interface to the functions in the DLL does not change.

Software developers can extend the Windows environment by creating a DLL that contains routines for performing operations and then making the DLL available to other Windows-based applications (in addition to internal Windows routines). DLLs most often appear as files with a .DLL filename extension; however, they may also have an .EXE or other filename extension.

Windows 95/98/NT/2000 Architecture

[The following is taken verbatim from Microsoft literature.] The operating environment for Windows 95/98 consists of a computer's hardware devices and the following software components:

A device driver is code that an operating system uses to control disk devices, display adapters, input devices such as a mouse or trackball, modems, fax machines, printers and other hardware.  Windows requires device drivers for the display, keyboard, and communication ports. Other drivers may also be required if the user adds optional devices to the system.

Monolithic Drivers

In Microsoft Windows 3.1, device most drivers were monolithic, meaning that the driver had to provide all services, user interfaces, Application Programming Interface (API) functions, and hardware-access services for a device to operate using Windows 3.1. Starting with Windows 95, a universal driver/mini-driver architecture was implemented. This architecture provides basic device services for certain hardware classes natively, so that independent hardware vendors (IHVs) need to supply device-specific code (drivers) for their particular hardware.


Universal Drivers

A universal driver includes most of the code necessary for devices in a particular class of devices (such as printers or modems) to communicate with the appropriate operating system components (such as the printer or communications subsystems). A minidriver is the small and simple driver that contains any additional instructions needed by a specific device. In many cases, however, the universal driver for a particular category of devices also includes the code needed to operate devices designed to the most common standard for that category. For example, the Unimodem driver works with all modems supporting AT commands.

Virtualization Driver

A virtualization device driver (VxD) is a 32-bit, protected-mode driver that manages system resources, such as a hardware device or a program, so that more than one program can use a resource at the same time. The term "VxD" refers to a generic virtual device driver, where the "x" represents the type of device driver. For example, a virtual device driver for a display adapter is known as a VDD (virtual display driver), a virtual device driver for a timer device is a VTD, a virtual device driver for a printer device is a VPD, and so on.

While a VxD dynamically supports device drivers, the virtual device keeps track of the status of the device for programs that use the specific device.

Win32 Driver Model

Windows 98 also uses the Win32 Driver Model (WDM) architecture, which provides a common set of input/output (I/O) services that can be understood by Windows 98 and Windows NT/2000. With WDM architecture, developers can write a single device driver for both operating systems.


Device Driver

It is our goal to explain what a device driver is in a more precise manner than the definition that we started off with.

A device driver is a set of routines statically (i.e., well ahead of need, once and for all) or dynamically (i.e., just when needed) linked into the kernel.  These routines are used as part of the mechanism to translate the general "file" (even a keyboard can be thought of as a file) handling system calls into commands that will operate the specific peripheral device.  Because the operating system handles general I/O management, the device driver must fulfill a  request by manipulating the hardware.  The device driver handles interrupts raised by the corresponding device.  The device driver is the only place where IO ports are read or written.  Separating the responsibilities of the device driver from the rest of operating system results in the ability to add new devices without having to change the operating system. 

A Windows device driver is a DLL that Windows uses to interact with a hardware device, such as a display or keyboard. Rather than access devices directly, Windows loads device drivers and calls functions in the drivers to carry out actions on the device. Each device driver exports a set of functions; Windows calls these functions to complete an action, such as drawing a circle or translating a keyboard scan code. The driver functions also contain the device-specific code needed to carry out actions on the device.

Writing device drivers requires three skills. 

  1. Drivers are written in the assembly (machine) language of the CPU, or in a low-level systems implementation language such as C.  Mastery of these languages is essential.
  2. It is possible to develop different device drivers for the same hardware device.  These design trade-offs cannot be made wisely unless the complete functionality of the device and its performance characteristics are fully understood.
  3. Device drivers are not stand-alone programs.  They are plugged-into the intricate jigsaw puzzle that an OS is.  As part of the OS, the device driver typically runs with unbridled privileges.  Mastery of the device driver interface to the given OS (Windows, Linux, etc.) is essential.
   

Procedures

In this Lab on Device Drivers, we will be only observing various related items.  Our lab machines are setup so that students do not have the privilege to change device driver settings.  If you have somehow managed to change the settings, and receive an advice from the system to shutdown and restart in order for the changes to take effect, please inform your TA and the professor before continuing further.

1.  Interrupt Numbers and Input/Output Port Addresses

The System Properties applet on the PCs in the 141 RC lab have been partially disabled.  So, follow the alternate procedure shown below as section 1.1 when you are in the 141 Russ, and follow section 1.2 when you are experimenting with your own PC.

For a device to work properly, its IRQ, IO ports, Memory Range, and DMA setting must match with those that the motherboard has set aside.  A mismatch is known as a resource conflict.  The Device Manager applet allows us to view and reset these resources.

1.1 Interrupt Numbers and Input/Output Port Addresses (141 Russ)

The program named MSD.EXE (MS Diagnostics) can show details of a PCs internals about as well as the System Properties.  But it must be run either in a DOS box within Windows, or more preferably you reboot the PC into MS-DOS and then invoke it.

  1. Click on Start/ShutDown.  Click on the radio button for restarting into MS-DOS.  Wait for the restart to complete.
  2. We installed MSD.EXE in C:\WINDOWS\COMMANDS.  Invoke it by typing the full path name:
    C:\WINDOWS\COMMANDS\MSD.EXE
  3. Explore the various tabs: CDROM, Disk Drives, Display Adapters, Floppy disk controllers, and Hard Disk Controllers.
  4. Describe what you know about each of these in a notepad journal.

1.2 Interrupt Numbers and Input/Output Port Addresses (Your own PC)

Device Manager
  1. Get to the System Properties applet.  There are two ways of doing that.  We want you try both. (a) Start/ Settings/ ControlPanel/ System. (b) Right click on the "My Computer" icon on the desk top, and choose Properties.
  2. Click on the Device Manager tab.  You will see a panel similar (not identical) to the one shown here.
  3. Print a hard copy of the screen after you expanded the CDROM, Disk Drives, Display Adapters, Floppy disk controllers, and Hard Disk Controllers.
  4. Annotate what you know about each of these.

2. Specific Device Drivers

Q2: We would like you to explore the details of at least two drivers, and turn in your discoveries as a printed text file.  Below our exploration of the display driver on a home PC is shown.  A similar exploration is possible using MSD.EXE.  Your turned in file should contain the IRQ, IO ports, memory range, and DMA information for each of the devices.

3. Device Driver Enhancements

Q3: We installed a mouse enhancement package called MouseImp.  With this enabled, you can scroll the contents of a window as follows.  Right click the mouse, and move the mouse up/down while holding the right button.  Try this and the usual scroll bar.  After a few trials, write a paragraph describing how well this user interface enhancement works for you.

4. System Tuning with X-Setup

Q4: We installed a system configuration monitoring tool called X-setup.  It is not a device driver.  Nevertheless, it interacts with the OS and the registry at level comparable to device drivers, and has a direct correlation to how the computer system behaves.  Explore the functionality of this tool.  Its Help file is self-explanatory.  As you explore what interests you in this tool, keep a journal and turn it in.

This step can take considerable amount of time.

Appendix A: Acronyms

AGP Accelerated Graphics Port
API Application programming interface
DMA Direct Memory Access
IHV Independent hardware vendors
IOCTL A device Input and Output Control
IRQ Interrupt ReQuest
ISA Industry Standard Architecture
PNP Plug and Play
VxD virtual x (some device) driver
WDM Win32 Driver Model
PCI Peripheral Component Interconnect
PIO Programmed IO
A few acronyms and their expansions are collected in the table here. If you are curious about an acronym or term not listed, type it in the input box below, and then press

the button to look it up in the TechEncyclopedia.

Appendix B:  Links

  1. For more information about dynamic-link libraries, see http://msdn.microsoft.com/ library/psdk/ winbase/ dll_512r.htm
  2. MouseImp, free download from http://www.tv4studios.com .
  3. X-Setup, "the ultimate tool for Black Belt system tuning," free download from http://www.xteq.com/  Xteq Systems makes only freeware.

Achievement Test

If you read this handout, and followed the above procedures carefully, you would have come across the answers to the following questions.  Turn in the journal you kept during the procedures and the answers to the questions below to your TA.
  1. Name at least five devices that every modern (1995--) PC has.
  2. Name the device drivers for the above.
  3. Answer Q2, Q3 and Q4
  4. What is a device driver?  Explain in a few (< 6) lines.
 
pmateti@cs.wright.edu