The Windows 2000 Device Driver Book: A Guide for Programmers

Overview


  • The #1 Windows device driver book—fully updated for Windows 2000!
  • Step-by-step planning, implementation, testing, debugging, installation, and distribution
  • Complete coverage of the new Windows Driver Model (WDM)
  • Practical debugging and interactive troubleshooting
  • ...
See more details below
Multimedia Set (REV)
$67.49
BN.com price
(Save 10%)$74.99 List Price
Other sellers (Multimedia Set)
  • All (18) from $1.99   
  • New (5) from $47.15   
  • Used (13) from $1.99   
Sending request ...

Overview


  • The #1 Windows device driver book—fully updated for Windows 2000!
  • Step-by-step planning, implementation, testing, debugging, installation, and distribution
  • Complete coverage of the new Windows Driver Model (WDM)
  • Practical debugging and interactive troubleshooting
  • CD-ROM: Exclusive tools for streamlining driver development, plus extensive C/C++ sample driver library!
  • Windows Driver Model (WDM) for Windows 2000 and 98—in depth!
  • Building drivers that support Plug-and-Play and Power Management
  • Windows Management Instrumentation: logging device errors and events—and interpreting them
  • Constructing safe reentrant driver code
  • Handling time-out conditions safely and effectively
  • Advanced techniques: kernel-mode threads, layered drivers, and more
  • Start-to-finish debugging and troubleshooting techniques

Foreword by Andrew Scoppa, UCI Corporation

The #1 book on Windows driver development—totally updated for Windows 2000!

With The Windows 2000 Device Driver Book, any experienced Windows programmer can master driver development start to finish: planning, implementation, testing, debugging, installation, and distribution. Totally updated to reflect Microsoft's Windows Driver Model (WDM) for Windows 2000 and 98, this programming bestseller covers everything from architecture to tools, and includes a powerhouse library of exclusive tools and code for streamlining any driver development project.

You'll start with a high-level overview of WDM components and then move quickly into the details of the development environment and driver installation. Next, master the Windows 2000 I/O Manager,its data structures, and its interaction with drivers. Using extensive practical examples, you'll implement Plug-and-Play and Power Management; construct safe reentrant driver code; use Windows Management Instrumentation to log errors and events, and more.

The book covers today's most advanced Windows driver development techniques and provides extensive debugging guidance, including crash dump analysis using WinDbg; lists of common bugcheck codes, meanings, and probable causes; and much more. About the CD-ROM

Bonus CD-ROM contains powerful resources for streamlining device driver development!

  • An exclusive Device Driver AppWizard that works with Visual Studio to instantly create your driver's framework
  • A library of complete sample drivers
  • C++ classes to jumpstart any project-including a Unicode string handling class that eliminates tedious, repetitive code
  • An exclusive Driver Installation Utility to simplify initial testing
UCI

UCI Software Training Centers specializes in high-end developer, systems, and Internet Training on Microsoft products and technologies. For more information about training in this topic and others, UCI can be reached at 800-884-1772, or on the Web at www.ucitraining.com

Read More Show Less

Product Details

  • ISBN-13: 9780130204318
  • Publisher: Prentice Hall
  • Publication date: 11/21/2000
  • Series: Microsoft Technologies Series
  • Edition description: REV
  • Edition number: 2
  • Pages: 480
  • Product dimensions: 7.06 (w) x 9.30 (h) x 1.01 (d)

Meet the Author

ART BAKER, founder of Cydonix Corporation, has spent 30 years writing device-control software. For 15 years, he has trained professional developers to write device drivers.

JERRY LOZANO is an Electrical Engineer and has been writing low-level device and OS code since 1976. For several years, he has been training and consulting on Microsoft system tools and development.

Read More Show Less

Read an Excerpt

Preface

This book explains how to write, install, and debug device drivers for Windows 2000. It is intended to be a companion to the Microsoft DDK documentation and software.

Windows 2000 represents a major improvement to previous versions of Windows NT. Device drivers for Windows 2000 may be designed for the new Windows Driver Model (WDM) architecture. If so, the driver will be source compatible with Windows 98. This book covers the new WDM specification.

This book will also prove useful to those studying the internals of Windows 2000, particularly the I/O subsystem and related components.What You Should Already Know

All instruction assumes a base knowledge level. First, the reader should be familiar with Windows 2000 administration—security and setup, for example. Since experimentation with kernel-mode code can (and will) cause system problems, the reader should be prepared and able to restore a chaotic OS.

