"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

dlite.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "version.h"
#include "eval.h"
#include "regs.h"
#include "memory.h"
#include "sim.h"
#include "symbol.h"
#include "loader.h"
#include "options.h"
#include "stats.h"
#include "range.h"
#include "dlite.h"

Include dependency graph for dlite.c:

Include dependency graph

Go to the source code of this file.

Compounds

Defines

Typedefs

Functions

Variables


Define Documentation

#define BYTES_PER_LINE   16
 

Definition at line 1493 of file dlite.c.

Referenced by dlite_dump().

#define DLITE_PROMPT   "DLite! > "
 

Definition at line 2251 of file dlite.c.

Referenced by dlite_main().

#define INSTS_PER_SCREEN   16
 

Definition at line 1622 of file dlite.c.

Referenced by dlite_dis().

#define LINES_PER_SCREEN   4
 

Definition at line 1494 of file dlite.c.

Referenced by dlite_dump().

#define MAX_ARGS   4
 

Definition at line 322 of file dlite.c.

Referenced by print_help().

#define MAX_STR   128
 

Definition at line 325 of file dlite.c.

#define MOD_BINARY   0x1000
 

Definition at line 135 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_BYTE   0x0001
 

Definition at line 117 of file dlite.c.

Referenced by dlite_display(), modifier_parser(), and print_val().

#define MOD_CHAR   0x0040
 

Definition at line 123 of file dlite.c.

Referenced by dlite_display(), modifier_parser(), and print_val().

#define MOD_DECIMAL   0x0100
 

Definition at line 131 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_DOUBLE   0x0020
 

Definition at line 122 of file dlite.c.

Referenced by dlite_display(), modifier_parser(), and print_val().

#define MOD_FLOAT   0x0010
 

Definition at line 121 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_FORMATS   (MOD_DECIMAL|MOD_UNSIGNED|MOD_OCTAL|MOD_HEX|MOD_BINARY)
 

Definition at line 137 of file dlite.c.

Referenced by print_val().

#define MOD_HALF   0x0002
 

Definition at line 118 of file dlite.c.

Referenced by dlite_display(), modifier_parser(), and print_val().

#define MOD_HEX   0x0800
 

Definition at line 134 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_OCTAL   0x0400
 

Definition at line 133 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_QWORD   0x0008
 

Definition at line 120 of file dlite.c.

Referenced by dlite_display(), modifier_parser(), and print_val().

#define MOD_SIZES
 

Value:

Definition at line 126 of file dlite.c.

Referenced by print_val().

#define MOD_STRING   0x0080
 

Definition at line 124 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_UNSIGNED   0x0200
 

Definition at line 132 of file dlite.c.

Referenced by modifier_parser(), and print_val().

#define MOD_WORD   0x0004
 

Definition at line 119 of file dlite.c.

Referenced by modifier_parser(), and print_val().


Typedef Documentation

typedef char*(* cmd_fn_t)(int nargs, union arg_val_t args[], struct regs_t *regs, struct mem_t *mem)
 

Definition at line 337 of file dlite.c.


Function Documentation

int __check_break md_addr_t    next_PC,
int    access,
md_addr_t    addr,
counter_t    icount,
counter_t    cycle
 

Definition at line 1815 of file dlite.c.

References ACCESS_EXEC, ACCESS_READ, ACCESS_WRITE, break_access, dlite_break_t::class, counter_t, FALSE, dlite_break_t::id, myfprintf(), dlite_break_t::next, panic(), pt_addr, pt_cycle, pt_inst, range_pos_t::ptype, dlite_break_t::range, range_cmp_range(), range_range_t::start, and TRUE.

01820 {
01821   struct dlite_break_t *bp;
01822 
01823   if (dlite_active)
01824     {
01825       /* single-stepping, break always */
01826       break_access = /* single step */0;
01827       return TRUE;
01828     }
01829   /* else, check for a breakpoint */
01830 
01831   for (bp=dlite_bps; bp != NULL; bp=bp->next)
01832     {
01833       switch (bp->range.start.ptype)
01834         {
01835         case pt_addr:
01836           if ((bp->class & ACCESS_EXEC)
01837               && !range_cmp_range(&bp->range, next_PC))
01838             {
01839               /* hit a code breakpoint */
01840               myfprintf(stdout,
01841                         "Stopping at code breakpoint #%d @ 0x%08p...\n",
01842                         bp->id, next_PC);
01843               break_access = ACCESS_EXEC;
01844               return TRUE;
01845             }
01846           if ((bp->class & ACCESS_READ)
01847               && ((access & ACCESS_READ)
01848                   && !range_cmp_range(&bp->range, addr)))
01849             {
01850               /* hit a read breakpoint */
01851               myfprintf(stdout,
01852                         "Stopping at read breakpoint #%d @ 0x%08p...\n",
01853                         bp->id, addr);
01854               break_access = ACCESS_READ;
01855               return TRUE;
01856             }
01857           if ((bp->class & ACCESS_WRITE)
01858               && ((access & ACCESS_WRITE)
01859                   && !range_cmp_range(&bp->range, addr)))
01860             {
01861               /* hit a write breakpoint */
01862               myfprintf(stdout,
01863                         "Stopping at write breakpoint #%d @ 0x%08p...\n",
01864                         bp->id, addr);
01865               break_access = ACCESS_WRITE;
01866               return TRUE;
01867             }
01868           break;
01869 
01870         case pt_inst:
01871           if (!range_cmp_range(&bp->range, icount))
01872             {
01873               /* hit a code breakpoint */
01874               fprintf(stdout,
01875                       "Stopping at inst count breakpoint #%d @ %.0f...\n",
01876                       bp->id, (double)icount);
01877               break_access = ACCESS_EXEC;
01878               return TRUE;
01879             }
01880           break;
01881 
01882         case pt_cycle:
01883           if (!range_cmp_range(&bp->range, cycle))
01884             {
01885               /* hit a code breakpoint */
01886               fprintf(stdout,
01887                       "Stopping at cycle count breakpoint #%d @ %.0f...\n",
01888                       bp->id, (double)cycle);
01889               break_access = ACCESS_EXEC;
01890               return TRUE;
01891             }
01892           break;
01893 
01894         default:
01895           panic("bogus range type");
01896         }
01897 
01898 
01899     }
01900 
01901   /* no matching breakpoint found */
01902   break_access = /* no break */0;
01903   return FALSE;
01904 }

char* bp_class_str int    class [static]
 

Definition at line 1710 of file dlite.c.

References ACCESS_EXEC, ACCESS_READ, ACCESS_WRITE, and panic().

Referenced by delete_break(), dlite_breaks(), and set_break().

01711 {
01712   if (class == (ACCESS_READ|ACCESS_WRITE|ACCESS_EXEC))
01713     return "read|write|exec";
01714   else if (class == (ACCESS_READ|ACCESS_WRITE))
01715     return "read|write";
01716   else if (class == (ACCESS_WRITE|ACCESS_EXEC))
01717     return "write|exec";
01718   else if (class == (ACCESS_READ|ACCESS_EXEC))
01719     return "read|exec";
01720   else if (class == ACCESS_READ)
01721     return "read";
01722   else if (class == ACCESS_WRITE)
01723     return "write";
01724   else if (class == ACCESS_EXEC)
01725     return "exec";
01726   else
01727     panic("bogus access class");
01728 }

char* delete_break int    id [static]
 

Definition at line 1762 of file dlite.c.

References bp_class_str(), dlite_break_t::class, dlite_check, FALSE, dlite_break_t::id, dlite_break_t::next, dlite_break_t::range, range_print_range(), and TRUE.

Referenced by dlite_clear(), and dlite_delete().

01763 {
01764   struct dlite_break_t *bp, *prev;
01765 
01766   if (!dlite_bps)
01767     return "no breakpoints set";
01768 
01769   for (bp=dlite_bps,prev=NULL; bp != NULL; prev=bp,bp=bp->next)
01770     {
01771       if (bp->id == id)
01772         break;
01773     }
01774   if (!bp)
01775     return "breakpoint not found";
01776 
01777   if (!prev)
01778     {
01779       /* head of list, unlink */
01780       dlite_bps = bp->next;
01781     }
01782   else
01783     {
01784       /* middle or end of list */
01785       prev->next = bp->next;
01786     }
01787 
01788   fprintf(stdout, "breakpoint #%d deleted @ ",  bp->id);
01789   range_print_range(&bp->range, stdout);
01790   fprintf(stdout, ", class: %s\n", bp_class_str(bp->class));
01791 
01792   bp->next = NULL;
01793   free(bp);
01794 
01795   if (!dlite_bps)
01796     {
01797       /* no breakpoints set, cancel checks */
01798       dlite_check = FALSE;
01799     }
01800   else
01801     {
01802       /* breakpoints are set, do checks */
01803       dlite_check = TRUE;
01804     }
01805 
01806   /* no error */
01807   return NULL;
01808 }

