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

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