TITLE: 04/21/86 PC DOS : PC-FLASH - DOS 3.2 STACK MANAGEMENT AS RELATED TO HARDWARE INTERRUPTS/ PAUSE KEY NOTES . $SOURCE: ITEM 959MG FROM EQUAL SYSTEM HONCDPD 3 SOURCE MATERIAL DATED: APR86 . Q: Due to the confusion surrounding DOS 3.2 and its interrupt processing and a known problem with the enhanced keyboard's pause key, I will try to set the record straight. . PAUSE KEY Repeated use of the pause key while scrolling is already paused, will cause repeated interrupts, within the same interrupt handler. This MAY lead to the exhaustion of DOS's stack pool leading to a DOS INTERNAL STACK ERROR. This exposure was alluded to in the announcement letter under the Technical Assistance paragraph. The supplemental information mentioned, is a software fix for the problem, which is available. To circumvent the problem without the fix, the user need only hit the pause key once to pause scrolling, and any other key to resume scrolling since the PAUSE key is not a toggle key. . DOS 3.2 DOS 3.2 has been enhanced to provide stack management for hardware interrupts, and allow the user to tune the system using the STACKS parameter of CONFIG.SYS. This enhancement allows for the use of available applications in an environment which is interrupt intensive, i.e., high speed communications etc., at the expense of loosing memory to a stack pool. Since most environments do not need more than 9 stacks, that number is the default and acceptable to most environments. . The following provides the details of DOS 3.2's stack management enhancement. Only the detail necessary to explain DOS Stack Management as it relates to hardware interrupts has been provided. . DOS 3.2 Stack Management . This version of DOS has implemented a technique known as stack swapping when handling hardware interrupts. When a hardware interrupt is generated, DOS gets control and swaps the stack that had been used for a clean DOS stack. After swapping stacks DOS passes control to the interrupt handler associated with the hardware interrupt. Upon return from the interrupt handler, DOS restores the old stack and adds the stack to its pool of stacks. . This implementation was necessary to allow existing applications to run in an interrupt intensive environment. Prior to stack swapping, it was up to an application to maintain a large enough stack so that interrupt processing routines could use its stack. Hardware interrupts are unscheduled events and can occur at any time. They may occur when executing a DOS function, an application or most importantly when another interrupt is being processed. The last case, "when another interrupt is being processed" has an exposure. . An explanation of the exposure necessitates the understanding of how interrupts and stacks relate to one another. We'll keep it as simple as we can. The stack is an area of memory which can be thought of as a stack of boxes. These boxes are used to temporarily store information. In the case of interrupt processing, this information is the register values saved at the acknowledgement of an interrupt. The interrupt handler saves these register values so they are preserved when the handler uses the registers for its own work. The registers belong to the application etc. which was running when the interrupt occurred. The interrupt handler must restore these registers when it prepares to return to the interrupted application so that application can continue processing where it was interrupted. Let's call the saving and restoring of these registers the preservation and restoration of the interrupted environment. Do not confuse the DOS ENVIRONMENT STRINGS, with environment as discussed in this article. . Keep in mind that this environment could refer to DOS, the application or an interrupt handler, i.e., any code being executed when a hardware interrupt occurs. So, the register values are put in the little boxes by the interrupt handler. They are filled sequentially starting at the bottom of the stack and working up. The pointer to the "next box" is maintained by the microprocessor. When the interrupted environment is restored the data is taken from the boxes and placed back into the registers. The stack is allocated and defined by the application which is running. . Before the days of high speed communications (Token Ring) and multitasking the users stack was generally adequate in size to handle normal hardware interrupt processing. Imagine, if you will, the problem encountered if an application is interrupted and the environment saved, then the interrupt handler is interrupted and the environment saved and on and on. This could represent an interrupt intensive environment. . Note that interrupts are occurring so fast that an interrupt handler never gets a chance to restore the environment and thus free up some boxes in the stack. If the stack is not large enough to accommodate all these saved environments then boxes are still filled even though they aren't within the allocated stack. When the stack is exceeded as discussed, an overlay condition exists where the environment was saved outside of the defined stack area. This leads to unexplained errors such as no response from the keyboard (hang), or divide overflow or divide by zero etc, because executable instructions or data was overlayed. . Since the application defines and owns the stack, and the PC, in an increasingly number of cases, is being subject to an abundance of interrupts, DOS 3.2 was designed to utilize stack swapping. With DOS 3.2 the exposure of interrupting an interrupt handler and over utilizing the application's stack has disappeared since DOS manages the stacks used by the hardware interrupt routines. Now when an interrupt occurs the applications stack is saved and DOS passes a free DOS stack, from its pool of stacks, to the interrupt handler. This stack is used the same way the original stack was used, to save and restore the environment. Now when a second interrupt occurs while processing the first interrupt, DOS uses another free stack, and so forth and so on until all the environments are restored, and all the stacks swap back until, finally, the application gets its stack back and continues processing. . There aren't an infinite number of DOS stacks, so it is possible for DOS to find itself in a position that he cannot swap to a free stack because they are all being used. This will result in an error message with DOS 3.2 which reads; FATAL:INTERNAL STACK FAILURE, SYSTEM HALTED In the past, the user could not be notified that they had a stack problem (overlay), except by hangs and unrelated error messages. With DOS 3.2, a notice is provided prior to locking up the machine. There is no way to recover from the error without loosing data integrity so the machine is put into a never-ending loop by DOS. While data may be lost, the error is an indication that the number of stacks used by DOS should be increased, as your configuration is exceeding the available stack space via hardware interrupts. . A new CONFIG.SYS parameter allows the user to redefine the number of stacks to be allocated and used by DOS to prevent future errors and the subsequent lose of data. This new parameter is the STACKS parameter and is located in the DOS users manual on page B-2. If you are worried about experiencing this problem you could set the STACKS parameter to its maximum and have an excellent chance of never experiencing the error. However, nothing is free, and you would have lost 32k of memory to the DOS stacks. Since DOS is growing from release to release it is better to allow the user to set the amount of memory he can afford to utilize for stack space, rather than add another 32k to DOS. Keep in mind that only users in an interrupt intensive environment will need to alter the default STACKS parameter. . For those of you unfamiliar with PC interrupts, the following is a partial list of some of the more popular adapters and PC functions using interrupts; TOD CLOCK (religiously 1 interrupt every 18.6 ms) KEYBOARD (pressing and releasing key) 3278/79 ADAPTER ASYNCH ADAPTER BSC ADAPTER SDLC ADAPTER NETWORK ADAPTER TOKEN RING ADAPTER DISKETTE DRIVE FIXED DISK DRIVE DACQ ADAPTER ------------------------------