diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript index 1f33caa1cc..0e4ae52f4b 100644 --- a/util/m5/src/SConscript +++ b/util/m5/src/SConscript @@ -33,7 +33,6 @@ env.Append(CPPPATH=Dir('.')) args = 'args.cc' call_type = 'call_type.cc' command = 'command.cc' -commands = 'commands.cc' m5 = 'm5.cc' m5_mmap = 'm5_mmap.c' usage = 'usage.cc' @@ -59,6 +58,7 @@ static_env.Append(LINKFLAGS=[ '-no-pie', '-static' ]) # libm5 = static_env.StaticLibrary('out/m5', [ m5_mmap ] + m5ops) +commands = env.SConscript('command/SConscript', exports={ "env": static_env }) # # The m5 stand alone command line utility. diff --git a/util/m5/src/command/SConscript b/util/m5/src/command/SConscript new file mode 100644 index 0000000000..a9a59a1345 --- /dev/null +++ b/util/m5/src/command/SConscript @@ -0,0 +1,44 @@ +# Copyright 2020 Google, Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Import('*') + +command_ccs = [ + 'addsymbol.cc', + 'checkpoint.cc', + 'dumpresetstats.cc', + 'dumpstats.cc', + 'exit.cc', + 'fail.cc', + 'sum.cc', + 'initparam.cc', + 'loadsymbol.cc', + 'readfile.cc', + 'resetstats.cc', + 'writefile.cc', +] + +command_objs = list(map(env.StaticObject, command_ccs)) +Return('command_objs') diff --git a/util/m5/src/command/addsymbol.cc b/util/m5/src/command/addsymbol.cc new file mode 100644 index 0000000000..dfd20d7c92 --- /dev/null +++ b/util/m5/src/command/addsymbol.cc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2003-2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "args.hh" +#include "command.hh" +#include "dispatch_table.hh" +#include "usage.hh" + +namespace +{ + +void +do_add_symbol(const DispatchTable &dt, Args &args) +{ + uint64_t addr; + if (!args.pop(addr)) + usage(); + const std::string &symbol = args.pop(); + + (*dt.m5_add_symbol)(addr, symbol.c_str()); +} + +Command add_symbol = { + "addsymbol", 2, 2, do_add_symbol, "
[delay]\n"
+ " Exit with failure code code after delay, or immediately" };
+
+} // anonymous namespace
diff --git a/util/m5/src/command/initparam.cc b/util/m5/src/command/initparam.cc
new file mode 100644
index 0000000000..3fe000c10c
--- /dev/null
+++ b/util/m5/src/command/initparam.cc
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2003-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+#include "usage.hh"
+
+namespace
+{
+
+void
+do_initparam(const DispatchTable &dt, Args &args)
+{
+ uint64_t key_str[2];
+ if (!args.pop(key_str, 2))
+ usage();
+ uint64_t val = (*dt.m5_init_param)(key_str[0], key_str[1]);
+ std::cout << val;
+}
+
+Command init_param = {
+ "initparam", 1, 1, do_initparam, "[key]\n"
+ " optional key may be at most 16 characters long" };
+
+} // anonymous namespace
diff --git a/util/m5/src/command/loadsymbol.cc b/util/m5/src/command/loadsymbol.cc
new file mode 100644
index 0000000000..c55ae9905c
--- /dev/null
+++ b/util/m5/src/command/loadsymbol.cc
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2003-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+#include "usage.hh"
+
+namespace
+{
+
+void
+do_loadsymbol(const DispatchTable &dt, Args &args)
+{
+ (*dt.m5_load_symbol)();
+}
+
+Command load_symbol = {
+ "loadsymbol", 0, 0, do_loadsymbol, "\n"
+ " load a preselected symbol file into gem5's symbol table" };
+
+} // anonymous namespace
diff --git a/util/m5/src/command/readfile.cc b/util/m5/src/command/readfile.cc
new file mode 100644
index 0000000000..9295dfd95e
--- /dev/null
+++ b/util/m5/src/command/readfile.cc
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2003-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+#include "usage.hh"
+
+namespace
+{
+
+int
+read_file(const DispatchTable &dt, std::ostream &os)
+{
+ char buf[256 * 1024];
+
+ // Touch all buffer pages to ensure they are mapped in the
+ // page table. This is required in the case of X86_FS, where
+ // Linux does demand paging.
+ memset(buf, 0, sizeof(buf));
+
+ int len;
+ int offset = 0;
+ while ((len = (*dt.m5_read_file)(buf, sizeof(buf), offset)) > 0) {
+ os.write(buf, len);
+ os.flush();
+ if (!os) {
+ std::cerr << "Failed to write file" << std::endl;
+ exit(2);
+ }
+ offset += len;
+ }
+
+ return offset;
+}
+
+void
+do_read_file(const DispatchTable &dt, Args &args)
+{
+ if (args.size() > 0)
+ usage();
+
+ read_file(dt, std::cout);
+}
+
+Command read_file_cmd = {
+ "readfile", 0, 0, do_read_file, "\n"
+ " read a preselected file from the host and write it to "
+ "stdout" };
+
+} // anonymous namespace
diff --git a/util/m5/src/command/resetstats.cc b/util/m5/src/command/resetstats.cc
new file mode 100644
index 0000000000..2408fb3341
--- /dev/null
+++ b/util/m5/src/command/resetstats.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2003-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+#include "usage.hh"
+
+namespace
+{
+
+void
+do_reset_stats(const DispatchTable &dt, Args &args)
+{
+ uint64_t ns_delay, ns_period;
+ if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
+ usage();
+
+ (*dt.m5_reset_stats)(ns_delay, ns_period);
+}
+
+Command reset_stats = {
+ "resetstats", 0, 2, do_reset_stats, "[delay [period]]\n"
+ " After delay (default 0) reset the stats, and then "
+ "optionally every period after" };
+
+} // anonymous namespace
diff --git a/util/m5/src/command/sum.cc b/util/m5/src/command/sum.cc
new file mode 100644
index 0000000000..c7d44b397e
--- /dev/null
+++ b/util/m5/src/command/sum.cc
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2003-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+#include "usage.hh"
+
+namespace
+{
+
+// For testing purposes.
+void
+do_sum(const DispatchTable &dt, Args &args)
+{
+ uint64_t a, b, c, d, e, f;
+ if (!args.pop(a) || !args.pop(b) || !args.pop(c, 0) ||
+ !args.pop(d, 0) || !args.pop(e, 0) || !args.pop(f, 0))
+ usage();
+
+ unsigned sum = (*dt.m5_sum)(a, b, c, d, e, f);
+ std::cout << "Sum is " << sum << "." << std::endl;
+}
+
+Command sum = {
+ "sum", 2, 6, do_sum, " [c [d [e [f]]]]\n"
+ " Sum a-f (defaults are 0), for testing purposes" };
+
+} // anonymous namespace
diff --git a/util/m5/src/command/writefile.cc b/util/m5/src/command/writefile.cc
new file mode 100644
index 0000000000..801b7af2a3
--- /dev/null
+++ b/util/m5/src/command/writefile.cc
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2003-2005 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include
+#include
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+#include "usage.hh"
+
+namespace
+{
+
+void
+write_file(const DispatchTable &dt, const std::string &filename,
+ const std::string &host_filename)
+{
+ std::cerr << "opening " << filename << std::endl;
+ std::ifstream src(filename, std::ios_base::in | std::ios_base::binary);
+
+ if (!src) {
+ std::cerr << "error opening " << filename << std::endl;
+ return;
+ }
+
+ char buf[256 * 1024];
+ int offset = 0;
+
+ memset(buf, 0, sizeof(buf));
+
+ while (true) {
+ src.seekg(offset);
+ src.read(buf, sizeof(buf));
+ int len = src.gcount();
+ if (!src && !src.eof())
+ break;
+ char *wbuf = buf;
+ while (len) {
+ int bytes = (*dt.m5_write_file)(
+ wbuf, len, offset, host_filename.c_str());
+ len -= bytes;
+ offset += bytes;
+ wbuf += bytes;
+ }
+ if (src.eof())
+ break;
+ }
+ std::cerr << "Wrote " << offset << " bytes." << std::endl;
+}
+
+void
+do_write_file(const DispatchTable &dt, Args &args)
+{
+ const std::string &filename = args.pop();
+ const std::string &host_filename = args.pop(filename);
+
+ write_file(dt, filename, host_filename);
+}
+
+Command write_file_cmd = {
+ "writefile", 1, 2, do_write_file, " [host filename]\n"
+ " Write a file to the host, optionally with a different "
+ "name" };
+
+} // anonymous namespace
diff --git a/util/m5/src/commands.cc b/util/m5/src/commands.cc
deleted file mode 100644
index 0dd971acf8..0000000000
--- a/util/m5/src/commands.cc
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (c) 2003-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include
-#include
-#include
-
-#include "args.hh"
-#include "command.hh"
-#include "dispatch_table.hh"
-#include "usage.hh"
-
-namespace
-{
-
-int
-read_file(const DispatchTable &dt, std::ostream &os)
-{
- char buf[256 * 1024];
-
- // Touch all buffer pages to ensure they are mapped in the
- // page table. This is required in the case of X86_FS, where
- // Linux does demand paging.
- memset(buf, 0, sizeof(buf));
-
- int len;
- int offset = 0;
- while ((len = (*dt.m5_read_file)(buf, sizeof(buf), offset)) > 0) {
- os.write(buf, len);
- os.flush();
- if (!os) {
- std::cerr << "Failed to write file" << std::endl;
- exit(2);
- }
- offset += len;
- }
-
- return offset;
-}
-
-void
-write_file(const DispatchTable &dt, const std::string &filename,
- const std::string &host_filename)
-{
- std::cerr << "opening " << filename << std::endl;
- std::ifstream src(filename, std::ios_base::in | std::ios_base::binary);
-
- if (!src) {
- std::cerr << "error opening " << filename << std::endl;
- return;
- }
-
- char buf[256 * 1024];
- int offset = 0;
-
- memset(buf, 0, sizeof(buf));
-
- while (true) {
- src.seekg(offset);
- src.read(buf, sizeof(buf));
- int len = src.gcount();
- if (!src && !src.eof())
- break;
- char *wbuf = buf;
- while (len) {
- int bytes = (*dt.m5_write_file)(
- wbuf, len, offset, host_filename.c_str());
- len -= bytes;
- offset += bytes;
- wbuf += bytes;
- }
- if (src.eof())
- break;
- }
- std::cerr << "Wrote " << offset << " bytes." << std::endl;
-}
-
-void
-do_add_symbol(const DispatchTable &dt, Args &args)
-{
- uint64_t addr;
- if (!args.pop(addr))
- usage();
- const std::string &symbol = args.pop();
-
- (*dt.m5_add_symbol)(addr, symbol.c_str());
-}
-
-Command add_symbol = {
- "addsymbol", 2, 2, do_add_symbol, " \n"
- " Adds a symbol with address \"address\" to gem5's "
- "symbol table" };
-
-
-void
-do_checkpoint(const DispatchTable &dt, Args &args)
-{
- uint64_t ns_delay, ns_period;
- if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
-
- (*dt.m5_checkpoint)(ns_delay, ns_period);
-}
-
-Command checkpoint = {
- "checkpoint", 0, 2, do_checkpoint, "[delay [period]]\n"
- " After delay (default 0) take a checkpoint, and then "
- "optionally every period after" };
-
-
-void
-do_dump_reset_stats(const DispatchTable &dt, Args &args)
-{
- uint64_t ns_delay, ns_period;
- if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
-
- (*dt.m5_dump_reset_stats)(ns_delay, ns_period);
-}
-
-Command dump_reset_stats = {
- "dumpresetstats", 0, 2, do_dump_reset_stats, "[delay [period]]\n"
- " After delay (default 0) dump and reset the stats, and then "
- "optionally every period after" };
-
-
-void
-do_dump_stats(const DispatchTable &dt, Args &args)
-{
- uint64_t ns_delay, ns_period;
- if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
-
- (*dt.m5_dump_stats)(ns_delay, ns_period);
-}
-
-Command dump_stats = {
- "dumpstats", 0, 2, do_dump_stats, "[delay [period]]\n"
- " After delay (default 0) dump the stats, and then optionally "
- "every period after" };
-
-
-void
-do_exit(const DispatchTable &dt, Args &args)
-{
- uint64_t ns_delay;
- if (!args.pop(ns_delay, 0))
- usage();
-
- (*dt.m5_exit)(ns_delay);
-}
-
-Command exit_cmd = {
- "exit", 0, 1, do_exit, "[delay]\n"
- " Exit after delay, or immediately" };
-
-
-void
-do_fail(const DispatchTable &dt, Args &args)
-{
- uint64_t ns_delay, code;
- if (!args.pop(code) || !args.pop(ns_delay, 0))
- usage();
-
- (*dt.m5_fail)(ns_delay, code);
-}
-
-Command fail_cmd = {
- "fail", 1, 2, do_fail, " [delay]\n"
- " Exit with failure code code after delay, or immediately" };
-
-
-// For testing purposes.
-void
-do_sum(const DispatchTable &dt, Args &args)
-{
- uint64_t a, b, c, d, e, f;
- if (!args.pop(a) || !args.pop(b) || !args.pop(c, 0) ||
- !args.pop(d, 0) || !args.pop(e, 0) || !args.pop(f, 0))
- usage();
-
- unsigned sum = (*dt.m5_sum)(a, b, c, d, e, f);
- std::cout << "Sum is " << sum << "." << std::endl;
-}
-
-Command sum = {
- "sum", 2, 6, do_sum, " [c [d [e [f]]]]\n"
- " Sum a-f (defaults are 0), for testing purposes" };
-
-
-void
-do_initparam(const DispatchTable &dt, Args &args)
-{
- uint64_t key_str[2];
- if (!args.pop(key_str, 2))
- usage();
- uint64_t val = (*dt.m5_init_param)(key_str[0], key_str[1]);
- std::cout << val;
-}
-
-Command init_param = {
- "initparam", 1, 1, do_initparam, "[key]\n"
- " optional key may be at most 16 characters long" };
-
-
-void
-do_loadsymbol(const DispatchTable &dt, Args &args)
-{
- (*dt.m5_load_symbol)();
-}
-
-Command load_symbol = {
- "loadsymbol", 0, 0, do_loadsymbol, "\n"
- " load a preselected symbol file into gem5's symbol table" };
-
-
-void
-do_read_file(const DispatchTable &dt, Args &args)
-{
- if (args.size() > 0)
- usage();
-
- read_file(dt, std::cout);
-}
-
-Command read_file_cmd = {
- "readfile", 0, 0, do_read_file, "\n"
- " read a preselected file from the host and write it to "
- "stdout" };
-
-
-void
-do_reset_stats(const DispatchTable &dt, Args &args)
-{
- uint64_t ns_delay, ns_period;
- if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
-
- (*dt.m5_reset_stats)(ns_delay, ns_period);
-}
-
-Command reset_stats = {
- "resetstats", 0, 2, do_reset_stats, "[delay [period]]\n"
- " After delay (default 0) reset the stats, and then "
- "optionally every period after" };
-
-
-void
-do_write_file(const DispatchTable &dt, Args &args)
-{
- const std::string &filename = args.pop();
- const std::string &host_filename = args.pop(filename);
-
- write_file(dt, filename, host_filename);
-}
-
-Command write_file_cmd = {
- "writefile", 1, 2, do_write_file, " [host filename]\n"
- " Write a file to the host, optionally with a different "
- "name" };
-
-} // anonymous namespace