Article ID: 84300 - Last Review: May 12, 2003 - Revision: 2.0 How to Use the STACKS= Setting in the CONFIG.SYS FileThis article was previously published under Q84300 On This PageSUMMARY
Mysterious hangs or failures can occur when a hardware routine does
not have enough storage space to perform its job. To avoid this
problem, MS-DOS versions 3.2 and later provide additional storage
space for the interrupt-handling code whenever a hardware interrupt
occurs. This is done by changing the current storage area (called a
"stack," because it is a place to stack information temporarily) to a
new storage area provided by MS-DOS.
By default, nine of these stacks, each 128 bytes in size, are provided. The number and size of stacks can be increased using the CONFIG.SYS STACKS=n,m command, where n is the number of stacks and m is the size of each stack in bytes. Changing the current stack takes time. It was discovered that changing the stack can slow the system enough that some programs, particularly high-speed communications programs, will fail. To avoid this problem, MS-DOS versions 3.3 and later allow disabling the stack swapping by specifying 0 stacks of 0 bytes in size (STACKS=0,0). Because the STACKS= command affects hardware- and configuration-dependent code, it can have unpredictable effects. Troubleshooting
MORE INFORMATION
Beginning in MS-DOS version 3.2, MS-DOS added code to swap the stack
whenever an asynchronous hardware interrupt occurs, before passing
control to the original interrupt handler. (Interrupt vectors 02H,
08-0EH, 70H, and 72-77H, corresponding to IRQs 0-15.) Before MS-DOS
3.2, interrupt handlers received control with the stack set to that of
whatever program or device driver was executing when the interrupt
occurred. Thus, if a program stack is nearly full and a hardware
interrupt occurs, random and unpredictable behavior will result
(typically a system hang).
Beginning in MS-DOS 3.3, the STACKS=0,0 line was added. This setting disables MS-DOS stack switching (thus returning MS-DOS stack behavior to that of MS-DOS versions 3.1 and earlier). That is, interrupts are processed using whichever stack happens to be loaded at the time of the interrupt. Because MS-DOS doesn't manage any stacks, less memory is required when 0,0 is specified. In addition, less time is required to handle interrupts because no code to swap stacks is executed. A negative aspect is that the same behavior that motivated support for stack swapping can occur (that is, system hangs and other random behavior as the stack overflows). If stack switching is enabled, MS-DOS ensures nested interrupts do not get the same stack. Upon completion of the interrupt processing, the stack is released so that MS-DOS may use it for a future interrupt. Ranges for n and m in STACKS=n,m
Default Values for STACKS
Troubleshooting NotesIf a system is experiencing random hangs or strange behavior and STACKS=0,0 is in the CONFIG.SYS file, this should be considered a prime suspect and removed. Conversely, some hardware that requires extremely fast interrupt processing may require STACKS=0,0 to operate properly. If you are having trouble with a high-speed communications or real-time program, try setting STACKS=0,0. If you have a program that worked correctly with MS-DOS 3.1 or earlier and you cannot get it to work with MS-DOS 3.2 or later, set STACKS=0,0.Error MessagesIf stack switching is enabled and MS-DOS runs out of free stacks, the following message will be displayed:
FATAL : Internal Stack Failure, System Halted.
Programming NotesIf you are hooking interrupts with the MS-DOS get/set interrupt vector services, stack switching will not be done before your interrupt handler gets control. Any stack switching necessary must be done by your interrupt handler.Reference(s): "Microsoft MS-DOS Encyclopedia," page 805 "Microsoft MS-DOS User's Guide and Reference," version 5.0 pages 250, 284, and 570 "Microsoft Systems Journal," July 1991; Vol. 6, No 4; pages 25-26 "Microsoft MS-DOS Programmer's Reference," version 5.0, pages 109-110 APPLIES TO
| Article Translations
|

Back to the top
