12.7  Compile Your Kernel PlugIn Driver

12.7.1  On Windows

The sample WinDriver\samples\pci_diag\kp_pci Kernel PlugIn directory and the generated DriverWizard Kernel PlugIn <project_dir>\kermode directory (where <project_dir> is the directory in which you selected to save the generated driver project) contain the following Kernel PlugIn project files (where xxx is the driver name – pci for the sample / the name you selected when generating the code with the wizard):

  • x86 – 32-bit project files:
    • msdev_2008\kp_xxx.vcproj – 32-bit MSDEV 2008 project.
    • msdev_2005\kp_xxx.vcproj – 32-bit MSDEV 2005 project.
    • msdev_2003\kp_xxx.vcproj – 32-bit MSDEV 2003 project.
    • msdev_6\kp_xxx.dsp – 32-bit MSDEV 6.0 project.
  • amd64 – 64-bit project files:
    • msdev_2008\kp_xxx.vcproj – 64-bit MSDEV 2008 project.
    • msdev_2005\kp_xxx.vcproj – 64-bit MSDEV 2005 project.

The sample WinDriver\samples\pci_diag directory and the generated <project_dir> directory contain the following project files for the user-mode application that drives the respective Kernel PlugIn driver (where xxx is the driver name – pci for the sample / the name you selected when generating the code with the wizard):

  • x86 – 32-bit project files:
    • msdev_2008\xxx_diag.vcproj – 32-bit MSDEV 2008 project.
    • msdev_2005\xxx_diag.vcproj – 32-bit MSDEV 2005 project.
    • msdev_2003\xxx_diag.vcproj – 32-bit MSDEV 2003 project.
    • msdev_6\xxx_diag.dsp – 32-bit MSDEV 6.0 project.
    • cbuilder4\xxx.bpr and xxx.cpp – Borland C++ Builder 4.0 project file and related CPP file. These files can also be used from version 5.0 and 6.0 of Borland C++ Builder.
    • cbuilder3\xxx.bpr and xxx.cpp – Borland C++ Builder 3.0 project file and related CPP file.
  • amd64 – 64-bit project files:
    • msdev_2085\xxx_diag.vcproj – 64-bit MSDEV 2008 project.
    • msdev_2005\xxx_diag.vcproj – 64-bit MSDEV 2005 project.

The MSDEV directories listed above also contain xxx_diag.dsw/.sln workspace/solution files that include both the Kernel PlugIn and user-mode projects.

To build your Kernel PlugIn driver and respective user-mode application on Windows, follow these steps:

  1. Verify that the Windows Driver Kit (WDK) is installed.
  2. Set the BASEDIR environment variable to point to the location of the directory in which WDK is installed.
  3. Start Microsoft Developer Studio (MSDEV) and do the following:
    1. From your driver project directory, open the generated workspace/solution file – <project_dir>\<MSDEV_dir>\xxx_diag.dsw/.sln, where <project_dir> is your driver project directory (pci_diag for the sample code / the directory in which you selected to save the generated DriverWizard code), <MSDEV_dir> is your target MSDEV directory (msdev_2008 / msdev_2005 / msdev_2003 / msdev_6) and xxx is the driver name (pci for the sample / the name you selected when generating the code with the wizard).

      Note that when selecting to generate code for the MSDEV IDE with DriverWizard, the wizard automatically starts MSDEV and opens the generated workspace/solution file after generating the code files, unless you explicitly revoke this behavior by setting the "IDE to Invoke" option in the code generation dialogue to "None".

    2. To build the Kernel PlugIn SYS driver (kp_pci.sys – sample / kp_xxx.sys – generated wizard code):

      1. Set the Kernel PlugIn project (kp_pci.dsp/vcproj / kp_xxx.dsp/vcproj) as the active project.
      2. Select the active configuration for your target platform: From the Build menu, choose Configuration Manager... (MSDEV 2003/2005/2008) / Set Active Configuration... (MSDEV 6.0), and select the desired configuration.
        [Note]
        To build the driver for multiple operating systems, select the lowest OS version that the driver must support. For example, to support Windows 2000, XP, and higher, select either Win32 win2k free (release mode) or Win32 win2k checked (debug mode).
      3. Build your driver: Build the project from the Build menu or using the relevant shortcut key (e.g., F7 in MSDEV 6.0).
    3. To build the user-mode application that drives the Kernel PlugIn driver (pci_diag.exe – sample / xxx_diag.exe – generated wizard code):

      1. Set the user-mode project (pci_diag.dsp/vcproj – sample / xxx_diag.dsp/vcproj – generated wizard code) as the active project.
      2. Build the application: Build the project from the Build menu or using the relevant shortcut key (e.g., F7 in MSDEV 6.0).

