Shop OBEX P1 Docs P2 Docs Learn Events
Debug SPIN and ASM - LMM style — Parallax Forums

Debug SPIN and ASM - LMM style

Cluso99Cluso99 Posts: 18,069
edited 2008-09-04 01:35 in Propeller 1
Here is the code I am using to trace my Fast Spin Intepreter. The debug section resides in hub ram and is executed LMM style in the cog which makes the debugger extremely flexible. It is not strictly PASM although it compiles that way - this is because a JMP actually needs to change the hub address.
Only 6 longs are used anywhere in the PASM·cog being tested. Currently it only gets executed once each loop of spin bytecode fetching. I am expanding it to be also single step, but I think this will require 8 longs in the PASM cog.
Enjoy cool.gif
'
loop
'  --------- Ray's Debugger Kernel ---------
              fit       $008                    '<--- hardcoded to $0008
:hptr         long      HUB_RAM                 'hub buffer (careful other programs don't overwrite)  executes as nop 
:dptr         long      HUB_RAM + $0200         'debug data from cog
:dloop        rdlong    :dinstr,:hptr           'read an instruction from hub                                         
:dinc         add       :hptr,#0                'inc hub ptr                                                          
:dinstr       nop                               '<--- instr to be executed  (reads "sub :hptr,#4" when waiting)                                          
              tjnz      :dinstr,#:dloop         'loop if not 0 (i.e. nop ends external execution)                     
'&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;&#61610;&#61609;


DAT
'  &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
'  &#9474;    Debugger LMM style code for RamInterpreter debugging                  &#9474;
'  &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
              org                                       '<---- following code copied to $0000_7000 in hub ram
debugger
'this is the debug code used in the RamInterpreter
'       :hptr         long      HUB_RAM                 'hub buffer (careful other programs don't overwrite)  executes as nop
'       :dptr         long      HUB_RAM + $0200         'debug data from cog
'       :dloop        rdlong    :dinstr,:hptr           'read an instruction from hub
'       :dinc         add       :hptr,#4                'inc hub ptr
'       :dinstr       nop                               '<--- instr to be executed
'       :dtjnz        tjnz      :dinstr,#:dloop         'loop if not 0 (i.e. nop ends external execution)
'Note: cannot use labels for effective jumps as cog is addressed as longs but we are using hub memory which is *4
              org       $0                              '<---- $0000_7000 in hub ram
              movs      dinc,#4                         'start the RamInterpreter debugger
                                                        '... the RamInterpreter is already running in cog 0
              cmp       id,#2   wz
'       if_z  movs      hptr,#do_debug << 2             'j if cog 2 goto debug
              movs      hptr,#do_debug << 2             'j if cog 2 goto debug
'--------------------------------------------
no_debug      movs      dptr,id
              wrbyte    hptr,dptr                       '#14  indicate active cogs not being debugged
no_debug1     nop                                       '\\ bypass debug for all other cogs
              movs      hptr,#no_debug1 << 2            '// 
'--------------------------------------------
do_debug      movs      dptr,id
              wrbyte    hptr,dptr                       '#24  indicates active cog being debugged
do_debug1
'copy parameters...
              rdlong    dptr,hptr                       '\\ set dptr to following long value
              long      $0000_7208                      '// (decodes into nop)
              
              wrlong    pcurr,dptr
              add       dptr,#4
              wrlong    op,dptr
              add       dptr,#4
              wrlong    x,dptr
              add       dptr,#4
              wrlong    y,dptr
              add       dptr,#4
              wrlong    a,dptr
              add       dptr,#4
              wrlong    t1,dptr
              add       dptr,#4
              wrlong    t2,dptr
              add       dptr,#4
              wrlong    op,dptr
              add       dptr,#4
              wrlong    op2,dptr
              add       dptr,#4
              wrlong    adr,dptr
              add       dptr,#4
              
              wrlong    dcall,dptr
              add       dptr,#4
              wrlong    pbase,dptr
              add       dptr,#4
              wrlong    vbase,dptr
              add       dptr,#4
              wrlong    dbase,dptr
              add       dptr,#4
              wrlong    pcurr,dptr
              add       dptr,#4
              wrlong    dcurr,dptr               
              add       dptr,#4
 
'now wait for sync from spin code
              mov       dptr,hptr                       '\ save next hub address
sync_debug    sub       hptr,#4                         '| <--- wait here until becomes "sub #0"                           
              wrbyte    dinc,dptr                       '/ set prev instr back to "sub #4" (wait)
              nop                                       'run another loop
              movs      hptr,#do_debug1 << 2            'send the debugger around another loop
'--------------------------------------------
              long      $0000_0001                      'should never get here - will cause the debug kernel to loop indef.


Post Edited (Cluso99) : 8/27/2008 10:52:52 PM GMT

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-27 22:49
    I have seen the joint work on other threads, particularly the sqrt one, so I thought I would throw the following open (unfinished) debuggers into the forum.

    ASM:
    ====
    The concept is simple. Your program must have 8 nops (long 0's) at the beginning of the asm code. Your spin code declares an object

    OBJ
    ·dbg : "ClusoDebugger"

    and before launching you asm code via cognew you call (in spin) the debugger

    · dbg.start(....params...)

    When the dbg.start routine returns the debugger·is·ready·and the 8 longs have been updated by the debugger (in spin) to be ready for the cognew of your asm code

    · Cog := cognew(@entry, @yourparam) + 1

    The debugger does not actually use a cog for itself, although it does use the FullDuplexSerial object to send out debug information. It is simple to modify this to be the TV or VGA output if you would rather.

    SPIN:
    ====
    Once again it uses 8 longs (actually working with 6 longs) at the start of the Ram Interpreter (a modified version). The same concept as the ASM debugger described above. I actually had this spin version working first. It uses the FDX object as well, and outputs each bytecode executed, the pc and results. The code is listed in the post above, but of course you will need the Ram Interpreter.

    See the thread·Spin Interpreter - Faster???·http://forums.parallax.com/showthread.php?p=731577

    DEBUGGER:
    ========
    The debugger runs much like an LMM model, which is a little more cumbersome to write/modify but makes it fairly simple to extend.

    I just use PST (Parallx/Propeller Serial Terminal) to watch the results. I'll use Hyperterminal to capture the results for later viewing. If someone would like to tie in the output with a PC program (Hippy - your prop viewer perhaps???) I think that would be great. Otherwise I can do that much later.

    I will post the ASM debugger code shortly - just making some changes. redface.gif
  • jazzedjazzed Posts: 11,803
    edited 2008-08-28 03:18
    I just wanted you to know that I am watching your project and will jump in when I have more time since you are opening up new opportunities with your work. Thanks for your persistence.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • Mike HuseltonMike Huselton Posts: 746
    edited 2008-08-28 07:29
    Steve and Cluso99,

    I too, am watching closely. Before I add anything, I want to allow you two cooks to take the lead.

    This one's hot!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH - Electronics: Engineer - Programming: Professional
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-29 06:00
    I promised to post where I am up to - not as far as I would have liked, so take it for what it's worth.

    Attached debug LMM style code for PASM.

    Postedit: There is a bug... $+4 and $-4 sould be $+1 and $-1 because they are then shifted <<2.

    Post Edited (Cluso99) : 8/31/2008 12:19:11 PM GMT
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-09-04 01:35
    See new thread... (Also intended to do spin debugging)

    PASM debug with Zero Footprint· http://forums.parallax.com/showthread.php?p=748420

    Enjoy cool.gif
Sign In or Register to comment.