Chapter
5
I
Device Drivers
Installation
of
Device Drivers
MS-DOS allows new device drivers
to
be installed dynamically at
boot time. This
is
accomplished by INIT code in the BIOS, which
reads and processes the CONFIG.SYS file.
MS-DOS calls
a
device driver by making a far call
to
its strat-
egy entry point, and passes the information describing the func-
tions of the device driver in
a
Request Header.
This structure allows you
to
program an interrupt-driven device
driver.
For
example, you may want
to
perform local buffering in a
printer.
MS-DOS passes
a
pointer
to
the Request Header in ES:BX. This
is
a
fixed-length header, followed by data pertinent
to
the opera-
tion being performed. Note that
it
is the device driver’s responsi-
bility
to
preserve the machine state (for example, save all
registers on entry and restore them on exit). There is enough
room on the stack
to
do about
20
pushes. If more stack space is
needed, the driver should set up its own stack.
Request
Header
BYTE Length of record
BYTE Unit code
Length in bytes of this Request Header
The subunit the operation is for (minor device)
(no meaning on character devices)
I
BYTE Command code
I
I
WORD
Status
I
18
bytes RESERVED
I
Unit Code Field
The unit code field identifies which unit in your device driver the
request
is
for.
For
example,
if
your device driver has
3
units de-
fined, then the possible values of the unit code field would be
0,
1,
and
2.
177