Second, the reader should be competent in the C programming language and somewhat familiar with C++. Only a little C++ is used in this book, and then only for the purpose of simplifying tedious code.

Third, experience with Win32 user-mode programming is useful. Knowing how user-mode code drives I/O devices is useful in designing and testing device driver code. The test code for the examples in this book rely on the console subsystem model for Windows. To review this topic, the reader is referred to the Win32 Programmers Reference, particularly the chapters on I/O primitives (CreateFile, ReadFile, WriteFile, and DeviceIoControl). The bibliography lists other references for this topic.

Finally, while no specific prior knowledge ofhardware or device driver software design is assumed, it would be useful if the reader had experience with some aspect of low-level device interfacing. For example, knowledge of writing device drivers for a Unix system will prove quite useful when reading this book.What's Covered

The focus of this book is to first explain the architecture of the hardware, environment, and device driver, and then to explain the details of writing code.

Chapters are grouped within this book as follows:


  • Chapters 1-5: The first five chapters of this book cover the foundation of what's needed to write a device driver. This includes coverage of the Windows 2000 architecture, hardware terminology and bus basics, and an in-depth view of the Windows 2000 I/O Manager and related services.
  • Chapters 6-13: The next eight chapters form the nucleus of this book. The chapters cover everything from the mechanics of building a driver to the specifics of instrumenting a driver to log errors and other events.
  • Chapters 14-15: These two chapters deal with somewhat more advanced topics within device driver construction. This includes the use of system threads, layering, filtering, and utilizing driver classes.
  • Chapters 16-17: The final chapters deal with the practical but necessary details of driver installation and debugging. The use of Windows 2000 INF files for "automatic" installation of a plug and play device driver is covered (as well as manual installation for legacy devices). The use of WinDbg is covered in sufficient detail so that the programmer can actually perform interactive debugging.
  • Appendices: The appendices cover reference information needed for driver development. The mechanics of Windows 2000 symbol file installation, bugcheck codes, and so on are listed.
What's Not

Since the purpose of this book is to cover driver development from "the ground up," some specific topics fall outside its scope. Specifically, the list of topics not covered includes

File system drivers
Currently, the construction of a full Windows 2000 Installable File System requires the acquisition of the Microsoft IFS kit. The bibliography of this book points to one source for more information on this topic. Potential users of the IFS kit will benefit greatly from this book, as the material covered is essential prerequisite knowledge.
Device-specific driver information
The construction of NIC (Network Interface Card), SCSI, video (including capture devices), printers, and multimedia drivers is not specifically covered in this book. Chapter 1 discusses the architectural implications of such drivers, but even individual chapters on each of these driver types would seriously shortchange the requisite knowledge.
Virtual DOS device drivers
The current wave of driver development is toward the WDM 32-bit model. Legacy 16-bit VDDs are no longer of interest.
About the Sample Code

Most chapters in this book include one or more sample drivers. All code is included on the accompanying CD. Samples for each chapter are in separate subdirectories on the CD, so installation of individual projects is straightforward.

The CD also includes a device driver application wizard for Microsoft Visual C++ version 6. This wizard configures the build environment so that code can be written, compiled, and linked within Visual Studio.

Platform dependencies:
The sample code included with this book has been targeted and tested on Intel platforms only. Since it appears that the last non-Intel platform (Alpha) was dropped from the final release of Windows 2000, this should come as no surprise. Be advised, however, that Windows 2000 is intrinsically a platform-independent OS. It is a straightforward process to port the OS to many modern hardware sets. Driver writers should consider designs that take advantage of the Windows 2000 abstractions that permit source compatibility with non-Intel platforms.
To build and run the examples:
Besides the Microsoft DDK (Device Driver Kit) (which is available on an MSDN subscription or, at present, free for download from the Microsoft web site at www.microsoft.com/DDK), the sample code assumes that Microsoft Visual C++ is installed. The device driver application wizard was built for Visual Studio version 6. Obviously, with some effort the sample code can be built using other vendors' compilers.

Of course, an installed version of Windows 2000 (Professional, Server, or Enterprise) is required. For interactive debugging using WinDbg, a second host platform is required.History of this Book

The first version of this book was written by Art Baker, entitled The Windows NT Device Driver Book. By any account, the book was required reading for any NT driver author. The Microsoft driver model is a continuously moving target. As such, recently introduced books on this subject provided more and up-to-date information. The goal of this revision of the book is to carry forward the goals, style, and clarity of Art's original work while updating the material with the very latest information available from Microsoft.

