Debug SPIN and ASM - LMM style
Cluso99
Posts: 18,069
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
Post Edited (Cluso99) : 8/27/2008 10:52:52 PM GMT
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
' 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) '
DAT ' ┌──────────────────────────────────────────────────────────────────────────┐ ' │ Debugger LMM style code for RamInterpreter debugging │ ' └──────────────────────────────────────────────────────────────────────────┘ 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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
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
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
PASM debug with Zero Footprint· http://forums.parallax.com/showthread.php?p=748420
Enjoy