diff --git a/Source/Core/DSPCore/Src/DSPCodeUtil.cpp b/Source/Core/DSPCore/Src/DSPCodeUtil.cpp index 370e945a12..d2578493b2 100644 --- a/Source/Core/DSPCore/Src/DSPCodeUtil.cpp +++ b/Source/Core/DSPCore/Src/DSPCodeUtil.cpp @@ -66,12 +66,34 @@ bool Compare(const std::vector &code1, const std::vector &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 &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 *code) void CodeToHeader(const std::vector &code, const char *name, std::string *header) { + std::vector 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"); diff --git a/Source/Core/DSPCore/Src/disassemble.cpp b/Source/Core/DSPCore/Src/disassemble.cpp index 4840517fbb..10da8e08c0 100644 --- a/Source/Core/DSPCore/Src/disassemble.cpp +++ b/Source/Core/DSPCore/Src/disassemble.cpp @@ -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; } diff --git a/Source/DSPTool/Src/main.cpp b/Source/DSPTool/Src/main.cpp index d355fc31d5..7df8353956 100644 --- a/Source/DSPTool/Src/main.cpp +++ b/Source/DSPTool/Src/main.cpp @@ -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 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 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)) { diff --git a/Source/DSPTool/Testdata/dsp_test.S b/Source/DSPTool/Testdata/dsp_test.S index 11de8ff33e..8fbbe0cf2e 100644 --- a/Source/DSPTool/Testdata/dsp_test.S +++ b/Source/DSPTool/Testdata/dsp_test.S @@ -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