-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvp.c
executable file
·156 lines (134 loc) · 2.86 KB
/
pvp.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "guest.h"
#include "pmem.h"
#include "rom.h"
#include "ppc-defs.h"
#include "term.h"
#include "mon.h"
#include "disk.h"
#define ENTER_MON_MSG "waiting for monitor"
static bool cpu_little_endian = false;
const char *fdt_path = "pvp.dtb";
void
usage(int argc, char **argv)
{
bool do_help = false;
while (1) {
int c;
opterr = 0;
c = getopt(argc, argv, "F:L");
if (c == -1) {
break;
} else if (c == '?') {
do_help = true;
break;
}
switch (c) {
case 'F':
fdt_path = optarg;
break;
case 'L':
cpu_little_endian = true;
break;
}
}
if (!do_help) {
return;
}
fprintf(stderr, "Usage: %s [-L] [-F fdt.dtb]\n", argv[0]);
exit(1);
}
int
main(int argc, char **argv)
{
err_t err;
usage(argc, argv);
err = guest_init(cpu_little_endian, MB(32));
ON_ERROR("guest_init", err, out);
err = term_init();
ON_ERROR("term_init", err, out);
err = rom_init(fdt_path);
ON_ERROR("rom_init", err, out);
err = mon_init();
ON_ERROR("mon_init", err, out);
LOG("Switching to guest virtual machine TI 0x%x",
guest->vmm->thread_index);
while (1) {
vmm_return_code_t vmm_ret;
vmm_ret = vmm_call(kVmmExecuteVM, guest->vmm->thread_index);
switch (vmm_ret) {
case kVmmReturnNull:
break;
case kVmmBogusContext:
goto unhandled;
case kVmmStopped:
goto unhandled;
case kVmmReturnDataPageFault:
case kVmmReturnInstrPageFault:
err = guest_fault(vmm_ret == kVmmReturnInstrPageFault);
if (err != ERR_NONE) {
goto unhandled;
}
break;
case kVmmReturnAlignmentFault:
goto unhandled;
case kVmmReturnProgramException:
err = guest_emulate();
if (err != ERR_NONE) {
goto unhandled;
}
break;
case kVmmReturnTraceException:
goto unhandled;
case kVmmAltivecAssist:
goto unhandled;
case kVmmInvalidAdSpace:
goto unhandled;
case kVmmReturnSystemCall:
err = rom_call();
if (err == ERR_SHUTDOWN) {
goto stop;
} else if (err != ERR_NONE) {
ERROR(err, "rom_call");
goto unhandled;
}
break;
default:
goto unhandled;
}
err = mon_trace();
if (err == ERR_SHUTDOWN) {
goto stop;
}
if (err != ERR_NONE) {
goto unhandled;
}
err = mon_check();
if (err == ERR_SHUTDOWN) {
goto stop;
}
if (err != ERR_NONE && err != ERR_CONTINUE) {
goto unhandled;
}
continue;
unhandled:
if (err != ERR_NONE) {
ERROR(err, ENTER_MON_MSG);
} else if (vmm_ret != kVmmReturnNull) {
VMM_ERROR(vmm_ret, ENTER_MON_MSG);
}
if (mon_activate() != ERR_NONE) {
break;
}
}
stop:
LOG("Requested VM stop");
guest_bye();
disk_bye();
term_bye();
mon_bye();
out:
if (err == ERR_NONE) {
return 0;
}
return 1;
}