The last and most complex part of a device driver is the interrupt routine (intr), which MS-DOS calls immediately after it calls the strategy routine. The interrupt routine implements the device driver proper; it performs (or calls other resident routines to perform) the actual input or output operations, based on the information passed in the request header. The strat routine may not make any Int 21H function calls, except for a restricted set during driver initialization.
When an I/O function is completed, the interrupt routine uses the status field in the request header to inform the DOS kernel about the outcome of the requested I/O operation. It can use other fields in the request header to pass back such useful information as counts of the actual sectors or bytes transferred.
The interrupt routine usually consists of the following elements:
A collection of subroutines to implement the various function types that may be requested by MS-DOS (sometimes called the command-code routines)
A centralized entry point that saves all affected registers, extracts the desired function code from the request header, and branches to the appropriate command-code routine (typically accomplished with a jump table)
A centralized exit point that stores status and error codes into the request header (Figures 14-5 and 14-6) and restores the previous contents of the affected registers
The command-code routines that implement the various functions supported by an installable device driver are discussed in detail in the following pages.
Bit(s) Significance
15 Error
12—14 Reserved
9 Busy
8 Done
0—7 Error code if bit 15 = 1
Figure 14-5. Values for the return status word of the request header.
Code Meaning
0 Write-protect violation
1 Unknown unit
2 Drive not ready
3 Unknown command
4 Data error (CRC)
5 Bad request-structure length
6 Seek error
7 Unknown medium
8 Sector not found
9 Printer out of paper
0AH Write fault
0BH Read fault
0CH General failure
0D—0EH Reserved
0FH Invalid disk change (MS-DOS versions 3.0 and later)
Figure 14-6. Driver error codes returned in bits 0 through 7 of the return status word of the request header.
Although its name suggests otherwise, the interrupt routine is never entered asynchronously (on an I/O completion interrupt, for example). Thus, the division of function between strategy and interrupt routines is completely artificial in the current versions of MS-DOS.