



















                                     MON12

                                       A
                             Software Debug Monitor

                                 For the 68HC12










                          Dunfield Development Systems
                          ----------------------------
                             High quality tools for
                              Embedded Development
                                 at low prices.

                            http://www.dunfield.com


                       ?COPY.TXT 1996-2007 Dave Dunfield
                              **See COPY.TXT**



                                     MON12

                               TABLE OF CONTENTS


                                                                         Page

     1. INTRODUCTION                                                        1


     2. USING MON12                                                         2

        2.1 Operand format                                                  2
        2.2 Monitor Commands                                                2
        2.3 Display Output                                                  6
        2.4 Breakpoints                                                     6
        2.5 Interrupts                                                      7

     3. MON12 INTERNALS                                                     8

        3.1 Reserved Memory Locations                                       8
        3.2 I/O Configuration Control Byte                                  8
    MON12                                                            Page: 1


    1. INTRODUCTION

          MON12 is an interactive software  debugger  and  machine  language
       monitor  for  the  motorola  68HC12   microprocessor.   It   contains
       display/alter memory/register facilities,  as well as a  full  68HC12
       disassembler, breakpoint, and software single step functions.

          MON12  requires  no  hardware  assist,  all  functions   including
       single-step are implemented in the MON12 firmware. MON12 communicates
       with the  user  via  am  internal  SCI  serial  port  of  the  68HC12
       microcontroller,  although the CHKCHR  and  WRCHR  subroutines  could
       easily be modified to support communications through an external UART
       device.

          MON12 requires 160 bytes of read/write memory,  for  stack,  local
       variables,  buffers etc,  and about 5700 bytes of ROM memory for  the
       program.  If MON12 is placed in an 8K (2764 or compatable) rom,  this
       will leave over 2k of space for the user I/O routines.  The MON12 rom
       must be at the top of the 68HC12 memory map, as it has to control the
       68HC12 interrupt vectors.
    MON12                                                            Page: 2


    2. USING MON12

       2.1 Operand format

        Anywhere that MON12 expects an 8 bit value, you may use:

            Two HEX digits                              Eg: 1F
            A QUOTE followed by an ASCII character      Eg: 'a

        Anywhere that MON12 expects a 16 bit value, you may use:

            Four HEX digits                             Eg: 09AB
            ASCII characters preceeded by quotes        Eg: 'a'b
            X, Y, P, or S for current CPU register      Eg: X

       2.2 Monitor Commands

             The following commands are implemented in the monitor.

               B <breakpoint#> <address>

                  Set breakpoint at specified address. Breakpoint is removed
                  if address is 0000.  There can be up to eight breakpoints,
                  which are referenced by the numbers 0 to 7.

               CR <register> <value>

                  Changes 68HC12 registers  values.  Register  is  a  single
                  character, which may be as follows:

                     A   - Set A accumulator (8 bit value).
                     B   - Set B accumulator (8 bit value).
                     C   - Set condition code register (8 bit value).
                     D   - Set D (A:B) accumlator (16 bit value)
                     X   - Set X register (16 bit value).
                     Y   - Set Y register (16 bit value).
                     S   - Set system stack pointer (16 bit value).
                     P   - Set program counter (16 bit value).
    MON12                                                            Page: 3


               CV <vector> <address>

                     Changes the interrupt vector handler addresses.  Vector
                  numbers begin at 00,  which is the FFFC  interrupt  vector
                  (just  below  RESET),  and  higher  number  address  lower
                  interrupt vectors.  The first five vectors are defined for
                  all 68HC12 CPU's and higher numbers are being dependant on
                  the exact CPU version:

                     00 - Clock Monitor Fail Reset
                     01 - COP Timeout Reset
                     02 - Unimplemented Opcode (TRAP)
                     03 - Software Interrupt (SWI) **
                     04 - XIRQ
                     05 - IRQ

                     MON12 supports 31 interrupt vectors which is enough for
                  the 68HC12 versions at the time it was written.  Since the
                  68HC12 could support up  to  63  interrupt  vectors  (plus
                  RESET),  it is possible that versions may be made  in  the
                  future having more than 31 interrupts.  MON12 is  designed
                  to be easily  modified  to  support  additional  interrupt
                  vectors.

                  **Note:  The SWI instruction and  the  Software  Interrupt
                  Vector are used by MON12 to provide execution breakpoints,
                  therefore  the  SWI  vector  is  initialized  to   MON12's
                  internal handler.  The action of this handler is  to  dump
                  the processor registers,  and return to the MON12  command
                  prompt.  If the SWI  vector  is  changed  (either  by  the
                  operator or by the program  under  test),  the  breakpoing
                  functionality will be lost.

               DB

                  Displays the current breakpoint settings.

               DI <start>,<end>

                  Disassembles memory,  starting at  indicated  address.  If
                  SPACE  is  entered  for  <end>  address,   assumes   FFFF.
                  Disassembler  output  contains  address,  opcodes   bytes,
                  instruction neumonic, and operands to instruction.

               DM <start>,<end>

                  Displays memory, in HEX/ASCII dump format, starting at the
                  indicated  address.  If  a  SPACE  is  entered  for  <end>
                  address, assumes FFFF.

               DR

                  Displays the values of the 68HC12 registers.

               DV

                  Display the current interrupt vector address assignments.
    MON12                                                            Page: 4


               E <address>

                  Edit's memory,  Address and contents are displayed,  Enter
                  two hex digits to change value, or a single quote followed
                  by a character. Entering SPACE skips to the next location,
                  BACKSPACE  backups  to  the  previous  location.  CARRIAGE
                  RETURN terminates the edit command.

               FM <start>,<end> <value>

                  Fill's memory from <start> to <end> with the byte <value>.

               G <address>

                  Begins execution at the indicated address.  (Hint:  Use 'G
                  P'  to begin execution at the address in the saved  68HC12
                  program counter, ie: to continue after a breakpoint etc.).

                  Note that  'G'  execute  one  single-step,  then  implants
                  breakpoints, and runs the program at full speed. See notes
                  under 'S'tep.

               L

                  Downloads data from the console  port,  which  may  be  in
                  either MOTOROLA or INTEL hex format.

                  If you accidently enter this command, you may enter either
                  'S9'  or ':00'  to signify a null download file and return
                  to the command prompt.

               MM <start>,<end> <destination>

                  Move's memory  from  <start>  to  <end>,  placeing  it  at
                  <destination>.

               RR <address>

                  This command loops,  performing a read  of  the  specified
                  address until it is terminated by the escape key.

               RW <address> <value>

                  This  command  loops,  writing  the  given  value  to  the
                  specified address until it is  terminated  by  the  escape
                  key.
    MON12                                                            Page: 5


               S <address>

                  Single-Steps one instruction at  the  address  in  the  PC
                  register.  The disassembled instruction is displayed, then
                  the  instruction  is  executed,  and  the  registers   are
                  updated.

                  NOTE:  MON12 single-steps most instruction by copying into
                  it's  own  buffer  to  execute  them.  This   means   that
                  instructions performing PC  indexed  addressing  will  not
                  single-step correctly. JMP and JSR with PC addressing will
                  work OK, because these instructions are emulated.

               W <address> <value>

                  Performs  a  single  write  of  the  given  value  to  the
                  specified address in memory.

               + <value>+<value>

                  Performs 16 bit addition of the values,  and displays  the
                  result.

               - <value>-<Value>

                  Performs 16 bit subtraction of the  values,  and  displays
                  the result.

               ?

                  Displays a short help summary of the commands.
    MON12                                                            Page: 6


       2.3 Display Output

             In order to maintain the maximum amount of data on the terminal
          screen during the debugging session,  MON12 has been  designed  to
          minimize the number of screen lines in any display.  All  commands
          which output only one line of data (such as 'DB' 'DR'), will do so
          on the same line on which the command is issued  (To the right  of
          the command).

             For commands which output larger amounts of data (such as 'DI',
          'DM'),  pressing the SPACE key during the display  will  halt  the
          display. Each subsequent SPACE entered will cause one more line of
          data be displayed. Pressing CARRIAGE RETURN will allow the display
          to continue at full speed.

             The escape key may be used to cancel command output, and return
          to the '*' prompt.

       2.4 Breakpoints

             MON12 allows breakpoints to be  placed  in  the  program  under
          test, which when encountered during the execution of that program,
          cause the program to interrupt, and MON12 is entered. Up to 8 such
          breakpoints (numbered from 0 to 7) may be placed in the program at
          any one time.

             When entered from a breakpoint,  MON12  will  first  display  a
          message  indicating  the  number  of  the  breakpoint  which   was
          encountered,  followed by the  processor  registers,  after  which
          MON12 enters command mode.

             Once MON12 has been entered from a breakpoint, the registers of
          the program under test are saved.  Note that the  address  of  the
          breakpoint is in the saved 68HC12 program counter,  and  therefore
          using 'P'  as the operand to 'G'  will allow execution to continue
          from the breakpoint.

             Breakpoints are entirely transparent,  and will remain  in  the
          program until explicitly removed.
    MON12                                                            Page: 7


       2.5 Interrupts

             MON12 re-vectors all interrupts though a vector table which may
          be written by the user program.  When an interrupt  occurs,  MON12
          will transfer  control  to  the  corresponding  address  from  the
          interrupt vector table (See 'CV' and 'DV' commands).

             If MON12 finds that the vector table  entry  for  an  interrupt
          that it is servicing is  set  to  zero  (uninitialized),  it  will
          perform processing similar to a breakpoint,  issuing  the  message
          "**Interrupt  ",  followed by the interrupt name,  after which  it
          will re-enter command mode.

             Execution following such an interrupt can be resumed by using a
          'P' as the operand to the 'G' command,  exactly as you would after
          a breakpoint.

             A useful debugging aid is to connect a debounced push button to
          the XIRQ interrupt line,  allowing you to re-gain MON12 control at
          any time simply by pressing the button.  (Note,  you may  have  to
          enabled the XIRQ with the MON12 initialization code).
    MON12                                                            Page: 8


    3. MON12 INTERNALS

       3.1 Reserved Memory Locations

             The following locations are located in the 128 bytes of  memory
          which are reserved for MON12:

    Offset|Size|  Name  |                   Description
    ------+----+--------+------------------------------------------------
     0000 | 62 | INTVEC | Vectors for the first 32 68HC12 interrupts.
    ------+----+--------+------------------------------------------------
     003E | 01 |  SAVA  | MON12's saved A Accumulator register.
    ------+----+--------+------------------------------------------------
     003F | 01 |  SAVB  | MON12's saved B Accumulator register.
    ------+----+--------+------------------------------------------------
     0040 | 02 |  SAVX  | MON12's saved X Index register.
    ------+----+--------+------------------------------------------------
     0042 | 02 |  SAVY  | MON12's saved Y Index register.
    ------+----+--------+------------------------------------------------
     0044 | 02 | SAVPC  | MON12's saved System Stack Pointer.
    ------+----+--------+------------------------------------------------
     0046 | 02 | SAVSP  | MON12's saved Program Counter.
    ------+----+--------+------------------------------------------------
     0048 | 01 | SAVCC  | MON12's saved Condition Code register.
    ------+----+--------+------------------------------------------------
     0056 | 01 | IOCTL  | MON12 I/O control byte 
    ------+----+--------+------------------------------------------------

       3.2 I/O Configuration Control Byte

             MON12 maintains a control  byte,  which  controls  the  console
          serial port. The definition of bits in this byte is as follows:

         Bit#    7   - Indicates that output is inhibited.
                 6   - Indicates that output is paused (via space)
                 5   - Indicates that the input should be "flushed" on error
               4-0   - Unused
