int simRunCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { int step_limit = 1; exc_t status; cc_t cc; sim_interp = interp; if (argc > 2) { interp->result = "At most one argument allowed"; return TCL_ERROR; } if (argc >= 2 && (sscanf(argv[1], "%d", &step_limit) != 1 || step_limit < 0)) { sprintf(tcl_msg, "Cannot run for '%s' cycles!", argv[1]); interp->result = tcl_msg; return TCL_ERROR; } sim_run(step_limit, &status, &cc); interp->result = exc_name(status); return TCL_OK; }
/* * run_tty_sim - Run the simulator in TTY mode */ static void run_tty_sim() { int icount = 0; exc_t status = EXC_NONE; cc_t result_cc = 0; int byte_cnt = 0; mem_t mem0, reg0; state_ptr isa_state = NULL; /* In TTY mode, the default object file comes from stdin */ if (!object_file) { object_file = stdin; } /* Initializations */ if (verbosity >= 2) sim_set_dumpfile(stdout); sim_init(); /* Emit simulator name */ printf("%s\n", simname); byte_cnt = load_mem(mem, object_file, 1); if (byte_cnt == 0) { fprintf(stderr, "No lines of code found\n"); exit(1); } else if (verbosity >= 2) { printf("%d bytes of code read\n", byte_cnt); } fclose(object_file); if (do_check) { isa_state = new_state(0); free_mem(isa_state->r); free_mem(isa_state->m); isa_state->m = copy_mem(mem); isa_state->r = copy_mem(reg); isa_state->cc = cc; } mem0 = copy_mem(mem); reg0 = copy_mem(reg); icount = sim_run(instr_limit, &status, &result_cc); if (verbosity > 0) { printf("%d instructions executed\n", icount); printf("Exception status = %s\n", exc_name(status)); printf("Condition Codes: %s\n", cc_name(result_cc)); printf("Changed Register State:\n"); diff_reg(reg0, reg, stdout); printf("Changed Memory State:\n"); diff_mem(mem0, mem, stdout); } if (do_check) { exc_t e = EXC_NONE; int step; bool_t match = TRUE; for (step = 0; step < instr_limit && e == EXC_NONE; step++) { e = step_state(isa_state, stdout); } if (diff_reg(isa_state->r, reg, NULL)) { match = FALSE; if (verbosity > 0) { printf("ISA Register != Pipeline Register File\n"); diff_reg(isa_state->r, reg, stdout); } } if (diff_mem(isa_state->m, mem, NULL)) { match = FALSE; if (verbosity > 0) { printf("ISA Memory != Pipeline Memory\n"); diff_mem(isa_state->m, mem, stdout); } } if (isa_state->cc != result_cc) { match = FALSE; if (verbosity > 0) { printf("ISA Cond. Codes (%s) != Pipeline Cond. Codes (%s)\n", cc_name(isa_state->cc), cc_name(result_cc)); } } if (match) { printf("ISA Check Succeeds\n"); } else { printf("ISA Check Fails\n"); } } }
int main(int argc, char **argv) { extern int alloc_core(void); extern void free_core(void); char *outfname = 0, *netfile; FILE *infile, *outfile; int status; static char const str_opts[] = "rf:dpvIsN:S:P:L:M:l:Vhu"; static const struct option long_opts[] = { {"remote", 0, 0, 'r'}, {"file", 1, 0, 'f'}, {"Nodes", 1, 0, 'N'}, {"Switches", 1, 0, 'S'}, {"Ports", 1, 0, 'P'}, {"Linearcap", 1, 0, 'L'}, {"Mcastcap", 1, 0, 'M'}, {"listen", 1, 0, 'l'}, {"Ignoredups", 0, 0, 'I'}, {"start", 0, 0, 's'}, {"debug", 0, 0, 'd'}, {"parsedebug", 0, 0, 'p'}, {"verbose", 0, 0, 'v'}, {"Version", 0, 0, 'V'}, {"help", 0, 0, 'h'}, {"usage", 0, 0, 'u'}, {} }; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if (ch == -1) break; switch (ch) { case 'r': remote_mode = 1; break; case 'f': outfname = optarg; break; case 'd': ibdebug++; break; case 'p': parsedebug++; break; case 'v': simverb++; break; case 's': netstarted = 1; break; case 'I': ignoreduplicate = 1; break; case 'N': maxnetnodes = strtoul(optarg, 0, 0); break; case 'S': maxnetswitches = strtoul(optarg, 0, 0); break; case 'P': maxnetports = strtoul(optarg, 0, 0); break; case 'L': maxlinearcap = strtoul(optarg, 0, 0); break; case 'M': maxmcastcap = strtoul(optarg, 0, 0); break; case 'l': listen_to_port = strtoul(optarg, 0, 0); break; case 'V': default: usage(argv[0]); } } maxnetaliases = maxnetports; infile = stdin; outfile = stdout; if (outfname && (outfile = fopen(outfname, "w")) == 0) IBPANIC("can't open out file %s for write", outfname); if (optind >= argc) usage(argv[0]); netfile = argv[optind]; if (alloc_core() < 0) IBPANIC("not enough memory for core structure"); DEBUG("initializing net \"%s\"", netfile); status = sim_init_net(netfile, outfile); if (status < 0) IBPANIC("sim_init failed, status %d", status); sim_init_console(outfile); sim_run(fileno(infile)); free_core(); exit(0); }