Debugging Keyboard Driver

Hi all,
Myself is a novice to drivers and in order to master
debugging and understand in detail kernel operations I took the sample code
for keyboard class driver .After building it and loading it,i wants to debug
it with softice.
Since this driver is always started at system time(keyboard driver can’t be
made to start manually because in that case u can’t login into system
:-),This is what I thinks) how can I debug it using softice.Since all the
commands are also given from keyboard,how to move or jump in code of driver.
Secondly which parameters decide whether to use softice or windbg??If this
choice is purely personal then what a fresher should start with because he
is not conditioned to use Windbg as many experienced programmers might be.

Thanx in advance…
Chandandeep Singh Pabla
DCM Technologies.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

The problem with using softice to debug a keyboard driver is deeper than it
seems. At least on NT4, softice actually does a binary patch to the
keyboard driver; the patch is not to catch the input, but to get around an
ancillary problem, as follows:

The way the PS/2 kbd controller works, every time a key is pending, a bit
is set in the I/O status port (and an interrupt is generated). When the
value of the key is read from the I/O data port (during the interrupt
routine), then this bit is reset.
Now, softice installs itself directly into the IDT of the machine, and thus
it gets notification of every key first. Softice checks the key, and then
chains to the regular interrupt procedure.
The problem is that when Softice checks the key, the pending bit is reset
to 0. Thus, when the keyboard driver checks the pending bit, it will find
that it is 0, and will ignore the key.
It seems that softice, in order to get around this, adds a JMP instruction
into the keyboard driver which just skips the check for the pending bit.

Thus, since Softice does a binary patch to the keyboard driver, if your
driver is not byte-for-byte identical with the original driver in that
place, you are in for a problem.

However, since Softice’s actual processing of the keys happens directly
from the IDT, and does not intefere with the keyboard driver, you can set
breakpoints at various points inside the default keyboard driver (which
Softice patches successfully) and step through them successfully in
Softice. (Just be aware that any read/writes to the I/O ports may be out of
sync).
Regarding your driver, you may be able to put softice in a mode where it
does not do the patch, or where it does the patch to a dummy portion of
your code. Then, set your code (in a debugging mode) to process all keys
whether or not the pending bit is set. You will be able to debug it in
Softice.
(Of course, though, all this is somewhat convoluted compared to WinDBG
which does not share these issues).

By the way, if you are writing for Win2000, in many cases you may be able
to use the KEYBOARD_HANDLER IOCTL, present in the default keyboard driver
with Win2000, instead of writing your own driver. This IOCTL allows you to
install a routine (of Ring 0 code) which will be called immediately upon
receipt of each key, and which will provides a parameter to allow you to
pass the key on to the regular keyboard processing mechanism, or to throw
out the key. This would allow you to rely on the default driver for most
processing, changing only what you need, making your debugging process
simpler in many ways.

  • Avi

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Avi Said,

(Of course, though, all this is somewhat convoluted compared to WinDBG
which does not share these issues).

Well, this is a problem that is unique to a single-machine debugger, which
AFAIK WinDBG ain’t. If you debug from a remote machine, you don’t have this
kind of issue in SoftIce either. But wait for DriverStudio 2.5, we may do
something about this too.

Alberto.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com