2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "commands.hh"
44 read_file(const DispatchTable
&dt
, int dest_fid
)
46 uint8_t buf
[256*1024];
50 // Touch all buffer pages to ensure they are mapped in the
51 // page table. This is required in the case of X86_FS, where
52 // Linux does demand paging.
53 memset(buf
, 0, sizeof(buf
));
55 while ((len
= (*dt
.m5_read_file
)(buf
, sizeof(buf
), offset
)) > 0) {
59 ret
= write(dest_fid
, base
, len
);
61 perror("Failed to write file");
63 } else if (ret
== 0) {
64 fprintf(stderr
, "Failed to write file: "
65 "Unhandled short write\n");
78 write_file(const DispatchTable
&dt
, const char *filename
,
79 const char *host_filename
)
81 fprintf(stderr
, "opening %s\n", filename
);
82 int src_fid
= open(filename
, O_RDONLY
);
85 fprintf(stderr
, "error opening %s\n", filename
);
94 memset(buf
, 0, sizeof(buf
));
96 while ((len
= read(src_fid
, buf
, sizeof(buf
))) > 0) {
97 bytes
+= (*dt
.m5_write_file
)(buf
, len
, offset
, host_filename
);
100 fprintf(stderr
, "written %d bytes\n", bytes
);
106 do_exit(const DispatchTable
&dt
, Args
&args
)
112 if (!args
.pop(ns_delay
, 0))
115 (*dt
.m5_exit
)(ns_delay
);
119 do_fail(const DispatchTable
&dt
, Args
&args
)
124 uint64_t ns_delay
, code
;
125 if (!args
.pop(code
) || !args
.pop(ns_delay
, 0))
128 (*dt
.m5_fail
)(ns_delay
, code
);
132 do_reset_stats(const DispatchTable
&dt
, Args
&args
)
137 uint64_t ns_delay
, ns_period
;
138 if (!args
.pop(ns_delay
, 0) || !args
.pop(ns_period
, 0))
141 (*dt
.m5_reset_stats
)(ns_delay
, ns_period
);
145 do_dump_stats(const DispatchTable
&dt
, Args
&args
)
150 uint64_t ns_delay
, ns_period
;
151 if (!args
.pop(ns_delay
, 0) || !args
.pop(ns_period
, 0))
154 (*dt
.m5_dump_stats
)(ns_delay
, ns_period
);
158 do_dump_reset_stats(const DispatchTable
&dt
, Args
&args
)
163 uint64_t ns_delay
, ns_period
;
164 if (!args
.pop(ns_delay
, 0) || !args
.pop(ns_period
, 0))
167 (*dt
.m5_dump_reset_stats
)(ns_delay
, ns_period
);
171 do_read_file(const DispatchTable
&dt
, Args
&args
)
176 read_file(dt
, STDOUT_FILENO
);
180 do_write_file(const DispatchTable
&dt
, Args
&args
)
182 if (args
.size() < 1 || args
.size() > 2)
185 const std::string
&filename
= args
.pop();
186 const std::string
&host_filename
= args
.pop(filename
);
188 write_file(dt
, filename
.c_str(), host_filename
.c_str());
192 do_checkpoint(const DispatchTable
&dt
, Args
&args
)
197 uint64_t ns_delay
, ns_period
;
198 if (!args
.pop(ns_delay
, 0) || !args
.pop(ns_period
, 0))
201 (*dt
.m5_checkpoint
)(ns_delay
, ns_period
);
205 do_addsymbol(const DispatchTable
&dt
, Args
&args
)
207 if (args
.size() != 2)
213 const std::string
&symbol
= args
.pop();
215 (*dt
.m5_add_symbol
)(addr
, symbol
.c_str());
220 do_loadsymbol(const DispatchTable
&dt
, Args
&args
)
225 (*dt
.m5_load_symbol
)();
229 do_initparam(const DispatchTable
&dt
, Args
&args
)
231 if (args
.size() != 1)
235 if (!args
.pop(key_str
, 2))
237 uint64_t val
= (*dt
.m5_init_param
)(key_str
[0], key_str
[1]);
241 CommandInfo command_table
[] = {
242 { "addsymbol", do_addsymbol
, "<address> <symbol> // Adds a "
243 "symbol with address \"address\" "
244 "to gem5's symbol table" },
245 { "checkpoint", do_checkpoint
, "[delay [period]] // After "
246 "delay (default 0) take a "
247 "checkpoint, and then optionally "
248 "every period after" },
249 { "dumpresetstats", do_dump_reset_stats
, "[delay [period]] // After "
250 "delay (default 0) dump and "
251 "reset the stats, and then "
252 "optionally every period after" },
253 { "dumpstats", do_dump_stats
, "[delay [period]] // After "
254 "delay (default 0) dump the "
255 "stats, and then optionally "
256 "every period after" },
257 { "exit", do_exit
, "[delay] // Exit after delay, "
259 { "fail", do_fail
, "<code> [delay] // Exit with "
260 "failure code code after delay, "
262 { "initparam", do_initparam
, "[key] // optional key may be at "
263 "most 16 characters long" },
264 { "loadsymbol", do_loadsymbol
, "load a preselected symbol file "
265 "into gem5's symbol table" },
266 { "readfile", do_read_file
, "read a preselected file from "
267 "the host and write it to "
269 { "resetstats", do_reset_stats
, "[delay [period]] // After "
270 "delay (default 0) reset the "
271 "stats, and then optionally "
272 "every period after" },
273 { "writefile", do_write_file
, "<filename> [host filename] // "
274 "Write a file to the host, "
275 "optionally with a different "
279 int num_commands
= sizeof(command_table
) / sizeof(CommandInfo
);