-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppc_exc.cpp
More file actions
152 lines (141 loc) · 5.86 KB
/
ppc_exc.cpp
File metadata and controls
152 lines (141 loc) · 5.86 KB
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
#include "source.h"
#include "ppc_exc.h"
PPC_exc::PPC_exc(
RAM& global_ram,
int start_address,
unordered_map<string, int> starting_int_registers,
unordered_map<string, double> starting_double_registers
) : ram(global_ram) {
current_address = start_address;
int_registers = starting_int_registers;
double_registers = starting_double_registers;
}
void PPC_exc::execute() {
//sanity checks
assert(sizeof(unsigned char) == 1);
assert(sizeof(int) == 4);
assert(sizeof(float) == 4);
assert(sizeof(double) == 8);
assert(sizeof(long long) == 8);
while (!end_reached) {
//breakpoint = 0x80188588;
if (current_address == breakpoint) {
debug = true;
}
if (debug) {
print_current_line();
cout << "press Enter to run line\n";
string enter;
getline(cin, enter);
}
string code = source[current_address];
replace(code.begin(), code.end(), ',', ' ');
stringstream f_args(code);
current_address += 4;
string f_name;
f_args >> f_name;
if (f_name == "add") { add(f_args); }
else if (f_name == "addi") { addi(f_args); }
else if (f_name == "b") { b(f_args); }
else if (f_name == "bdnz" or f_name == "bdnz-" or f_name == "bdnz+") { bdnz(f_args); }
else if (f_name == "beq" or f_name == "beq-" or f_name == "beq+") { beq(f_args); }
else if (f_name == "beqlr" or f_name == "beqlr-" or f_name == "beqlr+") { beqlr(f_args); }
else if (f_name == "bge" or f_name == "bge-" or f_name == "bge+") { bge(f_args); }
else if (f_name == "bgt" or f_name == "bgt-" or f_name == "bgt+") { bgt(f_args); }
else if (f_name == "bl") { bl(f_args); }
else if (f_name == "ble" or f_name == "ble-" or f_name == "ble+") { ble(f_args); }
else if (f_name == "blr") { blr(f_args); }
else if (f_name == "blt" or f_name == "blt-" or f_name == "blt+") { blt(f_args); }
else if (f_name == "bne" or f_name == "bne-" or f_name == "bne+") { bne(f_args); }
else if (f_name == "cmplw") { cmplw(f_args); }
else if (f_name == "cmplwi") { cmplwi(f_args); }
else if (f_name == "cmpw") { cmpw(f_args); }
else if (f_name == "cmpwi") { cmpwi(f_args); }
else if (f_name == "cror") { cror(f_args); }
else if (f_name == "end") { end_reached = true; }
else if (f_name == "fabs") { fabs(f_args); }
else if (f_name == "fadd") { fadd(f_args, false); }
else if (f_name == "fadds") { fadd(f_args, true); }
else if (f_name == "fcmpo") { fcmp(f_args); }
else if (f_name == "fcmpu") { fcmp(f_args); }
else if (f_name == "fctiwz") { fctiwz(f_args); }
else if (f_name == "fdiv") { fdiv(f_args, false); }
else if (f_name == "fdivs") { fdiv(f_args, true); }
else if (f_name == "fmadd") { fmadd(f_args, false); }
else if (f_name == "fmadds") {fmadd(f_args, true); }
else if (f_name == "fmr") { fmr(f_args); }
else if (f_name == "fmsub") { fmsub(f_args); }
else if (f_name == "fmul") { fmul(f_args, false); }
else if (f_name == "fmuls") { fmul(f_args, true); }
else if (f_name == "fneg") { fneg(f_args);}
else if (f_name == "fnmsub") { fnmsub(f_args, false); }
else if (f_name == "fnmsubs") { fnmsub(f_args, true); }
else if (f_name == "frsp") { frsp(f_args); }
else if (f_name == "frsqrte") { frsqrte(f_args); }
else if (f_name == "fsub") { fsub(f_args, false); }
else if (f_name == "fsubs") { fsub(f_args, true); }
else if (f_name == "lbz") { lbz(f_args, false); }
else if (f_name == "lbzu") { lbz(f_args, true); }
else if (f_name == "lfd") { lfd(f_args); }
else if (f_name == "lfdx") { lfdx(f_args); }
else if (f_name == "lfs") { lfs(f_args); }
else if (f_name == "li") { li(f_args); }
else if (f_name == "lis") { lis(f_args); }
else if (f_name == "lwz") { lwz(f_args); }
else if (f_name == "mflr") { mflr(f_args); }
else if (f_name == "mr") { mr(f_args, false); }
else if (f_name == "mr.") { mr(f_args, true); }
else if (f_name == "mtctr") { mtctr(f_args); }
else if (f_name == "mtlr") { mtlr(f_args); }
else if (f_name == "mulli") { mulli(f_args); }
else if (f_name == "neg") { neg(f_args); }
else if (f_name == "or") { or_f(f_args, false); }
else if (f_name == "or.") { or_f(f_args, true); }
else if (f_name == "oris") { oris(f_args);}
else if (f_name == "ps_add") { ps_add(f_args); }
else if (f_name == "ps_madd") { ps_madd(f_args); }
else if (f_name == "ps_mul") { ps_mul(f_args); }
else if (f_name == "ps_muls0") { ps_muls0(f_args); }
else if (f_name == "ps_sub") { ps_sub(f_args); }
else if (f_name == "ps_sum0") { ps_sum0(f_args); }
else if (f_name == "psq_l") { psq_l(f_args); }
else if (f_name == "psq_st") { psq_st(f_args); }
else if (f_name == "rlwimi") { rlwimi(f_args); }
else if (f_name == "rlwinm") { rlwinm(f_args, false); }
else if (f_name == "rlwinm.") { rlwinm(f_args, true); }
else if (f_name == "srawi") { srawi(f_args); }
else if (f_name == "stb") { stb(f_args, false); }
else if (f_name == "stbu") { stb(f_args, true); }
else if (f_name == "stfd") { stfd(f_args); }
else if (f_name == "stfs") { stfs(f_args); }
else if (f_name == "stw") { stw(f_args, false); }
else if (f_name == "stwu") { stw(f_args, true); }
else if (f_name == "sub") { sub(f_args, false); }
else if (f_name == "sub.") { sub(f_args, true); }
else if (f_name == "subi") { subi(f_args); }
else if (f_name == "subic") { subic(f_args, false); }
else if (f_name == "subic.") { subic(f_args, true); }
else if (f_name == "subis") { subis(f_args); }
else if (f_name == "xor") { xor_f(f_args); }
else if (f_name == "xoris") { xoris(f_args); }
else {throw f_name; }
if (debug) {
print_registers();
//print_ram();
}
}
}
void PPC_exc::print_current_line() {
cout << hex << current_address << R"(: )" << source[current_address] << '\n';
}
void PPC_exc::print_registers() {
for (auto const& r : int_registers) {
cout << r.first << R"(: )" << hex << r.second << '\n';
}
for (auto const& fr : double_registers) {
long long val;
memcpy(&val, &fr.second, 8);
cout << fr.first << R"(: )" << hex << val << '\n';
}
cout << '\n';
}