char * dlite_break int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1908 of file dlite.c.

References ACCESS_EXEC, range_range_t::end, eval_as_addr(), EVAL_INTEGRAL, range_pos_t::pos, pt_addr, range_pos_t::ptype, set_break(), and range_range_t::start.

01911 {
01912   md_addr_t addr;
01913   struct range_range_t range;
01914 
01915   if (nargs != 1)
01916     return "wrong number of arguments";
01917 
01918   /* check address */
01919   if (!EVAL_INTEGRAL(args[0].as_value.type))
01920     return "address argument must be an integral type";
01921 
01922   /* reset addr */
01923   addr = eval_as_addr(args[0].as_value);
01924 
01925   /* build the range */
01926   range.start.ptype = pt_addr;
01927   range.start.pos = addr;
01928   range.end.ptype = pt_addr;
01929 #ifdef TARGET_ALPHA
01930   /* need some extra space here, as functional have multiple entry points
01931      depending on if $GP needs to be loaded or not */
01932   range.end.pos = addr + 9;
01933 #else /* !TARGET_ALPHA */
01934   range.end.pos = addr + 1;
01935 #endif /* TARGET_ALPHA */
01936 
01937   /* set a code break point */
01938   return set_break(ACCESS_EXEC, &range);
01939 }

char * dlite_breaks int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2030 of file dlite.c.

References bp_class_str(), dlite_break_t::class, dlite_break_t::id, dlite_break_t::next, dlite_break_t::range, and range_print_range().

02033 {
02034   struct dlite_break_t *bp;
02035 
02036   if (!dlite_bps)
02037     {
02038       fprintf(stdout, "No active breakpoints.\n");
02039 
02040       /* no error */
02041       return NULL;
02042     }
02043 
02044   fprintf(stdout, "Active breakpoints:\n");
02045   for (bp=dlite_bps; bp != NULL; bp=bp->next)
02046     {
02047       fprintf(stdout, "  breakpoint #%d @ ",  bp->id);
02048       range_print_range(&bp->range, stdout);
02049       fprintf(stdout, ", class: %s\n", bp_class_str(bp->class));
02050     }
02051 
02052   /* no error */
02053   return NULL;
02054 }

char * dlite_clear int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2077 of file dlite.c.

References delete_break(), and dlite_break_t::id.

02080 {
02081   if (!dlite_bps)
02082     {
02083       fprintf(stdout, "No active breakpoints.\n");
02084 
02085       /* no error */
02086       return NULL;
02087     }
02088 
02089   while (dlite_bps != NULL)
02090     {
02091       /* delete first breakpoint */
02092       delete_break(dlite_bps->id);
02093     }
02094   fprintf(stdout, "All breakpoints cleared.\n");
02095 
02096   /* no error */
02097   return NULL;
02098 }

char * dlite_cont int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1100 of file dlite.c.

References dlite_active, dlite_return, et_addr, eval_as_addr(), EVAL_INTEGRAL, f_dlite_mem_obj, f_dlite_reg_obj, FALSE, myfprintf(), panic(), TRUE, eval_value_t::type, and eval_value_t::value.

01103 {
01104   struct eval_value_t val;
01105 
01106   if (!f_dlite_reg_obj || !f_dlite_mem_obj)
01107     panic("DLite is not configured");
01108 
01109   if (nargs != 0 && nargs != 1)
01110     return "too many arguments";
01111 
01112   if (nargs == 1)
01113     {
01114       /* continue from specified address, check address */
01115       if (!EVAL_INTEGRAL(args[0].as_value.type))
01116         return "address argument must be an integral type";
01117 
01118       /* reset PC */
01119       val.type = et_addr;
01120       val.value.as_addr = eval_as_addr(args[0].as_value);
01121       f_dlite_reg_obj(regs, /* is_write */TRUE, rt_PC, 0, &val);
01122 
01123       myfprintf(stdout, "DLite: continuing execution @ 0x%08p...\n",
01124                 val.value.as_addr);
01125     }
01126 
01127   /* signal end of main debugger loop, and continuation of prog execution */
01128   dlite_active = FALSE;
01129   dlite_return = TRUE;
01130 
01131   /* no error */
01132   return NULL;
01133 }

char * dlite_cregs int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1339 of file dlite.c.

References md_print_cregs(), and regs_t::regs_C.

Referenced by dlite_iregs(), and dlite_regs().

01342 {
01343   /* print floating point registers */
01344   md_print_cregs(regs->regs_C, stdout);
01345 
01346   /* no error */
01347   return NULL;
01348 }

char * dlite_dbreak int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1943 of file dlite.c.

References ACCESS_READ, ACCESS_WRITE, arg_val_t::as_access, range_range_t::end, eval_as_addr(), EVAL_INTEGRAL, range_pos_t::pos, pt_addr, range_pos_t::ptype, set_break(), and range_range_t::start.

01946 {
01947   int access;
01948   md_addr_t addr;
01949   struct range_range_t range;
01950 
01951   if (nargs != 1 && nargs != 2)
01952     return "wrong number of arguments";
01953 
01954   if (nargs == 1)
01955     {
01956       /* check address */
01957       if (!EVAL_INTEGRAL(args[0].as_value.type))
01958         return "address argument must be an integral type";
01959 
01960       /* reset addr */
01961       addr = eval_as_addr(args[0].as_value);
01962 
01963       /* break on read or write */
01964       access = ACCESS_READ|ACCESS_WRITE;
01965     }
01966   else if (nargs == 2)
01967     {
01968       /* check address */
01969       if (!EVAL_INTEGRAL(args[0].as_value.type))
01970         return "address argument must be an integral type";
01971 
01972       /* reset addr */
01973       addr = eval_as_addr(args[0].as_value);
01974 
01975       /* get access */
01976       access = args[1].as_access;
01977     }
01978 
01979   /* build the range */
01980   range.start.ptype = pt_addr;
01981   range.start.pos = addr;
01982   range.end.ptype = pt_addr;
01983   range.end.pos = addr + 1;
01984 
01985   /* set the breakpoint */
01986   return set_break(access, &range);
01987 }

char * dlite_delete int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2058 of file dlite.c.

References delete_break(), eval_as_uint(), and EVAL_INTEGRAL.

02061 {
02062   int id;
02063 
02064   if (nargs != 1)
02065     return "wrong number of arguments";
02066 
02067   /* check bp id */
02068   if (!EVAL_INTEGRAL(args[0].as_value.type))
02069     return "id must be an integral type";
02070   
02071   id = eval_as_uint(args[0].as_value);
02072   return delete_break(id);
02073 }

char * dlite_dis int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1626 of file dlite.c.

References eval_as_addr(), eval_as_uint(), EVAL_INTEGRAL, f_dlite_mem_obj, FALSE, INSTS_PER_SCREEN, md_print_insn(), MD_SWAPI, and myfprintf().

01629 {
01630   int i;
01631   int count = INSTS_PER_SCREEN;
01632   static md_addr_t addr = 0;
01633   md_inst_t inst;
01634   char *errstr;
01635 
01636   if (nargs < 0 || nargs > 2)
01637     return "too many arguments";
01638 
01639   if (nargs == 1)
01640     {
01641       /* check address */
01642       if (!EVAL_INTEGRAL(args[0].as_value.type))
01643         return "address argument must be an integral type";
01644 
01645       /* reset PC */
01646       addr = eval_as_addr(args[0].as_value);
01647     }
01648   else if (nargs == 2)
01649     {
01650       /* check address */
01651       if (!EVAL_INTEGRAL(args[0].as_value.type))
01652         return "address argument must be an integral type";
01653 
01654       /* reset addr */
01655       addr = eval_as_addr(args[0].as_value);
01656 
01657       /* check count */
01658       if (!EVAL_INTEGRAL(args[0].as_value.type))
01659         return "count argument must be an integral type";
01660 
01661       /* reset count */
01662       count = eval_as_uint(args[1].as_value);
01663 
01664       if (count < 0 || count > 1024)
01665         return "bad count argument";
01666     }
01667   /* else, nargs == 0, use addr, count */
01668 
01669   if ((addr % sizeof(md_inst_t)) != 0)
01670     return "instruction addresses are a multiple of eight";
01671 
01672   /* disassemble COUNT insts at ADDR */
01673   for (i=0; i<count; i++)
01674     {
01675       /* read and disassemble instruction */
01676       myfprintf(stdout, "    0x%08p:   ", addr);
01677       errstr =
01678         f_dlite_mem_obj(mem, /* !is_write */FALSE,
01679                         addr, (char *)&inst, sizeof(inst));
01680       inst = MD_SWAPI(inst);
01681       if (errstr)
01682         return errstr;
01683       md_print_insn(inst, addr, stdout);
01684       fprintf(stdout, "\n");
01685 
01686       /* go to next instruction */
01687       addr += sizeof(md_inst_t);
01688     }
01689 
01690   /* no error */
01691   return NULL;
01692 }

