## The FPUTEST Sample

The FPUTEST Sample accompanies Chapter 3 and illustrates how to perform floating point and MMX operations in Windows XP. This sample was distributed as part of Service Pack 2 and was revised in Service Pack 9 in the 1st edition.

The sample includes two components:

- FPUTEST.SYS (SYS subdirectory) is a WDM driver for a non-existent hardware device.
- TEST.EXE (TEST subdirectory) is a test program that calls FPUTEST.

### Building FPUTEST

To build FPUTEST.SYS for Windows XP, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named FPUTEST.DSP.

To build TEST.EXE, follow the general instructions for building user-mode samples

### Testing FPUTEST

This sample works only on an Intel x86 computer running Windows XP or Windows Xp.

This sample will not run under Windows 98/Me or Windows Millennium. This is because the virtualization of the math coprocessor in Windows operating systems does not correctly handle exceptions that occur when an FRSTOR operation is performed on an image that reflects an unsignalled floating point exception. Due to variations in math coprocessors, there is no way short of rewriting VMCPD.VXD to overcome this problem. There is no impediment to using floating point in a separate kernel thread, but this sample wasn’t intended to illustrate that possibility in the first place.

To test the sample, first install the FPUTEST.SYS driver. Follow the general instructions for using FastInst in Windows XP. The INF file is named SYS\FPUTEST.INF.

Now launch TEST.EXE from the TEST\DEBUG subdirectory. TEST will issue two DeviceIoControl calls to test floating point and MMX operations in FPUTEST.SYS. The first test occurs at PASSIVE_LEVEL, the second at DISPATCH_LEVEL. TEST will report the ending status. FPUTEST will print additional information about the tests on the debugging terminal.

### What to look for

The dotest function in control.cpp performs a few basic floating point operations. Other important things in control.cpp include:

- Definition of _fltused to satisfy a symbol demand that the compiler generates whenever you use floating point in a source file.
- Definition of transcendental functions like sin to take the place of runtime library functions that aren't available in a driver.
- Use of KeSaveFloatingPointState and KeRestoreFloatingPointState.
- Use of ExIsProcessorFeaturePresent to determine whether the MMX instruction set is installed.