forked from stephand/ptlsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptlctl.cpp
67 lines (54 loc) · 1.6 KB
/
ptlctl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// PTLsim: Cycle Accurate x86-64 Simulator
// Control program used inside target virtual machine
//
// Copyright 2006-2008 Matt T. Yourst <yourst@yourst.com>
//
#include <globals.h>
#include <superstl.h>
#include <config.h>
#include <logic.h>
#include <signal.h>
#include <errno.h>
#include <ptlcalls.h>
//
// Expand one command list,
//
int main(int argc, char* argv[]) {
argc--; argv++;
if (!argc) {
// Just get the PTLsim hypervisor version
if (check_ptlcall_insn()) {
if (check_running_under_ptlsim())
cout << "Currently running on PTLsim virtual CPU", endl;
else cout << "Currently running in native mode", endl;
} else {
cout << "Not running under PTLsim hypervisor", endl;
}
return 0;
}
if (strequal(argv[0], "-marker")) {
W64 marker = (argc > 1) ? atoll(argv[1]) : 0;
cout << "Making PTLsim marker '", marker, "'...", flush;
int rc = ptlcall_marker(marker);
cout << "rc = ", rc, endl;
return 0;
}
bool flushing = 0;
foreach (i, argc) { flushing |= strequal(argv[i], "-flush"); }
// Default behavior: always flush when we run this interactively:
flushing = 1;
dynarray<char*> list;
expand_command_list(list, argc, argv);
cout << "Sending ", (flushing ? "flush and" : ""), " command list to PTLsim hypervisor:", endl, flush;
foreach (i, list.length) {
cout << " ", list[i], endl, flush;
}
int rc = ptlcall_multi(list, list.length, flushing);
if (rc == -ENOSYS) {
cerr << "ptlctl: Not running under PTLsim", endl, endl, flush;
} else {
cerr << "PTLsim returned rc ", rc, endl, endl, flush;
}
return 0;
}