If you are a previous reader of the original version of this book, I hope you will find this version just as useful. I have attempted to provide accurate, concise, and clear information on the subject of Windows 2000 device drivers. While I have relied heavily on Art's original work, any errors present in this book are entirely mine.Training and Consulting Services

The material in this book is based on training and consulting performed for various companies within the industry.

The subject matter of this book is presented exclusively by UCI in the format of a five-day instructor-lead lecture/lab course. The course is available as public or on site classes. UCI provides comprehensive training in high-end programming, web development and administration, databases, and system technologies.

For more information please visit the UCI web site at www.ucitraining.com or use the address information below:

UCI Corporation
4 Constitution Way
Suite G
Woburn, MA 01801

1-800-884-1772

The revision author, Jerry Lozano, provides seminars and workshops on the topic of device drivers and other related subjects. For more information visit the web site: www.StarJourney.com

Read More Show Less

Table of Contents



1. Introduction to Windows 2000 Drivers.

Overall System Architecture. Design Goals for Windows 2000. Hardware Privilege Levels in Windows 2000. Portability. Extendability. Performance. Executive Components. System Service Interface. Object Manager. Configuration Manager. Process Manager. Virtual Memory Manager. Local Procedure Call Facility. I/O Manager. Active Directory Service. Extensions to the Base Operating System. The Win32 Subsystem. Integral Subsystems. Kernel-Mode I/O Components. Design Goals for the I/O Subsystem. Kinds of Drivers in Windows 2000. Special Driver Architectures. Video Drivers. Printer Drivers. Multimedia Drivers. Network Drivers. Summary.

2. The Hardware Environment.

Hardware Basics. Device Registers. Command. Status. Data. Accessing Device Registers. I/O Space Registers. Memory-Mapped Registers. Device Interrupts. Interrupt Priority. Interrupt Vectors. Signaling Mechanisms. Processor Affinity. Data Transfer Mechanisms. Programmed I/O. Direct Memory Access. DMA Mechanisms. System DMA. Bus Master DMA. Device-Dedicated Memory. Auto-regulation and Auto-configuration. Device Resource Lists. No Jumpers or Switches. Change Notification. Buses and Windows 2000. ISA: The Industry Standard Architecture. Register Access. Interrupt Mechanisms. DMA Capabilities. Automatic Recognition and Configuration. EISA: The Extended Industry Standard Architecture. Register Access. Interrupt Mechanisms. DMA Capabilities. Device Memory. Automatic Recognition and Configuration. PCI: The Peripheral Component Interconnec. Register Access. Interrupt Mechanisms. DMA Capabilities. Device Memory. Autoconfiguration. USB:The Universal Serial Bus. Register Access. Interrupt Mechanisms. DMA Capabilities. Automatic Recognition and Configuration. IEEE 1394: The FirewireTM Bus. Register Access. Interrupt Mechanisms. DMA Capabilities. Automatic Recognition and Configuration. The PC Card (PCMCIA) Bus. Register Access. Interrupt Mechanisms. DMA Capabilities. Automatic Recognition and Configuration. Hints for Working with Hardware. Learn about the Hardware. Bus Architecture. Control Registers. Error and Status Reporting. Interrupt Behavior. Data Transfer Mechanisms. Device Memory. Make Use of Hardware Intelligence. Test the Hardware. Basic Tests. Standalong Tests. Summary.

3. Kernel-Mode I/O Processing.

How Kernel-Mode Code Executes. Trap or Exception Context. Interrupt Context. Kernel-Mode Thread Context. Use of Interrupt Priorities by Windows 2000. CPU Priority Levels. Interrupt Processing Sequence. Software-Generated Interrupts. Deferred Procedure Calls (DPCs). Operation of a DPC. Behavior of DPCs. Accessing to User Buffers. Buffer Access Mechanisms. Structure of a Kernel-Mode Driver. Driver Initialization and Cleanup Routines. DriverEntry Routine. Reinitialization Routine. Unload Routine. Shutdown Routine. Bugcheck Callback Routine. I/O System Service Dispatch Routines. Open and Close Operations. Device Operations. Data Transfer Routines. Start I/O Routing. Interrupt Service Routine (ISR). DPC Routines. Resource Synchronization Callbacks. ControllerControl Routine. AdapterControl Routine. SynchCritSection. Other Driver Routines. I/O Processing Sequence. Preprocessing by the I/O Manager. Preprocessing by the Device Driver. Device Start and Interrupt Service. Start I/O. ISR. Postprocessing by the Driver. Postprocessing by the I/O Manager. Summary.

