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

📄 sim-profile.c

📁 RISC处理器仿真分析程序。可以用于研究通用RISC处理器的指令和架构设计。在linux下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
    }  if (prof_taddr)    {      /* text address profile (sparse profile), NOTE: a dense print format         is used, its more difficult to read, but the profiles are *much*	 smaller, I've assumed that the profiles are read by programs, at	 least for your sake I hope this is the case!! */      taddr_prof = stat_reg_sdist(sdb, "sim_text_addr_prof",				  "text address profile",				  /* initial value */0,				  /* print format */(PF_COUNT|PF_PDF),				  /* format */"0x%lx %lu %.2f",				  /* print fn */NULL);    }  for (i=0; i<pcstat_nelt; i++)    {      char buf[512], buf1[512];      struct stat_stat_t *stat;      /* track the named statistical variable by text address */      /* find it... */      stat = stat_find_stat(sdb, pcstat_vars[i]);      if (!stat)	fatal("cannot locate any statistic named `%s'", pcstat_vars[i]);      /* stat must be an integral type */      if (stat->sc != sc_int && stat->sc != sc_uint && stat->sc != sc_counter)	fatal("`-pcstat' statistical variable `%s' is not an integral type",	      stat->name);      /* register this stat */      pcstat_stats[i] = stat;      pcstat_lastvals[i] = STATVAL(stat);      /* declare the sparce text distribution */      sprintf(buf, "%s_by_pc", stat->name);      sprintf(buf1, "%s (by text address)", stat->desc);      pcstat_sdists[i] = stat_reg_sdist(sdb, buf, buf1,					/* initial value */0,					/* print format */(PF_COUNT|PF_PDF),					/* format */"0x%lx %lu %.2f",					/* print fn */NULL);    }}/* local machine state accessor */static char *					/* err str, NULL for no err */profile_mstate_obj(FILE *stream,		/* output stream */		   char *cmd)			/* optional command string */{  /* just dump intermediate stats */  sim_print_stats(stream);  /* no error */  return NULL;}/* initialize the simulator */voidsim_init(void){  SS_INST_TYPE inst;  sim_num_insn = 0;  sim_num_refs = 0;  regs_PC = ld_prog_entry;  /* decode all instructions */  {    SS_ADDR_TYPE addr;    if (OP_MAX > 255)      fatal("cannot perform fast decoding, too many opcodes");    fprintf(stderr, "sim: decoding text segment...");    for (addr=ld_text_base;	 addr < (ld_text_base+ld_text_size);	 addr += SS_INST_SIZE)      {	inst = __UNCHK_MEM_ACCESS(SS_INST_TYPE, addr);	inst.a = SWAP_WORD(inst.a);	inst.b = SWAP_WORD(inst.b);	inst.a = (inst.a & ~0xff) | (unsigned int)SS_OP_ENUM(SS_OPCODE(inst));	__UNCHK_MEM_ACCESS(SS_INST_TYPE, addr) = inst;      }    fprintf(stderr, "done.\n");  }  /* initialize the DLite debugger */  dlite_init(dlite_reg_obj, dlite_mem_obj, profile_mstate_obj);}/* print simulator-specific configuration information */voidsim_aux_config(FILE *stream)		/* output stream */{  /* nothing currently */}/* dump simulator-specific auxiliary simulator statistics */voidsim_aux_stats(FILE *stream)		/* output stream */{}/* un-initialize simulator-specific state */voidsim_uninit(void){  /* nada */}/* * configure the execution engine *//* * precise architected register accessors *//* next program counter */#define SET_NPC(EXPR)		(next_PC = (EXPR))/* current program counter */#define CPC			(regs_PC)/* general purpose registers */#define GPR(N)			(regs_R[N])#define SET_GPR(N,EXPR)		(regs_R[N] = (EXPR))/* floating point registers, L->word, F->single-prec, D->double-prec */#define FPR_L(N)		(regs_F.l[(N)])#define SET_FPR_L(N,EXPR)	(regs_F.l[(N)] = (EXPR))#define FPR_F(N)		(regs_F.f[(N)])#define SET_FPR_F(N,EXPR)	(regs_F.f[(N)] = (EXPR))#define FPR_D(N)		(regs_F.d[(N) >> 1])#define SET_FPR_D(N,EXPR)	(regs_F.d[(N) >> 1] = (EXPR))/* miscellaneous register accessors */#define SET_HI(EXPR)		(regs_HI = (EXPR))#define HI			(regs_HI)#define SET_LO(EXPR)		(regs_LO = (EXPR))#define LO			(regs_LO)#define FCC			(regs_FCC)#define SET_FCC(EXPR)		(regs_FCC = (EXPR))/* precise architected memory state help functions */#define __READ_WORD(DST_T, SRC_T, SRC)					\  ((unsigned int)((DST_T)(SRC_T)MEM_READ_WORD(addr = (SRC))))#define __READ_HALF(DST_T, SRC_T, SRC)					\  ((unsigned int)((DST_T)(SRC_T)MEM_READ_HALF(addr = (SRC))))#define __READ_BYTE(DST_T, SRC_T, SRC)					\  ((unsigned int)((DST_T)(SRC_T)MEM_READ_BYTE(addr = (SRC))))/* precise architected memory state accessor macros */#define READ_WORD(SRC)							\  __READ_WORD(unsigned int, unsigned int, (SRC))#define READ_UNSIGNED_HALF(SRC)						\  __READ_HALF(unsigned int, unsigned short, (SRC))#define READ_SIGNED_HALF(SRC)						\  __READ_HALF(signed int, signed short, (SRC))#define READ_UNSIGNED_BYTE(SRC)						\  __READ_BYTE(unsigned int, unsigned char, (SRC))#define READ_SIGNED_BYTE(SRC)						\  __READ_BYTE(signed int, signed char, (SRC))#define WRITE_WORD(SRC, DST)						\  (MEM_WRITE_WORD(addr = (DST), (unsigned int)(SRC)))#define WRITE_HALF(SRC, DST)						\  (MEM_WRITE_HALF(addr = (DST), (unsigned short)(unsigned int)(SRC)))#define WRITE_BYTE(SRC, DST)						\  (MEM_WRITE_BYTE(addr = (DST), (unsigned char)(unsigned int)(SRC)))/* system call handler macro */#define SYSCALL(INST)		(ss_syscall(mem_access, INST))/* instantiate the helper functions in the '.def' file */#define DEFINST(OP,MSK,NAME,OPFORM,RES,CLASS,O1,O2,I1,I2,I3,EXPR)#define DEFLINK(OP,MSK,NAME,MASK,SHIFT)#define CONNECT(OP)#define IMPL#include "ss.def"#undef DEFINST#undef DEFLINK#undef CONNECT#undef IMPL/* destination of last LUI, used for decoding addressing modes */static unsigned int imm_reg = 0;/* start simulation, program loaded, processor precise state initialized */voidsim_main(void){  int i;  SS_INST_TYPE inst;  register SS_ADDR_TYPE next_PC;  register SS_ADDR_TYPE addr;  register int is_write;  enum ss_opcode op;  unsigned int flags;  fprintf(stderr, "sim: ** starting functional simulation **\n");  /* set up initial default next PC */  next_PC = regs_PC + SS_INST_SIZE;  /* check for DLite debugger entry condition */  if (dlite_check_break(regs_PC, /* no access */0, /* addr */0, 0, 0))    dlite_main(regs_PC - SS_INST_SIZE, regs_PC, sim_num_insn);  while (TRUE)    {      /* maintain $r0 semantics */      regs_R[0] = 0;      /* keep an instruction count */      sim_num_insn++;      /* get the next instruction to execute */      inst = __UNCHK_MEM_ACCESS(SS_INST_TYPE, regs_PC);      /* set default reference address and access mode */      addr = 0; is_write = FALSE;      /* decode the instruction */      op = SS_OPCODE(inst);      switch (op)	{#define DEFINST(OP,MSK,NAME,OPFORM,RES,FLAGS,O1,O2,I1,I2,I3,EXPR)	\	case OP:                                                        \          EXPR;                                                         \          break;#define DEFLINK(OP,MSK,NAME,MASK,SHIFT)                                 \        case OP:                                                        \          panic("attempted to execute a linking opcode");#define CONNECT(OP)#include "ss.def"#undef DEFINST#undef DEFLINK#undef CONNECT	default:	  panic("bogus opcode");      }      if (SS_OP_FLAGS(op) & F_MEM)	{	  sim_num_refs++;	  if (SS_OP_FLAGS(op) & F_STORE)	    is_write = TRUE;	}      /*       * profile this instruction       */      flags = SS_OP_FLAGS(op);      if (prof_ic)	{	  enum inst_class_t ic;	  /* compute instruction class */	  if (flags & F_LOAD)	    ic = ic_load;	  else if (flags & F_STORE)	    ic = ic_store;	  else if (flags & F_UNCOND)	    ic = ic_uncond;	  else if (flags & F_COND)	    ic = ic_cond;      	  else if (flags & F_ICOMP)	    ic = ic_icomp;	  else if (flags & F_FCOMP)	    ic = ic_fcomp;	  else if (flags & F_TRAP)	    ic = ic_trap;	  else	    panic("instruction has no class");	  /* update instruction class profile */	  stat_add_sample(ic_prof, (int)ic);	}      if (prof_inst)	{	  /* update instruction profile */	  stat_add_sample(inst_prof, (int)op - /* skip NA */1);	}      if (prof_bc)	{	  enum branch_class_t bc;	  /* compute instruction class */	  if (flags & F_CTRL)	    {	      if ((flags & (F_CALL|F_DIRJMP)) == (F_CALL|F_DIRJMP))		bc = bc_call_dir;	      else if ((flags & (F_CALL|F_INDIRJMP)) == (F_CALL|F_INDIRJMP))		bc = bc_call_indir;	      else if ((flags & (F_UNCOND|F_DIRJMP)) == (F_UNCOND|F_DIRJMP))		bc = bc_uncond_dir;	      else if ((flags & (F_UNCOND|F_INDIRJMP))== (F_UNCOND|F_INDIRJMP))		bc = bc_uncond_indir;	      else if ((flags & (F_COND|F_DIRJMP)) == (F_COND|F_DIRJMP))		bc = bc_cond_dir;	      else if ((flags & (F_COND|F_INDIRJMP)) == (F_COND|F_INDIRJMP))		bc = bc_cond_indir;	      else		panic("branch has no class");	      /* update instruction class profile */	      stat_add_sample(bc_prof, (int)bc);	    }	}      if (prof_am)	{	  enum addr_mode_t am;	  /* track LUI's for decoding immediate addressing modes */	  if (op == LUI)	    {	      /* remember the immediate destination */	      imm_reg = (RT);	    }	  if (flags & F_MEM)	    {	      /* decode the addressing mode */	      if (flags & F_DISP)		{		  if ((BS) == imm_reg)		    am = am_imm;		  else if ((BS) == Rgp)		    am = am_gp;		  else if ((BS) == Rsp)		    am = am_sp;		  else if ((BS) == Rfp && bind_to_seg(addr) == seg_stack)		    am = am_fp;		  else		    am = am_disp;		}	      else if (flags & F_RR)		am = am_rr;	      else		panic("cannot decode addressing mode");	      /* update the addressing mode profile */	      stat_add_sample(am_prof, (int)am);	      /* blow away IMM_REG after next load/store inst is probed */	      imm_reg = 0;	    }	}      if (prof_seg)	{	  if (flags & F_MEM)	    {	      /* update instruction profile */	      stat_add_sample(seg_prof, (int)bind_to_seg(addr));	    }	}      if (prof_tsyms)	{	  int tindex;	  /* attempt to bind inst address to a text segment symbol */	  sym_bind_addr(regs_PC, &tindex, /* !exact */FALSE, sdb_text);	  if (tindex >= 0)	    {	      if (tindex > sym_ntextsyms)		panic("bogus text symbol index");	      stat_add_sample(tsym_prof, tindex);	    }	  /* else, could not bind to a symbol */	}      if (prof_dsyms)	{	  int dindex;	  if (flags & F_MEM)	    {	      /* attempt to bind inst address to a text segment symbol */	      sym_bind_addr(addr, &dindex, /* !exact */FALSE, sdb_data);	      if (dindex >= 0)		{		  if (dindex > sym_ndatasyms)		    panic("bogus data symbol index");		  stat_add_sample(dsym_prof, dindex);		}	      /* else, could not bind to a symbol */	    }	}      if (prof_taddr)	{	  /* add regs_PC exec event to text address profile */	  stat_add_sample(taddr_prof, regs_PC);	}      /* update any stats tracked by PC */      for (i=0; i<pcstat_nelt; i++)	{	  SS_COUNTER_TYPE newval;	  int delta;	  /* check if any tracked stats changed */	  newval = STATVAL(pcstat_stats[i]);	  delta = newval - pcstat_lastvals[i];	  if (delta != 0)	    {	      stat_add_samples(pcstat_sdists[i], regs_PC, delta);	      pcstat_lastvals[i] = newval;	    }	}      /* check for DLite debugger entry condition */      if (dlite_check_break(next_PC,			    is_write ? ACCESS_WRITE : ACCESS_READ,			    addr, sim_num_insn, sim_num_insn))	dlite_main(regs_PC, next_PC, sim_num_insn);      /* go to the next instruction */      regs_PC = next_PC;      next_PC += SS_INST_SIZE;    }}

⌨️ 快捷键说明

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