SAMPLE: Capturing Global Interrupts in Enhanced ModeLast reviewed: August 5, 1996Article ID: Q68250 |
The information in this article applies to:
SUMMARYA hardware interrupt in the 386 enhanced mode of the Microsoft Windows graphical environment is classified as either "global" or "owned." A global interrupt is typically reflected into whichever virtual machine (VM) is currently running, while an owned interrupt is reflected into the VM that owns that interrupt. For example, the floppy disk drive interrupt is typically made global, because any VM should be able to use the floppy disk drive and receive interrupts from it. On the other hand, an application that exclusively handles communications with a nonstandard device would become confused if interrupts from the device were routed to some other VM. For this reason, these interrupts should be "owned." In some circumstances, it may be advantageous to "capture" a global interrupt temporarily in one VM, effectively making the interrupt "owned." The text below discusses VFINTD.386, a sample virtual device (VxD) that does just that. With this VxD installed in a Windows system running in 386 enhanced mode, an application can issue the appropriate function calls to reflect all interrupts from the floppy disk drive into the application's VM, regardless of which VM is currently running. VFINTD is one of the sample applications provided with version 3.1 of the Microsoft Windows Device Driver Kit (DDK). VFINTD can also be found in the Microsoft Software Library. Download VFINTD.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
MORE INFORMATION
BackgroundStandard hardware for an MS-DOS compatible computer includes a programmable interrupt controller (PIC). One register in the PIC is the interrupt mask register (IMR), which defines which hardware interrupts are currently enabled and which are disabled (or masked). The MS-DOS utility DEBUG can display the contents of the IMR. To demonstrate this, run DEBUG from the MS-DOS prompt. Then enter the following command to display the value of port 21 on your machine:
i21Port 21 is the IMR for the hardware interrupts IRQ0 through IRQ7. The format of the IMR is that each bit (0-7) that is set corresponds to a disabled interrupt request (IRQ). Therefore, a typical IMR value might be 98h, which indicates that IRQ3, IRQ4, and IRQ7 are all masked, and that those interrupts are disabled:
Hexadecimal 98 = Binary 10011000 = IRQ3, IRQ4, and IRQ7 offNote: A PC/AT compatible system has two hardware PICs, and thus, two IMRs, that correspond to the fifteen possible IRQs. (The second PIC is cascaded to IRQ2, which consumes one IRQ.) While this point is included here for completeness, is not necessary to understand the overall picture. When an MS-DOS device driver or terminate-and-stay-resident program (TSR) installs an interrupt handler for a particular IRQ, the device driver or TSR hooks the interrupt vector and unmasks the corresponding bit in the IMR. When Windows is running, MS-DOS drivers and TSRs are normally shared by all virtual machines. Thus, if an interrupt occurs while an arbitrary VM is running, Windows is not required to perform a virtual machine task switch to access the interrupt handler, because the interrupt handler resides in the address space of each virtual machine. Alternatively, if an interrupt handler for a previously masked IRQ is installed within a virtual machine, and an interrupt occurs while another virtual machine is executing, Windows must make a task switch so that the local interrupt handler is accessible and executable.
Windows Default BehaviorThe VPICD VxD virtualizes the PICs when Windows is running in 386 enhanced mode. When hardware is virtualized, each virtual machine has access to its own "virtual" PIC. This allows transparently sharing hardware among all virtual machines. Unless some other mechanism processes an IRQ, the VPICD handles interrupts according to the following default behavior: When Windows boots into 386 enhanced mode, VPICD examines the value of the IMRs in the system to determine which interrupts are masked. If an interrupt is not masked (is enabled), Windows must assume that a valid interrupt handler is already installed for this IRQ. These IRQs are then flagged as "global," so that Windows can avoid the overhead of a task switch to service them. The remaining IRQs, which are masked (disabled), are flagged as "local" or "owned." An interrupt for one of these IRQs will be reflected only into each virtual machine that unmasks the IRQ.
Changing the Default BehaviorIt is possible to change the default behavior of interrupt handling (described above) by installing a VxD that virtualizes an IRQ with the VxD call VPICD_Virtualize_IRQ. This call replaces the VPICD default callback routines with routines supplied in the VxD. For example, the virtual communication device (VCD) virtualizes the communication interrupt so that it can control interrupts from communication devices regardless of the state of the IMR at Windows load time. The VFINTD sample VxD also uses VPICD_Virtualize_IRQ to allow an application to "capture" the interrupts on IRQ6 (the floppy disk device), which is normally global. For example, a hard disk backup program that directly accesses the floppy disk controller hardware to improve performance would "lose" interrupts to other virtual machines unless it changed the global nature of IRQ6. VFINTD can be used in this case to capture the "focus" of the floppy disk device and the interrupts it generates.
Using VFINTDThere are two pieces of code to the VFINTD sample: the VxD and a sample MS-DOS application. All the files that are named VFINTD are part of the VxD. The MS-DOS application is called TSTFINT. The only purpose of the MS-DOS application is to capture floppy disk interrupts. The sample application does not release the focus capture, but the VxD provides this functionality. To install the VxD in your machine, perform the following steps:
This sample has been provided to demonstrate how to virtualize a particular IRQ. It is a good place to start when developing another VxD to perform a similar function.
|
Additional reference words: 3.00 3.10 DDKVXD softlib VFINTD.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |