From 0ed3c84c7b05d7d3c9d5f0e3f1c05c20afef93b9 Mon Sep 17 00:00:00 2001 From: Dam Sunwoo Date: Tue, 31 Jan 2012 07:46:04 -0800 Subject: util: implements "writefile" gem5 op to export file from guest to host filesystem Usage: m5 writefile 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. --- util/m5/m5.c | 43 +++++++++++++++++++++++++++++++++++++++++-- util/m5/m5op.h | 1 + util/m5/m5op_arm.S | 2 ++ util/m5/m5ops.h | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) (limited to 'util') 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[]) { @@ -130,6 +157,17 @@ do_read_file(int argc, char *argv[]) read_file(STDOUT_FILENO); } +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[]) { @@ -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, "" }, + { "readfile", do_read_file, "" }, + { "writefile", do_write_file, "" }, + { "execfile", do_exec_file, "" }, { "checkpoint", do_checkpoint, "[delay [period]]" }, { "loadsymbol", do_load_symbol, "
" }, { "initparam", do_initparam, "" }, diff --git a/util/m5/m5op.h b/util/m5/m5op.h index 38815e3c3..4e1d0b638 100644 --- a/util/m5/m5op.h +++ b/util/m5/m5op.h @@ -49,6 +49,7 @@ void m5_reset_stats(uint64_t ns_delay, uint64_t ns_period); void m5_dump_stats(uint64_t ns_delay, uint64_t ns_period); void m5_dumpreset_stats(uint64_t ns_delay, uint64_t ns_period); uint64_t m5_readfile(void *buffer, uint64_t len, uint64_t offset); +uint64_t m5_writefile(void *buffer, uint64_t len, uint64_t offset, const char *filename); void m5_debugbreak(void); void m5_switchcpu(void); void m5_addsymbol(uint64_t addr, char *symbol); diff --git a/util/m5/m5op_arm.S b/util/m5/m5op_arm.S index b9557ee9d..8cdf5c62d 100644 --- a/util/m5/m5op_arm.S +++ b/util/m5/m5op_arm.S @@ -80,6 +80,7 @@ func: #define DUMPRST_STATS INST(m5_op, 0, 0, dumprststats_func) #define CHECKPOINT INST(m5_op, 0, 0, ckpt_func) #define READFILE INST(m5_op, 0, 0, readfile_func) +#define WRITEFILE INST(m5_op, 0, 0, writefile_func) #define DEBUGBREAK INST(m5_op, 0, 0, debugbreak_func) #define SWITCHCPU INST(m5_op, 0, 0, switchcpu_func) #define ADDSYMBOL INST(m5_op, 0, 0, addsymbol_func) @@ -121,6 +122,7 @@ SIMPLE_OP(m5_dump_stats, DUMP_STATS) SIMPLE_OP(m5_dumpreset_stats, DUMPRST_STATS) SIMPLE_OP(m5_checkpoint, CHECKPOINT) SIMPLE_OP(m5_readfile, READFILE) +SIMPLE_OP(m5_writefile, WRITEFILE) SIMPLE_OP(m5_debugbreak, DEBUGBREAK) SIMPLE_OP(m5_switchcpu, SWITCHCPU) SIMPLE_OP(m5_addsymbol, ADDSYMBOL) diff --git a/util/m5/m5ops.h b/util/m5/m5ops.h index bc2ae06be..f08524014 100644 --- a/util/m5/m5ops.h +++ b/util/m5/m5ops.h @@ -46,6 +46,7 @@ #define dumpstats_func 0x41 #define dumprststats_func 0x42 #define ckpt_func 0x43 +#define writefile_func 0x4F #define readfile_func 0x50 #define debugbreak_func 0x51 #define switchcpu_func 0x52 -- cgit v1.2.3