home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tcom96 / debugger / break96.seq < prev    next >
Encoding:
Text File  |  1991-04-09  |  7.4 KB  |  207 lines

  1. \\ Break96.SEQ       Part of a debugger for Intel 80c196        by Mike Mayo
  2. ─────────────────────────────────────────────────────────────────────────────
  3. $Header:   F:/tcom96/debugger/logs/break96.sev   1.0   23 Apr 1991 11:03:04   MikeM  $
  4. ─────────────────────────────────────────────────────────────────────────────
  5.  
  6. This is 80c196 target-specific stuff for the debugger.
  7. It configures the breakpoint system to use the TRAP instruction.
  8.  
  9. ─────────────────────────────────────────────────────────────────────────────
  10. $Log:   F:/tcom96/debugger/logs/break96.sev  $
  11.  \ 
  12.  \    Rev 1.0   23 Apr 1991 11:03:04   MikeM
  13.  \ Initial revision.
  14. ─────────────────────────────────────────────────────────────────────────────
  15. {
  16.  
  17. $F7 value TRAP-INST     \ the target's breakpoint instruction
  18. $C0 value targ-sp0      \ the target's parameter stack initial address
  19.  
  20. : untrap ( -- ) \ serial port command to return from a trap
  21.         26 command
  22.         ;
  23.  
  24. : tunbreak ( ta a -- )  \ remove trap from location ta
  25.                         \ Data to restore into target is at a
  26.         c@ swap tc!
  27.         ;
  28.  
  29. : tsetbreak ( a ta -- ) \ Set a trap at location ta
  30.                         \ Save data at that location into host at a
  31.         dup tc@ rot c!          \ save byte at breakpoint
  32.         trap-inst swap tc!      \ insert TRAP instruction
  33.         ;
  34.  
  35. }       Here is the breakpoint register configuration
  36.         There are 3 bytes per breakpoint for TMS320c14
  37. Bytes 0,1       Address  ( 0 means not set )
  38. Bytes 2         Saved byte, overwritten in the target by a TRAP instruction
  39.  
  40. {
  41. 2 value #breakregs      \ Maximum number of breakpoints allowed
  42. 1 value #trapbytes      \ Number of bytes occupied in the target by
  43.                         \ the patched-in code at a breakpoint
  44.  
  45. }
  46. ─────────────────────────────────────────────────────────────────────────────
  47.     Places to hold images of the registers that are sent back by
  48.     the trap interrupt handler in the target.
  49. ─────────────────────────────────────────────────────────────────────────────
  50. {
  51. variable debugRS                \ stack pointer
  52. debugRS         reg! =SP
  53. debugRS         reg@ SP-@
  54.  
  55. variable debugflags
  56. debugflags      reg! =flags
  57. debugflags      reg@ flags-@
  58.  
  59. variable debugw2
  60. debugw2         reg! =w2
  61. debugw2         reg@ w2-@
  62.  
  63. variable debugw0
  64. debugw0         reg! =w0
  65. debugw0         reg@ w0-@
  66.  
  67. variable debugttos2
  68. debugttos2      reg! =ttos2
  69. debugttos2      reg@ ttos2-@
  70.  
  71. variable debugttos
  72. debugttos       reg! =ttos
  73. debugttos       reg@ ttos-@
  74.  
  75. variable debugpsp
  76. debugpsp        reg! =psp
  77. debugpsp        reg@ psp-@
  78.  
  79. variable debugtrapadr
  80. debugtrapadr    reg! =trapadr
  81. debugtrapadr    reg@ trapadr-@
  82.  
  83.  
  84. }
  85. ─────────────────────────────────────────────────────────────────────────────
  86.   words to copy the target stack after a TRAP, and before returning
  87. ─────────────────────────────────────────────────────────────────────────────
  88. {
  89. : read-break-stack ( a -- ) \ read in the machine state that is placed on
  90.                             \ the stack after a TRAP
  91.            dup t@    =W2
  92.         2+ dup t@    =W0
  93.         2+ dup t@    =TTOS2
  94.         2+ dup t@    =TTOS
  95.         2+ dup t@    =PSP
  96.         2+ dup t@    =FLAGS
  97.         2+ dup t@ 1- =TRAPADR   \ 1- so we get the address where the trap was
  98.         2+           =SP
  99.         ;
  100.  
  101. : restore-break-stack ( -- ) \ place values, possibly modified, back on the
  102.                              \ machine stack before returning from a TRAP
  103.         SP-@  2-
  104.         TRAPADR-@       over t!  2-
  105.         FLAGS-@         over t!  2-
  106.         PSP-@           over t!  2-
  107.         TTOS-@          over t!  2-
  108.         TTOS2-@         over t!  2-
  109.         W0-@            over t!  2-
  110.         W2-@            swap t!
  111.         ;
  112. }
  113. ─────────────────────────────────────────────────────────────────────────────
  114.     Branching analysis, used when setting breakpoints
  115. ─────────────────────────────────────────────────────────────────────────────
  116. {
  117. 0 value nextonbranch
  118.  
  119. : branch-type ( -- type )
  120.         \ return a number saying what type of branch is next, if any.
  121.         \ Also compute branch destination
  122.  
  123.         TRAPADR-@
  124.         dup tc@
  125.         [ forth ]
  126.                 \ VARIOUS CONDITIONS AND EXITS
  127.                 \ type 0        non-branching instructions
  128.                 \ type 1        unconditional branch
  129.                 \ type 2        conditional branches
  130.                 \ type 3        calls
  131.  
  132.         dup $F8 and $28 = if    7 and 256 *             \ SCALL
  133.                                 over 1+ tc@ sext
  134.                                 + + 2+ =: nextonbranch
  135.                                 3 exit
  136.                         then
  137.  
  138.         dup         $EF = if    drop                    \ LCALL
  139.                                 1+ dup  dup tc@ swap 1+ tc@ 256 * +
  140.                                 + 2+ =: nextonbranch
  141.                                 3 exit
  142.                         then
  143.  
  144.         dup $F0 and $30 = if    drop                    \ bit conditionals
  145.                                 2+ dup tc@ sext
  146.                                 + 1+  =: nextonbranch
  147.                                 2 exit
  148.                         then
  149.  
  150.         dup $F0 and $D0 = if    drop                    \ flag conditionals
  151.                                 1+ dup tc@ sext
  152.                                 + 1+  =: nextonbranch
  153.                                 2 exit
  154.                         then
  155.  
  156.         dup $F8 and $20 = if    7 and 256 *             \ SJMP
  157.                                 over 1+ tc@ sext
  158.                                 + + 2+ =: nextonbranch
  159.                                 1 exit
  160.                         then
  161.  
  162.         dup         $E3 = if    drop                    \ BR [ reg ]
  163.                                 1+ tc@
  164.                                 t@  =: nextonbranch
  165.                                 1 exit
  166.                         then
  167.  
  168.         dup         $E7 = if    drop                    \ LJMP
  169.                                 1+ dup  dup tc@ swap 1+ tc@ 256 * +
  170.                                 + 2+ =: nextonbranch
  171.                                 1 exit
  172.                         then
  173.  
  174.         dup         $F0 = if    2drop                   \ RET
  175.                                 SP-@  t@  =: nextonbranch
  176.                                 1 exit
  177.                         then
  178.  
  179.         dup         $FF = if    2drop                   \ RESET
  180.                                 $2080  =: nextonbranch
  181.                                 1 exit
  182.                         then
  183.  
  184.         2drop 0         \ everything else
  185.         off> nextonbranch
  186.         ;
  187. }
  188. ─────────────────────────────────────────────────────────────────────────────
  189.   Display the processor registers
  190. ─────────────────────────────────────────────────────────────────────────────
  191. {
  192. : .regs         ( -- )
  193.         rplace 2@ at
  194.         ."  \1W0" w0-@                  space h.4       rcr
  195.         ."  \1W2" w2-@                  space h.4       rcr
  196.         ."  \1TTOS" ttos-@              space h.4       rcr
  197.         ."  \1TTOS2" ttos2-@            space h.4       rcr
  198.         ."  \1StatusReg" flags-@        space h.4       rcr
  199.         ."  ----------------"                           rcr
  200.         ."  --------znvtc-is"                           rcr
  201.         2 save!> base
  202.         space
  203.         flags-@ 0 <# 16 0 do # loop #> type
  204.         restore> base
  205.         ;
  206.  
  207.