12.7.2  On Mac OS X

[Note]
In the following instructions
  • <project_dir> signifies the path to the project directory that contains your Kernel PlugIn and/or user-mode application – for example, ~/WinDriver/wizard/my_projects/my_kp for a generated "my_kp" project, or ~/WinDriver/samples/pci_diag for the KP_PCI sample.
  • <KP_dir> signifies the directory that contains your Kernel PlugIn files – <project_dir>/kermode for the generated DriverWizard Kernel PlugIn projects, or WinDriver/samples/pci_diag/kp_pci for the KP_PCI sample.
  • xxx signifies the name of your Kernel PlugIn project – i.e., the project name you selected when generating the code with DriverWizard, or pci for the KP_PCI sample.

To build your Kernel PlugIn driver and respective user-mode application on Mac OS X, follow these steps:

  1. Build the Kernel PlugIn: Open your Kernel PlugIn project with Xcode, and build the code.
    The Kernel PlugIn project folder is located at <KP_dir>/macos/kp_xxx.xcodeproj – for example, ~/WinDriver/wizard/my_projects/my_kp/kermode/macos/KP_MY_KP.xcodeproj (for a MY_KP generated DriverWizard project), or ~/WinDriver/samples/pci_diag/kp_pci/macos/kp_pci.xcodeproj (for the KP_PCI sample).

    The build will create a kp_xxx.kext Kernel PlugIn kernel extension folder under a <KP_dir>/macos/build/Release or <KP_dir>/macos/build/Debug sub-directory – depending on how you selected to build the project. For example, ~/WinDriver/wizard/my_projects/my_kp/kermode/macos/build/Release/kp_my_kp.kext or ~/WinDriver/samples/pci_diag/kp_pci/macos/build/Release/kp_pci.kext.

  2. Build the user-mode application that drives your Kernel PlugIn project, using either of these methods:

    • Use Xcode to open the <project_dir>/macos/xxx.xcodeproj application project – for example, ~/WinDriver/wizard/my_projects/my_kp/macos/my_kp.xcodeproj or ~/WinDriver/samples/pci_diag/macos/pci_diag – and build the code.
    • Open a command-line prompt, change directory to the <project_dir>/macos directory – for example, ~/WinDriver/wizard/my_projects/my_kp/macos or ~/WinDriver/samples/pci_diag/macos – and run make to build the code.

    The build will create an xxx application under a <project_dir>/macos/build/Release or <project_dir>/macos/build/Debug sub-directory – depending on how you selected to build the project. For example, ~/WinDriver/wizard/my_projects/my_kp/macos/build/Release/my_kp or ~/WinDriver/samples/pci_diag/macos/build/Release/pci_diag.

12.7.3  On Linux

To build your Kernel PlugIn driver and respective user-mode application on Linux, follow these steps:

  1. Open a shell terminal.
  2. Change directory to your Kernel PlugIn directory.

    For example:

    • When compiling the sample KP_PCI driver, run this command:
      cd WinDriver/samples/pci_diag/kp_pci
    • When compiling the Kernel PlugIn driver for your generated DriverWizard Kernel PlugIn code, run the following command, where <path> signifies the path to your generated DriverWizard project directory (for example, /home/user/WinDriver/wizard/my_projects/my_kp):
      cd <path>/kermode/linux/

  3. Generate the makefile using the configure script:

    ./configure --disable-usb-support

    [Note]
    The configure script creates a makefile based on your specific running kernel. You may run the configure script based on another kernel source you have installed, by adding the flag --with-kernel-source=<path> to the configure script. The <path> is the full path to the kernel source directory, e.g., /usr/src/linux.
    If the Linux kernel is version 2.6.26 or higher, configure generates makefiles that use kbuild to compile the kernel modules. You can force the use of kbuild on earlier versions of Linux, by passing the --enable-kbuild flag to configure.
  4. Build the Kernel PlugIn module using the make command.
    This command creates a new LINUX.xxx directory (where xxx depends on the Linux kernel), which contains the created kp_xxx_module.o/.ko driver.
  5. Move to the directory that holds the makefile for the sample user-mode diagnostics application.

    For the KP_PCI sample driver:
    cd ../LINUX/

    For the generated DriverWizard Kernel PlugIn driver:
    cd ../../linux/

  6. Compile the sample diagnostics program using the make command.