"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  

sim-safe.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "regs.h"
#include "memory.h"
#include "loader.h"
#include "syscall.h"
#include "dlite.h"
#include "options.h"
#include "stats.h"
#include "sim.h"
#include "machine.def"

Include dependency graph for sim-safe.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define CONNECT OP   
 

#define CPC   (regs.regs_PC)
 

Definition at line 242 of file sim-safe.c.

#define DECLARE_FAULT FAULT       { fault = (FAULT); break; }
 

#define DEFINST OP,
MSK,
NAME,
OPFORM,
RES,
FLAGS,
O1,
O2,
I1,
I2,
I3   
 

Value:

case OP:                                                        \
          SYMCAT(OP,_IMPL);                                             \
          break;

#define DEFLINK OP,
MSK,
NAME,
MASK,
SHIFT   
 

Value:

case OP:                                                        \
          panic("attempted to execute a linking opcode");

#define FPCR   (regs.regs_C.fpcr)
 

Definition at line 275 of file sim-safe.c.

#define FPR N       (regs.regs_F.d[(N)])
 

Definition at line 271 of file sim-safe.c.

#define FPR_Q N       (regs.regs_F.q[N])
 

Definition at line 269 of file sim-safe.c.

#define GPR N       (regs.regs_R[N])
 

Definition at line 245 of file sim-safe.c.

#define READ_BYTE SRC,
FAULT       ((FAULT) = md_fault_none, MEM_READ_BYTE(mem, addr = (SRC)))
 

Definition at line 285 of file sim-safe.c.

#define READ_HALF SRC,
FAULT       ((FAULT) = md_fault_none, MEM_READ_HALF(mem, addr = (SRC)))
 

Definition at line 287 of file sim-safe.c.

#define READ_WORD SRC,
FAULT       ((FAULT) = md_fault_none, MEM_READ_WORD(mem, addr = (SRC)))
 

Definition at line 289 of file sim-safe.c.

#define SET_FPCR EXPR       (regs.regs_C.fpcr = (EXPR))
 

Definition at line 276 of file sim-safe.c.

#define SET_FPR N,
EXPR       (regs.regs_F.d[(N)] = (EXPR))
 

Definition at line 272 of file sim-safe.c.

#define SET_FPR_Q N,
EXPR       (regs.regs_F.q[N] = (EXPR))
 

Definition at line 270 of file sim-safe.c.

#define SET_GPR N,
EXPR       (regs.regs_R[N] = (EXPR))
 

Definition at line 246 of file sim-safe.c.

#define SET_NPC EXPR       (regs.regs_NPC = (EXPR))
 

Definition at line 239 of file sim-safe.c.

#define SET_UNIQ EXPR       (regs.regs_C.uniq = (EXPR))
 

Definition at line 278 of file sim-safe.c.

#define SYSCALL INST       sys_syscall(&regs, mem_access, mem, INST, TRUE)
 

Definition at line 308 of file sim-safe.c.

#define UNIQ   (regs.regs_C.uniq)
 

Definition at line 277 of file sim-safe.c.

#define WRITE_BYTE SRC,
DST,
FAULT       ((FAULT) = md_fault_none, MEM_WRITE_BYTE(mem, addr = (DST), (SRC)))
 

Definition at line 296 of file sim-safe.c.

#define WRITE_HALF SRC,
DST,
FAULT       ((FAULT) = md_fault_none, MEM_WRITE_HALF(mem, addr = (DST), (SRC)))
 

Definition at line 298 of file sim-safe.c.

#define WRITE_WORD SRC,
DST,
FAULT       ((FAULT) = md_fault_none, MEM_WRITE_WORD(mem, addr = (DST), (SRC)))
 

Definition at line 300 of file sim-safe.c.


Function Documentation

void sim_aux_config FILE *    stream
 

Definition at line 210 of file sim-safe.c.

Referenced by main().

00211 {
00212   /* nothing currently */
00213 }

void sim_aux_stats FILE *    stream
 

Definition at line 217 of file sim-safe.c.

Referenced by dlite_stats(), and sim_print_stats().

00218 {
00219   /* nada */
00220 }

void sim_check_options struct opt_odb_t   odb,
int    argc,
char **    argv
 

Definition at line 156 of file sim-safe.c.

References bimod_config, bimod_nelt, BPred2bit, BPred2Level, bpred_create(), BPredComb, BPredNotTaken, BPredTaken, btb_config, btb_nelt, comb_config, comb_nelt, fatal(), mystricmp(), pred_type, ras_size, twolev_config, and twolev_nelt.

Referenced by main().

00157 {
00158   /* nada */
00159 }

void sim_init void   
 

Definition at line 183 of file sim-safe.c.

References mem_create(), mem_init(), regs_init(), and sim_num_refs.

00184 {
00185   sim_num_refs = 0;
00186 
00187   /* allocate and initialize register file */
00188   regs_init(&regs);
00189 
00190   /* allocate and initialize memory space */
00191   mem = mem_create("mem");
00192   mem_init(mem);
00193 }

void sim_load_prog char *    fname,
int    argc,
char **    argv,
char **    envp
 

Definition at line 197 of file sim-safe.c.

References bpred_mstate_obj(), dlite_init(), ld_load_prog(), and TRUE.

Referenced by main().

00200 {
00201   /* load program text and data, set up environment, memory, and regs */
00202   ld_load_prog(fname, argc, argv, envp, &regs, mem, TRUE);
00203 
00204   /* initialize the DLite debugger */
00205   dlite_init(md_reg_obj, dlite_mem_obj, dlite_mstate_obj);
00206 }

void sim_main void   
 

Definition at line 312 of file sim-safe.c.

References ACCESS_READ, ACCESS_WRITE, bpred_lookup(), bpred_update(), md_fpr_t::d, dlite_check_break, dlite_main(), FALSE, fatal(), max_insts, MD_FETCH_INST, MD_IS_RETURN, MD_OP_FLAGS, md_print_insn(), MD_SET_OPCODE, md_xor_regs(), myfprintf(), panic(), regs_t::regs_F, regs_t::regs_NPC, regs_t::regs_PC, regs_t::regs_R, sim_num_branches, sim_num_refs, and TRUE.

00313 {
00314   md_inst_t inst;
00315   register md_addr_t addr;
00316   enum md_opcode op;
00317   register int is_write;
00318   enum md_fault_type fault;
00319 
00320   fprintf(stderr, "sim: ** starting functional simulation **\n");
00321 
00322   /* set up initial default next PC */
00323   regs.regs_NPC = regs.regs_PC + sizeof(md_inst_t);
00324 
00325   /* check for DLite debugger entry condition */
00326   if (dlite_check_break(regs.regs_PC, /* !access */0, /* addr */0, 0, 0))
00327     dlite_main(regs.regs_PC - sizeof(md_inst_t),
00328                regs.regs_PC, sim_num_insn, &regs, mem);
00329 
00330   while (TRUE)
00331     {
00332       /* maintain $r0 semantics */
00333       regs.regs_R[MD_REG_ZERO] = 0;
00334 #ifdef TARGET_ALPHA
00335       regs.regs_F.d[MD_REG_ZERO] = 0.0;
00336 #endif /* TARGET_ALPHA */
00337 
00338       /* get the next instruction to execute */
00339       MD_FETCH_INST(inst, mem, regs.regs_PC);
00340 
00341       /* keep an instruction count */
00342       sim_num_insn++;
00343 
00344       /* set default reference address and access mode */
00345       addr = 0; is_write = FALSE;
00346 
00347       /* set default fault - none */
00348       fault = md_fault_none;
00349 
00350       /* decode the instruction */
00351       MD_SET_OPCODE(op, inst);
00352 
00353       /* execute the instruction */
00354       switch (op)
00355         {
00356 #define DEFINST(OP,MSK,NAME,OPFORM,RES,FLAGS,O1,O2,I1,I2,I3)            \
00357         case OP:                                                        \
00358           SYMCAT(OP,_IMPL);                                             \
00359           break;
00360 #define DEFLINK(OP,MSK,NAME,MASK,SHIFT)                                 \
00361         case OP:                                                        \
00362           panic("attempted to execute a linking opcode");
00363 #define CONNECT(OP)
00364 #define DECLARE_FAULT(FAULT)                                            \
00365           { fault = (FAULT); break; }
00366 #include "machine.def"
00367         default:
00368           panic("attempted to execute a bogus opcode");
00369       }
00370 
00371       if (fault != md_fault_none)
00372         fatal("fault (%d) detected @ 0x%08p", fault, regs.regs_PC);
00373 
00374       if (verbose)
00375         {
00376           myfprintf(stderr, "%10n [xor: 0x%08x] @ 0x%08p: ",
00377                     sim_num_insn, md_xor_regs(&regs), regs.regs_PC);
00378           md_print_insn(inst, regs.regs_PC, stderr);
00379           if (MD_OP_FLAGS(op) & F_MEM)
00380             myfprintf(stderr, "  mem: 0x%08p", addr);
00381           fprintf(stderr, "\n");
00382           /* fflush(stderr); */
00383         }
00384 
00385       if (MD_OP_FLAGS(op) & F_MEM)
00386         {
00387           sim_num_refs++;
00388           if (MD_OP_FLAGS(op) & F_STORE)
00389             is_write = TRUE;
00390         }
00391 
00392       /* check for DLite debugger entry condition */
00393       if (dlite_check_break(regs.regs_NPC,
00394                             is_write ? ACCESS_WRITE : ACCESS_READ,
00395                             addr, sim_num_insn, sim_num_insn))
00396         dlite_main(regs.regs_PC, regs.regs_NPC, sim_num_insn, &regs, mem);
00397 
00398       /* go to the next instruction */
00399       regs.regs_PC = regs.regs_NPC;
00400       regs.regs_NPC += sizeof(md_inst_t);
00401 
00402       /* finish early? */
00403       if (max_insts && sim_num_insn >= max_insts)
00404         return;
00405     }
00406 }

