home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / forthmacs / htmldocs / !Forthmacs / docs / html / armtraps < prev    next >
Encoding:
Text File  |  1996-02-23  |  10.5 KB  |  256 lines

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