4. Drivers and Kernel-Mode Objects.

Data Objects and Windows 2000. Windows 2000 and OOP. Windows 2000 Objects and Win32 Objects. I/O Request Packets (IRPs). Layout of an IRP. IRP Header. I/O Stack Locations. Manipulating IRPs. IRPs as a Whole. IRP Stack Locations. Driver Objects. Layout of a Driver Object. Device Objects and Device Extensions. Layout of the Device Object. Manipulating Device Objects. Device Extensions. Controller Objects and Controller Extensions. Layout of the Controller Object. Manipulating Controller Objects. Controller Extensions. Adapter Objects. Layout of an Adapter Object. Manipulating Adapter Objects. Interrrupt Objects. Layout of an Interrupt Object. Manuipulating Interrupt Objects. Summary.

5. General Development Issues.

Driver Design Strategies. Use Formal Design Methods. Use Incremental Development. Examine and Use the Sample Drivers. Coding Conventions and Techniques. General Recommendations. Naming Conventions. Header Files. Status Return Values. Windows 2000 Driver Support Routines. Discarding Initialization Routines. Controlling Driver Paging. Driver Memory Allocation. Memory Available to Drivers. Working with the Kernel Stack. Working with the Pool Areas. System Support for Memory Suballocation. Zone Buffers. Lookaside Lists. Unicode Strings. Unicode String Data Types. Working with Unicode. Interrupt Synchronization. The Problem. Interrupt Blocking. Rules for Blocking Interrupts. Synchronization Using Deferred Procedure Calls. Synchronizing Multiple CPUs. How Spin Locks Work. Using Spin Locks. Rules for Using Spin Locks. Linked Lists. Singly Linked Lists. Doubly Linked Lists. Removing Blocks from a List. Summary.

6. Initialization and Cleanup Routines.

Writing a DriverEntry Routine. Execution Context. What a DriverEntry Routine Does. Announcing DriverEntry Points. Creating Device Objects. Choosing a Buffering Strategy. Device Names. Code Example: Driver Initialization. DriverEntry. CreatDevice. Writing Reinitialize Routines. Executive Context. What a Reinitialize Routine Does. Writing and Unload Routine. Execution Context. What an Unload Routine Does. Code Example: Driver Unload. Writing Shutdown Routines. Execution Context. What a Shutdown Routine Does. Enabling a Shutdown Notification. Testing the Driver. Testing Procedure. Visual C++ Device Driver AppWizard. The WIndows 2000 DDK. Results of the Driver Build. Installing a Kernel-Mode Driver Manually. Loading the Driver. Windows 2000 Computer Management Console. The WINOBJ Utility. Summary.

7. Driver Dispatch Routines.

Announcing Driver Dispatch Routines. I/O Request Dispatching Mechanism. Enabling Specific Function Codes. Deciding Which Function Codes to Support. Writing Driver Dispatch Routines. Execution Context. What Dispatch Routines Do. Exiting the Dispatch Routine. Signaling an Error. Completing a Request. Scheduling a Device Operation. Processing Read and Write Requests. User Buffer Access. Buffered I/O. Direct I/O. Neither Method. Code Example: A Loopback Device. Extending the Dispatch Interface. Defining Private IOCTL Values. IOCTL Argument-Passing Methods. Writing IOCTL Header Files. Processing IOCTL Requests. Managing IOCTL Buffers. METHOD_BUFFERED. MEHTOD_IN_DIRECT. METHOD_OUT_DIRECT. METHOD_NEITHER. Testing Driver Dispatch Routines. Testing Procedure. Sample Test Program. Summary.

8. Interrupt-Driven I/O.

How Programmed I/O Works. What Happens During Programmed I/O. Synchronizing Driver Routines. Driver Initialization and Cleanup. Initializing the Start I/O Entry Point. Initializing a DpcForIsr Routine. Connecting to an Interrupt Source. Disconnecting from an Interrupt Source. Writing a Start I/O Routine. Execution Context. What the Start I/O Routine Does. Writing an Interrupt Service Routine (ISR). Execution Context. What the Interrupt Service Routine Does. Writing a DpcForIsr Routine. Execution Context. What the DpcForIsr Routine Does. Priority Increments. Some Hardware: The Parallel Port. How the Parallel Port Works. Device Registers. Interrupt Behavior. A Loopback Connector for the Parallel Port. Code Example: Parallel Port Loopback Driver. Purpose of the Driver. Driver.H. Driver.cpp. CreateDevice. DispatchWrite. DispatchRead. StartIo. ISR. DpcForIsr. Testing the Parallel Port Loopback Driver. Testing Procedure. Summary.

