home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / f / forthmac / !Forthmacs / docs / html / armtraps < prev    next >
Encoding:
Text File  |  1997-05-01  |  10.3 KB  |  255 lines

  1. <!-- Forthmacs Formatter generated HTML V.2 output -->
  2. <html>
  3. <head>
  4. <title>Hardware crashes</title>
  5. </head>
  6. <body>
  7. <h1>Hardware crashes</h1>
  8. <hr>
  9. <p>
  10. This chapter describes how RISC OS Forthmacs copes with hardware exceptions such 
  11. as Prefetch Errors, Address Errors, and Divide by Zero, and offers suggestions 
  12. about debugging software which causes such problems.  
  13. <p>
  14. After a hardware exception (or a hardware-like trap) such as an Address Error, 
  15. Prefetch Error, Divide-by-Zero, etc, RISC OS Forthmacs will attempt to recover.  
  16. The state of the registers and the stacks just before the crash are stored in a 
  17. safe place, where it may be examined with <code><A href="_smal_BX#2CF">showcrash</A>.</code> 
  18. <p>
  19. The current RISC OS Forthmacs version works fine with StrongARM cpus.  
  20. <p>
  21. All registers are saved to the <code><A href="_smal_BG#4E">registers</A></code> 
  22. buffer.  The <code><A href="_smal_AX#167">bug</A></code> <code><A href="_smal_BR#329">vocabulary</A></code> 
  23. holds tools for handling the registers saved to this area.  There are objects 
  24. called <strong>r0 r1 top sp pc psr ...</strong> that can be inspected and 
  25. changed by the user.  An example: 
  26. <p>
  27. <p><pre>       h# fffffff @</pre><p>
  28. <p><pre>                ------ an exception occurs</pre><p>
  29. <p><pre>       showcrash</pre><p>
  30. <p><pre>       top .    h# 8000 to top</pre><p>
  31. <p><pre>       showcrash  top .</pre><p>
  32. <p><pre>       (restart</pre><p>
  33. <p>
  34. This is used by several debugger tools and can be freely extended by user 
  35. applications.  
  36. <p>
  37. <p>
  38. <h2>Error handling</h2>
  39. <p>
  40. The error-handling is rather complex in this implementation, all hardware- or 
  41. hardware related errors are managed within RISC OS Forthmacs runtime system, 
  42. processor-mode problems are hidden before you, and you will have to remember one 
  43. single level of <strong>error-managing</strong> .  
  44. <p>
  45. All error conditions at last use <strong>error-handle</strong> later branching 
  46. to the appropriate specialized error-handler.  You may redefine the handler 
  47. according to your needs.  The error handlers: 
  48. <p>
  49. <p><pre>
  50.     : serve-error       \ ( exeption# -- ) standard error handler
  51.         up@ main-task <> if drop -1 then throw ;
  52.     
  53.     defer handle-error      ' serve-error is handle-error
  54.     defer handle-breakpoint ' serve-error is handle-breakpoint
  55.     defer handle-escape     ' serve-error is handle-escape
  56.     defer handle-data       ' serve-error is handle-data
  57.     defer handle-address    ' serve-error is handle-address
  58.     defer handle-prefetch   ' serve-error is handle-prefetch
  59.     defer handle-div0       ' serve-error is handle-div0
  60. </pre><p>
  61. <p>
  62. <p>
  63. <code><A href="_smal_BD#4B">handle-error</A>,</code> all RISC OS error calls go 
  64. via this handler, use this to generate your own error conditions.  <code><A href="_smal_AD#333">why</A></code> 
  65. will work perfectly with this.  
  66. <p>
  67. <code><A href="_smal_BA#48">handle-breakpoint</A>,</code> a breakpoint 
  68. instruction OS_BreakPt will go via this handler.  
  69. <p>
  70. <code><A href="_smal_BE#4C">handle-escape</A>,</code> escape conditions use this 
  71. handler, currently this works like a RISC OS Forthmacs "reset" key outside the <code><A href="_smal_AP#1EF">expect</A></code> 
  72. loop.  
  73. <p>
  74. <code><A href="_smal_AX#47">handle-address</A>,</code> tried to access memory 
  75. above $3ffffff.  
  76. <p>
  77. <code><A href="_smal_BB#49">handle-data</A></code> and <code><A href="_smal_BF#4D">handle-prefetch</A>,</code> 
  78. access to data/instructions was aborted from the MMU, there wasn't any memory.  
  79. <p>
  80. <code><A href="_smal_BC#4A">handle-div0</A>,</code> tried to divide by zero 
  81. <p>
  82. <p>
  83. <h2>Debugging Tools Glossary</h2>
  84. <p>
  85.  
  86. <hr><h3><A name="42">(restart</A> ( -- )</h3>
  87.  Extra: bug
  88. <br>
  89. Restart RISC OS Forthmacs after a hardware crash, the registers must have been 
  90. saved before (this is done by the error-handler), <code><A href="_smal_AS#42">(restart</A></code> 
  91. takes care about the cpu status.  
  92. <p>
  93. This can be used for developing debuggers, virtual memory managers etc.  
  94. <p>
  95. Implementation Note: For security reasons, <code><A href="_smal_AS#42">(restart</A></code> 
  96. can't set supervisor mode.  This restricts debuggers using this word to user 
  97. mode debugging.  You could easily change this by adding the 
  98. "set-supervisor-mode" swi in the <code><A href="_smal_AS#42">(restart</A></code> 
  99. code.  
  100.  
  101. <hr><h3><A name="43">.registers</A> ( -- )</h3>
  102. <br>
  103. Displays the CPU registers values that were saved the last time that a 
  104. breakpoint or exception occurred.  
  105. <p>
  106. The contents of the <code><A href="_smal_BI#50">pc</A></code> have been split to 
  107. the program-counter <code><A href="_smal_BI#50">pc</A></code> and the 
  108. status/flag register <code><A href="_smal_BK#52">psr</A></code> 
  109.  
  110. <hr><h3><A name="44">.sr</A> ( --  )</h3>
  111. <br>
  112. Decodes and displays the contents of the ARM Status Register part of the <code><A href="_smal_BI#50">pc</A></code> 
  113. register that was saved at the last breakpoint or exception.  The Status 
  114. Register contains the Condition Codes, the Priority level and the interrupt 
  115. level.  The display looks something like this: 
  116. <p><pre>       nZcvif    user mode</pre><p>
  117. "nZcvif" is the condition codes.  An upper case letter indicates that the 
  118. corresponding bit is on.  In the case the "Z" (zero) bit is on and the other 
  119. bits (Negative, Carry, oVerflow and the mode registers) are off.  
  120.  
  121. <hr><h3><A name="45">.stack</A> ( --  )</h3>
  122. <br>
  123. Displays the Data Stack saved at the last breakpoint or exception.  If the 
  124. breakpoint occurred as a result of a RISC OS signal, the system may have been 
  125. executing a system call at the time of the signal.  If so, there may be extra 
  126. stuff on the stack such as C procedure activation frames.  
  127.  
  128. <hr><h3><A name="46">ftrace</A> ( -- )</h3>
  129. <br>
  130. Display the return stack after a crash, if the return stack pointer was outside 
  131. the RISC OS Forthmacs stack, there will only rudimentary information be given.  
  132. Tries to give not the cfa's but the words real names.  
  133.  
  134. <hr><h3><A name="47">handle-address</A> ( --  )</h3>
  135.  Extra: Deferred, System
  136. <br>
  137. This handler is used whenever an address exception has happened, mostly cause by 
  138. a wrong address using <strong>@ !</strong> etc.  
  139. <p>
  140. RISC OS Forthmacs has a common error handler for all kinds of errors.  This 
  141. handler takes care of cpu state, operating system level etc.  All register data 
  142. can be found in <strong>registers</strong> , r0 at the lowest address.  The 
  143. stacks are saved at <strong>rssave</strong> and <strong>pssave</strong> .  
  144.  
  145. See: <code><A href="_smal_BX#2CF">showcrash</A></code> At it's end it jumps into 
  146. the error-specific handler, by default this is <strong>serve-error</strong> in 
  147. all cases, but you can install your own error handling code instead.  The cpu 
  148. level debugger uses <code><A href="_smal_BA#48">handle-breakpoint</A>,</code> 
  149. virtual memory could be implemented easily using <code><A href="_smal_BB#49">handle-data</A></code> 
  150. and <code><A href="_smal_AX#47">handle-address</A>.</code> 
  151.  
  152. See: <code><A href="_smal_BX#2CF">showcrash</A></code> 
  153.  
  154. <hr><h3><A name="48">handle-breakpoint</A> ( --  )</h3>
  155.  Extra: Deferred, System
  156. <br>
  157. This handler is executed whenever a OS_Breakpt instruction was trapped.  Use 
  158. this for more advanced debugging tools.  
  159.  
  160. See: <code><A href="_smal_AX#47">handle-address</A></code> 
  161.  
  162. <hr><h3><A name="49">handle-data</A> ( --  )</h3>
  163.  Extra: Deferred, System
  164. <br>
  165. This handler is used whenever a data abort has happened, mostly cause by a wrong 
  166. address using <strong>@ !</strong> etc.  
  167.  
  168. See: <code><A href="_smal_AX#47">handle-address</A></code> 
  169.  
  170. <hr><h3><A name="4A">handle-div0</A> ( --  )</h3>
  171.  Extra: Deferred, System
  172. <br>
  173. This (emulated) exception is executed when a divide by zero error has happened.  
  174.  
  175. See: <code><A href="_smal_AX#47">handle-address</A></code> 
  176.  
  177. <hr><h3><A name="4B">handle-error</A> ( --  )</h3>
  178.  Extra: Deferred, System
  179. <br>
  180. This handler is used when errors requested by you take place.  Use this for your 
  181. application specific error handling.  
  182.  
  183. See: <code><A href="_smal_AX#47">handle-address</A></code> 
  184.  
  185. <hr><h3><A name="4C">handle-escape</A> ( --  )</h3>
  186.  Extra: Deferred, System
  187. <br>
  188. This handler is used when an escape condition has happened.  Escape conditions 
  189. can be generated by pressing the Ctrl-Sh-F12 key.  
  190. <p>
  191.  
  192. See: <code><A href="_smal_AX#47">handle-address</A></code> 
  193.  
  194. <hr><h3><A name="4D">handle-prefetch</A> ( --  )</h3>
  195.  Extra: Deferred, System
  196. <br>
  197. This handler is used whenever a prefetch abort has happened, usually caused by 
  198. executing code in nirvana.  
  199.  
  200. See: <code><A href="_smal_AX#47">handle-address</A></code> 
  201.  
  202. <hr><h3><A name="4E">registers</A> ( -- addr  )</h3>
  203.  Extra: bug 
  204. <br>
  205. The address of a buffer holding all register contents after the last exception.  
  206.  
  207. <hr><h3><A name="4F">r0</A> ( -- n )</h3>
  208.  Extra: bug
  209. <br>
  210. n is the value contained in the saved copy of register r0.  RR0 may be modified 
  211. with the <code><A href="_smal_BQ#2F8">to</A></code> command.  Other data 
  212. register names are RR0, RSP etc.  
  213.  
  214. See: <code><A href="_smal_BQ#2F8">to</A></code> <code><A href="_smal_AT#43">.registers</A></code> 
  215.  
  216. <hr><h3><A name="50">pc</A> ( -- n )</h3>
  217.  Extra: bug
  218. <br>
  219. n is the value contained in the saved copy of the Program Counter.  This value 
  220. is used as the address where the program is restarted for the <code><A href="_smal_AD#63">step</A></code> 
  221. , <code><A href="_smal_AE#64">steps</A></code> , and <code><A href="_smal_BW#5E">continue</A></code> 
  222. commands.  <code><A href="_smal_BI#50">pc</A></code> may be modified with the <code><A href="_smal_BQ#2F8">to</A></code> 
  223. command.  Pipeline effects have been cleared.  
  224.  
  225. <hr><h3><A name="51">sp</A> ( -- n )</h3>
  226.  Extra: bug 
  227. <br>
  228. n is the value contained in the saved copy of the Stack Pointer.  
  229.  
  230. <hr><h3><A name="52">psr</A> ( -- n )</h3>
  231.  Extra: bug 
  232. <br>
  233. n is the value contained in the saved copy of the Status Register.  The Status 
  234. Register contains the Condition Codes, the Priority level and the Interrupt 
  235. level.  RSR may be modified with the <code><A href="_smal_BQ#2F8">to</A></code> 
  236. command.  
  237.  
  238. See: <code><A href="_smal_AU#44">.sr</A></code> 
  239.  
  240. <hr><h3><A name="53">up</A> ( -- n )</h3>
  241.  Extra: bug 
  242. <br>
  243. n is the value contained in the saved copy of the User-area Pointer.  
  244.  
  245. See: RR0 
  246.  
  247. <hr><h3><A name="54">showcrash</A> ( --  )</h3>
  248. <br>
  249. Displays all the information saved at the last breakpoint or exception including 
  250. the registers (as in <code><A href="_smal_AT#43">.registers)</A>,</code> the 
  251. data stack (as in <code><A href="_smal_AV#45">.stack)</A>,</code> and the return 
  252. stack (as in <code><A href="_smal_AW#46">ftrace)</A>.</code> 
  253. </body>
  254. </html>
  255.