Interrupt 24h Critical-Error Handler

Critical-Error Handler (Interrupt 24h) carries out program-specific actions in response to critical errors during read and write operations. MS-DOS issues this interrupt if a critical error occurs while a system function is attempting to read from or write to a device or file. The handler carries out its actions then returns to the system to retry the function, terminate the function, or terminate the current program.

Programs must not issue Interrupt 24h.

Comments

MS-DOS sets the current critical-error handler when starting a program, copying the address of the parent program's handler to both the vector-table entry and offset 12h in the new program's PSP (pspCritErrorVector field). Although a program can change the vector-table entry, it must not change the address in its PSP, since MS-DOS uses this address to restore the parent program's handler.

Before issuing Interrupt 24h, MS-DOS does the following:

Sets the AX, DI, BP, and SI registers with information about the error, such as the error value, location of the error, type of device, and type of operation.

Sets the program's stack to be the current stack. When the handler receives control, the stack has the following contents (from the top of the stack):

The return address (CS:IP) and the flags needed for the iret
instruction back to the system.

The contents of the program's registers at the time the system function
that caused the error was called. The registers are preserved in the
following order: AX, BX, CX, DX, SI, DI, BP, DS, and ES.

The return address (CS:IP) and the flags needed for the iret
instruction back to the program.

Sets internal system variables, such as those for InDOS and ErrorMode. InDOS is set to zero to permit the handler to call system functions. ErrorMode is set to 1 to prevent the system from issuing Interrupt 24h again before the handler returns; MS-DOS issues only one Interrupt 24h at a time.

MS-DOS passes information about the error to the handler by using the following registers:

Register Description  

AH Specifies information about when and where the error occurred, as well as how the critical-error handler can respond to the error. The bits in this register can have the following values:  
  Bit Meaning
  0 Specifies the operation that caused the error. If this bit is 0, the error occurred during a read operation. Otherwise, the error occurred during a write operation.
  1,2 Specify the location of the error, but only if the error occurred on a block device. These bits can have the following values:
    00 = error in reserved sector (MS-DOS area) 01 = error in file allocation table (FAT) 10 = error in directory 11 = error in data area
  3 Specifies whether the handler can terminate the function. If this bit is 1, the handler can terminate the function. Otherwise, it must not.
  4 Specifies whether the handler can retry the function. If this bit is 1, the handler can retry the function. Otherwise, it must not.
  5 Specifies whether the handler can ignore the error. If this bit is 1, the handler can ignore the error. Otherwise, it must not.
  6 Reserved.
  7 Specifies the type of device on which the error occurred. If this bit is 0, the error occurred on a block drive. If this bit is 1, it indicates that the error occurred either on a character device or in the memory image of the FAT, and that the handler must check bit 15 in the dhAttributes field (offset 04h) of the DEVICEHEADER structure to determine the exact location. If bit 15 is set, the error occurred on a character device. Otherwise, the error occurred in the memory image of the FAT.
AL Specifies the drive number (0 = A, 1 = B, 2 = C, and so on) if the error occurred on a block device. This register is not used for errors that occur on character devices.  
DI Specifies the error value. The error value, in the lower byte only, can be one of the following:  
  Value Meaning
  00h Attempt to write on write-protected disk
  01h Unknown unit
  02h Drive not ready
  03h Unknown command
  04h CRC error in data
  05h Incorrect length of drive-request structure
  06h Seek error
  07h Unknown media type
  08h Sector not found
  09h Printer out of paper
  0Ah Write fault
  0Bh Read fault
  0Ch General failure
  The upper byte of the DI register is undefined.,  
BP:SI Points to the DEVICEHEADER structure that contains information about the device on which the error occurred. The DEVICEHEADER structure has the following form:  
  DEVICEHEADER STRUC
dhLink dd ? ;link to next driver
dhAttributes dw ? ;device attributes
dhStrategy dw ? ;strategy-routine offset
dhInterrupt dw ? ;interrupt-routine offset
dhNameOrUnits db '????????' ;logical-device name
;(character device only)
;or number of units
;(block device only)
DEVICEHEADER ENDS
 
  For a full description of the DEVICEHEADER structure, see Chapter 9, “Device Drivers.”  
  The handler must not change the contents of the DEVICEHEADER structure.  

The critical-error handler must determine what action to take in response to the error. For example, the default handler displays information about the error and prompts the user for input on how to proceed.

The critical-error handler can call the following Interrupt 21h functions:

Character I/O (Functions 01h through 0Ch)
Get CTRL+C Check Flag (Function 3300h)
Set CTRL+C Check Flag (Function 3301h)
Get Startup Drive (Function 3305h)
Get MS-DOS Version (Function 3306h)
Set PSP Address (Function 50h)
Get PSP Address (Functions 51h and 62h)
Get Extended Error (Function 59h)

No other system functions are permitted. Get Extended Error (Function 59h) retrieves detailed information about the error and is useful for handlers that display as much information as possible about the error.

The handler must preserve the BX, CX, DX, DS, ES, SS, and SP registers and restore the preserved values before returning to the system. The critical-error handler returns to the system by using the iret instruction. Before returning, it also must set the AL register to a value specifying the action the system should take. Depending on what actions are allowed (as specified by bits 3, 4, and 5 in the AH register), the AL register can contain one of the following values:

Value Meaning

00h Ignore the error. The system permits the system function to return to the program as if it had completed successfully.
01h Retry the operation. The system calls the system function again. In this case, the system expects the handler to have preserved and restored registers before returning.
02h Terminate the program. The system sets the termination type to be EXIT_CRITICAL_ERROR (02h) and carries out the same actions as End Program (Interrupt 21h Function 4Ch).
03h Terminate the function. The system permits the system function to return to the program with an error value.

MS-DOS checks the value to ensure that it is allowed. If values 00h and 01h are not allowed, the system terminates the function. If value 03h is not allowed, the system terminates the program.

COMMAND.COM provides the default critical-error handler, which displays a message about the error and, after displaying a question such as “Abort, Retry, Fail, or Ignore?”, prompts the user for a response.

See Also

Interrupt 21h Functions 01h through 12h (Character I/O Functions)
Interrupt 21h Function 3300h Get CTRL+C Check Flag
Interrupt 21h Function 3301h Set CTRL+C Check Flag
Interrupt 21h Function 3305h Get Startup Drive
Interrupt 21h Function 3306h Get MS-DOS Version
Interrupt 21h Function 50h Set PSP Address
Interrupt 21h Function 51h Get PSP Address
Interrupt 21h Function 59h Get Extended Error