9. Hardware Initialization.

The Plug and Play Architecture: A Brief History. Goals of Plug and Play. Components of Plug and Play. Plug and Play Manager. Power Manager. Registry. INF Files. Plug and Play Drivers. The Role of the Registry for Legacy Drivers. Detecting Devices with Plug and Play. The Role of Driver Layers in Plug and Play. The New WDM IRP Dispatch Functions. Required Plug and Play IRPs. PDO Plug and Play IRPs. Passing Down Plug and Play Requests. I/O Completion Routines. Bus Driver Plug and Play Requests. Device Enumeration. Hardware Resource Descriptions. Using Hardware Resources within the Driver. Driver Interfaces. Interface Definition. Interface Construction. Interface Reference Counting. Registering and Enabling an Interface. Code Example: A Simple Plug and Play Driver. Summary.

10. Power Management.

Hot Plug Devices. Bus Considerations. Device Considerations. OnNow Initiative. Power States. Power Policies. Power State Matrix. Power State Changes. Wake Requests. Canceling the Wake-Armed IRP. Power Management Issues. Idle Management. User Interface for Power Management. Summary.

11. Timers.

Handling Device Timeouts. How I/O Timer Routines Work. How to Catch Device Timeout Conditions. Code Example: Catching Device Timeouts. Device Extension Additions. AddDevice Additions. Create Dispatch Routine Changes. StartIo Changes. ISR Changes. I/O Timer Callback Routine. Managing Devices without Interrupts. Working with Polled Devices. How CustomTimerDpc Routines Work. How to Set Up a CustomTimerDpc Routine. How to Specify Expiration Times. Other Uses for CustomTimerDpc Routines. Code Example: A Timer-Based Driver. Device Extension Additions. AddDevice Modifications. TransmitBytes Changes. PollingTimerDpc Routine. Summary.

12. DMA Drivers.

How DMA Works under Windows. Hiding DMA Hardware Variations with Adapter Objects. The Scatter/Gather Problem. Memory Descriptor Lists. Maintaining Cache Coherency. CPU Data Cache. Adapter Object Cache. Packet-Based and Common Buffer DMA. Limitations of the Windows 2000 DMA Architecture. Working with Adapter Objects. Finding the Right Adapter Object. Acquiring and Releasing the Adapter Object. Setting Up the DMA Hardware. Flushing the Adapter Object Cache. Writing a Packet-Based Slave DMA Driver. How Packet-Based Slave DMA Works. IRP_MN_START_DEVICE Handler. Start I/O Routine. Adapter Control Routine. Interrupt Service Routine. DpcForIsr Routine. Splitting DMA Transfers. First Transfer. Additional Transfers. Code Example: A Packet-Based Slave DMA Driver. DRIVER.H. GetDmaInfo Routine. Start I/O Changes. AdapterControl Routine. DpcForIsr Routine. Writing a Packet-Based Bus Master DMA Driver. Setting Up Bus Master Hardware. AdapterControl Routine. DpcForIsr Routine. Hardware with Scatter/Gather Support. Building Scatter/Gather Lists with Map Transfer. AdapterControl Routine. DpcForIsr Routine. Writing a Common Buffer Slave DMA Driver. Allocating a Common Buffer. Using Common Buffer Slave DMA to Maintain Throughput. AddDevice Routine. IRP_MN_START_DEVICE Handler. Dispatch Routine. Start I/O Routine. Interrupt Service Routine. DpcForIsr Routine. IRP_MN_STOP_DEVICE Handler. Writing Common Buffer Bus Master DMA Driver. How Common-Buffer Bus Master DMA Works. IRP_MN_START_DEVICE Handler. Start I/O Routine. Interrupt Service Routine. IRP_MN_STOP_DEVICE Handler. Summary.

13. Windows Management and Instrumentation.

WMI: The Industry Picture. The WMI Architecture. Providing WMI Support in a WDM Driver. MOF Syntax. Example MOF Class Definition. Compiling the MOF Source. Handling WMI IRP Requests. Classes and Instances. WMILIB. DpWmiQueryReginfo. DpWmiQueryDataBlock. DpWmiSetDataBlock. DpWmiSetDataItem. DpWmiExecuteMethod. DpWmiFunctionControl. WMI Summary. Conventional Driver Event Logging. How Event Logging Works. Working with Messages. Writing a Message Definition Files. A Simple Example. Header Section. Message Section. Compiling a Message Definition File. Adding Message Resources to a Driver. Registering a Driver as an Event Source. Generating Log Entries. Allocating an Error-Log Packet. Logging the Error. Summary.

