Writing a Virtual Device

Many virtual devices are written to replace one of the standard virtual devices, that is, one of the virtual devices provided with the Microsoft Windows 95 operating system. However, most virtual devices are written to support new hardware devices or software. In such cases, it is often easier to write a virtual device from scratch than to modify an existing virtual device, because so much of a virtual device is device-specific. Nevertheless, the sources for existing virtual devices should be carefully examined whenever possible because they can reveal the general format and structure of virtual devices, as well as illustrate how to use VMM and virtual device services to carry out useful tasks.

Use the following guidelines when writing a virtual device:

  1. Start with a skeletal virtual device containing the virtual device segments, a virtual device declaration, a device control procedure, stubs for the procedures that process the system control messages, and stubs for the API procedures.
  2. Add a real-mode initialization procedure (optional).
  3. Fill out the procedures that process the initialization messages. These procedures should initialize the control block, allocate global memory, and install callback procedures for interrupts, I/O traps, and page faults.
  4. Fill out the callback procedures that handle the various interrupts and faults.
  5. Add a service table declaration and definitions for the services (optional).
  6. Fill out the API procedures (optional).
  7. Fill out the procedures that process system control messages for creating and destroying virtual machines.

At each stage in writing a virtual device, you can install the virtual device and run Windows under the control of the debugger. Setting breakpoints in your virtual device and monitoring the various interrupts managed by your virtual device can help you determine whether your virtual device is operating correctly.