Shop OBEX P1 Docs P2 Docs Learn Events
LMM P2 Debugger - Uses Serial Tx & Rx for debugging single cog programs - Page 10 — Parallax Forums

LMM P2 Debugger - Uses Serial Tx & Rx for debugging single cog programs

14567810»

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-12 17:33
    Sapieha suggested I use lower case as it looks neater (and that is what we normally use). I agree, so here is a sample of the next version..
    === Cluso's P2 Debugger v0.83 ===
    *1800,20l2
     addr- instr  zcr i cccc dst src - conds         opcode  operands   flags
     ---------------------------------------------------------------------------
    01800- 000111 110 0 1111 000 1E7 -              #JMPRET  $000, $1E7 wz,wc,nr
    01804- 000010 001 0 1111 1F4 1EE -              *rwLONG  $1F4, $1EE
    01808- 000000 000 0 0000 00C 090 -               long    $00001890
    0180C- 100000 001 1 1111 1EE 034 -               ADD     $1EE,#$034
    01810- 000010 001 0 1111 1F4 1EE -              *rwLONG  $1F4, $1EE
    01814- 000000 000 0 0000 00C 094 -               long    $00001894
    01818- 100000 001 1 1111 1EE 028 -               ADD     $1EE,#$028
    0181C- 000010 001 0 1111 1F4 1EE -              *rwLONG  $1F4, $1EE
    01820- 000000 000 0 0000 00C 068 -               long    $00001868
    01824- 000010 000 0 1111 1E8 1EF -              *rwLONG  $1E8, $1EF nr
    01828- 100000 001 1 1111 1EF 004 -               ADD     $1EF,#$004
    0182C- 100001 010 1 1111 1E8 120 -               SUB     $1E8,#$120 wc,nr
    01830- 101000 001 1 0011 1E8 120 - if_nc         MOV     $1E8,#$120
    01834- 001010 001 1 1111 1E8 003 -               SHR     $1E8,#$003
    01838- 100000 001 0 1111 1F4 1E8 -               ADD     $1F4, $1E8
    0183C- 100001 001 1 1111 1EF 004 -               SUB     $1EF,#$004
    01840- 000010 001 0 1111 1E8 1EF -              *rwLONG  $1E8, $1EF
    01844- 000010 000 0 1111 1E8 1EF -              *rwLONG  $1E8, $1EF nr
    01848- 100000 001 1 1111 1EF 004 -               ADD     $1EF,#$004
    0184C- 000010 000 0 1111 1EE 1EF -              *rwLONG  $1EE, $1EF nr
    *
    
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-13 02:14
    Next installment... v0.84

    Most instructions for opcode '000011' are now decoded. For example, see the disassembly of the rom monitor at $700...
    === Cluso's P2 Debugger v0.84 ===
    *700,32l2
     addr- instr  zcr i cccc dst src - conds         opcode  operands   flags
     ---------------------------------------------------------------------------
    00700- 000011 010 1 1101 030 165 - if_nz_or_c    setb    $030,#$165 wc,nr
    00704- 011101 010 1 0100 0B0 051 - if_nz_and_c   MUXNC   $0B0,#$051 wc,nr
    00708- 000000 000 0 0011 0BA 069 - if_nc         rdbyte  $0BA, $069
    0070C- 000000 000 0 0000 000 000 -               long    $00000000
    00710- 000011 011 1 0000 01D 040 -               long    $0DC03A40
    00714- 111000 000 0 0001 000 1D8 - if_nz_and_nc #SUBR    $000, $1D8 nr
    00718- 101000 001 1 0100 1F6 000 - if_nz_and_c   MOV     $1F6,#$000
    0071C- 000011 001 1 1111 1D8 012 -               getptra $1D8,#$012
    00720- 000011 001 1 1111 1D9 012 -               getptra $1D9,#$012
    00724- 001010 001 1 1111 1D9 009 -               SHR     $1D9,#$009
    00728- 000011 000 1 1111 1D9 0DB -               setp    $1D9,#$0DB nr
    0072C- 000011 001 1 1111 1DA 013 -               getptrb $1DA,#$013
    00730- 100001 001 1 1111 1DA 1B4 -               SUB     $1DA,#$1B4
    00734- 000011 001 1 1111 1BC 092 -               jmptask $1BC,#$092
    00738- 000011 001 1 1111 011 0CB -               settask $011,#$0CB
    0073C- 111110 000 1 1111 1F5 00C -              *TJZ     $1F5,#$00C nr
    00740- 000011 001 1 1111 1AD 094 -               jmptask $1AD,#$094
    00744- 000011 001 1 1111 019 0CB -               settask $019,#$0CB
    00748- 101000 001 1 1111 1E7 001 -               MOV     $1E7,#$001
    0074C- 000111 001 1 1111 0E1 0D4 -              #JMPRET  $0E1,#$0D4
    00750- 000011 001 1 1111 000 0AA -               pusha   $000,#$0AA
    00754- 000011 001 1 1111 051 0B2 -               setptra $051,#$0B2
    00758- 000111 001 1 1111 173 171 -              #JMPRET  $173,#$171
    0075C- 000111 001 1 1111 10F 0EB -              #JMPRET  $10F,#$0EB
    00760- 000111 001 1 1111 13B 12D -              #JMPRET  $13B,#$12D
    00764- 111110 000 1 1010 1DC 031 - if_z         *TJZ     $1DC,#$031 nr
    00768- 000111 000 1 1111 000 01B -              #JMPRET  $000,#$01B nr
    0076C- 000111 001 1 1111 10F 10D -              #JMPRET  $10F,#$10D
    00770- 000011 001 1 1111 001 0A4 -               addspa  $001,#$0A4
    00774- 000111 001 1 1111 13B 12D -              #JMPRET  $13B,#$12D
    00778- 000111 000 1 0101 000 021 - if_nz        #JMPRET  $000,#$021 nr
    0077C- 010101 001 1 1111 0B4 1DE -               MOVD    $0B4,#$1DE
    *
    
    
    Thought I should note that the operands do not reflect the specific instructions. It is just a simple disassembler, at least for now anyway.

    LSD_084.spin
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-15 19:14
    Here is v0.85d...

    It does more disassembly of the special P2 instructions (most of them, but not all).

    The disassembly is only simple the D & S operands are still shown even for those instructions that do not have these operands (eg setpz which only has a D/#n operand).

    A classic look at the ROM shows some of these instructions. For Listing the code from cog or hub, the address determines if it is in cog by being =<$1FF. Therefore, this means that ROM addresses (hub) below $200 cannot be displayed. But a quirk where the P2 ignores address bits >$1FFFF (>128KB) can be used to display these addresses. eg: use $80000 and this will display from $0 in hub. (*8000,32L2<cr>) (32 lines is the max that I permit to be displayed at a time but can be easily changed)

    Sapieha: I have not yet had time to look at your latest code - I will do that now and thanks again.

    Below is a sample dump of the Rom Monitor
    === Cluso's P2 Debugger v0.85 ===
    *70C.8FFL2
     addr- instr  zcr i cccc dst src - conds         opcode  operands   flags
     ---------------------------------------------------------------------------
    0070C- 000000 000 0 0000 000 000 -               nop
    00710- 000011 011 1 0000 01D 040 - if           *repd??? $01D,#$040 wc
    00714- 111000 000 0 0001 000 1D8 - if_nz_and_nc #subr    $000, $1D8 nr
    00718- 101000 001 1 0100 1F6 000 - if_nz_and_c   mov     $1F6,#$000
    0071C- 000011 001 1 1111 1D8 012 -               getptra $1D8,#$012
    00720- 000011 001 1 1111 1D9 012 -               getptra $1D9,#$012
    00724- 001010 001 1 1111 1D9 009 -               shr     $1D9,#$009
    00728- 000011 000 1 1111 1D9 0DB -               setp    $1D9,#$0DB nr
    0072C- 000011 001 1 1111 1DA 013 -               getptrb $1DA,#$013
    00730- 100001 001 1 1111 1DA 1B4 -               sub     $1DA,#$1B4
    00734- 000011 001 1 1111 1BC 092 -               jmptask $1BC,#$092
    00738- 000011 001 1 1111 011 0CB -               settask $011,#$0CB
    0073C- 111110 000 1 1111 1F5 00C -               tjz     $1F5,#$00C nr
    00740- 000011 001 1 1111 1AD 094 -               jmptask $1AD,#$094
    00744- 000011 001 1 1111 019 0CB -               settask $019,#$0CB
    00748- 101000 001 1 1111 1E7 001 -               mov     $1E7,#$001
    0074C- 000111 001 1 1111 0E1 0D4 -              #jmpret  $0E1,#$0D4
    00750- 000011 001 1 1111 000 0AA -               pusha   $000,#$0AA
    00754- 000011 001 1 1111 051 0B2 -               setptra $051,#$0B2
    00758- 000111 001 1 1111 173 171 -              #jmpret  $173,#$171
    0075C- 000111 001 1 1111 10F 0EB -              #jmpret  $10F,#$0EB
    00760- 000111 001 1 1111 13B 12D -              #jmpret  $13B,#$12D
    00764- 111110 000 1 1010 1DC 031 - if_z          tjz     $1DC,#$031 nr
    00768- 000111 000 1 1111 000 01B -              #jmpret  $000,#$01B nr
    0076C- 000111 001 1 1111 10F 10D -              #jmpret  $10F,#$10D
    00770- 000011 001 1 1111 001 0A4 -               addspa  $001,#$0A4
    00774- 000111 001 1 1111 13B 12D -              #jmpret  $13B,#$12D
    00778- 000111 000 1 0101 000 021 - if_nz        #jmpret  $000,#$021 nr
    0077C- 010101 001 1 1111 0B4 1DE -               movd    $0B4,#$1DE
    00780- 000011 001 1 1111 000 0B2 -               setptra $000,#$0B2
    00784- 000111 001 1 1111 0C4 0C2 -              #jmpret  $0C4,#$0C2
    00788- 000011 001 1 1111 072 0B2 -               setptra $072,#$0B2
    0078C- 000111 000 1 1111 000 013 -              #jmpret  $000,#$013 nr
    00790- 101000 001 0 1111 1DF 1E1 -               mov     $1DF, $1E1
    00794- 010101 001 1 1111 0B4 1E4 -               movd    $0B4,#$1E4
    00798- 000011 001 1 1111 01F 0B2 -               setptra $01F,#$0B2
    0079C- 000111 001 1 1111 0C4 0C2 -              #jmpret  $0C4,#$0C2
    007A0- 000111 000 1 1111 000 03A -              #jmpret  $000,#$03A nr
    007A4- 000111 001 1 1111 13B 12C -              #jmpret  $13B,#$12C
    007A8- 000111 000 1 1010 000 037 - if_z         #jmpret  $000,#$037 nr
    007AC- 101000 001 0 1111 1E0 1E1 -               mov     $1E0, $1E1
    007B0- 000011 001 1 1111 042 0B2 -               setptra $042,#$0B2
    007B4- 000111 001 1 1111 0C4 0C2 -              #jmpret  $0C4,#$0C2
    007B8- 000111 000 1 1111 000 03B -              #jmpret  $000,#$03B nr
    007BC- 101000 101 1 1111 1E7 001 -               mov     $1E7,#$001 wz
    007C0- 101000 101 1 1010 1E7 002 - if_z          mov     $1E7,#$002 wz
    007C4- 101000 001 1 1010 1E7 004 - if_z          mov     $1E7,#$004
    007C8- 000111 001 1 1111 0E1 0D4 -              #jmpret  $0E1,#$0D4
    007CC- 000111 000 1 1111 000 019 -              #jmpret  $000,#$019 nr
    007D0- 101000 001 1 1111 1E0 00F -               mov     $1E0,#$00F
    007D4- 000111 001 1 1111 170 14B -              #jmpret  $170,#$14B
    007D8- 000111 000 1 1111 000 014 -              #jmpret  $000,#$014 nr
    007DC- 101000 001 1 1111 1E0 0FF -               mov     $1E0,#$0FF
    007E0- 000111 001 1 1111 170 14B -              #jmpret  $170,#$14B
    007E4- 000111 000 1 1111 000 019 -              #jmpret  $000,#$019 nr
    007E8- 101000 001 1 1111 1E0 0FF -               mov     $1E0,#$0FF
    007EC- 000111 001 1 1111 170 14C -              #jmpret  $170,#$14C
    007F0- 000111 000 1 1111 000 01A -              #jmpret  $000,#$01A nr
    007F4- 101000 001 0 1111 1E0 1DF -               mov     $1E0, $1DF
    007F8- 000111 001 1 1111 170 14E -              #jmpret  $170,#$14E
    007FC- 000111 000 1 1111 000 01A -              #jmpret  $000,#$01A nr
    00800- 101000 001 0 1111 1DF 1E2 -               mov     $1DF, $1E2
    00804- 101000 001 0 1111 1E0 1E9 -               mov     $1E0, $1E9
    00808- 000111 001 1 1111 0D3 0C9 -              #jmpret  $0D3,#$0C9
    0080C- 000111 001 1 1111 124 110 -              #jmpret  $124,#$110
    00810- 000011 000 1 1111 1DF 0B2 -               setptra $1DF,#$0B2 nr
    00814- 111000 000 0 0001 000 000 - if_nz_and_nc #subr    $000, $000 nr
    00818- 101000 001 1 1111 1DC 000 -               mov     $1DC,#$000
    0081C- 000111 001 1 1111 0E8 0E7 -              #jmpret  $0E8,#$0E7
    00820- 100001 100 0 0001 1E1 1F6 - if_nz_and_nc  sub     $1E1, $1F6 wz,nr
    00824- 000111 000 1 1010 000 04D - if_z         #jmpret  $000,#$04D nr
    00828- 100000 001 0 1111 1DF 1E7 -               add     $1DF, $1E7
    0082C- 100001 110 0 1111 1DF 1E0 -               sub     $1DF, $1E0 wz,wc,nr
    00830- 000111 000 1 1110 000 041 - if_z_or_c    #jmpret  $000,#$041 nr
    00834- 101000 001 0 1111 1E2 1DF -               mov     $1E2, $1DF
    00838- 011000 001 0 1111 1E2 1E9 -               and     $1E2, $1E9
    0083C- 000111 000 1 1111 000 01A -              #jmpret  $000,#$01A nr
    00840- 111010 011 0 1111 1DC 1E5 -              $cfgpins $1DC, $1E5 wc
    00844- 000111 000 1 0011 000 044 - if_nc        #jmpret  $000,#$044 nr
    00848- 101000 001 0 1111 1E0 1E5 -               mov     $1E0, $1E5
    0084C- 001011 001 0 1111 1E0 1E8 -               shl     $1E0, $1E8
    00850- 100000 001 0 1111 1E0 1DF -               add     $1E0, $1DF
    00854- 000111 000 1 1111 000 03B -              #jmpret  $000,#$03B nr
    00858- 000111 001 1 1111 0D3 0C9 -              #jmpret  $0D3,#$0C9
    0085C- 101000 001 1 1111 1DD 001 -               mov     $1DD,#$001
    00860- 101000 001 0 1111 1E3 1DF -               mov     $1E3, $1DF
    00864- 011000 001 0 1111 1E3 1E9 -               and     $1E3, $1E9
    00868- 000111 001 1 1111 124 110 -              #jmpret  $124,#$110
    0086C- 111110 100 1 1111 1DD 05B -               tjnz    $1DD,#$05B wz,nr
    00870- 101000 001 0 1111 1DE 1E5 -               mov     $1DE, $1E5
    00874- 100000 001 1 1111 1DE 001 -               add     $1DE,#$001
    00878- 000011 000 1 1111 1E3 0B3 -               setptrb $1E3,#$0B3 nr
    0087C- 101000 001 0 0001 1E1 1F6 - if_nz_and_nc  mov     $1E1, $1F6
    00880- 000111 001 1 1111 0EA 0E9 -              #jmpret  $0EA,#$0E9
    00884- 111101 101 1 1111 1DE 05C -               djnz    $1DE,#$05C wz
    00888- 000011 001 1 1111 1E3 013 -               getptrb $1E3,#$013
    0088C- 000111 000 1 1111 000 01A -              #jmpret  $000,#$01A nr
    00890- 101000 001 0 1111 1DD 1DC -               mov     $1DD, $1DC
    00894- 000111 001 1 1111 0D3 0C9 -              #jmpret  $0D3,#$0C9
    00898- 000111 001 1 1111 12B 129 -              #jmpret  $12B,#$129
    0089C- 010011 001 0 1111 1E1 1E9 -               max     $1E1, $1E9
    008A0- 011000 001 0 1111 1E1 1E9 -               and     $1E1, $1E9
    008A4- 100001 100 1 1111 1DD 03C -               sub     $1DD,#$03C wz,nr
    008A8- 101000 001 0 1010 1DC 1DF - if_z          mov     $1DC, $1DF
    008AC- 101000 001 0 1010 1DF 1E1 - if_z          mov     $1DF, $1E1
    008B0- 101000 001 0 1010 1E1 1DC - if_z          mov     $1E1, $1DC
    008B4- 100001 010 0 1111 1DF 1E1 -               sub     $1DF, $1E1 wc,nr
    008B8- 101000 001 0 1100 1DC 1DE - if_c          mov     $1DC, $1DE
    008BC- 001011 001 0 1100 1DC 1E8 - if_c          shl     $1DC, $1E8
    008C0- 100000 001 0 1100 1DF 1DC - if_c          add     $1DF, $1DC
    008C4- 100000 001 0 1100 1E1 1DC - if_c          add     $1E1, $1DC
    008C8- 011011 001 1 1100 0E7 07E - if_c          xor     $0E7,#$07E
    008CC- 011011 001 1 1100 0E9 07E - if_c          xor     $0E9,#$07E
    008D0- 000011 000 1 1111 1DF 0B2 -               setptra $1DF,#$0B2 nr
    008D4- 000011 000 1 1111 1E1 0B3 -               setptrb $1E1,#$0B3 nr
    008D8- 000111 001 1 1111 0E8 0E7 -              #jmpret  $0E8,#$0E7
    008DC- 000111 001 1 1111 0EA 0E9 -              #jmpret  $0EA,#$0E9
    008E0- 111101 101 1 1111 1DE 073 -               djnz    $1DE,#$073 wz
    008E4- 011011 001 1 1100 0E7 07E - if_c          xor     $0E7,#$07E
    008E8- 011011 001 1 1100 0E9 07E - if_c          xor     $0E9,#$07E
    008EC- 000111 000 1 1111 000 01A -              #jmpret  $000,#$01A nr
    008F0- 000111 001 1 1111 0D3 0C9 -              #jmpret  $0D3,#$0C9
    008F4- 000011 000 1 1111 1DF 0B2 -               setptra $1DF,#$0B2 nr
    008F8- 000111 001 1 1111 0E8 0E7 -              #jmpret  $0E8,#$0E7
    008FC- 100000 001 0 1111 1DD 1E1 -               add     $1DD, $1E1
    *
    

    LSD_085d.spin

    Just a note that I chased an error that turned out to be some sort of end of line problem in the source - multiple lines became mixed together and those instructions were then ignored by the pnut compiler. Currently I am unsure where this occurred (Notepad++ or pnut), so it's just a heads up in canse someone else finds a problem like this.
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-16 01:44
    Here is v0.86...

    Sapieha changed the V command and those changes are included - thanks Sapieha.

    Almost all instructions are decoded. Those few are marked with * except for the cmp/sub, cmpr/subr, test/and, testn/andn.
    I have yet to properly decode the three repx instructions properly. Please report any errors, in particular wrong decoding.

    Note that because this is designed to be a simple disassembler, operands are not removed from those instructions that don't/cannot use them. The same applies to the conditionals (setindx/fixindx).

    LSD_086.spin
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-17 03:32
    Here is v0.86min (minimised user version)...

    It is ready for you to add your pasm code to this debugger. All sample code is removed from the cog (except a debug call).
    This simplifies the program for the user to start with. All functions still remain in the LMM hub code.

    Just paste your program into the cog section and you are ready to go.

    The debugger uses cog $1E0-$1F5 ($1F6-$1FF are special registers in the cog).

    LSD_086min.spin
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-23 00:37
    I have been thinking about adding a single breakpoint and what that entails.

    I think I will restrict to 1 breakpoint only. It can be preset during compile time - this saves a separate call to the debugger to setup a breakpoint.

    When a breakpoint is installed, the instruction is saved in a separate cog location, and a "call breakpoint" instruction is installed in its place.

    Once the breakpoint is reached, control is passed to the debugger. After performing whatever commands are required (within the debugger), the user may either "remove breakpoint", "set new breakpoint", or "keep breakpoint", and then "return", "restart", or "start" the user program (or quit or run the rom monitor).

    Any comments??
  • Bill HenningBill Henning Posts: 6,445
    edited 2013-05-24 15:21
    Looks good.

    Hmm... maybe add an primitive for BREAK, that you can resume from? Forgive me if this is already implemented, I have not tried your debugger yet.
    Cluso99 wrote: »
    I have been thinking about adding a single breakpoint and what that entails.

    I think I will restrict to 1 breakpoint only. It can be preset during compile time - this saves a separate call to the debugger to setup a breakpoint.

    When a breakpoint is installed, the instruction is saved in a separate cog location, and a "call breakpoint" instruction is installed in its place.

    Once the breakpoint is reached, control is passed to the debugger. After performing whatever commands are required (within the debugger), the user may either "remove breakpoint", "set new breakpoint", or "keep breakpoint", and then "return", "restart", or "start" the user program (or quit or run the rom monitor).

    Any comments??
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-05-24 20:44
    Looks good.

    Hmm... maybe add an primitive for BREAK, that you can resume from? Forgive me if this is already implemented, I have not tried your debugger yet.
    Yes, you will be able to continue from a break, either by leaving the existing break in place, setting a new break, or by removing the break entirely. You can also override the resume address to continue anywhere within the cog. There will be a new call for the break so that only a single call is required (ie no parameters).
    I have worked out how to implement this so it is only time to do it.
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-10-03 02:59
    Here is the latest version 0.90
    * Code starts at $E80 (not $1000) hub.
    * Disassembly has not been corrected for the new P2 instruction changes
    * Compile pasm and download using the new pnut.exe using F11 - there is a 5 second delay to allow for you to PST to start.

    Example commands..
    E80.FFFL2<cr> disassembles hub $e80-fff
    0.1EFL2<cr> disassembles cog $000-1EF
    1000,50L<cr> lists hub $1000 for a length of 50 in bytes and ascii (L & L0 are equivalent)
    ? displays help
    The basic format is
    {addr1}.{addr2},{length}{command+parameter}<cr>

    LSD_090.spin
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-10-03 23:04
    The last code posted above does not correctly reflect the version no.

    If you wish to list memory (L command) then all addresses below $200 are treated as cog memory and addresses 200 and above are treated as hub. However, it is possible to "trick" the debugger into listing the hub addresses below $200 by specifying $20xxx because this specifies hub >128KB and the addresses wrap. So 20000,20L2<cr> will list (disassemble) the first 20 longs of hub memory. (note not all instructions are correctly disassembled, particularly those whose opcodes changed in the new fpga code)

    Currently the debugger occupies $1E0-1F5 of the users cog space. All remaining code runs from hub space as LMM.

    The debugger code released includes lots of example calls to the debugger from user code (fills user space). This can be removed/deleted. Occasionally I will release a minimal version which removes all example code.
Sign In or Register to comment.