home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / dosstack.arc / DOSSTACK.TXT
Encoding:
Text File  |  1987-04-18  |  9.0 KB  |  175 lines

  1.  
  2. Date: Fri 16 May 86 13:21:00-PDT
  3. From: Ted Shapin <BEC.SHAPIN@USC-ECL.ARPA>
  4. Subject: DOS 3.2 Fatal Internal Stack Failure
  5. To: info-ibmpc@USC-ISIB.ARPA
  6.  
  7.  
  8.  TITLE:    04/21/86 PC DOS :   PC-FLASH - DOS 3.2 STACK MANAGEMENT AS
  9.                     RELATED TO HARDWARE INTERRUPTS/ PAUSE KEY NOTES
  10. .
  11.  $SOURCE: ITEM 959MG  FROM EQUAL SYSTEM HONCDPD   3
  12.  SOURCE MATERIAL DATED:  APR86
  13. .
  14.  Q:
  15. Due to the confusion surrounding DOS 3.2 and its interrupt
  16. processing and a known problem with the enhanced keyboard's
  17. pause key, I will try to set the record straight.
  18. .
  19. PAUSE KEY
  20. Repeated use of the pause key while scrolling is already paused,
  21. will cause repeated interrupts, within the same interrupt
  22. handler.  This MAY lead to the exhaustion of DOS's stack pool
  23. leading to a DOS INTERNAL STACK ERROR.  This exposure was alluded
  24. to in the announcement letter under the Technical Assistance
  25. paragraph.  The supplemental information mentioned, is a software
  26. fix for the problem, which is available.  To circumvent the
  27. problem without the fix, the user need only hit the pause key
  28. once to pause scrolling, and any other key to resume scrolling
  29. since the PAUSE key is not a toggle key.
  30. .
  31. DOS 3.2
  32. DOS 3.2 has been enhanced to provide stack management for
  33. hardware interrupts, and allow the user to tune the system using
  34. the STACKS parameter of CONFIG.SYS.  This enhancement allows for
  35. the use of available applications in an environment which is
  36. interrupt intensive, i.e., high speed communications etc., at the
  37. expense of loosing memory to a stack pool.  Since most
  38. environments do not need more than 9 stacks, that number is the
  39. default and acceptable to most environments.
  40. .
  41. The following provides the details of DOS 3.2's stack management
  42. enhancement.  Only the detail necessary to explain DOS Stack
  43. Management as it relates to hardware interrupts has been
  44. provided.
  45. .
  46. DOS 3.2 Stack Management
  47. .
  48. This version of DOS has implemented a technique known as stack
  49. swapping when handling hardware interrupts.  When a hardware
  50. interrupt is generated, DOS gets control and swaps the stack that
  51. had been used for a clean DOS stack.  After swapping stacks DOS
  52. passes control to the interrupt handler associated with the
  53. hardware interrupt.  Upon return from the interrupt handler, DOS
  54. restores the old stack and adds the stack to its pool of stacks.
  55. .
  56. This implementation was necessary to allow existing applications
  57. to run in an interrupt intensive environment.  Prior to stack
  58. swapping, it was up to an application to maintain a large enough
  59. stack so that interrupt processing routines could use its stack.
  60. Hardware interrupts are unscheduled events and can occur at any
  61. time.  They may occur when executing a DOS function, an
  62. application or most importantly when another interrupt is being
  63. processed.  The last case, "when another interrupt is being
  64. processed" has an exposure.
  65. .
  66. An explanation of the exposure necessitates the understanding of
  67. how interrupts and stacks relate to one another.  We'll keep it
  68. as simple as we can.  The stack is an area of memory which can be
  69. thought of as a stack of boxes.  These boxes are used to
  70. temporarily store information.  In the case of interrupt
  71. processing, this information is the register values saved at the
  72. acknowledgement of an interrupt.  The interrupt handler saves
  73. these register values so they are preserved when the handler uses
  74. the registers for its own work.  The registers belong to the
  75. application etc.  which was running when the interrupt occurred.
  76. The interrupt handler must restore these registers when it
  77. prepares to return to the interrupted application so that
  78. application can continue processing where it was interrupted.
  79. Let's call the saving and restoring of these registers the
  80. preservation and restoration of the interrupted environment.  Do
  81. not confuse the DOS ENVIRONMENT STRINGS, with environment as
  82. discussed in this article.
  83. .
  84. Keep in mind that this environment could refer to DOS, the
  85. application or an interrupt handler, i.e., any code being executed
  86. when a hardware interrupt occurs.  So, the register values are
  87. put in the little boxes by the interrupt handler.  They are
  88. filled sequentially starting at the bottom of the stack and
  89. working up.  The pointer to the "next box" is maintained by the
  90. microprocessor.  When the interrupted environment is restored the
  91. data is taken from the boxes and placed back into the registers.
  92. The stack is allocated and defined by the application which is
  93. running.
  94. .
  95. Before the days of high speed communications (Token Ring) and
  96. multitasking the users stack was generally adequate in size to
  97. handle normal hardware interrupt processing.  Imagine, if you
  98. will, the problem encountered if an application is interrupted
  99. and the environment saved, then the interrupt handler is
  100. interrupted and the environment saved and on and on.  This could
  101. represent an interrupt intensive environment.
  102. .
  103. Note that interrupts are occurring so fast that an interrupt
  104. handler never gets a chance to restore the environment and thus
  105. free up some boxes in the stack.  If the stack is not large
  106. enough to accommodate all these saved environments then boxes are
  107. still filled even though they aren't within the allocated stack.
  108. When the stack is exceeded as discussed, an overlay condition
  109. exists where the environment was saved outside of the defined
  110. stack area.  This leads to unexplained errors such as no response
  111. from the keyboard (hang), or divide overflow or divide by zero
  112. etc, because executable instructions or data was overlayed.
  113. .
  114. Since the application defines and owns the stack, and the PC, in
  115. an increasingly number of cases, is being subject to an abundance
  116. of interrupts, DOS 3.2 was designed to utilize stack swapping.
  117. With DOS 3.2 the exposure of interrupting an interrupt handler
  118. and over utilizing the application's stack has disappeared since
  119. DOS manages the stacks used by the hardware interrupt routines.
  120. Now when an interrupt occurs the applications stack is saved and
  121. DOS passes a free DOS stack, from its pool of stacks, to the
  122. interrupt handler.  This stack is used the same way the original
  123. stack was used, to save and restore the environment.  Now when a
  124. second interrupt occurs while processing the first interrupt, DOS
  125. uses another free stack, and so forth and so on until all the
  126. environments are restored, and all the stacks swap back until,
  127. finally, the application gets its stack back and continues
  128. processing.
  129. .
  130. There aren't an infinite number of DOS stacks, so it is possible
  131. for DOS to find itself in a position that he cannot swap to a
  132. free stack because they are all being used.  This will result in
  133. an error message with DOS 3.2 which reads;
  134.            FATAL:INTERNAL STACK FAILURE, SYSTEM HALTED
  135. In the past, the user could not be notified that they had a stack
  136. problem (overlay), except by hangs and unrelated error messages.
  137. With DOS 3.2, a notice is provided prior to locking up the
  138. machine.  There is no way to recover from the error without
  139. loosing data integrity so the machine is put into a never-ending
  140. loop by DOS.  While data may be lost, the error is an indication
  141. that the number of stacks used by DOS should be increased, as
  142. your configuration is exceeding the available stack space via
  143. hardware interrupts.
  144. .
  145. A new CONFIG.SYS parameter allows the user to redefine the number
  146. of stacks to be allocated and used by DOS to prevent future
  147. errors and the subsequent lose of data.  This new parameter is
  148. the STACKS parameter and is located in the DOS users manual on
  149. page B-2.  If you are worried about experiencing this problem you
  150. could set the STACKS parameter to its maximum and have an
  151. excellent chance of never experiencing the error.  However,
  152. nothing is free, and you would have lost 32k of memory to the DOS
  153. stacks.  Since DOS is growing from release to release it is
  154. better to allow the user to set the amount of memory he can
  155. afford to utilize for stack space, rather than add another 32k to
  156. DOS.  Keep in mind that only users in an interrupt intensive
  157. environment will need to alter the default STACKS parameter.
  158. .
  159. For those of you unfamiliar with PC interrupts, the following is
  160. a partial list of some of the more popular adapters and PC
  161. functions using interrupts;
  162.            TOD CLOCK       (religiously 1 interrupt every 18.6 ms)
  163.            KEYBOARD        (pressing and releasing key)
  164.            3278/79 ADAPTER
  165.            ASYNCH ADAPTER
  166.            BSC ADAPTER
  167.            SDLC ADAPTER
  168.            NETWORK ADAPTER
  169.            TOKEN RING ADAPTER
  170.            DISKETTE DRIVE
  171.            FIXED DISK DRIVE
  172.            DACQ ADAPTER
  173.  
  174. ------------------------------
  175.