2020-01-31 03:10:53 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "../ppcemu.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int ntested; /* number of tested instructions */
|
|
|
|
int nfailed; /* number of failed instructions */
|
|
|
|
|
|
|
|
/** testing vehicle */
|
|
|
|
void read_test_data()
|
|
|
|
{
|
|
|
|
string line, token;
|
|
|
|
int i, lineno;
|
|
|
|
uint32_t opcode, dest, src1, src2, check_xer, check_cr;
|
|
|
|
|
|
|
|
ifstream tfstream("ppcinttests.csv");
|
|
|
|
if (!tfstream.is_open()) {
|
|
|
|
cout << "Could not open tests CSV file. Exiting..." << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lineno = 0;
|
|
|
|
|
|
|
|
while(getline(tfstream, line)) {
|
|
|
|
lineno++;
|
|
|
|
|
|
|
|
if (line.empty() || !line.rfind("#", 0))
|
|
|
|
continue; /* skip empty/comment lines */
|
|
|
|
|
|
|
|
istringstream lnstream(line);
|
|
|
|
|
|
|
|
vector<string> tokens;
|
|
|
|
|
|
|
|
while(getline(lnstream, token, ',' )) {
|
|
|
|
tokens.push_back(token);
|
|
|
|
}
|
|
|
|
|
2020-01-31 17:04:50 +00:00
|
|
|
if (tokens.size() < 5) {
|
2020-01-31 03:10:53 +00:00
|
|
|
cout << "Too few values in line " << lineno << ". Skipping..." << endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-01-31 20:53:02 +00:00
|
|
|
opcode = stoul(tokens[1], NULL, 16);
|
2020-01-31 03:10:53 +00:00
|
|
|
|
|
|
|
dest = 0;
|
|
|
|
src1 = 0;
|
|
|
|
src2 = 0;
|
|
|
|
check_xer = 0;
|
|
|
|
check_cr = 0;
|
|
|
|
|
|
|
|
for (i = 2; i < tokens.size(); i++) {
|
|
|
|
if (tokens[i].rfind("rD=", 0) == 0) {
|
2020-01-31 20:53:02 +00:00
|
|
|
dest = stoul(tokens[i].substr(3), NULL, 16);
|
2020-01-31 03:10:53 +00:00
|
|
|
} else if (tokens[i].rfind("rA=", 0) == 0) {
|
2020-01-31 20:53:02 +00:00
|
|
|
src1 = stoul(tokens[i].substr(3), NULL, 16);
|
2020-01-31 03:10:53 +00:00
|
|
|
} else if (tokens[i].rfind("rB=", 0) == 0) {
|
2020-01-31 20:53:02 +00:00
|
|
|
src2 = stoul(tokens[i].substr(3), NULL, 16);
|
2020-01-31 03:10:53 +00:00
|
|
|
} else if (tokens[i].rfind("XER=", 0) == 0) {
|
2020-01-31 20:53:02 +00:00
|
|
|
check_xer = stoul(tokens[i].substr(4), NULL, 16);
|
2020-01-31 03:10:53 +00:00
|
|
|
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
2020-01-31 20:53:02 +00:00
|
|
|
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
2020-01-31 03:10:53 +00:00
|
|
|
} else {
|
|
|
|
cout << "Unknown parameter " << tokens[i] << " in line " << lineno <<
|
|
|
|
". Exiting..." << endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ppc_state.ppc_gpr[3] = src1;
|
|
|
|
ppc_state.ppc_gpr[4] = src2;
|
|
|
|
ppc_state.ppc_spr[SPR::XER] = 0;
|
|
|
|
ppc_state.ppc_cr = 0;
|
|
|
|
|
|
|
|
ppc_cur_instruction = opcode;
|
|
|
|
|
|
|
|
ppc_main_opcode();
|
|
|
|
|
|
|
|
ntested++;
|
|
|
|
|
2020-01-31 17:04:50 +00:00
|
|
|
if ((tokens[0].rfind("CMP") && (ppc_state.ppc_gpr[3] != dest)) ||
|
2020-01-31 03:10:53 +00:00
|
|
|
(ppc_state.ppc_spr[SPR::XER] != check_xer) ||
|
|
|
|
(ppc_state.ppc_cr != check_cr)) {
|
|
|
|
cout << "Mismatch: instr=" << tokens[0] << ", src1=0x" << hex << src1
|
|
|
|
<< ", src2=0x" << hex << src2 << endl;
|
|
|
|
cout << "expected: dest=0x" << hex << dest << ", XER=0x" << hex
|
|
|
|
<< check_xer << ", CR=0x" << hex << check_cr << endl;
|
|
|
|
cout << "got: dest=0x" << hex << ppc_state.ppc_gpr[3] << ", XER=0x"
|
|
|
|
<< hex << ppc_state.ppc_spr[SPR::XER] << ", CR=0x" << hex
|
2020-01-31 17:04:50 +00:00
|
|
|
<< ppc_state.ppc_cr << endl << endl;
|
2020-01-31 03:10:53 +00:00
|
|
|
|
|
|
|
nfailed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
|
|
|
|
|
|
|
cout << "Testing integer instructions:" << endl;
|
|
|
|
|
|
|
|
nfailed = 0;
|
|
|
|
|
|
|
|
read_test_data();
|
|
|
|
|
|
|
|
cout << "... completed." << endl;
|
|
|
|
cout << "--> Tested instructions: " << dec << ntested << endl;
|
|
|
|
cout << "--> Failed: " << dec << nfailed << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|