Shop OBEX P1 Docs P2 Docs Learn Events
P2 Taqoz V2.8 TRACING of a Variable: Serial Output of Return Chain and Stack — Parallax Forums

P2 Taqoz V2.8 TRACING of a Variable: Serial Output of Return Chain and Stack

Hi, this might perhaps be useful for others, groping because of mysterious trouble.
It uses absolute addresses of serial routines and cog, so they are fix here for the version! **So this will only work with the version _BOOT_P2.BIX in Taqoz.zip in https://sourceforge.net/projects/tachyon-forth/files/TAQOZ/binaries/ .
The assembler routines from TRACE are used here, so it should work, even, if the Forth system is defective.
It is meant for cog0.

What does it do?
While haunting some tricky bug, I tried to use TRACE! The problem was, that this can output very much text. So the question was, if this can be modified with a trigger to output text only, if something more specific has happened. Here a variable is monitored. If it's value is altered, an output is generated:
1. the Variable's Value
2. Instruction Pointer after the change and it contents
3. The chain in the return stack
4. The depth and contents of the parameter stack.

The new routine is patched into the code of the original TRACING routine (not instead), which starts at $440. This TRACING routine on the other hand is patched instead of doNext into the cog code by TRACE!. So we can control the modified TRACING routine with the same means as the original.
Other ideas for interesting triggers?
Have Fun, Christof

{   
   TriggerTrace.fth

   19.04.23 Christof Eberspaecher 

}

!polls \ clear multitasking

IFDEF *Tests*   
    oldorgT org
    FORGET *Tests*   }

pub *Tests*     PRINT" P2 Test" ;

0 bytes oldorgT

{ 
                   ' TRACE
00420     ff000002 TRACE        rdlong  doNext,##TRACER     ' Replace 1st instruction of doNEXt with a call to TRACING'
00424     fb046230 
00428     f607de00          mov traceL,#0
0042c     fd64002d          ret             ' !!! use discrete ret to delay before returning to doNEXT'
00430     fda00440 TRACER       call    #\TRACING
00434     ff000002 UNTRACE  rdlong  doNext,##TRACING
00438     fb046240 
0043c     fd64002d          ret

00440              TRACING
00440     fae41f61          rdword  x,PTRA++                ' read word code instruction
00444     f213f1ef          cmp     PTRA,traceL wc
00448     cd64002d  if_c    ret
0044c     fdb00184          call    #DBIP           ' PRINT IP '
00450     fdb000a4          call    #DBNAME         ' PRINT NAME'
}

\ Timer event and toggle pin P2 Docu Page 51 uses cog register deltaR

57 := ledPin
$1c := deltaR
$fdb00184 := call_DBIP \ original in $44c
long aVariable
aVariable := trAddr \ <<<<< set variable address here
long oldVariable
oldVariable := oldVar

$0f := x
$1ee := xreg
$17 := retptr \ return stack pointer
$15 := auxptr

$5d4 := prtIP
$4bc := prtHex
$0a4 := prtName
$5f8 = prtCrlf

code trigTrace           ' trace when variable changes
   rdlong r1,##trAddr
   rdlong xreg,##oldVar
   cmp r1,xreg wz       ' 
   if_z ret          ' nothing happened
   mov xreg,r1
   wrlong xreg,##oldVar    ' update
   call #\$4bc          ' print Variable value  
   mov r1,retptr
   push x
   call #\$5d4          ' prt IP
   call #\$5f8          ' crlf 
   .l1                  ' from top of return stack
      mov xreg,retptr   ' stack position    
      call #\$4bc
      rdlut xreg,retptr     ' address
      sub xreg,#2
      call #\$4bc
      rdword xreg,xreg      ' word code
      mov x,xreg
      call #\$4bc          ' print word code
      call #\$4f8          ' print word name
      call #\$5f8          ' crlf 
      cmp retptr,#$40 wz
      if_nz sub retptr,#1
   if_nz jmp #l1
   call #\$5f8       ' crlf
   call #\$454       ' print stack
   call #\$5f8
   pop x
   mov retptr,r1
   ret
end

' trigTrace 2 + := tTraceAddr \ get asm start address

: startTrig
   $FD80_0000 tTraceAddr + \ JMP absolute
   $44c ! \ patch into TRACING
;

: stopTrig
   call_DBIP
   $44c ! \ patch into TRACING   
;



: trigTest 
   nop
   %red %pen
   0 aVariable !
   KEY drop   
   begin
      aVariable ++
      500 ms
    KEY until
    %white %pen
;

startTrig
' trigTest TRACE!


Sign In or Register to comment.