char * dlite_display int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1404 of file dlite.c.

References arg_val_t::as_modifier, et_double, et_int, et_uint, eval_as_addr(), EVAL_INTEGRAL, f_dlite_mem_obj, FALSE, MOD_BYTE, MOD_CHAR, MOD_DOUBLE, MOD_HALF, MOD_QWORD, print_val(), size, eval_value_t::type, and eval_value_t::value.

01407 {
01408   int modifiers, size;
01409   md_addr_t addr;
01410   unsigned char buf[512];
01411   struct eval_value_t val;
01412   char *errstr;
01413 
01414   if (nargs != 1 && nargs != 2)
01415     return "wrong number of arguments";
01416 
01417   if (nargs == 1)
01418     {
01419       /* no modifiers */
01420       modifiers = 0;
01421 
01422       /* check address */
01423       if (!EVAL_INTEGRAL(args[0].as_value.type))
01424         return "address argument must be an integral type";
01425 
01426       /* reset address */
01427       addr = eval_as_addr(args[0].as_value);
01428     }
01429   else if (nargs == 2)
01430     {
01431       modifiers = args[0].as_modifier;
01432 
01433       /* check address */
01434       if (!EVAL_INTEGRAL(args[1].as_value.type))
01435         return "address argument must be an integral type";
01436 
01437       /* reset address */
01438       addr = eval_as_addr(args[1].as_value);
01439     }
01440 
01441   /* determine operand size */
01442   if (modifiers & (MOD_BYTE|MOD_CHAR))
01443     size = 1;
01444   else if (modifiers & MOD_HALF)
01445     size = 2;
01446   else if (modifiers & (MOD_QWORD|MOD_DOUBLE))
01447     size = 8;
01448   else /* no modifiers, or MOD_WORD|MOD_FLOAT */
01449     size = 4;
01450 
01451   /* read memory */
01452   errstr = f_dlite_mem_obj(mem, /* !is_write */FALSE, addr, (char *)buf, size);
01453   if (errstr)
01454     return errstr;
01455 
01456   /* marshall a value */
01457   if (modifiers & (MOD_BYTE|MOD_CHAR))
01458     {
01459       /* size == 1 */
01460       val.type = et_int;
01461       val.value.as_int = (int)*(unsigned char *)buf;
01462     }
01463   else if (modifiers & MOD_HALF)
01464     {
01465       /* size == 2 */
01466       val.type = et_int;
01467       val.value.as_int = (int)*(unsigned short *)buf;
01468     }
01469   else if (modifiers & (MOD_QWORD|MOD_DOUBLE))
01470     {
01471       /* size == 8 */
01472       val.type = et_double;
01473       val.value.as_double = *(double *)buf;
01474     }
01475   else /* no modifiers, or MOD_WORD|MOD_FLOAT */
01476     {
01477       /* size == 4 */
01478       val.type = et_uint;
01479       val.value.as_uint = *(unsigned int *)buf;
01480     }
01481 
01482   /* print the value */
01483   errstr = print_val(modifiers, val);
01484   if (errstr)
01485     return errstr;
01486   fprintf(stdout, "\n");
01487 
01488   /* no error */
01489   return NULL;
01490 }

char * dlite_dsymbols int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2146 of file dlite.c.

References FALSE, sym_dumpsym(), and sym_loadsyms().

02149 {
02150   int i;
02151 
02152   if (nargs != 0)
02153     return "wrong number of arguments";
02154 
02155   /* load symbols, if not already loaded */
02156   sym_loadsyms(ld_prog_fname, /* !locals */FALSE);
02157 
02158   /* print all symbol values */
02159   for (i=0; i<sym_ndatasyms; i++)
02160     sym_dumpsym(sym_datasyms[i], stdout);
02161 
02162   /* no error */
02163   return NULL;
02164 }

char * dlite_dump int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1498 of file dlite.c.

References BYTES_PER_LINE, eval_as_addr(), eval_as_uint(), EVAL_INTEGRAL, f_dlite_mem_obj, FALSE, LINES_PER_SCREEN, myfprintf(), and panic().

01501 {
01502   int i, j;
01503   int count = LINES_PER_SCREEN * BYTES_PER_LINE, i_count, fmt_count, fmt_lines;
01504   md_addr_t fmt_addr, i_addr;
01505   static md_addr_t addr = 0;
01506   unsigned char byte;
01507   char buf[512];
01508   char *errstr;
01509 
01510   if (nargs < 0 || nargs > 2)
01511     return "too many arguments";
01512 
01513   if (nargs == 1)
01514     {
01515       /* check address */
01516       if (!EVAL_INTEGRAL(args[0].as_value.type))
01517         return "address argument must be an integral type";
01518 
01519       /* reset PC */
01520       addr = eval_as_addr(args[0].as_value);
01521     }
01522   else if (nargs == 2)
01523     {
01524       /* check address */
01525       if (!EVAL_INTEGRAL(args[0].as_value.type))
01526         return "address argument must be an integral type";
01527 
01528       /* reset addr */
01529       addr = eval_as_addr(args[0].as_value);
01530 
01531       /* check count */
01532       if (!EVAL_INTEGRAL(args[1].as_value.type))
01533         return "count argument must be an integral type";
01534 
01535       if (eval_as_uint(args[1].as_value) > 1024)
01536         return "bad count argument";
01537 
01538       /* reset count */
01539       count = eval_as_uint(args[1].as_value);
01540     }
01541   /* else, nargs == 0, use addr, count */
01542 
01543   /* normalize start address and count */
01544   fmt_addr = addr & ~(BYTES_PER_LINE - 1);
01545   fmt_count = (count + (BYTES_PER_LINE - 1)) & ~(BYTES_PER_LINE - 1);
01546   fmt_lines = fmt_count / BYTES_PER_LINE;
01547 
01548   if (fmt_lines < 1)
01549     panic("no output lines");
01550 
01551   /* print dump */
01552   if (fmt_lines == 1)
01553     {
01554       /* unformatted dump */
01555       i_addr = fmt_addr;
01556       myfprintf(stdout, "0x%08p: ", i_addr);
01557       for (i=0; i < count; i++)
01558         {
01559           errstr =
01560             f_dlite_mem_obj(mem, /* !is_write */FALSE,
01561                             i_addr, (char *)&byte, 1);
01562           if (errstr)
01563             return errstr;
01564           fprintf(stdout, "%02x ", byte);
01565           if (isprint(byte))
01566             buf[i] = byte;
01567           else
01568             buf[i] = '.';
01569           i_addr++;
01570           addr++;
01571         }
01572       buf[i] = '\0';
01573 
01574       /* character view */
01575       fprintf(stdout, "[%s]\n", buf);
01576     }
01577   else /* lines > 1 */
01578     {
01579       i_count = 0;
01580       i_addr = fmt_addr;
01581       for (i=0; i < fmt_lines; i++)
01582         {
01583           myfprintf(stdout, "0x%08p: ", i_addr);
01584 
01585           /* byte view */
01586           for (j=0; j < BYTES_PER_LINE; j++)
01587             {
01588               if (i_addr >= addr && i_count <= count)
01589                 {
01590                   errstr =
01591                     f_dlite_mem_obj(mem, /* !is_write */FALSE,
01592                                     i_addr, (char *)&byte, 1);
01593                   if (errstr)
01594                     return errstr;
01595                   fprintf(stdout, "%02x ", byte);
01596                   if (isprint(byte))
01597                     buf[j] = byte;
01598                   else
01599                     buf[j] = '.';
01600                   i_count++;
01601                   addr++;
01602                 }
01603               else
01604                 {
01605                   fprintf(stdout, "   ");
01606                   buf[j] = ' ';
01607                 }
01608               i_addr++;
01609             }
01610           buf[j] = '\0';
01611 
01612           /* character view */
01613           fprintf(stdout, "[%s]\n", buf);
01614         }
01615     }
01616 
01617   /* no error */
01618   return NULL;
01619 }

