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.
39 #include "commands.hh"
43 read_file(DispatchTable
*dt
, int dest_fid
)
45 uint8_t buf
[256*1024];
49 // Touch all buffer pages to ensure they are mapped in the
50 // page table. This is required in the case of X86_FS, where
51 // Linux does demand paging.
52 memset(buf
, 0, sizeof(buf
));
54 while ((len
= (*dt
->m5_read_file
)(buf
, sizeof(buf
), offset
)) > 0) {
58 ret
= write(dest_fid
, base
, len
);
60 perror("Failed to write file");
62 } else if (ret
== 0) {
63 fprintf(stderr
, "Failed to write file: "
64 "Unhandled short write\n");
77 write_file(DispatchTable
*dt
, const char *filename
, const char *host_filename
)
79 fprintf(stderr
, "opening %s\n", filename
);
80 int src_fid
= open(filename
, O_RDONLY
);
83 fprintf(stderr
, "error opening %s\n", filename
);
92 memset(buf
, 0, sizeof(buf
));
94 while ((len
= read(src_fid
, buf
, sizeof(buf
))) > 0) {
95 bytes
+= (*dt
->m5_write_file
)(buf
, len
, offset
, host_filename
);
98 fprintf(stderr
, "written %d bytes\n", bytes
);
104 do_exit(DispatchTable
*dt
, Args
*args
)
110 if (!parse_int_args(args
, ints
, 1))
112 (*dt
->m5_exit
)(ints
[0]);
116 do_fail(DispatchTable
*dt
, Args
*args
)
118 if (args
->argc
< 1 || args
->argc
> 2)
121 uint64_t ints
[2] = { 0, 0 };
122 if (!parse_int_args(args
, ints
, args
->argc
))
124 (*dt
->m5_fail
)(ints
[1], ints
[0]);
128 do_reset_stats(DispatchTable
*dt
, Args
*args
)
131 if (!parse_int_args(args
, ints
, 2))
133 (*dt
->m5_reset_stats
)(ints
[0], ints
[1]);
137 do_dump_stats(DispatchTable
*dt
, Args
*args
)
140 if (!parse_int_args(args
, ints
, 2))
142 (*dt
->m5_dump_stats
)(ints
[0], ints
[1]);
146 do_dump_reset_stats(DispatchTable
*dt
, Args
*args
)
149 if (!parse_int_args(args
, ints
, 2))
151 (*dt
->m5_dump_reset_stats
)(ints
[0], ints
[1]);
155 do_read_file(DispatchTable
*dt
, Args
*args
)
160 read_file(dt
, STDOUT_FILENO
);
164 do_write_file(DispatchTable
*dt
, Args
*args
)
166 if (args
->argc
!= 1 && args
->argc
!= 2)
169 const char *filename
= pop_arg(args
);
170 const char *host_filename
= pop_arg(args
);
172 host_filename
= filename
;
174 write_file(dt
, filename
, host_filename
);
178 do_checkpoint(DispatchTable
*dt
, Args
*args
)
181 if (!parse_int_args(args
, ints
, 2))
183 (*dt
->m5_checkpoint
)(ints
[0], ints
[1]);
187 do_addsymbol(DispatchTable
*dt
, Args
*args
)
192 uint64_t addr
= strtoul(pop_arg(args
), NULL
, 0);
193 const char *symbol
= pop_arg(args
);
194 (*dt
->m5_add_symbol
)(addr
, symbol
);
199 do_loadsymbol(DispatchTable
*dt
, Args
*args
)
204 (*dt
->m5_load_symbol
)();
208 do_initparam(DispatchTable
*dt
, Args
*args
)
214 if (!pack_arg_into_regs(args
, key_str
, 2))
216 uint64_t val
= (*dt
->m5_init_param
)(key_str
[0], key_str
[1]);
220 CommandInfo command_table
[] = {
221 { "addsymbol", do_addsymbol
, "<address> <symbol> // Adds a "
222 "symbol with address \"address\" "
223 "to gem5's symbol table" },
224 { "checkpoint", do_checkpoint
, "[delay [period]] // After "
225 "delay (default 0) take a "
226 "checkpoint, and then optionally "
227 "every period after" },
228 { "dumpresetstats", do_dump_reset_stats
, "[delay [period]] // After "
229 "delay (default 0) dump and "
230 "reset the stats, and then "
231 "optionally every period after" },
232 { "dumpstats", do_dump_stats
, "[delay [period]] // After "
233 "delay (default 0) dump the "
234 "stats, and then optionally "
235 "every period after" },
236 { "exit", do_exit
, "[delay] // Exit after delay, "
238 { "fail", do_fail
, "<code> [delay] // Exit with "
239 "failure code code after delay, "
241 { "initparam", do_initparam
, "[key] // optional key may be at "
242 "most 16 characters long" },
243 { "loadsymbol", do_loadsymbol
, "load a preselected symbol file "
244 "into gem5's symbol table" },
245 { "readfile", do_read_file
, "read a preselected file from "
246 "the host and write it to "
248 { "resetstats", do_reset_stats
, "[delay [period]] // After "
249 "delay (default 0) reset the "
250 "stats, and then optionally "
251 "every period after" },
252 { "writefile", do_write_file
, "<filename> [host filename] // "
253 "Write a file to the host, "
254 "optionally with a different "
258 int num_commands
= sizeof(command_table
) / sizeof(CommandInfo
);