Книга: Writing Windows WDM Device Drivers
Win32 Interface
Win32 Interface
The WdmIo driver is a Plug and Play driver for Windows 98 and Windows 2000. It is based on most of the previous drivers. However, it does not support Power Management, WMI, or NT events. Its installation INF file specifies the resources that are available to a WdmIo device. A WdmIo device must have one (and only one) I/O port address range. It usually has one interrupt line resource as well. This is needed if interrupt-driven reads or writes are to be used. More than one WdmIo device can be installed, provided that separate INF files with different resources are used.
The PHDIo driver is an NT style driver, primarily for NT 3.51, NT 4, and Windows 2000. However, it works perfectly well in Windows 98. When the driver is loaded, it creates one device called .PHDIo. The I/O port and interrupt resources are specified as a part of the filename used to open a handle to this device. Again, one I/O port must be given, and one interrupt can be specified, if need be.
Win32 programs must open a handle to a WdmIo or PHDIo device. WdmIo devices are accessed using the device interface identified by WDMIO_GUID. The one PHDIo device has a symbolic link name of .PHDIo. However, the filename passed to CreateFile must include a definition of the resources required.
Having opened a handle to a WdmIo or PHDIo device, the Win32 program can use several IOCTLs as well as issuing read and write requests. Finally, it must close the device handle.
IOCTLs
Table 15.1 lists the supported IOCTLs, including whether they need input or output parameters.
Most of the IOCTLs pass an input buffer that contains one or more PHDIO commands and their parameters.
IOCTL_PHDIO_RUN_CMDS is used to run a set of commands straightaway. The three following IOCTLs store the commands that are used later in the processing of read and write requests. Finally, IOCTL_PHDIO_GET_RW_RESULTS retrieves the command results and output from the last read or write.
Table 15.1 WdmIo and PHDIo IOCTL codes
IOCTL | Input | Output | Description |
---|---|---|---|
IOCTL_PHDIO_RUN_CMDS |
Yes | Optional | Run the passed commands |
IOCTL_PHDIO_CMDS_FOR_READ |
Yes | No | Store the commands to read a byteand store in the read buffer |
IOCTL_PHDIO_CMDS_FOR_READ_START |
Yes | No | Store the commands that start theread process |
IOCTL_PHDIO_CMDS_FOR_WRITE |
Yes | No | Store the commands to output a byte from the write buffer |
IOCTL_PHDIO_GET_RW_RESULTS |
No | Yes | Get the command results of the last read or write operation |
Commands
A Win32 program passes a block of commands in an IOCTL input buffer. These commands are either run straightaway or are run one or more times during the processing of read or write requests.
A command is a single byte, followed by one or more parameter bytes. Table 15.2 lists all the commands, their parameters, and their output. The Ioctl.h header in the WdmIoSys directory contains the command definitions. Note that all operations are currently byte-sized. However, the two top bits of the command byte are reserved to indicate 16-bit word transfers and 32-bit long word transfers. If either of these bits is currently set, the command is not run and command processing is aborted. All command parameters are BYTEs. A BYTE is an unsigned 8-bit value, so you cannot use negative values.
Most of the commands are fairly self-explanatory. They are best explained using examples in the context of a sample application, WdmIoTest, that outputs data to the LPT printer parallel port.
Table 15.2 WdmIo and PhdIo commands
Command | Input parameters | Output | Description |
---|---|---|---|
PHDIO_OR |
reg, Value |
Read register, OR with value, and write back. Use to set bit(s) | |
PHDIO_AND |
reg, Value |
Read register, AND with value, and write back. Use to clear bit(s) | |
PHDIO_XOR |
reg, Value |
Read register, XOR with value, and write back. Use to toggle bit(s) | |
PHDIO_WRITE |
reg, Value |
Write value to a register | |
PHDIO_READ |
reg |
Value |
Read value from a register |
PHDIO_DELAY |
delay |
Delay for given microseconds. Delay must be 60µs or less | |
PHDIO_WRITES |
reg, count, Values, delay |
Write values to same register with delay (<=60µs) | |
PHDIO_READS |
reg, count, delay |
Values |
Read values from same register with delay (<=60µs) |
PHDIO_IRQ_CONNECT |
reg, mask, Value |
Connect to interrupt | |
PHDIO_TIMEOUT |
seconds |
Specify time-out for reads and writes | |
PHDIO_WRITE_NEXT |
reg |
Write next value from write buffer | |
PHDIO_READ_NEXT |
reg |
Store next value in read buffer |
- Win32 Program Interface
- Win32 Device Interface Access
- InterBase Super Server для Windows
- Интеграция с платформой Windows NT
- Часы в Windows показывают неправильное время
- Классическая архитектура на Windows NT (Yaffil CS)
- 4.2. Центр уведомлений Windows 10
- Chapter 15. Graphical User Interfaces for Iptables
- Загрузочные дискеты и Live CD для Windows
- 6.8. Разгон видеокарты на Windows 10
- Smss, Csrss и Winlogon
- Интеграция Windows SharePoint и Microsoft Office