diff options
author | Gabe Black <gblack@eecs.umich.edu> | 2012-01-31 22:40:08 -0800 |
---|---|---|
committer | Gabe Black <gblack@eecs.umich.edu> | 2012-01-31 22:40:08 -0800 |
commit | ea8b347dc5d375572d8d19770024ec8be5fd5017 (patch) | |
tree | 56bb75b1f071a749b7e90218d0d6b0e9265657bb /util/m5/m5.c | |
parent | e88165a431a90cf7e33e205794caed898ca6fcb1 (diff) | |
parent | 7d4f18770073d968c70cd3ffcdd117f50a6056a2 (diff) | |
download | gem5-ea8b347dc5d375572d8d19770024ec8be5fd5017.tar.xz |
Merge with head, hopefully the last time for this batch.
Diffstat (limited to 'util/m5/m5.c')
-rw-r--r-- | util/m5/m5.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/util/m5/m5.c b/util/m5/m5.c index 40328bc38..a0ce9b3ec 100644 --- a/util/m5/m5.c +++ b/util/m5/m5.c @@ -88,6 +88,33 @@ read_file(int dest_fid) } } +int +write_file(const char *filename) +{ + fprintf(stderr, "opening %s\n", filename); + int src_fid = open(filename, O_RDONLY); + + if (src_fid < 0) { + fprintf(stderr, "error opening %s\n", filename); + return; + } + + char buf[256*1024]; + int offset = 0; + int len; + int bytes = 0; + + memset(buf, 0, sizeof(buf)); + + while ((len = read(src_fid, buf, sizeof(buf))) > 0) { + bytes += m5_writefile(buf, len, offset, filename); + offset += len; + } + fprintf(stderr, "written %d bytes\n", bytes); + + close(src_fid); +} + void do_exit(int argc, char *argv[]) { @@ -131,6 +158,17 @@ do_read_file(int argc, char *argv[]) } void +do_write_file(int argc, char *argv[]) +{ + if (argc != 1) + usage(); + + const char *filename = argv[0]; + + write_file(filename); +} + +void do_exec_file(int argc, char *argv[]) { if (argc > 0) @@ -227,8 +265,9 @@ struct MainFunc mainfuncs[] = { { "resetstats", do_reset_stats, "[delay [period]]" }, { "dumpstats", do_dump_stats, "[delay [period]]" }, { "dumpresetstats", do_dump_reset_stats, "[delay [period]]" }, - { "readfile", do_read_file, "[filename]" }, - { "execfile", do_exec_file, "<filename>" }, + { "readfile", do_read_file, "" }, + { "writefile", do_write_file, "<filename>" }, + { "execfile", do_exec_file, "" }, { "checkpoint", do_checkpoint, "[delay [period]]" }, { "loadsymbol", do_load_symbol, "<address> <symbol>" }, { "initparam", do_initparam, "" }, |