char* dlite_exec char *    cmd_str,
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 560 of file dlite.c.

References ACCESS_EXEC, ACCESS_READ, ACCESS_WRITE, dlite_cmd_t::arg_strs, arg_val_t::as_access, arg_val_t::as_modifier, arg_val_t::as_str, arg_val_t::as_value, dlite_cmd_t::cmd_fn, dlite_cmd_t::cmd_str, eval_expr(), modifier_parser(), and panic().

Referenced by dlite_main().

00563 {
00564   int i, arg_cnt;
00565   struct dlite_cmd_t *cmd;
00566   char cmd_buf[512], *p, *q, *endp;
00567   union arg_val_t args[MAX_ARGS];
00568 
00569   p = cmd_str;
00570   q = cmd_buf;
00571 
00572   /* skip any whitespace before argument */
00573   while (*p == ' ' || *p == '\t' || *p == '\n')
00574     p++;
00575 
00576   /* anything left? */
00577   if (*p == '\0')
00578     {
00579       /* NOP, no error */
00580       return NULL;
00581     }
00582 
00583   /* copy out command name string */
00584   while (*p != '\0' && *p != '\n' && *p != ' ' && *p != '\t' && *p != '/')
00585     *q++ = *p++;
00586   *q = '\0';
00587 
00588   /* find matching command */
00589   for (cmd=cmd_db; cmd->cmd_str != NULL; cmd++)
00590     {
00591       if (!strcmp(cmd->cmd_str, cmd_buf))
00592         break;
00593     }
00594   if (cmd->cmd_str == NULL)
00595     return "unknown command";
00596 
00597   /* match arguments for *CMD */
00598   for (i=0, arg_cnt=0; i<MAX_ARGS && cmd->arg_strs[i] != NULL; i++, arg_cnt++)
00599     {
00600       int optional, access, modifiers;
00601       char *arg, arg_type, *err_str;
00602       struct eval_value_t val;
00603 
00604       /* skip any whitespace before argument */
00605       while (*p == ' ' || *p == '\t' || *p == '\n')
00606         p++;
00607 
00608       arg = cmd->arg_strs[i];
00609       arg_type = arg[0];
00610       optional = (arg[1] == '?');
00611 
00612       if (*p == '\0')
00613         {
00614           if (optional)
00615             {
00616               /* all arguments parsed */
00617               break;
00618             }
00619           else
00620             return "missing an argument";
00621         }
00622 
00623       endp = p;
00624       switch (arg_type)
00625         {
00626         case 'm':
00627           err_str = modifier_parser(p, &endp, &modifiers);
00628           if (err_str)
00629             return err_str;
00630           args[arg_cnt].as_modifier = modifiers;
00631           break;
00632         case 'a':
00633           local_regs = regs;
00634           val = eval_expr(dlite_evaluator, p, &endp);
00635           if (eval_error)
00636             return eval_err_str[eval_error];
00637           args[arg_cnt].as_value = val;
00638           break;
00639         case 'c':
00640           local_regs = regs;
00641           val = eval_expr(dlite_evaluator, p, &endp);
00642           if (eval_error)
00643             return eval_err_str[eval_error];
00644           args[arg_cnt].as_value = val;
00645           break;
00646         case 'e':
00647           local_regs = regs;
00648           val = eval_expr(dlite_evaluator, p, &endp);
00649           if (eval_error)
00650             return eval_err_str[eval_error];
00651           args[arg_cnt].as_value = val;
00652           break;
00653         case 't':
00654           access = 0;
00655           while (*p != '\0' && *p != '\n' && *p != ' ' && *p != '\t')
00656             {
00657               switch (*p)
00658                 {
00659                 case 'r':
00660                   access |= ACCESS_READ;
00661                   break;
00662                 case 'w':
00663                   access |= ACCESS_WRITE;
00664                   break;
00665                 case 'x':
00666                   access |= ACCESS_EXEC;
00667                   break;
00668                 default:
00669                   return "bad access type specifier (use r|w|x)";
00670                 }
00671               p++;
00672             }
00673           endp = p;
00674           args[arg_cnt].as_access = access;
00675           break;
00676         case 'i':
00677           local_regs = regs;
00678           val = eval_expr(dlite_evaluator, p, &endp);
00679           if (eval_error)
00680             return eval_err_str[eval_error];
00681           args[arg_cnt].as_value = val;
00682           break;
00683         case 's':
00684           q = args[arg_cnt].as_str;
00685           while (*p != ' ' && *p != '\t' && *p != '\0')
00686             *q++ = *p++;
00687           *q = '\0';
00688           endp = p;
00689           break;
00690         default:
00691           panic("bogus argument type: `%c'", arg_type);
00692         }
00693       p = endp;
00694     }
00695 
00696 
00697   /* skip any whitespace before any trailing argument */
00698   while (*p == ' ' || *p == '\t' || *p == '\n')
00699     p++;
00700 
00701   /* check for any orphan arguments */
00702   if (*p != '\0')
00703     return "too many arguments";
00704 
00705   /* if we reach here, all arguments were parsed correctly, call handler */
00706   return cmd->cmd_fn(arg_cnt, args, regs, mem);
00707 }

char * dlite_fpregs int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1326 of file dlite.c.

References md_print_fpregs(), and regs_t::regs_F.

Referenced by dlite_regs().

01329 {
01330   /* print floating point registers */
01331   md_print_fpregs(regs->regs_F, stdout);
01332 
01333   /* no error */
01334   return NULL;
01335 }

char * dlite_help int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1004 of file dlite.c.

References arg_val_t::as_str, dlite_cmd_t::cmd_str, dlite_help_tail, dlite_pause(), and print_help().

01007 {
01008   struct dlite_cmd_t *cmd;
01009 
01010   if (nargs != 0 && nargs != 1)
01011     return "too many arguments";
01012 
01013   if (nargs == 1)
01014     {
01015       /* print help for specified commands */
01016       for (cmd=cmd_db; cmd->cmd_str != NULL; cmd++)
01017         {
01018           if (!strcmp(cmd->cmd_str, args[0].as_str))
01019             break;
01020         }
01021       if (!cmd->cmd_str)
01022         return "command unknown";
01023 
01024       print_help(cmd);
01025     }
01026   else
01027     {
01028       /* print help for all commands */
01029       for (cmd=cmd_db; cmd->cmd_str != NULL; cmd++)
01030         {
01031           /* `---' specifies a good point for a scroll pause */
01032           if (!strcmp(cmd->cmd_str, "---"))
01033             dlite_pause();
01034           else
01035             print_help(cmd);
01036         }
01037 
01038       fprintf (stdout, "\n");
01039       if (dlite_help_tail)
01040         fprintf (stdout, "%s\n", dlite_help_tail);
01041     }
01042 
01043   /* no error */
01044   return NULL;
01045 }

void dlite_init dlite_reg_obj_t    reg_obj,
dlite_mem_obj_t    mem_obj,
dlite_mstate_obj_t    mstate_obj
 

Definition at line 2195 of file dlite.c.

References dlite_mem_obj_t, dlite_mstate_obj_t, dlite_reg_obj_t, eval_new(), f_dlite_mem_obj, f_dlite_mstate_obj, and f_dlite_reg_obj.

Referenced by sim_load_prog().

02198 {
02199   /* architected state accessors */
02200   f_dlite_reg_obj = reg_obj;
02201   f_dlite_mem_obj = mem_obj;
02202   f_dlite_mstate_obj = mstate_obj;
02203 
02204   /* instantiate the expression evaluator */
02205   dlite_evaluator = eval_new(ident_evaluator, NULL);
02206 }

char * dlite_iregs int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1304 of file dlite.c.

References dlite_cregs(), md_print_iregs(), myfprintf(), regs_t::regs_NPC, regs_t::regs_PC, and regs_t::regs_R.

01307 {
01308   char *err_str;
01309 
01310   if (nargs != 0)
01311     return "too many arguments";
01312 
01313   /* print integer registers */
01314   myfprintf(stdout, "PC: 0x%08p   NPC: 0x%08p\n",
01315             regs->regs_PC, regs->regs_NPC);
01316   if ((err_str = dlite_cregs(nargs, args, regs, mem)) != NULL)
01317     return err_str;
01318   md_print_iregs(regs->regs_R, stdout);
01319 
01320   /* no error */
01321   return NULL;
01322 }

