/**************************************************************************
* psim.c - Pipelined Y86-64 simulator
*
* Copyright (c) 2010, 2015. Bryant and D. O'Hallaron, All rights reserved.
* May not be used, modified, or copied without permission.
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include "isa.h"
#include "pipeline.h"
#include "stages.h"
#include "sim.h"
#define MAXBUF 1024
#define DEFAULTNAME "Y86-64 Simulator: "
#ifdef HAS_GUI
#include <tk.h>
#endif /* HAS_GUI */
#define MAXARGS 128
#define MAXBUF 1024
#define TKARGS 3
/***************
* Begin Globals
***************/
/* Simulator name defined and initialized by the compiled HCL file */
/* according to the -n argument supplied to hcl2c */
extern char simname[];
/* Parameters modifed by the command line */
int gui_mode = FALSE; /* Run in GUI mode instead of TTY mode? (-g) */
char *object_filename; /* The input object file name. */
FILE *object_file; /* Input file handle */
bool_t verbosity = 2; /* Verbosity level [TTY only] (-v) */
word_t instr_limit = 10000; /* Instruction limit [TTY only] (-l) */
bool_t do_check = FALSE; /* Test with ISA simulator? [TTY only] (-t) */
/*************
* End Globals
*************/
/***************************
* Begin function prototypes
***************************/
word_t sim_run_pipe(word_t max_instr, word_t max_cycle, byte_t *statusp, cc_t *ccp);
static void usage(char *name); /* Print helpful usage message */
static void run_tty_sim(); /* Run simulator in TTY mode */
#ifdef HAS_GUI
void addAppCommands(Tcl_Interp *interp); /* Add application-dependent commands */
#endif /* HAS_GUI */
/*************************
* End function prototypes
*************************/
/*******************************************************************
* Part 1: This part is the initial entry point that handles general
* initialization. It parses the command line and does any necessary
* setup to run in either TTY or GUI mode, and then starts the
* simulation.
*******************************************************************/
/*
* sim_main - main simulator routine. This function is called from the
* main() routine in the HCL file.
*/
int sim_main(int argc, char **argv)
{
int i;
int c;
char *myargv[MAXARGS];
/* Parse the command line arguments */
while ((c = getopt(argc, argv, "htgl:v:")) != -1) {
switch(c) {
case 'h':
usage(argv[0]);
break;
case 'l':
instr_limit = atoll(optarg);
break;
case 'v':
verbosity = atoi(optarg);
if (verbosity < 0 || verbosity > 2) {
printf("Invalid verbosity %d\n", verbosity);
usage(argv[0]);
}
break;
case 't':
do_check = TRUE;
break;
case 'g':
gui_mode = TRUE;
break;
default:
printf("Invalid option '%c'\n", c);
usage(argv[0]);
break;
}
}
/* Do we have too many arguments? */
if (optind < argc - 1) {
printf("Too many command line arguments:");
for (i = optind; i < argc; i++)
printf(" %s", argv[i]);
printf("\n");
usage(argv[0]);
}
/* The single unflagged argument should be the object file name */
object_filename = NULL;
object_file = NULL;
if (optind < argc) {
object_filename = argv[optind];
object_file = fopen(object_filename, "r");
if (!object_file) {
fprintf(stderr, "Couldn't open object file %s\n", object_filename);
exit(1);
}
}
/* Run the simulator in GUI mode (-g flag) */
if (gui_mode) {
#ifndef HAS_GUI
printf("To run in GUI mode, you must recompile with the HAS_GUI constant defined.\n");
exit(1);
#endif /* HAS_GUI */
/* In GUI mode, we must specify the object file on command line */
if (!object_file) {
printf("Missing object file argument in GUI mode\n");
usage(argv[0]);
}
/* Build the command line for the GUI simulator */
for (i = 0; i < TKARGS; i++) {
if ((myargv[i] = malloc(MAXBUF*sizeof(char))) == NULL) {
perror("malloc error");
exit(1);
}
}
strcpy(myargv[0], argv[0]);
strcpy(myargv[1], "pipe.tcl");
strcpy(myargv[2], object_filename);
myargv[3] = NULL;
/* Start the GUI simulator */
#ifdef HAS_GUI
Tk_Main(TKARGS, myargv, Tcl_AppInit);
#endif /* HAS_GUI */
exit(0);
}
/* Otherwise, run the simulator in TTY mode (no -g flag) */
run_tty_sim();
exit(0);
}
/*
* run_tty_sim - Run the simulator in TTY mode
*/
static void run_tty_sim()
{
word_t icount = 0;
byte_t run_status = STAT_AOK;
cc_t result_cc = 0;
word_t 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;
}
if (verbosity >= 2)
sim_set_dumpfile(stdout);
sim_init();
/* Emit simulator name */
if (verbosity >= 2)
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("%lld 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_pipe(instr_limit, 5*instr_limit, &run_status, &result_cc);
if (verbosity > 0) {
printf("%lld instructions executed\n", icount);
printf("Status = %s\n", stat_name(run_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) {
byte_t e = STAT_AOK;
word_t step;
bool_t match = TRUE;
for (step = 0; step < instr_limit && e == STAT_AOK; 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");
}
}
/* Emit CPI statistics */
{
double cpi = instructions > 0 ? (double) cycles/instructions : 1.0;
printf("CPI: %lld cycles/%lld instructions = %.2f\n",
cycles, instructions, cpi);
}
}
/*
* usage - print helpful diagnostic information
*/
static void usage(char *name)
{
printf("Usage: %s [-htg] [-l m] [-v n] file.yo\n", name);
printf("file.yo arg required in GUI mode, optional in TTY mode (default stdin)\n");
printf(" -h Print this message\n");
printf(" -g Run in GUI mode instead of TTY mode (default TTY)\n");
printf(" -l m Set instruction limit to m [TTY mode only] (default %lld)\n", instr_limit);
printf(" -v n Set verbosity level to 0 <= n <= 2 [TTY mode only] (default %d)\n", verbosity);
printf(" -t Test result against ISA simulator [TTY mode only]\n");
exit(0);
}
/*********************************************************
* Part 2: This part contains the core simulator routines.
*********************************************************/
/*****************
* Part 2 Globals
*****************/
/* Performance monitoring */
/* How many cycles have been simulated? */
word_t cycles = 0;
/* How many instructions have passed through
没有合适的资源?快使用搜索试试~ 我知道了~
sim.zip_cmu ics y86 yis_deskti8_guardw66_replacect3_shot5nm
共79个文件
ys:22个
hcl:12个
pl:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 64 浏览量
2022-09-23
18:46:05
上传
评论
收藏 122KB ZIP 举报
温馨提示
CMU ICS的ORG+方向,Y86的模拟器
资源推荐
资源详情
资源评论
收起资源包目录
sim.zip (79个子文件)
sim
misc
yas.h 264B
yas.c 13KB
node.h 1KB
outgen.h 459B
isa.c 21KB
isa.h 6KB
node.c 15KB
examples.c 899B
yis.c 1KB
README 2KB
outgen.c 1KB
hcl.lex 2KB
Makefile 1KB
hcl.y 2KB
mux4.hcl 2KB
yas-grammar.lex 1KB
ptest
optest.pl 2KB
ctest.pl 2KB
htest.pl 4KB
README 2KB
tester.pm 4KB
Makefile 273B
etest.pl 1KB
jtest.pl 2KB
README 3KB
pipe
pipe-btfnt.hcl 13KB
pipe-broken.hcl 11KB
sim.h 4KB
pipeline.h 2KB
ncopy.ys 1KB
check-len.pl 526B
psim.c 43KB
gen-driver.pl 5KB
pipe-full.hcl 12KB
pipe-lf.hcl 13KB
benchmark.pl 2KB
pipe-nt.hcl 13KB
pipe-nobypass.hcl 12KB
README 6KB
pipe-1w.hcl 14KB
stages.h 3KB
pipe.tcl 19KB
Makefile 2KB
correctness.pl 3KB
ncopy.c 563B
pipe-std.hcl 12KB
Makefile 1KB
y86-code
prog1.ys 104B
prog3.ys 90B
prog4.ys 80B
cjr.ys 504B
poptest.ys 209B
prog6.ys 398B
prog5.ys 182B
asumi.ys 823B
README 760B
j-cc.ys 276B
asumr.ys 967B
prog7.ys 267B
pushtest.ys 298B
ret-hazard.ys 430B
prog8.ys 91B
Makefile 1KB
pushquestion.ys 107B
abs-asum-cmov.ys 1KB
abs-asum-jmp.ys 1KB
prog2.ys 98B
prog10.ys 315B
asum.ys 874B
prog9.ys 216B
seq
seq-std.hcl 7KB
sim.h 2KB
seq+-std.hcl 7KB
seq-full.hcl 7KB
README 3KB
seq.tcl 16KB
ssim.c 28KB
Makefile 2KB
seq+.tcl 16KB
共 79 条
- 1
资源评论
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功