⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlite.c

📁 RISC处理器仿真分析程序。可以用于研究通用RISC处理器的指令和架构设计。在linux下编译
💻 C
📖 第 1 页 / 共 4 页
字号:
dlite_terminate(int nargs, union arg_val_t args[]) /* command arguments */{  if (nargs != 0)    return "too many arguments";  fprintf(stdout, "DLite: terminating simulation...\n");  longjmp(sim_exit_buf, /* exitcode */1);  /* no error */  return NULL;}/* quit the simulator, omit any stats dump */static char *					/* err str, NULL for no err */dlite_quit(int nargs, union arg_val_t args[])	/* command arguments */{  if (nargs != 0)    return "too many arguments";  fprintf(stdout, "DLite: exiting simulator...\n");  exit(1);  /* no error */  return NULL;}/* continue executing program (possibly at specified address) */static char *					/* err str, NULL for no err */dlite_cont(int nargs, union arg_val_t args[])	/* command arguments */{  union dlite_reg_val_t val;  if (!f_dlite_reg_obj || !f_dlite_mem_obj)    panic("DLite is not configured");  if (nargs != 0 && nargs != 1)    return "too many arguments";  if (nargs == 1)    {      /* continue from specified address, check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset PC */      val.as_address = args[0].as_value.value.as_uint;      f_dlite_reg_obj(at_write, rt_PC, 0, &val);      fprintf(stdout, "DLite: continuing execution @ 0x%08x...\n",	      val.as_address);    }  /* signal end of main debugger loop, and continuation of prog execution */  dlite_active = FALSE;  dlite_return = TRUE;  /* no error */  return NULL;}/* step program one instruction */static char *					/* err str, NULL for no err */dlite_step(int nargs, union arg_val_t args[])	/* command arguments */{  if (nargs != 0)    return "too many arguments";  /* signal on instruction step */  dlite_active = TRUE;  dlite_return = TRUE;  /* no error */  return NULL;}#if 0 /* NYI *//* step program one instruction in current procedure */static char *					/* err str, NULL for no err */dlite_next(int nargs, union arg_val_t args[])	/* command arguments */{  if (nargs != 0)    return "too many arguments";  /* signal on instruction step */  dlite_step_cnt = 1;  dlite_step_into = FALSE;  /* no error */  return NULL;}#endif/* print the value of <expr> using format <modifiers> */static char *				      	/* err str, NULL for no err */dlite_print(int nargs, union arg_val_t args[])	/* command arguments */{  int modifiers = 0;  char *err_str;  struct eval_value_t val;  if (nargs != 1 && nargs != 2)    return "wrong number of arguments";  if (nargs == 2)    {      /* arguments include modifiers and expression value */      modifiers = args[0].as_modifier;      val = args[1].as_value;    }  else    {      /* arguments include only expression value */      val = args[0].as_value;    }  /* print expression value */  err_str = print_val(modifiers, val);  if (err_str)    return err_str;  fprintf(stdout, "\n");  /* no error */  return NULL;}/* print the value of all command line options */static char *					/* err str, NULL for no err */dlite_options(int nargs, union arg_val_t args[])/* command arguments */{  if (nargs != 0)    return "wrong number of arguments";  /* print all options */  opt_print_options(sim_odb, stdout, /* terse */TRUE, /* !notes */FALSE);  /* no error */  return NULL;}/* print the value of all (or single) command line options */static char *					/* err str, NULL for no err */dlite_option(int nargs, union arg_val_t args[])	/* command arguments */{  struct opt_opt_t *opt;  if (nargs != 1)    return "wrong number of arguments";  /* print a single option, specified by argument */  opt = opt_find_option(sim_odb, args[0].as_str);  if (!opt)    return "option is not defined";  /* else, print this option's value */  fprintf(stdout, "%-16s  ", opt->name);  opt_print_option(opt, stdout);  if (opt->desc)    fprintf(stdout, " # %s", opt->desc);  fprintf(stdout, "\n");  /* no error */  return NULL;}/* print the value of all statistical variables */static char *					/* err str, NULL for no err */dlite_stats(int nargs, union arg_val_t args[])	/* command arguments */{  if (nargs != 0)    return "wrong number of arguments";  /* print all options */  stat_print_stats(sim_sdb, stdout);  sim_aux_stats(stdout);  /* no error */  return NULL;}/* print the value of a statistical variable */static char *					/* err str, NULL for no err */dlite_stat(int nargs, union arg_val_t args[])	/* command arguments */{  struct stat_stat_t *stat;  if (nargs != 1)    return "wrong number of arguments";  /* print a single option, specified by argument */  stat = stat_find_stat(sim_sdb, args[0].as_str);  if (!stat)    return "statistical variable is not defined";  /* else, print this option's value */  stat_print_stat(sim_sdb, stat, stdout);  /* no error */  return NULL;}/* print the type of expression <expr> */static char *					/* err str, NULL for no err */dlite_whatis(int nargs, union arg_val_t args[])	/* command arguments */{  if (nargs != 1)    return "wrong number of arguments";  fprintf(stdout, "type == `%s'\n", eval_type_str[args[0].as_value.type]);  /* no error */  return NULL;}/* print integer register contents */static char *					/* err str, NULL for no err */dlite_iregs(int nargs, union arg_val_t args[])	/* command arguments */{  int i;  union dlite_reg_val_t val, PC, HI, LO;  if (!f_dlite_reg_obj || !f_dlite_mem_obj)    panic("DLite is not configured");  if (nargs != 0)    return "too many arguments";  /* integer registers */  f_dlite_reg_obj(at_read, rt_PC, 0, &PC);  f_dlite_reg_obj(at_read, rt_hi, 0, &HI);  f_dlite_reg_obj(at_read, rt_lo, 0, &LO);  fprintf(stdout, "PC: 0x%08x   HI: 0x%08x   LO: %08x\n",	 PC.as_word, HI.as_word, LO.as_word);  for (i=0; i<SS_NUM_REGS; i += 2)    {      f_dlite_reg_obj(at_read, rt_gpr, i, &val);      fprintf(stdout, "R[%2d]: %12d/0x%08x", i, val.as_word, val.as_word);      f_dlite_reg_obj(at_read, rt_gpr, i+1, &val);      fprintf(stdout, " R[%2d]: %12d/0x%08x\n",	      i+1, val.as_word, val.as_word);    }  /* no error */  return NULL;}/* print floating point register contents */static char *					/* err str, NULL for no err */dlite_fpregs(int nargs, union arg_val_t args[])	/* command arguments */{  int i;  union dlite_reg_val_t val, val1, FCC;  /* floating point registers */  f_dlite_reg_obj(at_read, rt_FCC, 0, &FCC);  fprintf(stdout, "FCC: 0x%08x\n", FCC.as_word);  for (i=0; i<SS_NUM_REGS; i += 2)    {      f_dlite_reg_obj(at_read, rt_fpr, i, &val);      f_dlite_reg_obj(at_read, rt_dpr, i/2, &val1);      fprintf(stdout, "F[%2d]: %12d/0x%08x/%f (F[%2d,%2d] as double: %f)\n",	      i, val.as_word, val.as_word, val.as_float,	      i, i+1, val1.as_double);      f_dlite_reg_obj(at_read, rt_fpr, i+1, &val);      fprintf(stdout, "F[%2d]: %12d/0x%08x/%f\n",	      i+1, val.as_word, val.as_word, val.as_float);    }  /* no error */  return NULL;}/* print all register contents */static char *					/* err str, NULL for no err */dlite_regs(int nargs, union arg_val_t args[])	/* command arguments */{  char *err_str;  if ((err_str = dlite_iregs(nargs, args)) != NULL)    return err_str;  dlite_pause();  if ((err_str = dlite_fpregs(nargs, args)) != NULL)    return err_str;  /* no error */  return NULL;}/* print machine specific state (simulator dependent) */static char *					/* err str, NULL for no err */dlite_mstate(int nargs, union arg_val_t args[])	/* command arguments */{  char *errstr;  if (nargs != 0 && nargs != 1)    return "too many arguments";  if (f_dlite_mstate_obj)    {      if (nargs == 0)	{	  errstr = f_dlite_mstate_obj(stdout, NULL);	  if (errstr)	    return errstr;	}      else	{	  errstr = f_dlite_mstate_obj(stdout, args[0].as_str);	  if (errstr)	    return errstr;	}    }  /* no error */  return NULL;}/* display the value at memory location <addr> using format <modifiers> */char *						/* err str, NULL for no err */dlite_display(int nargs, union arg_val_t args[])/* command arguments */{  int modifiers, size;  SS_ADDR_TYPE addr;  unsigned char buf[512];  struct eval_value_t val;  char *errstr;  if (nargs != 1 && nargs != 2)    return "wrong number of arguments";  if (nargs == 1)    {      /* no modifiers */      modifiers = 0;      /* check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset address */      addr = args[0].as_value.value.as_uint;    }  else if (nargs == 2)    {      modifiers = args[0].as_modifier;      /* check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset address */      addr = args[0].as_value.value.as_uint;    }  /* determine operand size */  if (modifiers & (MOD_BYTE|MOD_CHAR))    size = 1;  else if (modifiers & MOD_HALF)    size = 2;  else if (modifiers & MOD_DOUBLE)    size = 8;  else /* no modifiers, or MOD_WORD|MOD_FLOAT */    size = 4;  /* read memory */  errstr = f_dlite_mem_obj(at_read, addr, (char *)buf, size);  if (errstr)    return errstr;  /* marshall a value */  if (modifiers & (MOD_BYTE|MOD_CHAR))    {      /* size == 1 */      val.value.as_int = (int)*(unsigned char *)buf;    }  else if (modifiers & MOD_HALF)    {      /* size == 2 */      val.value.as_int = (int)*(unsigned short *)buf;    }  else if (modifiers & MOD_DOUBLE)    {      /* size == 8 */      val.value.as_double = *(double *)buf;    }  else /* no modifiers, or MOD_WORD|MOD_FLOAT */    {      /* size == 4 */      val.value.as_uint = *(unsigned int *)buf;    }  /* print the value */  return print_val(modifiers, val);}/* `dump' command print format */#define BYTES_PER_LINE			16 /* must be a power of two */#define LINES_PER_SCREEN		4/* dump the contents of memory to screen */static char *					/* err str, NULL for no err */dlite_dump(int nargs, union arg_val_t args[])	/* command arguments */{  int i, j;  int count = LINES_PER_SCREEN * BYTES_PER_LINE, i_count, fmt_count, fmt_lines;  SS_ADDR_TYPE fmt_addr, i_addr;  static SS_ADDR_TYPE addr = 0;  unsigned char byte;  char buf[512];  char *errstr;  if (nargs < 0 || nargs > 2)    return "too many arguments";  if (nargs == 1)    {      /* check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset PC */      addr = args[0].as_value.value.as_uint;    }  else if (nargs == 2)    {      /* check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset addr */      addr = args[0].as_value.value.as_uint;      /* check count */      if (args[1].as_value.type != et_int && args[1].as_value.type != et_uint)	return "count argument must be an integral type";      if (args[1].as_value.value.as_uint > 1024)	return "bad count argument";      /* reset count */      count = args[1].as_value.value.as_uint;    }  /* else, nargs == 0, use addr, count */  /* normalize start address and count */  fmt_addr = addr & ~(BYTES_PER_LINE - 1);  fmt_count = (count + (BYTES_PER_LINE - 1)) & ~(BYTES_PER_LINE - 1);  fmt_lines = fmt_count / BYTES_PER_LINE;  if (fmt_lines < 1)    panic("no output lines");  /* print dump */  if (fmt_lines == 1)    {      /* unformatted dump */      i_addr = fmt_addr;      fprintf(stdout, "0x%08x: ", i_addr);      for (i=0; i < count; i++)	{	  errstr = f_dlite_mem_obj(at_read, i_addr, (char *)&byte, 1);	  if (errstr)	    return errstr;	  fprintf(stdout, "%02x ", byte);	  if (isprint(byte))	    buf[i] = byte;	  else	    buf[i] = '.';	  i_addr++;	  addr++;	}      buf[i] = '\0';      /* character view */      fprintf(stdout, "[%s]\n", buf);    }  else /* lines > 1 */    {      i_count = 0;      i_addr = fmt_addr;      for (i=0; i < fmt_lines; i++)	{	  fprintf(stdout, "0x%08x: ", i_addr);	  /* byte view */	  for (j=0; j < BYTES_PER_LINE; j++)	    {	      if (i_addr >= addr && i_count <= count)		{		  errstr = f_dlite_mem_obj(at_read, i_addr, (char *)&byte, 1);		  if (errstr)		    return errstr;		  fprintf(stdout, "%02x ", byte);		  if (isprint(byte))		    buf[j] = byte;		  else		    buf[j] = '.';		  i_count++;		  addr++;		}	      else		{		  fprintf(stdout, "   ");		  buf[j] = ' ';		}	      i_addr++;	    }	  buf[j] = '\0';	  /* character view */	  fprintf(stdout, "[%s]\n", buf);	}    }  /* no error */  return NULL;}/* disassembler print format */#define INSTS_PER_SCREEN		16/* disassemble instructions at specified address */static char *					/* err str, NULL for no err */dlite_dis(int nargs, union arg_val_t args[])	/* command arguments */{  int i;  int count = INSTS_PER_SCREEN;  static SS_ADDR_TYPE addr = 0;  SS_INST_TYPE inst;  char *errstr;  if (nargs < 0 || nargs > 2)    return "too many arguments";  if (nargs == 1)    {      /* check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset PC */      addr = args[0].as_value.value.as_uint;    }  else if (nargs == 2)    {      /* check address */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "address argument must be an integral type";      /* reset addr */      addr = args[0].as_value.value.as_uint;      /* check count */      if (args[0].as_value.type != et_int && args[0].as_value.type != et_uint)	return "count argument must be an integral type";      if (count < 0 || count > 1024)	return "bad count argument";      /* reset count */      count = args[1].as_value.value.as_uint;    }  /* else, nargs == 0, use addr, count */  if ((addr % SS_INST_SIZE) != 0)    return "instruction addresses are a multiple of eight";  /* disassemble COUNT insts at ADDR */  for (i=0; i<count; i++)    {      /* read and disassemble instruction */      fprintf(stdout, "    0x%08x:   ", addr);      errstr = f_dlite_mem_obj(at_read, addr, (char *)&inst, sizeof(inst));      if (errstr)	return errstr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -