*  @(#)reloc.mac  1.7  
*  By Peter S. Gilmour, Motorola Development Systems, Austin, TX
*
*  This file contains items useful for debugging code assembled in
*  several relocatable modules and then linked into one object file.
*  It also contains some hints and serves as an example of what macro
*  operations can do.
*
*  The problem with debugging a relocatable module is that the assembly
*  listing shows module relative addresses and the code will execute at
*  address $XXXX while it's data will be at $DDDD.  To overcome this
*  problem, the following named macros and local symbols make life bearable
*  again.
*
*  Local symbol definitions:
*    X     = base address of relocatable module being debugged.
*    D     = base address of initialized   data section.
*    B     = base address of uninitialized data section.
*    W     = "where am i"; just type "'W" to calculate the current PC
*            offset from the base address of the module.  This is a local
*            symbol "command".
*    START = starting execution address of program.
*    FDC   = "floppy disk controller register display"; just type "'FDC" to
*            do a memory display of the controller register values.  This is
*            a local symbol "command".
*    PIA1  = "PIA 1 register display"; just type "'PIA" to do a memory
*            display of the PIA 1 register values.  This is a local symbol
*            "command".
*    TBL   = "table display"; just type "'TBL" to do a memory display of
*            table values.  This is a local symbol "command".
*
*  Named Macros:
*    T        = new single step trace cmd with register display and PC
*               disassembly.
*    U        = trace until <address> is reached cmd.  Deletes BR at current
*               PC, sets BR at <address> entered, and issues G cmd.
*    BU       = set BR at current PC and does U named macro.
*    L        = list (disassemble) 5 lines from the current PC.
*    TT       = old single step trace cmd.
*    TW4      = trace thru a  4 byte subroutine call (sets brkpt at .PC+4).
*    TW8      = trace thru an 8 byte subroutine call (sets brkpt at .PC+8).
*    MODULE1  = set up for Module 1 debug and patches.
*    MODULE2  = set up for Module 2 debug and patches.
*    WAITDONE = wait until Status is no longer "RUNNING".
*    XADD     = adds parameter 1 to local symbol X (module base)
*    XSUB     = subtracts parameter 1 from local symbol X (module base)
*    SUBX     = subtracts local symbol X (module base) from parameter 1 
*    CYCLE    = alternately stores parameter 2 and parameter 3 at the
*               location specified by parameter 1 until the abort character
*               is entered (^A).
*
*  Sample debug session:
*    LOAD MYPROG          Load saved copy of program.
*    MODULE2              Setup for debugging module 2.
*    G 'START             Start program.  Stops at preset breakpoint.
*    BR 'X+2ed            Set new breakpoint at module address $2ED.
*    G                    Execute to breakpoint.
*    T ,20                Trace 20 decimal instructions, then display regs.
*    'W                   Display relative PC (where am i)
*    'FDC                 Display FDC registers.
*    'PIA1                Display PIA 1 registers.
*    'TBL                 Display table contents.
*    T                    Trace 1 instruction, then display regs.
*    TW4                  Trace thru 4 byte subr. call.
*    MD 'B+32,4           Display memory in base section.
*    BR 'X+35e            Set new breakpoint at module address $35E.
*    G                    Execute to breakpoint.
*    NOBR .PC             Delete this breakpoint.
*    NOBR 'X+2ed          Delete old breakpoint.
*    L                    List 5 disassembled lines from current PC.
*    G                    Execute to breakpoint.
*    U  'X+4ac            Execute from this breakpoint until new breakpoint.
*    T ,3                 Trace 3 instructions, then display regs.
*    BU 'X+4dc            Set BP at PC, then go until new breakpoint.
*
*    etc.
*
*  Hints:
*    1. You can use the current value of any register in expressions for any
*       HDS-300 command as shown below.  Consult the help system for the
*       calculate command (HELP C) for more details on allowable expressions
*       for your pod.
*
*         a. Set or delete breakpoints using the program counter as follows;
*               BR   .PC            Set brkpt at current PC.
*               BR   .PC+4          Set brkpt at current PC+4.
*               NOBR .PC            Delete brkpt at current PC.
*
*         b. Display memory via register values as follows;
*               MD   .A0,40         Display $40 bytes at location in A0.
*               MD   [.A0],40       Display $40 bytes at location indirectly
*                                   referenced in A0.
*
*  Notes:
*    1. This macro was set up for HDS-300/68008 operation.  There may be
*       some changes required if used on a different system, i.e. the
*       68020 has to have double quotes around the command text entered
*       for BR commands.
*          Ex:     @br .pc+4 rd            for 68008
*                  @br .pc+4 "rd"          for 68020
*
*  References:
*    1. "HDS-300 Hardware Development Station Operations Manual" for your
*       pod, under "The Macro Utility" section.
*
*  You may delete all the above comments from your working version copy
*  or modify this file to suite your particular needs.
T
 @t \0
 @rd
 @dasm .pc,1
U
 @nobr .pc
 @br \0 DB
 @g
BU
 @br .pc
 U \0
L
 @dasm .pc,5
DB
 @rd
 @dasm .pc,1
TT
 @t \0
TW4
 @br .pc+4 @rd
 @g
 @whilel 0 "RUNNING"
 @end
 @nobr .pc
 @dasm .pc,1
 'w
TW8
 @br .pc+8 @rd
 @g
 @whilel 0 "RUNNING"
 @end
 @nobr .pc
 @dasm .pc,1
 'w
***
* Common symbols for all modules
COMSYMB
 @ls start 1000
 @ls w C .PC-'X
 @ls fdc md fe78,4
 @ls pia1 md fea0,2
MODULE1
 ** Setup for 01/27/88 assembly version of Module 1 **
 @ls x 24b9
 @ls d 47ce
 @ls b 3e
 * Table is 39 entries of 2 bytes each!
 @ls tbl md 'd+34,&39*2 ;wd
 COMSYMB
 *** no patches at this time ***
 * Set breakpoints.
 @nobr
 @br 'x @rd
 @br 'x+e @rd
MODULE2
 ** Setup for 01/29/88 assembly version of Module 2 **
 @ls x 24b9
 @ls d 47ce
 @ls b 3e
 * Table is 47 entries of 2 bytes each!
 @ls tbl md 'd+4b,&47*2 ;wd
 COMSYMB
 @asm 'x+2a9
   nop;q
 @ms 'd+10c 4 21 39
 * Set breakpoints.
 @nobr
 @br 'x @rd
 @br 'x+e @rd
WAITDONE
 @whilel 0 "RUNNING"
 @end
XADD
 @c 'x+\0
XSUB
 @c 'x-\0
SUBX
 @c \0-'x
CYCLE
 @repeat
  @ms \0 \1
  @wait 10
  @ms \0 \2
  @wait 10
 @end
**EOF**