void dlite_main md_addr_t    regs_PC,
md_addr_t    next_PC,
counter_t    cycle,
struct regs_t   regs,
struct mem_t   mem
 

Definition at line 2255 of file dlite.c.

References ACCESS_READ, ACCESS_WRITE, break_access, counter_t, dlite_active, dlite_exec(), DLITE_PROMPT, dlite_return, dlite_status(), FALSE, and TRUE.

Referenced by ruu_dispatch(), and sim_main().

02260 {
02261   char buf[512], *err_str;
02262   int dbreak = (break_access & (ACCESS_READ|ACCESS_WRITE)) != 0;
02263   static char cmd[512] = "";
02264 
02265   dlite_active = TRUE;
02266   dlite_return = FALSE;
02267   dlite_status(regs_PC, next_PC, cycle, dbreak, regs, mem);
02268 
02269   while (dlite_active && !dlite_return)
02270     {
02271       fprintf(stdout, DLITE_PROMPT);
02272       fflush(stdout);
02273       fgets(buf, 512, stdin);
02274 
02275       /* chop */
02276       if (buf[strlen(buf)-1] == '\n')
02277         buf[strlen(buf)-1] = '\0';
02278 
02279       if (buf[0] != '\0')
02280         {
02281           /* use this command */
02282           strcpy(cmd, buf);
02283         }
02284       /* else, use last command */
02285 
02286       err_str = dlite_exec(cmd, regs, mem);
02287       if (err_str)
02288         fprintf(stdout, "Dlite: error: %s\n", err_str);
02289     }
02290 }

char* dlite_mem_obj struct mem_t   mem,
int    is_write,
md_addr_t    addr,
char *    p,
int    nbytes
 

Definition at line 887 of file dlite.c.

References FALSE, mem_access(), mem_cmd, Read, and Write.

00892 {
00893   enum mem_cmd cmd;
00894 
00895   if (!is_write)
00896     cmd = Read;
00897   else
00898     cmd = Write;
00899 
00900 #if 0
00901   char *errstr;
00902   errstr = mem_valid(cmd, addr, nbytes, /* !declare */FALSE);
00903   if (errstr)
00904     return errstr;
00905 #endif
00906 
00907   /* else, no error, access memory */
00908   mem_access(mem, cmd, addr, p, nbytes);
00909 
00910   /* no error */
00911   return NULL;
00912 }

char * dlite_mstate int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1373 of file dlite.c.

References f_dlite_mstate_obj.

01376 {
01377   char *errstr;
01378 
01379   if (nargs != 0 && nargs != 1)
01380     return "too many arguments";
01381 
01382   if (f_dlite_mstate_obj)
01383     {
01384       if (nargs == 0)
01385         {
01386           errstr = f_dlite_mstate_obj(stdout, NULL, regs, mem);
01387           if (errstr)
01388             return errstr;
01389         }
01390       else
01391         {
01392           errstr = f_dlite_mstate_obj(stdout, args[0].as_str, regs, mem);
01393           if (errstr)
01394             return errstr;
01395         }
01396     }
01397 
01398   /* no error */
01399   return NULL;
01400 }

char* dlite_mstate_obj FILE *    stream,
char *    cmd,
struct regs_t   regs,
struct mem_t   mem
 

Definition at line 916 of file dlite.c.

00920 {
00921   /* nada */
00922   fprintf(stream, "No machine state.\n");
00923 
00924   /* no error */
00925   return NULL;
00926 }

char * dlite_option int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1222 of file dlite.c.

References opt_opt_t::desc, opt_opt_t::name, opt_find_option(), and opt_print_option().

01225 {
01226   struct opt_opt_t *opt;
01227 
01228   if (nargs != 1)
01229     return "wrong number of arguments";
01230 
01231   /* print a single option, specified by argument */
01232   opt = opt_find_option(sim_odb, args[0].as_str);
01233   if (!opt)
01234     return "option is not defined";
01235 
01236   /* else, print this option's value */
01237   fprintf(stdout, "%-16s  ", opt->name);
01238   opt_print_option(opt, stdout);
01239   if (opt->desc)
01240     fprintf(stdout, " # %s", opt->desc);
01241   fprintf(stdout, "\n");
01242 
01243   /* no error */
01244   return NULL;
01245 }

char * dlite_options int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1206 of file dlite.c.

References FALSE, opt_print_options(), and TRUE.

01209 {
01210   if (nargs != 0)
01211     return "wrong number of arguments";
01212 
01213   /* print all options */
01214   opt_print_options(sim_odb, stdout, /* terse */TRUE, /* !notes */FALSE);
01215 
01216   /* no error */
01217   return NULL;
01218 }

void dlite_pause void    [static]
 

Definition at line 930 of file dlite.c.

Referenced by dlite_help(), and dlite_regs().

00931 {
00932   char buf[512];
00933   fprintf(stdout, "Press <return> to continue...");
00934   fflush(stdout);
00935   fgets(buf, 512, stdin);
00936 }

char * dlite_print int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1171 of file dlite.c.

References arg_val_t::as_modifier, arg_val_t::as_value, and print_val().

01174 {
01175   int modifiers = 0;
01176   char *err_str;
01177   struct eval_value_t val;
01178 
01179   if (nargs != 1 && nargs != 2)
01180     return "wrong number of arguments";
01181 
01182   if (nargs == 2)
01183     {
01184       /* arguments include modifiers and expression value */
01185       modifiers = args[0].as_modifier;
01186       val = args[1].as_value;
01187     }
01188   else
01189     {
01190       /* arguments include only expression value */
01191       val = args[0].as_value;
01192     }
01193 
01194   /* print expression value */
01195   err_str = print_val(modifiers, val);
01196   if (err_str)
01197     return err_str;
01198   fprintf(stdout, "\n");
01199 
01200   /* no error */
01201   return NULL;
01202 }

char * dlite_quit int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1084 of file dlite.c.

01087 {
01088   if (nargs != 0)
01089     return "too many arguments";
01090 
01091   fprintf(stdout, "DLite: exiting simulator...\n");
01092   exit(1);
01093 
01094   /* no error */
01095   return NULL;
01096 }

char * dlite_rbreak int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1991 of file dlite.c.

References ACCESS_EXEC, ACCESS_READ, ACCESS_WRITE, arg_val_t::as_access, range_range_t::end, range_pos_t::pos, range_pos_t::ptype, range_parse_range(), set_break(), and range_range_t::start.

01994 {
01995   int access;
01996   char *errstr;
01997   struct range_range_t range;
01998 
01999   if (nargs != 1 && nargs != 2)
02000     return "wrong number of arguments";
02001 
02002   if (nargs == 2)
02003     {
02004       /* get access */
02005       access = args[1].as_access;
02006     }
02007   else
02008     {
02009       /* break on read or write or exec */
02010       access = ACCESS_READ|ACCESS_WRITE|ACCESS_EXEC;
02011     }
02012 
02013   /* check range */
02014   errstr = range_parse_range(args[0].as_str, &range);
02015   if (errstr)
02016     return errstr;
02017 
02018   /* sanity checks for ranges */
02019   if (range.start.ptype != range.end.ptype)
02020     return "range endpoints are not of the same type";
02021   else if (range.start.pos > range.end.pos)
02022     return "range start is after range end";
02023 
02024   /* set the breakpoint */
02025   return set_break(access, &range);
02026 }

char * dlite_regs int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1352 of file dlite.c.

References dlite_cregs(), dlite_fpregs(), dlite_pause(), md_print_iregs(), myfprintf(), regs_t::regs_NPC, regs_t::regs_PC, and regs_t::regs_R.

01355 {
01356   char *err_str;
01357 
01358   myfprintf(stdout, "PC: 0x%08p   NPC: 0x%08p\n",
01359             regs->regs_PC, regs->regs_NPC);
01360   if ((err_str = dlite_cregs(nargs, args, regs, mem)) != NULL)
01361     return err_str;
01362   md_print_iregs(regs->regs_R, stdout);
01363   dlite_pause();
01364   if ((err_str = dlite_fpregs(nargs, args, regs, mem)) != NULL)
01365     return err_str;
01366 
01367   /* no error */
01368   return NULL;
01369 }

char * dlite_stat int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1266 of file dlite.c.

References stat_find_stat(), and stat_print_stat().