14. System Threads.

Definition and Use of System Threads. When to Use Threads. Creating and Terminating System Threads. Managing Thread Priority. System Worker Threads. Thread Synchronization. Time Synchronization. General Synchronization. KeWaitForSingleObject. KeWaitForMultipleObjects. Using Dispatcher Objects. Event Objects. Sharing Events Between Drivers. Mutex Objects. Semaphore Objects. Timer Objects. Thread Objects. Variations on the Mutex. Fast Mutexes. Executive Resources. Synchronization Deadlocks. Code Example: A Thread-Based Driver. How the Driver Works. The DEVICE_EXTENSION Structure. The AddDevice Function. The DispatchReadWrite Function. Thread.C. WorkerThreadMain. KillThread. Transfer.C. PerformDataTransfer. AcquireAdapterObject and AdapterControl. PerformSynchronousTransfer. DpcForIsr. Summary.

15. Layered Drivers.

An Overview of Intermediate Drivers. Intermediate Drivers Defined. When to Use a Layered Architecture. Pros of Layered Architecture. Cons of Layered Architecture. Writing Layered Drivers. How Layered Drivers Work. Initialization and Cleanup in Layered Drivers. DriverEntry. AddDevice. RemoveDevice. Code Fragment: COnnecting to Another Driver. Other Initialization Concerns for Layered Drivers. Transparent. Virtual or Logical Device Layer. I/O Request Processing in Layered Drivers. Complete the Original IRP. Pass the IRP to Another Driver. Allocate Additional IRPs. Code Fragment: Calling a Lower-Level Driver. Writing I/O Completion Routines. Requesting an I/O Completion Callback. Execution Context. What I/O Completion Routines Do. Release the Original IRP. Deallocate the IRP. Recycle the IRP. Code Fragment: An I/O Completion Routine. Allocating Additional IRPs. The IRP's I/O Srtack Revisited. Controlling the Size of the IRP Stack. Creating IRPs with IoBuildSynchronousFsdRequest. Creating IRPs with IoBuildAsynchronousFsdRequest. Creating IRPs with IoBuildDevice IoControlRequest. Creating IRPs from Scratch. IRPs from IoAllocateIrp. IRPs from ExAllocatePool. IRPs from Driver-Managed Memory. Setting Up Buffers for Lower Drivers. Buffered I/O Requests. Direct I/P Requests. Keeping Track of Driver-Allocated IRPs. Synchronous I/O. Asynchronous I/O. Writing Filter Drivers. How Filter Drivers Work. Initialization and Cleanup in Filter Drivers. AddDevice Routine. RemoveDevice Routine. Making the Attachment Transparent. Code Example: A Filter Driver. The DEVICE_EXTENSION Structure. The DriverEntry Fuction. The AddDevice Function. GetBufferLimits. The OverriddenDispatchWrite Function. The OverriddenDispatchDeviceIoControl Function. The DispatchPassThru Function. The I/O Completion Routines. WriteCompletion. GenericCompletion. Writing Tightly Coupled Drivers. How Tightly Coupled Drivers Work. Initialization and Cleanup in Tightly Coupled Drivers. Lower AddDevice Routine. Upper AddDevice Routine. Upper RemoveDevice Routine. Lower RemoveDevice Routine. Summary.

16. Driver Installation.

Installation of a Driver. Auto-Install Using INF Files. INF File Structure. Version Section. Manufacturers Section. Models Section. DDInstall Section. CopyFiles Section. AddReg Section. SourceDisksNames Section. SourceDisksFiles Section. DestinationDirs Section. DDInstall.Services Section. ServiceInstall Section. INF Example. Validating INF Syntax. Using a Driver INF File. Manual Installation. Automatic Installation. The Add/Remove Hardware Wizard. Class Names and Device IDs. Customizing an Installation. Controlling Driver Load Sequence. Driver Stack Order. Digital Signing of a Driver. Why Microsoft Verifies Drivers. Digital Signatures. Summary.

17. Testing and Debugging Drivers.

