How MS-DOS 6.22 Handles Interrupt 20h Termination

Interrupt 20h (INT 20h) is a legacy system call in MS-DOS 6.22 designed to terminate the currently running executable and return control to the parent process, typically COMMAND.COM. When invoked, MS-DOS restores critical interrupt vectors saved inside the application's Program Segment Prefix (PSP), flushes internal disk buffers, deallocates memory blocks assigned to the process, and jumps to the parent program's return address. While fully supported in version 6.22 for backward compatibility with early DOS 1.x applications, its execution flow relies on specific register states and data structures embedded in the PSP.

Prerequisites for Invocation

Unlike modern DOS termination functions, INT 20h requires the Code Segment (CS) register to point directly to the base segment of the executing program's Program Segment Prefix (PSP). At offset 0000h of the PSP, DOS places a two-byte opcode CD 20 (the machine instruction for INT 20h). If CS does not point to the PSP when INT 20h is triggered, the operating system reads corrupted vector tables, leading to a system crash or lockup.

Vector Restoration

Once INT 20h is triggered, the MS-DOS kernel immediately accesses the PSP to restore system interrupt vectors that the terminating program may have altered:

  1. Interrupt 22h (Terminate Address): Stored at PSP:000Ah, this far pointer holds the return address within the parent program.
  2. Interrupt 23h (Ctrl-C Handler): Stored at PSP:000Eh, restoring the parent's handler for user break sequences.
  3. Interrupt 24h (Critical Error Handler): Stored at PSP:0012h, restoring the default hardware error handling vector.

By copying these three far pointers back into the Interrupt Vector Table (IVT) in lower memory (0000:0000h), DOS guarantees that hardware events and user interrupts return to the context of the calling shell.

Resource Cleanup and Memory Management

After restoring the core vectors, the kernel executes clean-up operations on the system resources assigned to the process:

  • File Buffer Flushing: DOS flushes any dirty cache buffers associated with open handles to physical disk storage. However, unlike INT 21h, Function 4Ch, INT 20h does not automatically close all open file handles stored in the Job File Table (JFT). Unclosed files can lead to orphaned handles or lost data if file lengths change without an explicit close call prior to exit.
  • Memory Deallocation: The DOS memory manager parses the Memory Control Block (MCB) chain. It releases the memory arena containing the transient program and, if allocated, frees the process’s local copy of the environment block segment stored at PSP:002Ch.

Transfer of Control

The final stage of INT 20h execution transfers execution flow back to the caller. The kernel sets the stack pointer to the parent's stack frame, clears any transient flags, and performs a far jump to the address retrieved from PSP:000Ah (the restored INT 22h vector).

In MS-DOS 6.22, this address typically returns control to the resident portion of COMMAND.COM. The command interpreter verifies its own checksum in memory; if corrupt, it reloads its transient portion from disk before displaying the standard command prompt.

Limitations in MS-DOS 6.22

While functional in MS-DOS 6.22, INT 20h is considered obsolete compared to INT 21h, Function 4Ch. INT 20h cannot pass an exit return code (ERRORLEVEL) to batch files, requires strict preservation of CS matching the PSP segment, and leaves handle management partially dependent on prior application cleanup. DOS 6.22 processes INT 20h by internally routing components of the call through the general process termination routines used by INT 21h, but without the benefit of return-code signaling.