01269 {
01270   struct stat_stat_t *stat;
01271 
01272   if (nargs != 1)
01273     return "wrong number of arguments";
01274 
01275   /* print a single option, specified by argument */
01276   stat = stat_find_stat(sim_sdb, args[0].as_str);
01277   if (!stat)
01278     return "statistical variable is not defined";
01279 
01280   /* else, print this option's value */
01281   stat_print_stat(sim_sdb, stat, stdout);
01282 
01283   /* no error */
01284   return NULL;
01285 }

char * dlite_stats int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1249 of file dlite.c.

References sim_aux_stats(), and stat_print_stats().

01252 {
01253   if (nargs != 0)
01254     return "wrong number of arguments";
01255 
01256   /* print all options */
01257   stat_print_stats(sim_sdb, stdout);
01258   sim_aux_stats(stdout);
01259 
01260   /* no error */
01261   return NULL;
01262 }

void dlite_status md_addr_t    regs_PC,
md_addr_t    next_PC,
counter_t    cycle,
int    dbreak,
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2210 of file dlite.c.

References counter_t, f_dlite_mem_obj, FALSE, md_print_insn(), MD_SWAPI, and myfprintf().

Referenced by dlite_main().

02216 {
02217   md_inst_t inst;
02218   char *errstr;
02219 
02220   if (dbreak)
02221     {
02222       fprintf(stdout, "\n");
02223       fprintf(stdout, "Instruction (now finished) that caused data break:\n");
02224       myfprintf(stdout, "[%10n] 0x%08p:    ", cycle, regs_PC);
02225       errstr =
02226         f_dlite_mem_obj(mem, /* !is_write */FALSE,
02227                         regs_PC, (char *)&inst, sizeof(inst));
02228       inst = MD_SWAPI(inst);
02229       if (errstr)
02230         fprintf(stdout, "<invalid memory>: %s", errstr);
02231       else
02232         md_print_insn(inst, regs_PC, stdout);
02233       fprintf(stdout, "\n");
02234       fprintf(stdout, "\n");
02235     }
02236 
02237   /* read and disassemble instruction */
02238   myfprintf(stdout, "[%10n] 0x%08p:    ", cycle, next_PC);
02239   errstr =
02240     f_dlite_mem_obj(mem, /* !is_write */FALSE,
02241                     next_PC, (char *)&inst, sizeof(inst));
02242   inst = MD_SWAPI(inst);
02243   if (errstr)
02244     fprintf(stdout, "<invalid memory>: %s", errstr);
02245   else
02246     md_print_insn(inst, next_PC, stdout);
02247   fprintf(stdout, "\n");
02248 }

char * dlite_step int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1137 of file dlite.c.

References dlite_active, dlite_return, and TRUE.

01140 {
01141   if (nargs != 0)
01142     return "too many arguments";
01143 
01144   /* signal on instruction step */
01145   dlite_active = TRUE;
01146   dlite_return = TRUE;
01147 
01148   /* no error */
01149   return NULL;
01150 }

char * dlite_symbol int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2168 of file dlite.c.

References FALSE, sdb_any, sym_bind_name(), sym_dumpsym(), and sym_loadsyms().

02171 {
02172   int index;
02173   struct sym_sym_t *sym;
02174 
02175   if (nargs != 1)
02176     return "wrong number of arguments";
02177 
02178   /* load symbols, if not already loaded */
02179   sym_loadsyms(ld_prog_fname, /* !locals */FALSE);
02180 
02181   /* print a single option, specified by argument */
02182   sym = sym_bind_name(args[0].as_str, &index, sdb_any);
02183   if (!sym)
02184     return "symbol is not defined";
02185 
02186   /* else, print this symbols's value */
02187   sym_dumpsym(sym_syms_by_name[index], stdout);
02188 
02189   /* no error */
02190   return NULL;
02191 }

char * dlite_symbols int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2102 of file dlite.c.

References FALSE, sym_dumpsym(), and sym_loadsyms().

02105 {
02106   int i;
02107 
02108   if (nargs != 0)
02109     return "wrong number of arguments";
02110 
02111   /* load symbols, if not already loaded */
02112   sym_loadsyms(ld_prog_fname, /* !locals */FALSE);
02113 
02114   /* print all symbol values */
02115   for (i=0; i<sym_nsyms; i++)
02116     sym_dumpsym(sym_syms[i], stdout);
02117 
02118   /* no error */
02119   return NULL;
02120 }

char * dlite_terminate int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1068 of file dlite.c.

01071 {
01072   if (nargs != 0)
01073     return "too many arguments";
01074 
01075   fprintf(stdout, "DLite: terminating simulation...\n");
01076   longjmp(sim_exit_buf, /* exitcode */1);
01077 
01078   /* no error */
01079   return NULL;
01080 }

char * dlite_tsymbols int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 2124 of file dlite.c.

References FALSE, sym_dumpsym(), and sym_loadsyms().

02127 {
02128   int i;
02129 
02130   if (nargs != 0)
02131     return "wrong number of arguments";
02132 
02133   /* load symbols, if not already loaded */
02134   sym_loadsyms(ld_prog_fname, /* !locals */FALSE);
02135 
02136   /* print all symbol values */
02137   for (i=0; i<sym_ntextsyms; i++)
02138     sym_dumpsym(sym_textsyms[i], stdout);
02139 
02140   /* no error */
02141   return NULL;
02142 }

char * dlite_version int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1049 of file dlite.c.

References VER_MAJOR, VER_MINOR, and VER_UPDATE.

01052 {
01053   if (nargs != 0)
01054     return "too many arguments";
01055 
01056   /* print simulator version info */
01057   fprintf(stdout, "The SimpleScalar/%s Tool Set, version %d.%d of %s.\n",
01058           VER_TARGET, VER_MAJOR, VER_MINOR, VER_UPDATE);
01059   fprintf(stdout,
01060     "Copyright (c) 1994-1998 by Todd M. Austin.  All Rights Reserved.\n");
01061 
01062   /* no error */
01063   return NULL;
01064 }

char * dlite_whatis int    nargs,
union arg_val_t    args[],
struct regs_t   regs,
struct mem_t   mem
[static]
 

Definition at line 1289 of file dlite.c.

01292 {
01293   if (nargs != 1)
01294     return "wrong number of arguments";
01295 
01296   fprintf(stdout, "type == `%s'\n", eval_type_str[args[0].as_value.type]);
01297 
01298   /* no error */
01299   return NULL;
01300 }

struct eval_value_t ident_evaluator struct eval_state_t   es [static]
 

Definition at line 221 of file dlite.c.

References sym_sym_t::addr, ERR_BADEXPR, ERR_NOERR, ERR_UNDEFVAR, et_addr, et_double, et_float, et_int, et_uint, eval_delete(), eval_expr(), eval_new(), f_dlite_reg_obj, FALSE, file, stat_stat_t::stat_variant_t::for_double, stat_stat_t::stat_variant_t::for_float, stat_stat_t::stat_variant_t::for_formula, stat_stat_t::stat_variant_t::for_int, stat_stat_t::stat_variant_t::for_uint, stat_stat_t::stat_variant_t::stat_for_formula_t::formula, mystricmp(), panic(), stat_stat_t::sc, sc_dist, sc_double, sc_float, sc_formula, sc_int, sc_sdist, sc_uint, sdb_any, stat_find_stat(), sym_bind_name(), sym_loadsyms(), TRUE, eval_value_t::type, eval_value_t::value, stat_stat_t::stat_variant_t::stat_for_double_t::var, stat_stat_t::stat_variant_t::stat_for_float_t::var, stat_stat_t::stat_variant_t::stat_for_uint_t::var, stat_stat_t::stat_variant_t::stat_for_int_t::var, and stat_stat_t::variant.