Guidelines for Driver Testing. A Generalized Approach to Testing Drivers. When to Test. What to Test. How to Develop the Tests. How to Perform the Tests. Who Should Perform the Tests. The Microsoft Hardware Compatibility Tests. Why Drivers Fail. Categories of Driver Errors. Hardware Problems. System Crashes. Resource Leaks. Thread Hangs. System Hangs. Reproducing Driver Errors. Time Dependencies. Multiprocessor Dependencies. Multithreading Dependencies. Other Causes. Defensive Coding Strategies. Keeping Track of Driver Bugs. Reading Crash Screens. What Happens When the System Crashes. The Blue Screen of Death. An Overview of WinDbg. The Key to Source Code Debugging. Symbol Directories. Source Code Directories. Some WinDbg Commands. Analyzing a Crash Dump. Goals of the Analysis. Starting the Analysis. Tracing the Stack. High IRQL Crashes. Crashes Below DISPATCH_LEVEL. Indirect Methods of Investigation. Finding I/O Requests. Examining Processes. Interactive Debugging. Starting and Stopping a Debug Session. Setting Breakpoints. Setting Hard Breakpoints. Intermediate Output. Writing WinDbg Extensions. How WinDbg Extensions Work. Initialization and Version-Checking Functions. WinDbgExtensionDllInit. ExtensionApiVersion. CheckVersion. Writing Extension Commands. WinDbg Helper Functions. Building and Using an Extension DLL. Code Example: A WinDbg Extension. DBG.C. Header. Globals. Required Functions. Command Routines. Sample Output. Miscellaneous Debugging Techniques. Leaving Debugged Code in the Driver. Catching Incorrect Assumptions. Using Bugcheck Callbacks. Catching Memory Leaks. Using Counters, Bits, and Buffers. Sanity Counters. Event Bits. Trace Buffers. Summary.

A. The Driver Debug Environment.


B. Bugcheck Codes.


C. Building Drivers.


Bibliography.


Index.

Read More Show Less

Preface

Preface

This book explains how to write, install, and debug device drivers for Windows 2000. It is intended to be a companion to the Microsoft DDK documentation and software.

Windows 2000 represents a major improvement to previous versions of Windows NT. Device drivers for Windows 2000 may be designed for the new Windows Driver Model (WDM) architecture. If so, the driver will be source compatible with Windows 98. This book covers the new WDM specification.

This book will also prove useful to those studying the internals of Windows 2000, particularly the I/O subsystem and related components.

What You Should Already Know

All instruction assumes a base knowledge level. First, the reader should be familiar with Windows 2000 administration—security and setup, for example. Since experimentation with kernel-mode code can (and will) cause system problems, the reader should be prepared and able to restore a chaotic OS.

Second, the reader should be competent in the C programming language and somewhat familiar with C++. Only a little C++ is used in this book, and then only for the purpose of simplifying tedious code.

Third, experience with Win32 user-mode programming is useful. Knowing how user-mode code drives I/O devices is useful in designing and testing device driver code. The test code for the examples in this book rely on the console subsystem model for Windows. To review this topic, the reader is referred to the Win32 Programmers Reference, particularly the chapters on I/O primitives (CreateFile, ReadFile, WriteFile, and DeviceIoControl). The bibliography lists other references for this topic.

Finally, while no specific prior knowledge of hardware or device driver software design is assumed, it would be useful if the reader had experience with some aspect of low-level device interfacing. For example, knowledge of writing device drivers for a Unix system will prove quite useful when reading this book.

What's Covered

The focus of this book is to first explain the architecture of the hardware, environment, and device driver, and then to explain the details of writing code.

Chapters are grouped within this book as follows:

  • Chapters 1-5: The first five chapters of this book cover the foundation of what's needed to write a device driver. This includes coverage of the Windows 2000 architecture, hardware terminology and bus basics, and an in-depth view of the Windows 2000 I/O Manager and related services.
  • Chapters 6-13: The next eight chapters form the nucleus of this book. The chapters cover everything from the mechanics of building a driver to the specifics of instrumenting a driver to log errors and other events.
  • Chapters 14-15: These two chapters deal with somewhat more advanced topics within device driver construction. This includes the use of system threads, layering, filtering, and utilizing driver classes.
  • Chapters 16-17: The final chapters deal with the practical but necessary details of driver installation and debugging. The use of Windows 2000 INF files for "automatic" installation of a plug and play device driver is covered (as well as manual installation for legacy devices). The use of WinDbg is covered in sufficient detail so that the programmer can actually perform interactive debugging.
  • Appendices: The appendices cover reference information needed for driver development. The mechanics of Windows 2000 symbol file installation, bugcheck codes, and so on are listed.