void sim_reg_options struct opt_odb_t   odb
 

Definition at line 137 of file sim-safe.c.

References bimod_config, bimod_nelt, btb_config, btb_nelt, comb_config, comb_nelt, FALSE, max_insts, opt_reg_header(), opt_reg_int(), opt_reg_int_list(), opt_reg_note(), opt_reg_string(), opt_reg_uint(), pred_type, ras_size, TRUE, twolev_config, and twolev_nelt.

Referenced by main().

00138 {
00139   opt_reg_header(odb, 
00140 "sim-safe: This simulator implements a functional simulator.  This\n"
00141 "functional simulator is the simplest, most user-friendly simulator in the\n"
00142 "simplescalar tool set.  Unlike sim-fast, this functional simulator checks\n"
00143 "for all instruction errors, and the implementation is crafted for clarity\n"
00144 "rather than speed.\n"
00145                  );
00146 
00147   /* instruction limit */
00148   opt_reg_uint(odb, "-max:inst", "maximum number of inst's to execute",
00149                &max_insts, /* default */0,
00150                /* print */TRUE, /* format */NULL);
00151 
00152 }

void sim_reg_stats struct stat_sdb_t   sdb
 

Definition at line 163 of file sim-safe.c.

References bpred_reg_stats(), ld_reg_stats(), mem_reg_stats(), sim_num_branches, sim_num_refs, stat_reg_counter, stat_reg_formula(), and stat_reg_int().

Referenced by main().

00164 {
00165   stat_reg_counter(sdb, "sim_num_insn",
00166                    "total number of instructions executed",
00167                    &sim_num_insn, sim_num_insn, NULL);
00168   stat_reg_counter(sdb, "sim_num_refs",
00169                    "total number of loads and stores executed",
00170                    &sim_num_refs, 0, NULL);
00171   stat_reg_int(sdb, "sim_elapsed_time",
00172                "total simulation time in seconds",
00173                &sim_elapsed_time, 0, NULL);
00174   stat_reg_formula(sdb, "sim_inst_rate",
00175                    "simulation speed (in insts/sec)",
00176                    "sim_num_insn / sim_elapsed_time", NULL);
00177   ld_reg_stats(sdb);
00178   mem_reg_stats(mem, sdb);
00179 }

void sim_uninit void   
 

Definition at line 224 of file sim-safe.c.

00225 {
00226   /* nada */
00227 }


Variable Documentation

unsigned int max_insts [static]
 

Definition at line 133 of file sim-safe.c.

Referenced by sim_main(), and sim_reg_options().

struct mem_t* mem = NULL [static]
 

Definition at line 127 of file sim-safe.c.

struct regs_t regs [static]
 

Definition at line 124 of file sim-safe.c.

counter_t sim_num_refs = 0 [static]
 

Definition at line 130 of file sim-safe.c.

Referenced by sim_init(), sim_main(), and sim_reg_stats().



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