DSPtool: Better code comparer + cmdline interface added. header generator bugfixed. dsp_test.S now matches the binary.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2994 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e7e4ef4481
commit
ee933cb5d4
|
@ -66,12 +66,34 @@ bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2)
|
||||||
printf("Size difference! 1=%i 2=%i\n", (int)code1.size(), (int)code2.size());
|
printf("Size difference! 1=%i 2=%i\n", (int)code1.size(), (int)code2.size());
|
||||||
int count_equal = 0;
|
int count_equal = 0;
|
||||||
const int min_size = (int)std::min(code1.size(), code2.size());
|
const int min_size = (int)std::min(code1.size(), code2.size());
|
||||||
|
|
||||||
|
AssemblerSettings settings;
|
||||||
|
DSPDisassembler disassembler(settings);
|
||||||
for (int i = 0; i < min_size; i++)
|
for (int i = 0; i < min_size; i++)
|
||||||
{
|
{
|
||||||
if (code1[i] == code2[i])
|
if (code1[i] == code2[i])
|
||||||
count_equal++;
|
count_equal++;
|
||||||
else
|
else
|
||||||
printf("!! %04x : %04x vs %04x\n", i, code1[i], code2[i]);
|
{
|
||||||
|
std::string line1, line2;
|
||||||
|
u16 pc = i;
|
||||||
|
disassembler.DisOpcode(&code1[0], 2, &pc, &line1);
|
||||||
|
pc = i;
|
||||||
|
disassembler.DisOpcode(&code2[0], 2, &pc, &line2);
|
||||||
|
printf("!! %04x : %04x vs %04x - %s vs %s\n", i, code1[i], code2[i], line1.c_str(), line2.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (code2.size() != code1.size())
|
||||||
|
{
|
||||||
|
printf("Extra code words:\n");
|
||||||
|
const std::vector<u16> &longest = code1.size() > code2.size() ? code1 : code2;
|
||||||
|
for (int i = min_size; i < longest.size(); i++)
|
||||||
|
{
|
||||||
|
u16 pc = i;
|
||||||
|
std::string line;
|
||||||
|
disassembler.DisOpcode(&longest[0], 2, &pc, &line);
|
||||||
|
printf("!! %s\n", line.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf("Equal instruction words: %i / %i\n", count_equal, min_size);
|
printf("Equal instruction words: %i / %i\n", count_equal, min_size);
|
||||||
return code1.size() == code2.size() && code1.size() == count_equal;
|
return code1.size() == code2.size() && code1.size() == count_equal;
|
||||||
|
@ -88,21 +110,25 @@ void GenRandomCode(int size, std::vector<u16> *code)
|
||||||
|
|
||||||
void CodeToHeader(const std::vector<u16> &code, const char *name, std::string *header)
|
void CodeToHeader(const std::vector<u16> &code, const char *name, std::string *header)
|
||||||
{
|
{
|
||||||
|
std::vector<u16> code_copy = code;
|
||||||
|
// Add some nops at the end to align the size a bit.
|
||||||
|
while (code_copy.size() & 7)
|
||||||
|
code_copy.push_back(0);
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
header->clear();
|
header->clear();
|
||||||
header->reserve(code.size() * 4);
|
header->reserve(code.size() * 4);
|
||||||
header->append("#ifndef _MSCVER\n");
|
header->append("#ifndef _MSCVER\n");
|
||||||
sprintf(buffer, "const __declspec(align:64) unsigned short %s = {\n");
|
sprintf(buffer, "const unsigned short %s = {\n", name);
|
||||||
header->append(buffer);
|
header->append(buffer);
|
||||||
header->append("#else\n");
|
header->append("#else\n");
|
||||||
sprintf(buffer, "const unsigned short %s __attribute__(aligned:64) = {\n");
|
sprintf(buffer, "const unsigned short %s __attribute__ ((aligned (64))) = {\n", name);
|
||||||
header->append(buffer);
|
header->append(buffer);
|
||||||
header->append("#endif\n\n ");
|
header->append("#endif\n\n ");
|
||||||
for (int i = 0; i < code.size(); i++)
|
for (int i = 0; i < code.size(); i++)
|
||||||
{
|
{
|
||||||
if (((i + 1) & 15) == 0)
|
if (i && ((i & 15) == 0))
|
||||||
header->append("\n ");
|
header->append("\n ");
|
||||||
sprintf(buffer, "%02x, ", code[i]);
|
sprintf(buffer, "0x%04x, ", code[i]);
|
||||||
header->append(buffer);
|
header->append(buffer);
|
||||||
}
|
}
|
||||||
header->append("\n};\n");
|
header->append("\n};\n");
|
||||||
|
|
|
@ -200,6 +200,7 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::strin
|
||||||
if ((*pc & 0x7fff) >= 0x1000)
|
if ((*pc & 0x7fff) >= 0x1000)
|
||||||
{
|
{
|
||||||
*pc++;
|
*pc++;
|
||||||
|
dest->append("; outside memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,15 +144,18 @@ void RunAsmTests()
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
code.clear();
|
|
||||||
for (int i = 0; i < sizeof(dsp_test)/4; i++)
|
|
||||||
{
|
{
|
||||||
code.push_back(dsp_test[i] >> 16);
|
std::vector<u16> code;
|
||||||
code.push_back(dsp_test[i] & 0xFFFF);
|
code.clear();
|
||||||
}
|
for (int i = 0; i < sizeof(dsp_test)/4; i++)
|
||||||
|
{
|
||||||
|
code.push_back(dsp_test[i] >> 16);
|
||||||
|
code.push_back(dsp_test[i] & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
SaveBinary(code, "dsp_test.bin");
|
SaveBinary(code, "dsp_test2.bin");
|
||||||
RoundTrip(code);*/
|
RoundTrip(code);
|
||||||
|
}*/
|
||||||
//if (Compare(code, hermes))
|
//if (Compare(code, hermes))
|
||||||
// printf("Successs\n");
|
// printf("Successs\n");
|
||||||
/*
|
/*
|
||||||
|
@ -216,6 +219,7 @@ int main(int argc, const char *argv[])
|
||||||
std::string output_name;
|
std::string output_name;
|
||||||
|
|
||||||
bool disassemble = false;
|
bool disassemble = false;
|
||||||
|
bool compare = false;
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (!strcmp(argv[i], "-d"))
|
if (!strcmp(argv[i], "-d"))
|
||||||
|
@ -224,6 +228,8 @@ int main(int argc, const char *argv[])
|
||||||
output_name = argv[++i];
|
output_name = argv[++i];
|
||||||
else if (!strcmp(argv[i], "-h"))
|
else if (!strcmp(argv[i], "-h"))
|
||||||
output_header_name = argv[++i];
|
output_header_name = argv[++i];
|
||||||
|
else if (!strcmp(argv[i], "-c"))
|
||||||
|
compare = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!input_name.empty())
|
if (!input_name.empty())
|
||||||
|
@ -235,11 +241,24 @@ int main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (compare)
|
||||||
|
{
|
||||||
|
// Two binary inputs, let's diff.
|
||||||
|
std::string binary_code;
|
||||||
|
std::vector<u16> code1, code2;
|
||||||
|
File::ReadFileToString(false, input_name.c_str(), &binary_code);
|
||||||
|
BinaryStringBEToCode(binary_code, &code1);
|
||||||
|
File::ReadFileToString(false, output_name.c_str(), &binary_code);
|
||||||
|
BinaryStringBEToCode(binary_code, &code2);
|
||||||
|
Compare(code1, code2);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (disassemble)
|
if (disassemble)
|
||||||
{
|
{
|
||||||
if (input_name.empty())
|
if (input_name.empty())
|
||||||
{
|
{
|
||||||
printf("Must specify input.\n");
|
printf("Disassemble: Must specify input.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::string binary_code;
|
std::string binary_code;
|
||||||
|
@ -248,10 +267,18 @@ int main(int argc, const char *argv[])
|
||||||
BinaryStringBEToCode(binary_code, &code);
|
BinaryStringBEToCode(binary_code, &code);
|
||||||
std::string text;
|
std::string text;
|
||||||
Disassemble(code, true, &text);
|
Disassemble(code, true, &text);
|
||||||
File::WriteStringToFile(true, text, output_name.c_str());
|
if (!output_name.empty())
|
||||||
|
File::WriteStringToFile(true, text, output_name.c_str());
|
||||||
|
else
|
||||||
|
printf("%s", text.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (input_name.empty())
|
||||||
|
{
|
||||||
|
printf("Assemble: Must specify input.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
std::string source;
|
std::string source;
|
||||||
if (File::ReadFileToString(true, input_name.c_str(), &source))
|
if (File::ReadFileToString(true, input_name.c_str(), &source))
|
||||||
{
|
{
|
||||||
|
|
|
@ -429,15 +429,15 @@ do_dma:
|
||||||
sr @DSBL, $r1a
|
sr @DSBL, $r1a
|
||||||
wait_dma:
|
wait_dma:
|
||||||
LRS $ACL1, @DSCR
|
LRS $ACL1, @DSCR
|
||||||
andf $acl1, #0x0004
|
andcf $acl1, #0x0004
|
||||||
JNZ wait_dma
|
JLZ wait_dma
|
||||||
RET
|
RET
|
||||||
|
|
||||||
|
|
||||||
wait_for_dsp_mbox:
|
wait_for_dsp_mbox:
|
||||||
lrs $ACL1, @DMBH
|
lrs $ACL1, @DMBH
|
||||||
andf $acl1, #0x8000
|
andcf $acl1, #0x8000
|
||||||
jnz wait_for_dsp_mbox
|
jlz wait_for_dsp_mbox
|
||||||
ret
|
ret
|
||||||
|
|
||||||
wait_for_cpu_mbox:
|
wait_for_cpu_mbox:
|
||||||
|
@ -489,8 +489,8 @@ irq7:
|
||||||
|
|
||||||
irq:
|
irq:
|
||||||
lrs $ACL1, @DMBH
|
lrs $ACL1, @DMBH
|
||||||
andf $acl1, #0x8000
|
andcf $acl1, #0x8000
|
||||||
jnz irq
|
jlz irq
|
||||||
si @DMBH, #0x8BAD
|
si @DMBH, #0x8BAD
|
||||||
sr @DMBL, $r0b
|
sr @DMBL, $r0b
|
||||||
;sr @DMBL, $acl0
|
;sr @DMBL, $acl0
|
||||||
|
|
Loading…
Reference in New Issue