What's Not

Since the purpose of this book is to cover driver development from "the ground up," some specific topics fall outside its scope. Specifically, the list of topics not covered includes

File system drivers
Currently, the construction of a full Windows 2000 Installable File System requires the acquisition of the Microsoft IFS kit. The bibliography of this book points to one source for more information on this topic. Potential users of the IFS kit will benefit greatly from this book, as the material covered is essential prerequisite knowledge.
Device-specific driver information
The construction of NIC (Network Interface Card), SCSI, video (including capture devices), printers, and multimedia drivers is not specifically covered in this book. Chapter 1 discusses the architectural implications of such drivers, but even individual chapters on each of these driver types would seriously shortchange the requisite knowledge.
Virtual DOS device drivers
The current wave of driver development is toward the WDM 32-bit model. Legacy 16-bit VDDs are no longer of interest.

About the Sample Code

Most chapters in this book include one or more sample drivers. All code is included on the accompanying CD. Samples for each chapter are in separate subdirectories on the CD, so installation of individual projects is straightforward.

The CD also includes a device driver application wizard for Microsoft Visual C++ version 6. This wizard configures the build environment so that code can be written, compiled, and linked within Visual Studio.

Platform dependencies:
The sample code included with this book has been targeted and tested on Intel platforms only. Since it appears that the last non-Intel platform (Alpha) was dropped from the final release of Windows 2000, this should come as no surprise. Be advised, however, that Windows 2000 is intrinsically a platform-independent OS. It is a straightforward process to port the OS to many modern hardware sets. Driver writers should consider designs that take advantage of the Windows 2000 abstractions that permit source compatibility with non-Intel platforms.
To build and run the examples:
Besides the Microsoft DDK (Device Driver Kit) (which is available on an MSDN subscription or, at present, free for download from the Microsoft web site at www.microsoft.com/DDK), the sample code assumes that Microsoft Visual C++ is installed. The device driver application wizard was built for Visual Studio version 6. Obviously, with some effort the sample code can be built using other vendors' compilers.

Of course, an installed version of Windows 2000 (Professional, Server, or Enterprise) is required. For interactive debugging using WinDbg, a second host platform is required.

History of this Book

The first version of this book was written by Art Baker, entitled The Windows NT Device Driver Book. By any account, the book was required reading for any NT driver author. The Microsoft driver model is a continuously moving target. As such, recently introduced books on this subject provided more and up-to-date information. The goal of this revision of the book is to carry forward the goals, style, and clarity of Art's original work while updating the material with the very latest information available from Microsoft.

If you are a previous reader of the original version of this book, I hope you will find this version just as useful. I have attempted to provide accurate, concise, and clear information on the subject of Windows 2000 device drivers. While I have relied heavily on Art's original work, any errors present in this book are entirely mine.

Training and Consulting Services

The material in this book is based on training and consulting performed for various companies within the industry.

The subject matter of this book is presented exclusively by UCI in the format of a five-day instructor-lead lecture/lab course. The course is available as public or on site classes. UCI provides comprehensive training in high-end programming, web development and administration, databases, and system technologies.

For more information please visit the UCI web site at www.ucitraining.com or use the address information below:

UCI Corporation
4 Constitution Way Suite G Woburn, MA 01801

1-800-884-1772

The revision author, Jerry Lozano, provides seminars and workshops on the topic of device drivers and other related subjects. For more information visit the web site: www.StarJourney.com

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted August 26, 2001

    Excellent book

    This is one of the best books i have read. I have several years of experience in C/C++ and some experience in windows programming however I am a 'absolute beginner' with Windows device drivers and kernel mode programming and i was able to grasp almost everything the book spoke about with relative ease and with NO confusions. I would recommend this book to anyone who has absolutely no background in device driver programming but wants to make a career doing just that. I must admit that the books assumes that you are versed with C/C++ and some understanding of programming paradigm for windows, but it is pretty obvious since this is not a book to teach a programming language nor it is aimed at teaching regular windows programming. It is a complete 'NO NONSENSE' book that deals with topics right upto the point. The contents of the book flow gracefully explaining each and every step with precise detail. The author seems to have made the best possible effort to explain the basics before jumping directly into details. And that does help an absolute beginner. This book does not cover details about device specific drivers but it does help you reach a point where you are confident that 'you will understand' whatever you research on your own. A very good book... have seen very few of these types lately.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)