Windows NT Device Driver Book: A Guide for Programmers, with Disk with Cdrom

  • Authors:
  • Art Baker

  • Affiliations:
  • -

  • Venue:
  • Windows NT Device Driver Book: A Guide for Programmers, with Disk with Cdrom
  • Year:
  • 1996

Quantified Score

Hi-index 0.00

Visualization

Abstract

From the Book:PREFACE: In case you haven't guessed, this book explains how to write, install, and debug kernel-mode device drivers for Windows NT. If you're in the process of designing or coding an NT driver, or if you're porting an existing driver from some other operating system, this book is a valuable companion to the Microsoft DDK documentation. This book might also have something to say to you if you just need a little more insight into the workings of Windows NT, particularly the I/O subsystem. Perhaps you're trying to decide if NT is a reasonable platform for some specific purpose. Or you may be studying operating systems, and you want to see how theory gets applied in the real world. And of course, we mustn't discount the power of morbid curiosity. The same fascination that forces us to slow down as we drive past a car accident can also motivate us to pull a volume off the bookstore shelf. What You Should Already Know Throughout this book, I make several assumptions about what you already know. First of all, you need to have all the basic Windows NT user skills such as logging in and running various utilities. Since driver installation requires you to have administrator-level privileges, you can trash things pretty badly if you don't know how to use the system. Second, you'll need decent C-language programming skills. I've tried to avoid the use of “cleverness” in my code examples, but you still have to be able to read them. Next, some experience with Win32 user-mode programming is helpful, but it isn't really required. If you haven't worked with the Win32 API, you might want to browse throughvolumetwo of the Win32 Programmers Reference. This is the one that describes system services. Take a look at the chapters on the I/O primitives (CreateFile, ReadFile, WriteFile, and DeviceIoControl) and the thread-model. See the bibliography for other books on Win32 programming. Finally, you need to understand something about hardware in order to write drivers. It would be helpful if you already had some experience working with hardware, but if not, Chapter 2 will give you a basic introduction. Again, the bibliography will point you toward other, more-detailed sources for this kind of information. What You'll Find Here One of the most difficult choices any author has to make is deciding what to write about and what to leave out. In general, I've attempted to focus on core issues that are crucial to kernel-mode driver development. I've also tried to provide enough background information so that you'll be able to read the sample code supplied with the NT DDK, and make intelligent design choices for your own drivers. The overall flow of the book goes from the theoretical to the practical, with earlier chapters providing the underpinnings for later topics. Here's what's covered: Chapters 1-5: The first part of this book provides the basic foundation you'll need if you plan to write drivers. This includes a general examination of the Windows NT driver architecture, a little bit about hardware, and a rather detailed look at the NT I/O Manager and its data structures. This group of topics ends with some general kernel-mode coding guidelines and techniques. Chapters 6-13: These eight chapters form the nucleus of the book and present all the details of writing kernel-mode NT device drivers. You'll also find discussions here of full-duplex driver architectures, handling timeout conditions, and logging device errors. Unless you're already familiar with NT's driver architecture, you should probably read these chapters in order. Chapters 14 and 15: The next two chapters deal with alternative driver architectures supported by Windows NT. This includes the use of kernel-mode threads in drivers and higher-level drivers. Chapters 16-18: The final part of the book deals with various practical details of writing NT drivers. Chapter 16 takes a look at all the things your mother never told you about the BUILD utility. Chapter 17 covers various aspects of testing and debugging drivers, including how to analyze crash dumps and how to really get WINDBG to work. If you're actually writing a driver while you read this book, you may want to read these chapters out of order. Chapter 18 examines the crucial issue of driver performance and how to tie your driver into NT's performance monitoring mechanisms. Appendices: The appendices cover various topics that people in my classes have asked about. The first one deals with the mechanics of setting up a driver development environment. The second appendix contains a list of the bugcheck codes you're most likely to encounter, along with descriptions of their various parameters. Used in conjunction with the material in Chapter 17, this may help you track down the cause of a blue screen or two. What You Won't Find I excluded topics from this book for several reasons. Some subjects were just too large to cover. Others addressed the needs of too small a segment of the driver-writing community. Finally, some areas of driver-development are simply unsupported by Microsoft. Specifically, you won't find anything here about the following items: File system drivers: At the time this book went to press, Microsoft still hadn't released any kind of developer's kit for NT file system drivers. In fact, there seemed to be a great deal of resistance to the idea within Microsoft. Until this situation changes, there's not much point in talking about the architecture of file system drivers. Net-card and network protocol drivers: NDIS and TDI drivers are both very large topics—large enough to fill a book of their own. Unfortunately, there just wasn't enough room for all of it here. I can offer one bit of consolation: The material in this book will give you much of the background you need in order to understand what's happening inside the NDIS/TDI framework. SCSI miniport and class drivers: Although SCSI HBA miniport drivers are vital system components, the number of people actually writing them is (I suspect) rather small. Consequently, the only reference to SCSI miniports is the overview material in Chapter 1. I would have liked to include a discussion of SCSI class drivers in this book, but unfortunately there just wasn't any time to write it. The material on developing intermediate drivers in Chapter 15 will give you much of the necessary background. Fro m there, take a look at the sample SCSI class driver for CD-ROMs that comes with the NT DDK. Video, display, and printer drivers: This is another area where I had to make a tradeoff between the number of people writing these kinds of drivers and the time available to finish the book. Unfortunately, graphics drivers for video and hardcopy de vices didn't make the cut this time. Perhaps in a later, expanded version of the book. Virtual DOS device drivers: In my opinion, the best way to run 16-bit MS-DOS and Windows applications under Windows NT is to port the source code to Win32. In any event, the Microsoft documentation does a decent job describing the mechanics of writing VDDs so I haven't included anything about them here. About the Sample Code There's a great deal of sample driver code scattered throughout this book. You'll find all of it on the accompanying floppy disk. I've created separate directories on the floppy for each chapter, and where appropriate, subdirectories for each component or driver in the chapter. Coding style: Since the purpose of this book is instruction, I've done a couple things to improve the clarity of the samples. First, I've adopted a coding style that avoids smart tricks. Some of the examples could probably have been written in fewer lines of code, but I don't think they would have been as easy to understand. Also in the name of clarity, I've eliminated everything except the bare essentials from each sample. For example, most of the drivers don't contain any error-logging or debugging code, although a real driver ought to include these things. These topics have their own chapters, and you shouldn't have too much trouble back-fitting the code into other sample drivers. Naming conventions: You'll notice that almost all the sample drivers appearing in this book are called “XXDRIVER.” (The only exception is the higher-level driver Chapter 15. Its name is “YYDRIVER.”) This makes it somewhat easier to interchange the parts of different samples. It also reduces the amount of clutter that you'll be adding to the Registry while you're playing with these drivers. Within any particular driver, I've also adopted the convention of adding the prefix, Xx to the names of any driver-defined functions. Similarly, device registers, driver structures, and constants are also prefixed with XX_. This makes it easy to see which things you have to write and which ones come from the folks at Microsoft. Platform dependencies: It's worth mentioning that these samples have been targeted to run on Intel 80x86 platforms. In particular, the drivers all assume that device registers live in I/O space rather than being memory-mapped. This is relatively easy to fix with a little bit of coding and some modifications to each driver's hardware-specific header file. To build and run the examples: You'll need several tools if you plan to do any driver development for Windows NT. First, get yourself a Level II subscription to the Microsoft Developer Network CDs. This is the only source for the NT DDK and the Win3 2 SDK. You'll also need a C compiler. I've chosen to use the Microsoft compiler for developing and testing all the code in this book. Your mileage may vary if you're using some other vendor's tools. See Appendix A for more information on setting up your driver development environment. Training and Consulting Services The material in this book is based on classes that I've been delivering for several years through Cydonix Corporation—a training and consulting firm whose goal is to help its clients develop device drivers and other high-performance Windows NT soft ware. Cydonix offers services that range from formal classroom training to direct participation in software design and coding. For the past three years, Cydonix has been helping companies like Adaptec, AT&T, Compaq Computers, Hewlett-Packard, and Intel to learn more about the workings of Windows NT. We have training available in a number of areas including: Windows NT device driver programming Win32 system service programming Advanced server development techniques Cydonix offers both onsite training at customer facilities and open enrollment classes that are available to the general public. The public classes are hosted by training vendors in several geographic areas. For more information about training and consulting from Cydonix Corporation, visit our Web site at ...