summaryrefslogtreecommitdiff
path: root/util/m5/m5.c
diff options
context:
space:
mode:
authorDam Sunwoo <dam.sunwoo@arm.com>2012-01-31 07:46:04 -0800
committerDam Sunwoo <dam.sunwoo@arm.com>2012-01-31 07:46:04 -0800
commit0ed3c84c7b05d7d3c9d5f0e3f1c05c20afef93b9 (patch)
tree9663b1af4da7ee4c063fa0047da7cbf7e8a2b9de /util/m5/m5.c
parentaf6aaf258171027af8d3cf0ef86dddff501a3ccb (diff)
downloadgem5-0ed3c84c7b05d7d3c9d5f0e3f1c05c20afef93b9.tar.xz
util: implements "writefile" gem5 op to export file from guest to host filesystem
Usage: m5 writefile <filename> File will be created in the gem5 output folder with the identical filename. Implementation is largely based on the existing "readfile" functionality. Currently does not support exporting of folders.
Diffstat (limited to 'util/m5/m5.c')
-rw-r--r--util/m5/m5.c43
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, "" },