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.
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