00222 {
00223   int i;
00224   char *err_str;
00225   struct eval_value_t val;
00226   struct stat_stat_t *stat;
00227   struct sym_sym_t *sym;
00228   static struct eval_value_t err_value = { et_int, { 0 } };
00229 
00230   /* is this a builtin register definition? */
00231   for (i=0; md_reg_names[i].str != NULL; i++)
00232     {
00233       if (!mystricmp(es->tok_buf, md_reg_names[i].str))
00234         {
00235           err_str =
00236             f_dlite_reg_obj(local_regs, /* !is_write */FALSE,
00237                             md_reg_names[i].file, md_reg_names[i].reg, &val);
00238           if (err_str)
00239             {
00240               eval_error = ERR_UNDEFVAR;
00241               val = err_value;
00242             }
00243           return val;
00244         }
00245     }
00246 
00247   /* else, try to locate a program symbol */
00248   sym_loadsyms(ld_prog_fname, /* load locals */TRUE);
00249   sym = sym_bind_name(es->tok_buf, NULL, sdb_any);
00250   if (sym)
00251     {
00252       /* found a symbol with this name, return it's (address) value */
00253       val.type = et_addr;
00254       val.value.as_addr = sym->addr;
00255       return val;
00256     }
00257 
00258   /* else, try to locate a statistical value symbol */
00259   stat = stat_find_stat(sim_sdb, es->tok_buf);
00260   if (stat)
00261     {
00262       /* found it, convert stat value to an eval_value_t value */
00263       switch (stat->sc)
00264         {
00265         case sc_int:
00266           val.type = et_int;
00267           val.value.as_int = *stat->variant.for_int.var;
00268           break;
00269         case sc_uint:
00270           val.type = et_uint;
00271           val.value.as_uint = *stat->variant.for_uint.var;
00272           break;
00273 #ifdef HOST_HAS_QWORD
00274         case sc_qword:
00275           val.type = et_qword;
00276           val.value.as_qword = *stat->variant.for_qword.var;
00277           break;
00278 #endif /* HOST_HAS_QWORD */
00279         case sc_float:
00280           val.type = et_float;
00281           val.value.as_float = *stat->variant.for_float.var;
00282           break;
00283         case sc_double:
00284           val.type = et_double;
00285           val.value.as_double = *stat->variant.for_double.var;
00286           break;
00287         case sc_dist:
00288         case sc_sdist:
00289           eval_error = ERR_BADEXPR;
00290           val = err_value;
00291           break;
00292         case sc_formula:
00293           {
00294             /* instantiate a new evaluator to avoid recursion problems */
00295             struct eval_state_t *es = eval_new(ident_evaluator, sim_sdb);
00296             char *endp;
00297 
00298             val = eval_expr(es, stat->variant.for_formula.formula, &endp);
00299             if (eval_error != ERR_NOERR || *endp != '\0')
00300               {
00301                 /* pass through eval_error */
00302                 val = err_value;
00303               }
00304             /* else, use value returned */
00305             eval_delete(es);
00306           }
00307           break;
00308         default:
00309           panic("bogus stat class");
00310         }
00311       return val;
00312     }
00313   /* else, not found */
00314 
00315   /* else, this is a bogus symbol */
00316   eval_error = ERR_UNDEFVAR;
00317   val = err_value;
00318   return val;
00319 }

char* modifier_parser char *    p,
char **    endp,
int *    pmod
[static]
 

Definition at line 143 of file dlite.c.

References MOD_BINARY, MOD_BYTE, MOD_CHAR, MOD_DECIMAL, MOD_DOUBLE, MOD_FLOAT, MOD_HALF, MOD_HEX, MOD_OCTAL, MOD_QWORD, MOD_STRING, MOD_UNSIGNED, and MOD_WORD.

Referenced by dlite_exec().

00146 {
00147   int modifiers = 0;
00148 
00149   /* default modifiers */
00150   *pmod = 0;
00151 
00152   /* is this a valid modifier? */
00153   if (*p == '/')
00154     {
00155       p++;
00156       /* parse modifiers until end-of-string or whitespace is found */
00157       while (*p != '\0' && *p != '\n' && *p != ' ' && *p != '\t')
00158         {
00159           switch (*p)
00160             {
00161             case 'b':
00162               modifiers |= MOD_BYTE;
00163               break;
00164             case 'h':
00165               modifiers |= MOD_HALF;
00166               break;
00167             case 'w':
00168               modifiers |= MOD_WORD;
00169               break;
00170             case 'q':
00171               modifiers |= MOD_QWORD;
00172               break;
00173             case 'd':
00174               modifiers |= MOD_DECIMAL;
00175               break;
00176             case 'u':
00177               modifiers |= MOD_UNSIGNED;
00178               break;
00179             case 'o':
00180               modifiers |= MOD_OCTAL;
00181               break;
00182             case 'x':
00183               modifiers |= MOD_HEX;
00184               break;
00185             case '1':
00186               modifiers |= MOD_BINARY;
00187               break;
00188             case 'F':
00189               modifiers |= MOD_FLOAT;
00190               break;
00191             case 'f':
00192               modifiers |= MOD_DOUBLE;
00193               break;
00194             case 'c':
00195               modifiers |= MOD_CHAR;
00196               break;
00197             case 's':
00198               modifiers |= MOD_STRING;
00199               break;
00200             default:
00201               return "bad modifier (use one or more of /bhwqduox1fdcs)";
00202             }
00203           p++;
00204         }
00205     }
00206 
00207   /* no error, return end of string and modifier mask */
00208   *endp = p;
00209   *pmod = modifiers;
00210   return NULL;
00211 }

void print_help struct dlite_cmd_t   cmd [static]
 

Definition at line 940 of file dlite.c.

References dlite_cmd_t::arg_strs, dlite_cmd_t::cmd_str, dlite_cmd_t::help_str, MAX_ARGS, and panic().

00941 {
00942   int i;
00943 
00944   /* print command name */
00945   fprintf(stdout, "  %s ", cmd->cmd_str);
00946 
00947   /* print arguments of command */
00948   for (i=0; i < MAX_ARGS && cmd->arg_strs[i] != NULL; i++)
00949     {
00950       int optional;
00951       char *arg, arg_type;
00952 
00953       arg = cmd->arg_strs[i];
00954       arg_type = arg[0];
00955       optional = (arg[1] == '?');
00956 
00957       if (optional)
00958         fprintf(stdout, "{");
00959       else
00960         fprintf(stdout, "<");
00961 
00962       switch (arg_type)
00963         {
00964         case 'm':
00965           fprintf(stdout, "/modifiers");
00966           break;
00967         case 'a':
00968           fprintf(stdout, "addr");
00969           break;
00970         case 'c':
00971           fprintf(stdout, "count");
00972           break;
00973         case 'e':
00974           fprintf(stdout, "expr");
00975           break;
00976         case 't':
00977           fprintf(stdout, "r|w|x");
00978           break;
00979         case 'i':
00980           fprintf(stdout, "id");
00981           break;
00982         case 's':
00983           fprintf(stdout, "string");
00984           break;
00985         default:
00986           panic("bogus argument type: `%c'", arg_type);
00987         }
00988 
00989       if (optional)
00990         fprintf(stdout, "}");
00991       else
00992         fprintf(stdout, ">");
00993 
00994       fprintf(stdout, " ");
00995     }
00996   fprintf(stdout, "\n");
00997 
00998   /* print command description */
00999   fprintf(stdout, "    %s\n", cmd->help_str);
01000 }

char* print_val int    modifiers,
struct eval_value_t    val
[static]
 

Definition at line 711 of file dlite.c.

References et_addr, et_double, et_float, et_int, et_symbol, et_uint, eval_as_double(), eval_as_float(), eval_as_uint(), MOD_BINARY, MOD_BYTE, MOD_CHAR, MOD_DECIMAL, MOD_DOUBLE, MOD_FLOAT, MOD_FORMATS, MOD_HALF, MOD_HEX, MOD_OCTAL, MOD_QWORD, MOD_SIZES, MOD_STRING, MOD_UNSIGNED, MOD_WORD, myfprintf(), panic(), and eval_value_t::type.

Referenced by dlite_display(), and dlite_print().

