9.3.2 Strategy and Interrupt Routines

Each driver has two routines: a strategy routine and an interrupt routine. MS-DOS calls both routines, but only the interrupt routine carries out any work.

MS-DOS first makes a far call to the device driver's strategy routine, passing (in the ES:BX registers) the 32-bit address (segment:offset) of a request packet. The strategy routine saves this address and returns immediately by using a far return. MS-DOS then calls the interrupt routine. At this point, the device driver carries out the requested function, accessing the hardware either directly or by using ROM BIOS calls. When processing is complete, the interrupt routine must set the status value in the request packet and return to MS-DOS by using a far return. The request is completed when the interrupt routine returns.

The interrupt routine, despite its name, is never started as a result of an interrupt. Instead, the routine always receives control from an explicit call made by MS-DOS. When called, the interrupt routine must examine the function field in the request packet to determine what action to take. Since a device driver must never have more than one pending request at any given time, the interrupt routine must, for each request, either carry out an action or indicate to MS-DOS that the device is busy or in error.

The strategy and interrupt routines must preserve any registers they use, including flags. The routines can save registers on the stack (restoring them before returning), although there is limited space on the stack when these routines are called (usually about 40 to 50 bytes). If the driver requires more room, it should set up its own stack. The direction flag and interrupt-enable bits are especially critical and must be preserved in all cases.