home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / f / forthmac / !Forthmacs / lib / arm / machdep < prev    next >
Encoding:
Text File  |  1997-02-26  |  2.3 KB  |  72 lines

  1. \ ARM specific mpu-code debugger
  2.  
  3. hex
  4. only forth also  bug also  system also  hidden also definitions
  5.  
  6. headerless \ **************************************************
  7.  
  8. defer op@    ' @  is op@
  9. defer op!    ' instruction! is op!
  10.  
  11. ef020017 constant breakpoint-opcode  \ XOS_Breakpt
  12. : amask        ( adr -- adr1)    3fffffc and ;
  13. : pc@        ( -- adr )    pc amask op@ ;
  14. : nxtpc        ( -- adr )    pc cell+ ;
  15.  
  16. : at-breakpoint? ( adr -- f)    @  breakpoint-opcode =  ;
  17. : put-breakpoint ( adr -- )    breakpoint-opcode swap op! ;
  18. : adr?        ( adr --adr/0)    amask dup ['] digit < if drop false then ;
  19.  
  20. : (tobranch)    ( -- addr )    pc dup @ ffffff and 2+ cells+ adr? ;
  21. : (to-mov)    ( -- addr )    registers pc@ 0f and cells+ @ adr? ;
  22. : (to-ldr)    ( -- addr )    registers pc@ 10 rshift 0f and cells+ @ @ adr? ;
  23.  
  24. \ Keep on improving:
  25. \ So far branch addresses are found for
  26. \ 1 branch, branch+link instructions
  27. \ 2 simple  pc r?? mov    instructions ( execute, return )
  28. \ 3 post-in/decremented  pc r??  ldr instructions
  29. \ 4 to-do    a general handling of mov and ldr instructions
  30. \        b ldm
  31. \        c pc r?? xx add   pc r?? xx sub <-- adr instruction
  32.  
  33. : next-instruction    ( following-jsrs? -- next-addr branch-target|0 )
  34.    if    ( bl )    pc@ 0f000000 and 0b000000 = if nxtpc (tobranch)    exit then
  35.    then
  36.     ( bl )    pc@ 0f000000 and 0b000000 = if nxtpc 0        exit then
  37.     ( al b)    pc@ ff000000 and ea000000 = if (tobranch) 0    exit then
  38.     ( b )    pc@ 0f000000 and 0a000000 = if nxtpc (tobranch) exit then
  39.  
  40. ( pc r?? mov )    pc@ fde0f000 and e1a0f000 = if (to-mov) 0    exit then
  41. ( pc r?? mov )    pc@ 0de0f000 and 01a0f000 = if nxtpc (to-mov)    exit then
  42.  
  43. ( pc r?? ldr )    pc@ fc50f000 and e410f000 = if (to-ldr) 0    exit then
  44. ( pc r?? ldr )    pc@ 0c50f000 and 0410f000 = if nxtpc (to-ldr)    exit then
  45.  
  46. ( others ..)    nxtpc 0 ;
  47.  
  48. code goto    ( adr -- )
  49.     r0    top    mov
  50.     top    sp    pop
  51.     pc    r0    mov end-code
  52. bug also
  53.  
  54. : bumppc    ( -- )        nxtpc is pc ;
  55. : set-pc    ( adr -- )    amask is pc ;
  56. : return-adr    ( -- adr )    rp cell+ @ ;    \ Word above stored link
  57. : leaf-return-adr  ( -- adr )    sp @ ;        \ Top of stack
  58. : loop-exit-adr  ( -- adr )
  59.     pc >r
  60.     begin    0 next-instruction ?dup        ( next-addr branch-target|0 )
  61.         if                \ If the branch was backwards, we're done
  62.             pc <  if drop pc r> is pc exit then    ( next-adr )
  63.         then
  64.         \ Not a branch or a branch forwards.
  65.         \ Advance to next instruction.
  66.         is pc
  67.         pc r@ - [ d# 250 cells ] literal >
  68.     until r> is pc
  69.     d# -350 throw ;
  70. headers \ ****************
  71. only forth also definitions
  72.