00713 {
00714   char *format = "", *prefix = "", radix, buf[512];
00715 
00716   /* fill in any default size */
00717   if ((modifiers & MOD_SIZES) == 0)
00718     {
00719       /* compute default size */
00720       switch (val.type)
00721         {
00722         case et_int:    modifiers |= MOD_WORD; break;
00723         case et_uint:   modifiers |= MOD_WORD; break;
00724         case et_addr:
00725 #ifdef HOST_HAS_QWORD
00726           if (sizeof(md_addr_t) > 4)
00727             modifiers |= MOD_QWORD;
00728           else
00729 #endif /* HOST_HAS_QWORD */
00730             modifiers |= MOD_WORD;
00731           break;
00732 #ifdef HOST_HAS_QWORD
00733         case et_qword:  modifiers |= MOD_QWORD; break;
00734         case et_sqword: modifiers |= MOD_QWORD; break;
00735 #endif /* HOST_HAS_QWORD */
00736         case et_float:  modifiers |= MOD_FLOAT; break;
00737         case et_double: modifiers |= MOD_DOUBLE; break;
00738         case et_symbol:
00739         default:        return "bad print value";
00740         }
00741     }
00742   if (((modifiers & MOD_SIZES) & ((modifiers & MOD_SIZES) - 1)) != 0)
00743     return "multiple size specifiers";
00744 
00745   /* fill in any default format */
00746   if ((modifiers & MOD_FORMATS) == 0)
00747     {
00748       /* compute default size */
00749       switch (val.type)
00750         {
00751         case et_int:    modifiers |= MOD_DECIMAL; break;
00752         case et_uint:   modifiers |= MOD_UNSIGNED; break;
00753         case et_addr:   modifiers |= MOD_HEX; break;
00754 #ifdef HOST_HAS_QWORD
00755         case et_qword:  modifiers |= MOD_UNSIGNED; break;
00756         case et_sqword: modifiers |= MOD_DECIMAL; break;
00757 #endif /* HOST_HAS_QWORD */
00758         case et_float:  /* use default format */break;
00759         case et_double: /* use default format */break;
00760         case et_symbol:
00761         default:        return "bad print value";
00762         }
00763     }
00764   if (((modifiers & MOD_FORMATS) & ((modifiers & MOD_FORMATS) - 1)) != 0)
00765     return "multiple format specifiers";
00766 
00767   /* decode modifiers */
00768   if (modifiers & (MOD_BYTE|MOD_HALF|MOD_WORD|MOD_QWORD))
00769     {
00770       if (modifiers & MOD_DECIMAL)
00771         radix = 'd';
00772       else if (modifiers & MOD_UNSIGNED)
00773         radix = 'u';
00774       else if (modifiers & MOD_OCTAL)
00775         radix = 'o';
00776       else if (modifiers & MOD_HEX)
00777         radix = 'x';
00778       else if (modifiers & MOD_BINARY)
00779         return "binary format not yet implemented";
00780       else
00781         panic("no default integer format");
00782 
00783       if (modifiers & MOD_BYTE)
00784         {
00785           if (modifiers & MOD_OCTAL)
00786             {
00787               prefix = "0";
00788               format = "03";
00789             }
00790           else if (modifiers & MOD_HEX)
00791             {
00792               prefix = "0x";
00793               format = "02";
00794             }
00795           else
00796             {
00797               prefix = "";
00798               format = "";
00799             }
00800 
00801           sprintf(buf, "%s%%%s%c", prefix, format, radix);
00802           myfprintf(stdout, buf, eval_as_uint(val));
00803         }
00804       else if (modifiers & MOD_HALF)
00805         {
00806           if (modifiers & MOD_OCTAL)
00807             {
00808               prefix = "0";
00809               format = "06";
00810             }
00811           else if (modifiers & MOD_HEX)
00812             {
00813               prefix = "0x";
00814               format = "04";
00815             }
00816           else
00817             {
00818               prefix = "";
00819               format = "";
00820             }
00821 
00822           sprintf(buf, "%s%%%s%c", prefix, format, radix);
00823           myfprintf(stdout, buf, eval_as_uint(val));
00824         }
00825       else if (modifiers & MOD_WORD)
00826         {
00827           if (modifiers & MOD_OCTAL)
00828             {
00829               prefix = "0";
00830               format = "011";
00831             }
00832           else if (modifiers & MOD_HEX)
00833             {
00834               prefix = "0x";
00835               format = "08";
00836             }
00837           else
00838             {
00839               prefix = "";
00840               format = "";
00841             }
00842 
00843           sprintf(buf, "%s%%%s%c", prefix, format, radix);
00844           myfprintf(stdout, buf, eval_as_uint(val));
00845         }
00846 #ifdef HOST_HAS_QWORD
00847       else if (modifiers & MOD_QWORD)
00848         {
00849           if (modifiers & MOD_OCTAL)
00850             {
00851               prefix = "0";
00852               format = "022";
00853             }
00854           else if (modifiers & MOD_HEX)
00855             {
00856               prefix = "0x";
00857               format = "016";
00858             }
00859           else
00860             {
00861               prefix = "";
00862               format = "";
00863             }
00864 
00865           sprintf(buf, "%s%%%sl%c", prefix, format, radix);
00866           myfprintf(stdout, buf, eval_as_qword(val));
00867         }
00868 #endif /* HOST_HAS_QWORD */
00869     }
00870   else if (modifiers & MOD_FLOAT)
00871     fprintf(stdout, "%f", (double)eval_as_float(val));
00872   else if (modifiers & MOD_DOUBLE)
00873     fprintf(stdout, "%f", eval_as_double(val));
00874   else if (modifiers & MOD_CHAR)
00875     fprintf(stdout, "`%c'", eval_as_uint(val));
00876   else if (modifiers & MOD_STRING)
00877     return "string format not yet implemented";
00878   else /* no format specified, default to value type format */
00879     panic("no default format");
00880 
00881   /* no error */
00882   return NULL;
00883 }

char* set_break int    class,
struct range_range_t   range
[static]
 

Definition at line 1732 of file dlite.c.

References bp_class_str(), break_id, dlite_break_t::class, dlite_check, fatal(), dlite_break_t::id, dlite_break_t::next, dlite_break_t::range, range_print_range(), and TRUE.

Referenced by dlite_break(), dlite_dbreak(), and dlite_rbreak().

01734 {
01735   struct dlite_break_t *bp;
01736 
01737   /* add breakpoint to break list */
01738   bp = calloc(1, sizeof(struct dlite_break_t));
01739   if (!bp)
01740     fatal("out of virtual memory");
01741 
01742   bp->id = break_id++;
01743   bp->range = *range;
01744   bp->class = class;
01745 
01746   bp->next = dlite_bps;
01747   dlite_bps = bp;
01748 
01749   fprintf(stdout, "breakpoint #%d set @ ", bp->id);
01750   range_print_range(&bp->range, stdout);
01751   fprintf(stdout, ", class: %s\n", bp_class_str(class));
01752 
01753   /* a breakpoint is set now, check for a breakpoint */
01754   dlite_check = TRUE;
01755 
01756   /* no error */
01757   return NULL;
01758 }


Variable Documentation

int break_access = 0 [static]
 

Definition at line 1811 of file dlite.c.

Referenced by __check_break(), and dlite_main().

int break_id = 1 [static]
 

Definition at line 1706 of file dlite.c.

Referenced by set_break().

struct dlite_cmd_t cmd_db[] [static]
 

Definition at line 453 of file dlite.c.

int dlite_active = FALSE
 

Definition at line 108 of file dlite.c.

Referenced by dlite_cont(), dlite_main(), and dlite_step().

struct dlite_break_t* dlite_bps = NULL [static]
 

Definition at line 1703 of file dlite.c.

int dlite_check = FALSE
 

Definition at line 111 of file dlite.c.

Referenced by delete_break(), and set_break().

struct eval_state_t* dlite_evaluator = NULL [static]
 

Definition at line 214 of file dlite.c.

char* dlite_help_tail [static]
 

Initial value:

  "Arguments <addr>, <cnt>, <expr>, and <id> are any legal expression:\n"
  "  <expr>    <-  <factor> +|- <expr>\n"
  "  <factor>  <-  <term> *|/ <factor>\n"
  "  <term>    <-  ( <expr> )\n"
  "                | - <term>\n"
  "                | <const>\n"
  "                | <symbol>\n"
  "                | <file:loc>\n"
  "\n"
  "Command modifiers <mods> are any of the following:\n"
  "\n"
  "  b - print a byte\n"
  "  h - print a half (short)\n"
  "  w - print a word (default)\n"


 
  "  F - print a float\n"
  "  f - print a double\n"
  "  c - print a character\n"
  "  s - print a string\n"
  "  d - print in decimal format (default)\n"
  "  u - print in unsigned decimal format\n"
  "  o - print in octal format\n"
  "  x - print in hex format\n"
  "  1 - print in binary format\n"

Definition at line 529 of file dlite.c.

Referenced by dlite_help().

int dlite_return = FALSE [static]
 

Definition at line 114 of file dlite.c.

Referenced by dlite_cont(), dlite_main(), and dlite_step().

dlite_mem_obj_t f_dlite_mem_obj = NULL [static]
 

Definition at line 104 of file dlite.c.

Referenced by dlite_cont(), dlite_dis(), dlite_display(), dlite_dump(), dlite_init(), and dlite_status().

dlite_mstate_obj_t f_dlite_mstate_obj = NULL [static]
 

Definition at line 105 of file dlite.c.

Referenced by dlite_init(), and dlite_mstate().

dlite_reg_obj_t f_dlite_reg_obj = NULL [static]
 

Definition at line 103 of file dlite.c.

Referenced by dlite_cont(), dlite_init(), and ident_evaluator().

struct regs_t* local_regs = NULL [static]
 

Definition at line 215 of file dlite.c.



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214