Showing posts with label Device Driver. Show all posts
Showing posts with label Device Driver. Show all posts

Thursday, March 8, 2007

Developing Drivers from Windows

Download Free ScreenSavers and Wallpapers! - http://offr.biz/HLSCR300468KXRFJFT




Definition Device Driver

A device driver, often called a driver for short, is a computer program that enables another program, typically, an operating system (e.g., Windows, Linux) to interact with a hardware device. A driver is essentially an instruction manual that provides the operating system with the information on how to control and communicate with a particular piece of hardware.





Windows 2000 Driver Design Goals

  • Portability
    • The driver program should be compatible across all platforms. So it is must not be written in assembly language coding since instruction sets changes from processor to processors. Coding in C would be good idea since it can be recompiled and run on any platform. But care should be taken as to, no library function are used. Since those library function may not be available on another platform.
  • Configurability
  • Always pre-emptive and interruptive
    • Pre-emptive scheduling means if a higher priority process arrives then the processor sends the process, which is in execution to the wait state and executes the higher priority process. This type of scheduling is an effective way to maximize average performance.
    • Two schemes are used here
      • The Kernel-defined run-time priority scheme for threads
      • The Kernel-defined interrupt request level (IRQL)
        • Priority order of IRQL
          • Software Interrupts - low priority
          • Decvice drivers - higher priority
          • System-critical such as system clock or bus-error interrupts - highest priority.
  • Multiprocessor-safe on multiprocessor platforms
    • In a multiprocessor environment a process will check each processor to execute its process. Care should be taken as to, that the process should not be executed in two processors.
  • Object-based
    • If we design our driver program as separate routines or objects then modifying the driver can be very useful in future implementations.
  • Packet-driven I/O with reusable I/O request packets
    • I/O requests can be small or big. Sending then as such would result in tremendous overhead. So as such we group them into packets or split large packets and send them across to various destinations.
  • Support for asynchronous I/O
    • Asynchronous means the process does not wait for the request to be completed. Instead it carries on with the next set of instruction.
    • This is very good time saving mechanism.

How to run a Device Driver in Windows


Creating the code

· First create a separate directory for your driver.

· Then create the driver code in .c files and store it in that directory.

· Then create the following two files

Makefile

!INCLUDE $(NTMAKEENV)\makefile.def

Build

TARGETNAME = test //the name of the .sys file we desire

TARGETPATH = obj

TARGETTYPE = DRIVER

INCLUDES = %BUILD%\inc

LIBS = %BUILD%\lib

SOURCES = test.c // the name of the file that contains the driver code

  • Both these files should be stored in the same directory as of the .c file.
  • Both should be saves without any extensions.

Compiling Your Driver Code

· Then go to the DDK in the start menu and select

_>Development Kit

__>Windows 2000 DDK

___>Check Build Environment

· A command prompt opens.

· Navigate to the directory where your driver code resides.

· Then Type build in the command prompt.

· It compiles your driver code.

· Once the compilation is over the .sys file is created.

Registering your Driver

· Before executing the .sys file it has to be registered with the windows registry.

· To register a .sys file download the OSR Driver Loader from the net and first install it.

· Then open and it and in the Driver Path give your newly created .sys file.

· All device driver can be loaded only once but it can be started or stopped frequently.

· The software itself contains all the options such as registering a driver and unregistering a driver, start and stopping the service.

· You can also start and stop the service from command prompt itself using the commands

· netstart (driver name without extension) and netstop(driver name without extension).

Viewing the Output

· To view the output, use the DebugView for debugging and viewing output. Once again it should be downloaded from net.

· Run this first before starting the service and hence you can view the output.