d39098c687dd4519c1bc76f8b1b77dedda974845
2 * Copyright (c) 2011, 2017 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Authors: Nathan Binkert
56 #include <sys/types.h>
64 char *command
= "unspecified";
68 parse_int_args(int argc
, char *argv
[], uint64_t ints
[], int len
)
73 // On 32 bit platforms we need to use strtoull to do the conversion
75 #define strto64 strtoul
77 #define strto64 strtoull
80 for (i
= 0; i
< len
; ++i
)
81 ints
[i
] = (i
< argc
) ? strto64(argv
[i
], NULL
, 0) : 0;
87 parse_str_args_to_regs(int argc
, char *argv
[], uint64_t regs
[], int len
)
89 if (argc
> 1 || (argc
> 0 && strlen(argv
[0]) > len
* sizeof(uint64_t)))
93 for (i
= 0; i
< len
; i
++)
100 for (n
= 0, i
= 0; i
< len
&& n
< strlen(argv
[0]); n
++) {
101 *((char *)(®s
[i
]) + (n
% 8)) = argv
[0][n
];
108 read_file(int dest_fid
)
110 uint8_t buf
[256*1024];
114 // Touch all buffer pages to ensure they are mapped in the
115 // page table. This is required in the case of X86_FS, where
116 // Linux does demand paging.
117 memset(buf
, 0, sizeof(buf
));
119 while ((len
= m5_readfile(buf
, sizeof(buf
), offset
)) > 0) {
123 ret
= write(dest_fid
, base
, len
);
125 perror("Failed to write file");
127 } else if (ret
== 0) {
128 fprintf(stderr
, "Failed to write file: "
129 "Unhandled short write\n");
142 write_file(const char *filename
)
144 fprintf(stderr
, "opening %s\n", filename
);
145 int src_fid
= open(filename
, O_RDONLY
);
148 fprintf(stderr
, "error opening %s\n", filename
);
157 memset(buf
, 0, sizeof(buf
));
159 while ((len
= read(src_fid
, buf
, sizeof(buf
))) > 0) {
160 bytes
+= m5_writefile(buf
, len
, offset
, filename
);
163 fprintf(stderr
, "written %d bytes\n", bytes
);
169 do_exit(int argc
, char *argv
[])
175 parse_int_args(argc
, argv
, ints
, 1);
180 do_fail(int argc
, char *argv
[])
182 if (argc
< 1 || argc
> 2)
185 uint64_t ints
[2] = {0,0};
186 parse_int_args(argc
, argv
, ints
, argc
);
187 m5_fail(ints
[1], ints
[0]);
191 do_reset_stats(int argc
, char *argv
[])
194 parse_int_args(argc
, argv
, ints
, 2);
195 m5_reset_stats(ints
[0], ints
[1]);
199 do_dump_stats(int argc
, char *argv
[])
202 parse_int_args(argc
, argv
, ints
, 2);
203 m5_dump_stats(ints
[0], ints
[1]);
207 do_dump_reset_stats(int argc
, char *argv
[])
210 parse_int_args(argc
, argv
, ints
, 2);
211 m5_dumpreset_stats(ints
[0], ints
[1]);
215 do_read_file(int argc
, char *argv
[])
220 read_file(STDOUT_FILENO
);
224 do_write_file(int argc
, char *argv
[])
229 const char *filename
= argv
[0];
231 write_file(filename
);
235 do_exec_file(int argc
, char *argv
[])
240 const char *destname
= "/tmp/execfile";
242 int fid
= open(destname
, O_WRONLY
, 0777);
243 int len
= read_file(fid
);
246 execl(destname
, "execfile", NULL
);
247 err(1, "execl failed!");
252 do_checkpoint(int argc
, char *argv
[])
255 parse_int_args(argc
, argv
, ints
, 2);
256 m5_checkpoint(ints
[0], ints
[1]);
260 do_addsymbol(int argc
, char *argv
[])
265 uint64_t addr
= strtoul(argv
[0], NULL
, 0);
266 char *symbol
= argv
[1];
267 m5_addsymbol(addr
, symbol
);
272 do_loadsymbol(int argc
, char *argv
[])
281 do_initparam(int argc
, char *argv
[])
287 parse_str_args_to_regs(argc
, argv
, key_str
, 2);
288 uint64_t val
= m5_initparam(key_str
[0], key_str
[1]);
289 printf("%"PRIu64
, val
);
293 do_sw99param(int argc
, char *argv
[])
298 uint64_t param
= m5_initparam(0, 0);
300 // run-time, rampup-time, rampdown-time, warmup-time, connections
301 printf("%"PRId64
" %"PRId64
" %"PRId64
" %"PRId64
" %"PRId64
,
302 (param
>> 48) & 0xfff,
303 (param
>> 36) & 0xfff, (param
>> 24) & 0xfff,
304 (param
>> 12) & 0xfff, (param
>> 0) & 0xfff);
309 do_pin(int argc
, char *argv
[])
317 const char *sep
= ",";
318 char *target
= strtok(argv
[0], sep
);
320 CPU_SET(atoi(target
), &mask
);
321 target
= strtok(NULL
, sep
);
324 if (sched_setaffinity(0, sizeof(cpu_set_t
), &mask
) < 0)
325 err(1, "setaffinity");
327 execvp(argv
[1], &argv
[1]);
328 err(1, "execvp failed!");
335 void (*func
)(int argc
, char *argv
[]);
339 struct MainFunc mainfuncs
[] = {
340 { "exit", do_exit
, "[delay]" },
341 { "fail", do_fail
, "<code> [delay]" },
342 { "resetstats", do_reset_stats
, "[delay [period]]" },
343 { "dumpstats", do_dump_stats
, "[delay [period]]" },
344 { "dumpresetstats", do_dump_reset_stats
, "[delay [period]]" },
345 { "readfile", do_read_file
, "" },
346 { "writefile", do_write_file
, "<filename>" },
347 { "execfile", do_exec_file
, "" },
348 { "checkpoint", do_checkpoint
, "[delay [period]]" },
349 { "addsymbol", do_addsymbol
, "<address> <symbol>" },
350 { "loadsymbol", do_loadsymbol
, "" },
351 { "initparam", do_initparam
, "[key] // key must be shorter than 16 chars" },
352 { "sw99param", do_sw99param
, "" },
354 { "pin", do_pin
, "<cpu> <program> [args ...]" }
357 int numfuncs
= sizeof(mainfuncs
) / sizeof(mainfuncs
[0]);
364 for (i
= 0; i
< numfuncs
; ++i
) {
365 char *header
= i
? "" : "usage:";
366 fprintf(stderr
, "%-6s %s %s %s\n",
367 header
, progname
, mainfuncs
[i
].name
, mainfuncs
[i
].usage
);
369 fprintf(stderr
, "\n");
370 fprintf(stderr
, "All times in nanoseconds!\n");
381 fd
= open("/dev/mem", O_RDWR
| O_SYNC
);
383 perror("Can't open /dev/mem");
387 m5_mem
= mmap(NULL
, 0x10000, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, M5OP_ADDR
);
389 perror("Can't mmap /dev/mem");
396 main(int argc
, char *argv
[])
410 for (i
= 0; i
< numfuncs
; ++i
) {
411 if (strcmp(command
, mainfuncs
[i
].name
) != 0)
414 mainfuncs
[i
].func(argc
, argv
);