?? eio.cc
字號:
/* $Id: eio.cc 1.51 05/06/04 22:33:09-04:00 binkertn@crampon.my.domain $ *//* * eio.cc - external interfaces to external I/O f\iles * * This file is a part of the SimpleScalar tool suite written by * Todd M. Austin as a part of the Multiscalar Research Project. * * The tool suite is currently maintained by Doug Burger and Todd M. Austin. * * Copyright (C) 1997, 1998 by Todd M. Austin * * This source file is distributed "as is" in the hope that it will be * useful. The tool set comes with no warranty, and no author or * distributor accepts any responsibility for the consequences of its * use. * * Everyone is granted permission to copy, modify and redistribute * this tool set under the following conditions: * * This source code is distributed for non-commercial use only. * Please contact the maintainer for restrictions applying to * commercial use. * * Permission is granted to anyone to make or distribute copies * of this source code, either as received or modified, in any * medium, provided that all copyright notices, permission and * nonwarranty notices are preserved, and that the distributor * grants the recipient permission for further redistribution as * permitted by this document. * * Permission is granted to distribute this file in compiled * or executable form under the same conditions that apply for * source code, provided that either: * * A. it is accompanied by the corresponding machine-readable * source code, * B. it is accompanied by a written offer, with no time limit, * to give anyone a machine-readable copy of the corresponding * source code in return for reimbursement of the cost of * distribution. This written offer must permit verbatim * duplication by anyone, or * C. it is distributed by someone who received only the * executable form, and is accompanied by a copy of the * written offer of source code that they received concurrently. * * In other words, you are welcome to use, share and improve this * source file. You are forbidden to forbid anyone else to use, share * and improve what you give them. * * INTERNET: dburger@cs.wisc.edu * US Mail: 1210 W. Dayton Street, Madison, WI 53706 * */#include <unistd.h>#include <string>#include "base/cprintf.hh"#include "base/endian.hh"#include "base/misc.hh"#include "cpu/smt.hh"#include "encumbered/cpu/full/spec_state.hh"#include "encumbered/eio/eio.hh"#include "sim/builder.hh"#include "sim/host.hh"#include "sim/root.hh" // for curTick// note that libexo.h has to be last, as it does some nasty #defines;// specifically, it #defines as_float in a way that conflicts with a// field name in eval.h.#include "encumbered/eio/libexo.h"using namespace std;static struct { char *type; char *ext; char *cmd;} gzcmds[] = { /* type */ /* extension */ /* command */ { "r", ".gz", "%s -dc %s" }, { "rb", ".gz", "%s -dc %s" }, { "r", ".Z", "%s -dc %s" }, { "rb", ".Z", "%s -dc %s" }, { "w", ".gz", "%s > %s" }, { "wb", ".gz", "%s > %s" }};#ifndef GZIP_PATH#define GZIP_PATH "gzip"#endif/* same semantics as fopen() except that filenames ending with a ".gz" or ".Z" will be automagically get compressed */FILE *gzopen(const char *fname, const char *type){ int i; char *cmd = NULL; const char *ext; FILE *fd; char str[2048]; /* get the extension */ ext = strrchr(fname, '.'); /* check if extension indicates compressed file */ if (ext != NULL && *ext != '\0') { for (i=0; i < sizeof(gzcmds) / sizeof(gzcmds[0]); i++) { if (!strcmp(gzcmds[i].type, type) && !strcmp(gzcmds[i].ext, ext)) { cmd = gzcmds[i].cmd; break; } } } if (!cmd) { /* open file */ fd = fopen(fname, type); } else { /* open pipe to compressor/decompressor */ sprintf(str, cmd, GZIP_PATH, fname); fd = popen(str, type); } return fd;}/* close compressed stream */voidgzclose(FILE *fd){ /* attempt pipe close, otherwise file close */ if (pclose(fd) == -1) fclose(fd);}#ifdef _MSC_VER#define write _write#endif#define EIO_FILE_HEADER \ "/* This is a SimpleScalar EIO file - DO NOT MOVE OR EDIT THIS LINE! */\n"/* EIO transaction format: (inst_count, pc, ... reg inputs ... [r2, r3, r4, r5, r6, r7], ... mem inputs ... ((addr, size, blob), ...) ... reg outputs ... [r2, r3, r4, r5, r6, r7], ... mem outputs ... ((addr, size, blob), ...) )*/FILE *eio_open(const string &fname){ FILE *fd; struct exo_term_t *exo; int file_format, file_version, big_endian, target_big_endian; target_big_endian = HostBigEndian(); fd = gzopen(fname.c_str(), "r"); if (!fd) fatal("unable to open EIO file `%s'", fname); /* read and check EIO file header */ exo = exo_read(fd); if (!exo || exo->ec != ec_list || !exo->as_list.head || exo->as_list.head->ec != ec_integer || !exo->as_list.head->next || exo->as_list.head->next->ec != ec_integer || !exo->as_list.head->next->next || exo->as_list.head->next->next->ec != ec_integer || exo->as_list.head->next->next->next != NULL) fatal("could not read EIO file header"); file_format = exo->as_list.head->as_integer.val; file_version = exo->as_list.head->next->as_integer.val; big_endian = exo->as_list.head->next->next->as_integer.val; exo_delete(exo); if (file_format != MD_EIO_FILE_FORMAT) fatal("EIO file `%s' has incompatible format", fname); if (file_version != EIO_FILE_VERSION) fatal("EIO file `%s' has incompatible version", fname); if (!!big_endian != !!target_big_endian) fatal("EIO file `%s' has incompatible endian format", fname); return fd;}/* returns non-zero if file FNAME has a valid EIO header */inteio_valid(const string &fname){ FILE *fd; char buf[512]; /* open possible EIO file */ fd = gzopen(fname.c_str(), "r"); if (!fd) return false; /* read and check EIO file header */ fgets(buf, 512, fd); /* check the header */ if (strcmp(buf, EIO_FILE_HEADER)) return false; /* all done, close up file */ gzclose(fd); /* else, has a valid header, go with it... */ return true;}voideio_close(FILE * fd){ gzclose(fd);}/* read check point of architected state from stream FD, returns EIO transaction count (an EIO file pointer) */exo_integer_tEioProcess::read_chkpt(RegFile *regs, FILE *fd) /* stream to read */{ int i, page_count; exo_integer_t trans_icnt; struct exo_term_t *exo, *elt; /* read the EIO file pointer */ exo = exo_read(fd); if (!exo || exo->ec != ec_integer) fatal("could not read EIO file pointer"); trans_icnt = exo->as_integer.val; exo_delete(exo); /* read misc regs: icnt, PC, NPC, HI, LO, FCC */ exo = exo_read(fd); MD_EXO_TO_MISC_REGS(exo, chkpt_num_inst, regs); exo_delete(exo); /* read integer registers */ exo = exo_read(fd); if (!exo || exo->ec != ec_list) fatal("could not read EIO integer regs"); elt = exo->as_list.head; for (i = 0; i < NumIntRegs; i++) { if (!elt) fatal("could not read EIO integer regs (too few)"); if (elt->ec != ec_address) fatal("could not read EIO integer regs (bad value)"); MD_EXO_TO_IREG(elt, regs, i); elt = elt->next; } if (elt != NULL) fatal("could not read EIO integer regs (too many)"); exo_delete(exo); /* read FP registers */ exo = exo_read(fd); if (!exo || exo->ec != ec_list) fatal("could not read EIO FP regs"); elt = exo->as_list.head; for (i = 0; i < NumFloatRegs; i++) { if (!elt) fatal("could not read EIO FP regs (too few)"); if (elt->ec != ec_address) fatal("could not read EIO FP regs (bad value)"); MD_EXO_TO_FREG(elt, regs, i); elt = elt->next; } if (elt != NULL) fatal("could not read EIO FP regs (too many)"); exo_delete(exo); /* read the number of page defs, and memory config */ exo = exo_read(fd); if (!exo || exo->ec != ec_list || !exo->as_list.head || exo->as_list.head->ec != ec_integer || !exo->as_list.head->next || exo->as_list.head->next->ec != ec_address || !exo->as_list.head->next->next || exo->as_list.head->next->next->ec != ec_address || exo->as_list.head->next->next->next != NULL) fatal("could not read EIO memory page count"); page_count = exo->as_list.head->as_integer.val; brk_point = (Addr) exo->as_list.head->next->as_integer.val; stack_min = (Addr) exo->as_list.head->next->next->as_integer.val; exo_delete(exo); /* read text segment specifiers */ exo = exo_read(fd); if (!exo || exo->ec != ec_list || !exo->as_list.head || exo->as_list.head->ec != ec_address || !exo->as_list.head->next || exo->as_list.head->next->ec != ec_integer || exo->as_list.head->next->next != NULL) fatal("count not read EIO text segment specifiers"); text_base = (Addr) exo->as_list.head->as_integer.val; text_size = (unsigned int) exo->as_list.head->next->as_integer.val; exo_delete(exo); /* read data segment specifiers */ exo = exo_read(fd); if (!exo || exo->ec != ec_list || !exo->as_list.head || exo->as_list.head->ec != ec_address || !exo->as_list.head->next || exo->as_list.head->next->ec != ec_integer || exo->as_list.head->next->next != NULL) fatal("count not read EIO data segment specifiers"); data_base = (Addr) exo->as_list.head->as_integer.val; data_size = (unsigned int) exo->as_list.head->next->as_integer.val; exo_delete(exo); /* read stack segment specifiers */ exo = exo_read(fd); if (!exo || exo->ec != ec_list || !exo->as_list.head || exo->as_list.head->ec != ec_address || !exo->as_list.head->next || exo->as_list.head->next->ec != ec_integer || exo->as_list.head->next->next != NULL) fatal("count not read EIO stack segment specifiers"); stack_base = (Addr) exo->as_list.head->as_integer.val; stack_size = (unsigned int) exo->as_list.head->next->as_integer.val; //Make the stack size 16MB next_thread_stack_base = stack_base - (16 * 1024 * 1024); exo_delete(exo); for (i = 0; i < page_count; i++) { int j;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -