home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / debugger.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  4.3 KB  |  176 lines

  1. /*
  2.  
  3.  
  4. */
  5.  
  6. #ifndef __DEBUGGER_H__
  7. #define __DEBUGGER_H__
  8.  
  9. #include "memory.h"
  10.  
  11. #include "centry.h"
  12.  
  13. void debugger_init(void);
  14. void debugger_enable(bool enable);
  15. INLINE bool debugger_enabled(void) { return !!(stateflag & ST_DEBUG); }
  16. void debugger(void);
  17.  
  18. //     operands for instructions
  19.  
  20. typedef enum {
  21.     OP_NONE=-1,    // no operand
  22.  
  23.     // from ts/td field of opcode, don't change order
  24.     OP_REG=0,    // register Rx
  25.     OP_IND=1,    // indirect *Rx
  26.     OP_ADDR=2,    // address @>xxxx
  27.     OP_INC=3,    // register increment *Rx+
  28.  
  29.     OP_IMMED,    // immediate >xxxx
  30.     OP_CNT,        // shift count x (4 bits)
  31.     OP_JUMP,       // jump target >xxxx
  32.     OP_OFFS,    // offset >xxxx or ->xxxx
  33.     OP_STATUS,    // status word >xxxx
  34.     OP_INST,    // instruction for X
  35. }    OperandType;
  36.  
  37. #define OP_DEST_KILLED 2
  38.  
  39. typedef struct Operand {
  40.     OperandType    type;            // type of operand
  41.     u16            val;            // value in opcode
  42.     u16            immed;            // immediate word
  43.     u16            ea;                // effective address of operand
  44.     bool        byteop;            // for OP_REG...OP_INC
  45.     bool        dest;            // operand changes (OP_DEST_KILLED=killed)
  46.     bool        ignore;            // operand is not meaningful to display
  47. }    Operand;
  48.  
  49. #define OP_IS_MEMORY(op) \
  50.         (((op).type == OP_IND || (op).type == OP_ADDR || (op).type == OP_INC) \
  51.         && !(op).ignore)
  52.  
  53.  
  54. /*
  55.  *    Print out an operand into a disassembler operand
  56.  */
  57. char *
  58. debugger_instruction_operand_print(Operand *op, char *buffer);
  59.  
  60. typedef struct Instruction {
  61.     const char    *name;            // name of instruction
  62.     u16            pc;                // PC of opcode
  63.     u16            wp;                // current WP
  64.     u16            status;            // current status
  65.     u16            opcode;            // opcode 
  66.     Operand        op1, op2;           // operands of instruction
  67. }    Instruction;
  68.  
  69. /*
  70.  *    Print value of operand to buffer
  71.  *
  72.  *    verbose==true means to print extra info
  73.  *    dest==true means print this operand as the result of 
  74.  *    a previous instruction
  75.  */
  76. char *
  77. debugger_operand_value_print(Instruction *inst, Operand *op, 
  78.                              bool verbose, bool dest, 
  79.                              char *buffer);
  80.  
  81.  
  82. //    memory views
  83. typedef enum
  84. {
  85.     MEMORY_VIEW_CPU_1,
  86.     MEMORY_VIEW_CPU_2,
  87.     MEMORY_VIEW_VIDEO,
  88.     MEMORY_VIEW_GRAPHICS,
  89.     MEMORY_VIEW_SPEECH,
  90.     MEMORY_VIEW_COUNT
  91. }    MemoryView;
  92.  
  93. //    Struct keeps track of active addresses in the
  94. //    areas of memory so frontend can maintain views
  95. typedef struct Memory {
  96.     MemoryView    which;            // MEMORY_VIEW_xxx
  97.     u16            base;            // base address 
  98.     u16         addr;            // last accessed addr
  99.     int            len;            // last accessed length of memory
  100.     u8            *mem;            // pointer to that memory
  101.     int            coverage;        // amount of times selected
  102. } Memory;
  103.  
  104. //    Size of area Memory is expected to cover (changed by frontend)
  105. extern int debugger_memory_view_size[MEMORY_VIEW_COUNT];
  106.  
  107. //     Send verbose operand views (changed by frontend)
  108. extern bool debugger_operand_view_verbose;
  109.  
  110. #define DOMAIN_TOKEN(dmn)        ((dmn) == md_cpu ? '>' : \
  111.                                 (dmn) == md_graphics ? 'G' : \
  112.                                 (dmn) == md_video ? 'V' : \
  113.                                 (dmn) == md_speech ? 'S' : '?')
  114.  
  115. #define MEMORY_VIEW_TOKEN(v)    ((v) == MEMORY_VIEW_CPU_1 ? '>' : \
  116.                                 (v) == MEMORY_VIEW_CPU_2 ? '>' : \
  117.                                 (v) == MEMORY_VIEW_GRAPHICS ? 'G' : \
  118.                                 (v) == MEMORY_VIEW_VIDEO ? 'V' : \
  119.                                 (v) == MEMORY_VIEW_SPEECH ? 'S' : '?')
  120.  
  121. /*
  122.  *    Utility for status reporters.  Given the slot, it writes a one-line hex dump to
  123.  *    the given buffer, and sets start/astart and end/aend to point to the extent
  124.  *    of the last memory access within the buffer.  (These will be spaces.)
  125.  *
  126.  *    addr_separator: char appearing between address and bytes
  127.  *    byte_separator: char appearing between each hex byte
  128.  *    ascii_separator: char appearing between hex field and ascii field
  129.  */    
  130. void
  131. debugger_hex_dump_line(Memory * slot, int offset, int length,
  132.                        char addr_separator, char byte_separator, 
  133.                        char ascii_separator, char line_separator,
  134.                        char *buffer, int bufsz,
  135.                        char **start, char **end,
  136.                        char **astart, char **aend);
  137.  
  138. /*
  139.  *    How long will this text be?
  140.  */
  141. int 
  142. debugger_hex_dump_bytes_to_chars(int bytes);
  143.  
  144. /*
  145.  *    How many bytes fit in this length?
  146.  */
  147. int 
  148. debugger_hex_dump_chars_to_bytes(int chars);
  149.  
  150. /*
  151.  *    Force updates of these items by sending system_report_status() messages
  152.  */ 
  153. void
  154. debugger_register_clear_view(void);
  155. void
  156. debugger_memory_clear_views(void);
  157. void
  158. debugger_instruction_clear_view(void);
  159.  
  160. /*
  161.  *    Force next update to refresh all status items
  162.  */
  163. void 
  164. debugger_refresh(void);
  165.  
  166. /*
  167.  *    Check current PC to see if it's breakpointed
  168.  */
  169. int
  170. debugger_check_breakpoint(u16 pc);
  171.  
  172. #include "cexit.h"
  173.  
  174. #endif
  175.  
  176.