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());
|
||||
int count_equal = 0;
|
||||
const int min_size = (int)std::min(code1.size(), code2.size());
|
||||
|
||||
AssemblerSettings settings;
|
||||
DSPDisassembler disassembler(settings);
|
||||
for (int i = 0; i < min_size; i++)
|
||||
{
|
||||
if (code1[i] == code2[i])
|
||||
count_equal++;
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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];
|
||||
header->clear();
|
||||
header->reserve(code.size() * 4);
|
||||
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("#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("#endif\n\n ");
|
||||
for (int i = 0; i < code.size(); i++)
|
||||
{
|
||||
if (((i + 1) & 15) == 0)
|
||||
if (i && ((i & 15) == 0))
|
||||
header->append("\n ");
|
||||
sprintf(buffer, "%02x, ", code[i]);
|
||||
sprintf(buffer, "0x%04x, ", code[i]);
|
||||
header->append(buffer);
|
||||
}
|
||||
header->append("\n};\n");
|
||||
|
|
|
@ -200,6 +200,7 @@ void DSPDisassembler::DisOpcode(const u16 *binbuf, int pass, u16 *pc, std::strin
|
|||
if ((*pc & 0x7fff) >= 0x1000)
|
||||
{
|
||||
*pc++;
|
||||
dest->append("; outside memory");
|
||||
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);
|
||||
code.push_back(dsp_test[i] & 0xFFFF);
|
||||
}
|
||||
std::vector<u16> code;
|
||||
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");
|
||||
RoundTrip(code);*/
|
||||
SaveBinary(code, "dsp_test2.bin");
|
||||
RoundTrip(code);
|
||||
}*/
|
||||
//if (Compare(code, hermes))
|
||||
// printf("Successs\n");
|
||||
/*
|
||||
|
@ -216,6 +219,7 @@ int main(int argc, const char *argv[])
|
|||
std::string output_name;
|
||||
|
||||
bool disassemble = false;
|
||||
bool compare = false;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!strcmp(argv[i], "-d"))
|
||||
|
@ -224,6 +228,8 @@ int main(int argc, const char *argv[])
|
|||
output_name = argv[++i];
|
||||
else if (!strcmp(argv[i], "-h"))
|
||||
output_header_name = argv[++i];
|
||||
else if (!strcmp(argv[i], "-c"))
|
||||
compare = true;
|
||||
else
|
||||
{
|
||||
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 (input_name.empty())
|
||||
{
|
||||
printf("Must specify input.\n");
|
||||
printf("Disassemble: Must specify input.\n");
|
||||
return 1;
|
||||
}
|
||||
std::string binary_code;
|
||||
|
@ -248,10 +267,18 @@ int main(int argc, const char *argv[])
|
|||
BinaryStringBEToCode(binary_code, &code);
|
||||
std::string 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
|
||||
{
|
||||
if (input_name.empty())
|
||||
{
|
||||
printf("Assemble: Must specify input.\n");
|
||||
return 1;
|
||||
}
|
||||
std::string source;
|
||||
if (File::ReadFileToString(true, input_name.c_str(), &source))
|
||||
{
|
||||
|
|
|
@ -429,15 +429,15 @@ do_dma:
|
|||
sr @DSBL, $r1a
|
||||
wait_dma:
|
||||
LRS $ACL1, @DSCR
|
||||
andf $acl1, #0x0004
|
||||
JNZ wait_dma
|
||||
andcf $acl1, #0x0004
|
||||
JLZ wait_dma
|
||||
RET
|
||||
|
||||
|
||||
wait_for_dsp_mbox:
|
||||
lrs $ACL1, @DMBH
|
||||
andf $acl1, #0x8000
|
||||
jnz wait_for_dsp_mbox
|
||||
andcf $acl1, #0x8000
|
||||
jlz wait_for_dsp_mbox
|
||||
ret
|
||||
|
||||
wait_for_cpu_mbox:
|
||||
|
@ -489,8 +489,8 @@ irq7:
|
|||
|
||||
irq:
|
||||
lrs $ACL1, @DMBH
|
||||
andf $acl1, #0x8000
|
||||
jnz irq
|
||||
andcf $acl1, #0x8000
|
||||
jlz irq
|
||||
si @DMBH, #0x8BAD
|
||||
sr @DMBL, $r0b
|
||||
;sr @DMBL, $acl0
|
||||
|
|
Loading…
Reference in New Issue