2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2018-06-22 20:32:53 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-10-12 02:21:51 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2018-06-22 20:32:53 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-19 18:52:31 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "Core/DSP/DSPCodeUtil.h"
|
2017-05-20 00:07:26 +00:00
|
|
|
#include "Core/DSP/DSPDisassembler.h"
|
2014-03-09 17:00:51 +00:00
|
|
|
#include "Core/DSP/DSPHost.h"
|
2014-02-19 18:52:31 +00:00
|
|
|
#include "Core/DSP/DSPTables.h"
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2009-04-12 10:21:40 +00:00
|
|
|
// Stub out the dsplib host stuff, since this is just a simple cmdline tools.
|
2016-12-30 18:25:40 +00:00
|
|
|
u8 DSP::Host::ReadHostMemory(u32 addr)
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-30 18:25:40 +00:00
|
|
|
void DSP::Host::WriteHostMemory(u8 value, u32 addr)
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
|
|
|
}
|
2020-04-08 21:25:33 +00:00
|
|
|
void DSP::Host::DMAToDSP(u16* dst, u32 addr, u32 size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void DSP::Host::DMAFromDSP(const u16* src, u32 addr, u32 size)
|
|
|
|
{
|
|
|
|
}
|
2019-07-29 02:46:08 +00:00
|
|
|
void DSP::Host::OSD_AddMessage(std::string str, u32 ms)
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
|
|
|
}
|
2016-12-30 18:25:40 +00:00
|
|
|
bool DSP::Host::OnThread()
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2014-03-09 17:00:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-30 18:25:40 +00:00
|
|
|
bool DSP::Host::IsWiiHost()
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-21 14:22:06 +00:00
|
|
|
void DSP::Host::CodeLoaded(DSPCore& dsp, u32 addr, size_t size)
|
2020-04-08 21:25:33 +00:00
|
|
|
{
|
|
|
|
}
|
2020-12-21 14:22:06 +00:00
|
|
|
void DSP::Host::CodeLoaded(DSPCore& dsp, const u8* ptr, size_t size)
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
|
|
|
}
|
2016-12-30 18:25:40 +00:00
|
|
|
void DSP::Host::InterruptRequest()
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
|
|
|
}
|
2016-12-30 18:25:40 +00:00
|
|
|
void DSP::Host::UpdateDebugger()
|
2014-03-09 17:00:51 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2018-06-22 20:44:32 +00:00
|
|
|
static std::string CodeToHeader(const std::vector<u16>& code, const std::string& filename)
|
2017-05-20 02:18:17 +00:00
|
|
|
{
|
|
|
|
std::vector<u16> code_padded = code;
|
2018-06-22 20:44:32 +00:00
|
|
|
|
2017-05-20 02:18:17 +00:00
|
|
|
// Pad with nops to 32byte boundary
|
|
|
|
while (code_padded.size() & 0x7f)
|
|
|
|
code_padded.push_back(0);
|
2018-06-22 20:44:32 +00:00
|
|
|
|
|
|
|
std::string header;
|
2017-05-20 02:18:17 +00:00
|
|
|
header.reserve(code_padded.size() * 4);
|
|
|
|
header.append("#define NUM_UCODES 1\n\n");
|
|
|
|
std::string filename_without_extension;
|
|
|
|
SplitPath(filename, nullptr, &filename_without_extension, nullptr);
|
2022-10-12 02:21:51 +00:00
|
|
|
header.append(fmt::format("const char* UCODE_NAMES[NUM_UCODES] = {{\"{}\"}};\n\n",
|
|
|
|
filename_without_extension));
|
2023-01-23 23:30:49 +00:00
|
|
|
header.append("alignas(0x20) const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n");
|
2017-05-20 02:18:17 +00:00
|
|
|
|
|
|
|
header.append("\t{\n\t\t");
|
|
|
|
for (u32 j = 0; j < code_padded.size(); j++)
|
|
|
|
{
|
|
|
|
if (j && ((j & 15) == 0))
|
|
|
|
header.append("\n\t\t");
|
2022-10-12 02:21:51 +00:00
|
|
|
header.append(fmt::format("{:#06x}, ", code_padded[j]));
|
2017-05-20 02:18:17 +00:00
|
|
|
}
|
|
|
|
header.append("\n\t},\n");
|
|
|
|
|
|
|
|
header.append("};\n");
|
2018-06-22 20:44:32 +00:00
|
|
|
return header;
|
2017-05-20 02:18:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 20:56:57 +00:00
|
|
|
static std::string CodesToHeader(const std::vector<std::vector<u16>>& codes,
|
|
|
|
const std::vector<std::string>& filenames)
|
2017-05-20 02:18:17 +00:00
|
|
|
{
|
|
|
|
std::vector<std::vector<u16>> codes_padded;
|
2018-06-22 20:56:57 +00:00
|
|
|
std::size_t reserve_size = 0;
|
|
|
|
for (std::size_t i = 0; i < codes.size(); i++)
|
2017-05-20 02:18:17 +00:00
|
|
|
{
|
|
|
|
codes_padded.push_back(codes[i]);
|
|
|
|
// Pad with nops to 32byte boundary
|
2018-06-22 20:56:57 +00:00
|
|
|
while (codes_padded[i].size() & 0x7f)
|
|
|
|
codes_padded[i].push_back(0);
|
2017-05-20 02:18:17 +00:00
|
|
|
|
2018-06-22 20:56:57 +00:00
|
|
|
reserve_size += codes_padded[i].size();
|
2017-05-20 02:18:17 +00:00
|
|
|
}
|
2018-06-22 20:44:32 +00:00
|
|
|
|
|
|
|
std::string header;
|
2018-06-22 20:56:57 +00:00
|
|
|
header.reserve(reserve_size * 4);
|
2022-10-12 02:21:51 +00:00
|
|
|
header.append(fmt::format("#define NUM_UCODES {}\n\n", codes.size()));
|
2017-05-20 02:18:17 +00:00
|
|
|
header.append("const char* UCODE_NAMES[NUM_UCODES] = {\n");
|
2018-06-22 20:56:57 +00:00
|
|
|
for (const std::string& in_filename : filenames)
|
2017-05-20 02:18:17 +00:00
|
|
|
{
|
|
|
|
std::string filename;
|
2018-06-22 20:56:57 +00:00
|
|
|
if (!SplitPath(in_filename, nullptr, &filename, nullptr))
|
|
|
|
filename = in_filename;
|
2022-10-12 02:21:51 +00:00
|
|
|
header.append(fmt::format("\t\"{}\",\n", filename));
|
2017-05-20 02:18:17 +00:00
|
|
|
}
|
|
|
|
header.append("};\n\n");
|
|
|
|
header.append("const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n");
|
|
|
|
|
2018-06-22 20:56:57 +00:00
|
|
|
for (std::size_t i = 0; i < codes.size(); i++)
|
2017-05-20 02:18:17 +00:00
|
|
|
{
|
2018-06-22 20:56:57 +00:00
|
|
|
if (codes[i].empty())
|
2017-05-20 02:18:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
header.append("\t{\n\t\t");
|
2018-06-22 20:56:57 +00:00
|
|
|
for (std::size_t j = 0; j < codes_padded[i].size(); j++)
|
2017-05-20 02:18:17 +00:00
|
|
|
{
|
|
|
|
if (j && ((j & 15) == 0))
|
|
|
|
header.append("\n\t\t");
|
2022-10-12 02:21:51 +00:00
|
|
|
header.append(fmt::format("{:#06x}, ", codes_padded[i][j]));
|
2017-05-20 02:18:17 +00:00
|
|
|
}
|
|
|
|
header.append("\n\t},\n");
|
|
|
|
}
|
|
|
|
header.append("};\n");
|
2018-06-22 20:44:32 +00:00
|
|
|
return header;
|
2017-05-20 02:18:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 00:56:49 +00:00
|
|
|
static bool PerformBinaryComparison(const std::string& lhs, const std::string& rhs)
|
2018-06-17 22:05:58 +00:00
|
|
|
{
|
|
|
|
std::string binary_code;
|
|
|
|
|
|
|
|
File::ReadFileToString(lhs, binary_code);
|
|
|
|
const std::vector<u16> code1 = DSP::BinaryStringBEToCode(binary_code);
|
|
|
|
|
|
|
|
File::ReadFileToString(rhs, binary_code);
|
|
|
|
const std::vector<u16> code2 = DSP::BinaryStringBEToCode(binary_code);
|
|
|
|
|
2022-06-14 00:56:49 +00:00
|
|
|
return DSP::Compare(code1, code2);
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintResults(const std::string& input_name, const std::string& output_name,
|
|
|
|
bool print_results_srhack, bool print_results_prodhack)
|
|
|
|
{
|
|
|
|
std::string dumpfile;
|
|
|
|
|
|
|
|
File::ReadFileToString(input_name, dumpfile);
|
|
|
|
const std::vector<u16> reg_vector = DSP::BinaryStringBEToCode(dumpfile);
|
|
|
|
|
|
|
|
std::string results("Start:\n");
|
|
|
|
for (int initial_reg = 0; initial_reg < 32; initial_reg++)
|
|
|
|
{
|
2022-10-12 02:21:51 +00:00
|
|
|
results.append(fmt::format("{:02x} {:04x} ", initial_reg, reg_vector.at(initial_reg)));
|
2018-06-17 22:05:58 +00:00
|
|
|
if ((initial_reg + 1) % 8 == 0)
|
|
|
|
results.append("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
results.append("\n");
|
|
|
|
results.append("Step [number]:\n[Reg] [last value] [current value]\n\n");
|
|
|
|
|
|
|
|
for (unsigned int step = 1; step < reg_vector.size() / 32; step++)
|
|
|
|
{
|
|
|
|
bool changed = false;
|
|
|
|
u16 current_reg;
|
|
|
|
u16 last_reg;
|
|
|
|
u32 htemp;
|
2022-10-12 02:21:51 +00:00
|
|
|
// results.append(fmt::format("Step {:3d}: (CW {:#06x}) UC:{:03d}\n", step, 0x8fff+step,
|
2018-06-17 22:05:58 +00:00
|
|
|
// (step-1)/32));
|
2022-10-12 02:21:51 +00:00
|
|
|
results.append(fmt::format("Step {:3d}:\n", step));
|
2018-06-17 22:05:58 +00:00
|
|
|
for (int reg = 0; reg < 32; reg++)
|
|
|
|
{
|
|
|
|
if (reg >= 0x0c && reg <= 0x0f)
|
|
|
|
continue;
|
|
|
|
if (print_results_srhack && reg == 0x13)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (print_results_prodhack && reg >= 0x15 && reg <= 0x17)
|
|
|
|
{
|
|
|
|
switch (reg)
|
|
|
|
{
|
|
|
|
case 0x15: // DSP_REG_PRODM
|
|
|
|
last_reg =
|
|
|
|
reg_vector.at((step * 32 - 32) + reg) + reg_vector.at((step * 32 - 32) + reg + 2);
|
|
|
|
current_reg = reg_vector.at(step * 32 + reg) + reg_vector.at(step * 32 + reg + 2);
|
|
|
|
break;
|
|
|
|
case 0x16: // DSP_REG_PRODH
|
|
|
|
htemp = ((reg_vector.at(step * 32 + reg - 1) + reg_vector.at(step * 32 + reg + 1)) &
|
|
|
|
~0xffff) >>
|
|
|
|
16;
|
|
|
|
current_reg = (u8)(reg_vector.at(step * 32 + reg) + htemp);
|
|
|
|
htemp =
|
|
|
|
((reg_vector.at(step * 32 - 32 + reg - 1) + reg_vector.at(step * 32 - 32 + reg + 1)) &
|
|
|
|
~0xffff) >>
|
|
|
|
16;
|
|
|
|
last_reg = (u8)(reg_vector.at(step * 32 - 32 + reg) + htemp);
|
|
|
|
break;
|
|
|
|
case 0x17: // DSP_REG_PRODM2
|
|
|
|
default:
|
|
|
|
current_reg = 0;
|
|
|
|
last_reg = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current_reg = reg_vector.at(step * 32 + reg);
|
|
|
|
last_reg = reg_vector.at((step * 32 - 32) + reg);
|
|
|
|
}
|
|
|
|
if (last_reg != current_reg)
|
|
|
|
{
|
2022-10-12 02:21:51 +00:00
|
|
|
results.append(fmt::format("{:02x} {:7s}: {:04x} {:04x}\n", reg, DSP::pdregname(reg),
|
|
|
|
last_reg, current_reg));
|
2018-06-17 22:05:58 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
results.append("\n");
|
|
|
|
else
|
|
|
|
results.append("No Change\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_name.empty())
|
|
|
|
printf("%s", results.c_str());
|
|
|
|
else
|
2019-05-28 21:45:36 +00:00
|
|
|
File::WriteStringToFile(output_name, results);
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool PerformDisassembly(const std::string& input_name, const std::string& output_name)
|
|
|
|
{
|
|
|
|
if (input_name.empty())
|
|
|
|
{
|
|
|
|
printf("Disassemble: Must specify input.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string binary_code;
|
|
|
|
File::ReadFileToString(input_name, binary_code);
|
|
|
|
const std::vector<u16> code = DSP::BinaryStringBEToCode(binary_code);
|
|
|
|
std::string text;
|
|
|
|
DSP::Disassemble(code, true, text);
|
|
|
|
|
|
|
|
if (output_name.empty())
|
|
|
|
printf("%s", text.c_str());
|
|
|
|
else
|
2019-05-28 21:45:36 +00:00
|
|
|
File::WriteStringToFile(output_name, text);
|
2018-06-17 22:05:58 +00:00
|
|
|
|
|
|
|
printf("Disassembly completed successfully!\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:32:53 +00:00
|
|
|
static std::vector<std::string> GetAssemblerFiles(const std::string& source)
|
|
|
|
{
|
|
|
|
std::vector<std::string> files;
|
|
|
|
std::size_t last_pos = 0;
|
|
|
|
std::size_t pos = 0;
|
|
|
|
|
|
|
|
while ((pos = source.find('\n', last_pos)) != std::string::npos)
|
|
|
|
{
|
|
|
|
std::string temp = source.substr(last_pos, pos - last_pos);
|
|
|
|
if (!temp.empty())
|
|
|
|
files.push_back(std::move(temp));
|
|
|
|
last_pos = pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2018-06-17 22:05:58 +00:00
|
|
|
static bool PerformAssembly(const std::string& input_name, const std::string& output_name,
|
|
|
|
const std::string& output_header_name, bool multiple, bool force,
|
|
|
|
bool output_size)
|
|
|
|
{
|
|
|
|
if (input_name.empty())
|
|
|
|
{
|
|
|
|
printf("Assemble: Must specify input.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string source;
|
2018-06-22 20:38:12 +00:00
|
|
|
if (File::ReadFileToString(input_name, source))
|
2018-06-17 22:05:58 +00:00
|
|
|
{
|
|
|
|
if (multiple)
|
|
|
|
{
|
2018-06-22 20:32:53 +00:00
|
|
|
source.append("\n");
|
|
|
|
|
2018-06-17 22:05:58 +00:00
|
|
|
// When specifying a list of files we must compile a header
|
|
|
|
// (we can't assemble multiple files to one binary)
|
|
|
|
// since we checked it before, we assume output_header_name isn't empty
|
2018-06-22 20:32:53 +00:00
|
|
|
std::string currentSource;
|
|
|
|
const std::vector<std::string> files = GetAssemblerFiles(source);
|
2018-06-17 22:05:58 +00:00
|
|
|
|
2018-06-22 21:00:47 +00:00
|
|
|
std::size_t lines = files.size();
|
2018-06-17 22:05:58 +00:00
|
|
|
if (lines == 0)
|
|
|
|
{
|
|
|
|
printf("ERROR: Must specify at least one file\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:56:57 +00:00
|
|
|
std::vector<std::vector<u16>> codes(lines);
|
2018-06-17 22:05:58 +00:00
|
|
|
|
2018-06-22 21:00:47 +00:00
|
|
|
for (std::size_t i = 0; i < lines; i++)
|
2018-06-17 22:05:58 +00:00
|
|
|
{
|
2018-06-22 20:38:12 +00:00
|
|
|
if (!File::ReadFileToString(files[i], currentSource))
|
2018-06-17 22:05:58 +00:00
|
|
|
{
|
|
|
|
printf("ERROR reading %s, skipping...\n", files[i].c_str());
|
|
|
|
lines--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!DSP::Assemble(currentSource, codes[i], force))
|
|
|
|
{
|
|
|
|
printf("Assemble: Assembly of %s failed due to errors\n", files[i].c_str());
|
|
|
|
lines--;
|
|
|
|
}
|
|
|
|
if (output_size)
|
|
|
|
{
|
2018-06-22 21:00:47 +00:00
|
|
|
printf("%s: %zu\n", files[i].c_str(), codes[i].size());
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:56:57 +00:00
|
|
|
const std::string header = CodesToHeader(codes, files);
|
2019-05-28 21:45:36 +00:00
|
|
|
File::WriteStringToFile(output_header_name + ".h", header);
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<u16> code;
|
|
|
|
|
|
|
|
if (!DSP::Assemble(source, code, force))
|
|
|
|
{
|
|
|
|
printf("Assemble: Assembly failed due to errors\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_size)
|
|
|
|
{
|
2018-06-22 21:00:47 +00:00
|
|
|
printf("%s: %zu\n", input_name.c_str(), code.size());
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!output_name.empty())
|
|
|
|
{
|
|
|
|
const std::string binary_code = DSP::CodeToBinaryStringBE(code);
|
2019-05-28 21:45:36 +00:00
|
|
|
File::WriteStringToFile(output_name, binary_code);
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
if (!output_header_name.empty())
|
|
|
|
{
|
2018-06-22 20:44:32 +00:00
|
|
|
const std::string header = CodeToHeader(code, input_name);
|
2019-05-28 21:45:36 +00:00
|
|
|
File::WriteStringToFile(output_header_name + ".h", header);
|
2018-06-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
source.clear();
|
|
|
|
|
|
|
|
if (!output_size)
|
|
|
|
printf("Assembly completed successfully!\n");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-05 07:36:00 +00:00
|
|
|
static bool IsHelpFlag(const std::string& argument)
|
|
|
|
{
|
|
|
|
return argument == "--help" || argument == "-?";
|
|
|
|
}
|
|
|
|
|
2009-04-18 11:31:37 +00:00
|
|
|
// Usage:
|
|
|
|
// Disassemble a file:
|
|
|
|
// dsptool -d -o asdf.txt asdf.bin
|
|
|
|
// Disassemble a file, output to standard output:
|
|
|
|
// dsptool -d asdf.bin
|
|
|
|
// Assemble a file:
|
2009-07-19 20:14:09 +00:00
|
|
|
// dsptool [-f] -o asdf.bin asdf.txt
|
2009-04-18 11:31:37 +00:00
|
|
|
// Assemble a file, output header:
|
2009-07-19 20:14:09 +00:00
|
|
|
// dsptool [-f] -h asdf.h asdf.txt
|
|
|
|
// Print results from DSPSpy register dump
|
|
|
|
// dsptool -p dsp_dump0.bin
|
2009-04-12 10:21:40 +00:00
|
|
|
int main(int argc, const char* argv[])
|
|
|
|
{
|
2018-07-05 07:36:00 +00:00
|
|
|
if (argc == 1 || (argc == 2 && IsHelpFlag(argv[1])))
|
2009-04-22 09:03:06 +00:00
|
|
|
{
|
2009-07-19 20:14:09 +00:00
|
|
|
printf("USAGE: DSPTool [-?] [--help] [-f] [-d] [-m] [-p <FILE>] [-o <FILE>] [-h <FILE>] <DSP "
|
|
|
|
"ASSEMBLER FILE>\n");
|
2009-04-24 15:31:13 +00:00
|
|
|
printf("-? / --help: Prints this message\n");
|
2009-04-22 09:03:06 +00:00
|
|
|
printf("-d: Disassemble\n");
|
2009-06-11 07:11:05 +00:00
|
|
|
printf("-m: Input file contains a list of files (Header assembly only)\n");
|
2009-06-15 16:48:34 +00:00
|
|
|
printf("-s: Print the final size in bytes (only)\n");
|
2009-07-19 20:14:09 +00:00
|
|
|
printf("-f: Force assembly (errors are not critical)\n");
|
2009-04-22 09:03:06 +00:00
|
|
|
printf("-o <OUTPUT FILE>: Results from stdout redirected to a file\n");
|
|
|
|
printf("-h <HEADER FILE>: Output assembly results to a header\n");
|
2009-07-19 20:14:09 +00:00
|
|
|
printf("-p <DUMP FILE>: Print results of DSPSpy register dump\n");
|
2010-03-18 00:18:36 +00:00
|
|
|
printf("-ps <DUMP FILE>: Print results of DSPSpy register dump (disable SR output)\n");
|
|
|
|
printf("-pm <DUMP FILE>: Print results of DSPSpy register dump (convert PROD values)\n");
|
|
|
|
printf("-psm <DUMP FILE>: Print results of DSPSpy register dump (convert PROD values/disable "
|
|
|
|
"SR output)\n");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-04-22 09:03:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-04-18 11:31:37 +00:00
|
|
|
std::string input_name;
|
|
|
|
std::string output_header_name;
|
|
|
|
std::string output_name;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-03-18 00:18:36 +00:00
|
|
|
bool disassemble = false, compare = false, multiple = false, outputSize = false, force = false,
|
|
|
|
print_results = false, print_results_prodhack = false, print_results_srhack = false;
|
2009-04-18 11:31:37 +00:00
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
2018-07-05 07:36:00 +00:00
|
|
|
const std::string argument = argv[i];
|
|
|
|
if (argument == "-d")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
2009-04-18 11:31:37 +00:00
|
|
|
disassemble = true;
|
2019-06-23 18:32:32 +00:00
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-o")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
|
|
|
if (++i < argc)
|
|
|
|
output_name = argv[i];
|
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-h")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
|
|
|
if (++i < argc)
|
|
|
|
output_header_name = argv[i];
|
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-c")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
2009-04-18 12:27:24 +00:00
|
|
|
compare = true;
|
2019-06-23 18:32:32 +00:00
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-s")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
2009-06-15 16:48:34 +00:00
|
|
|
outputSize = true;
|
2019-06-23 18:32:32 +00:00
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-m")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
2009-06-11 07:11:05 +00:00
|
|
|
multiple = true;
|
2019-06-23 18:32:32 +00:00
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-f")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
2009-07-19 10:08:25 +00:00
|
|
|
force = true;
|
2019-06-23 18:32:32 +00:00
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-p")
|
2019-06-23 18:32:32 +00:00
|
|
|
{
|
2009-07-19 20:14:09 +00:00
|
|
|
print_results = true;
|
2019-06-23 18:32:32 +00:00
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-ps")
|
2010-03-18 00:18:36 +00:00
|
|
|
{
|
|
|
|
print_results = true;
|
|
|
|
print_results_srhack = true;
|
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-pm")
|
2010-03-18 00:18:36 +00:00
|
|
|
{
|
|
|
|
print_results = true;
|
|
|
|
print_results_prodhack = true;
|
|
|
|
}
|
2018-07-05 07:36:00 +00:00
|
|
|
else if (argument == "-psm")
|
2010-03-18 00:18:36 +00:00
|
|
|
{
|
|
|
|
print_results = true;
|
|
|
|
print_results_srhack = true;
|
|
|
|
print_results_prodhack = true;
|
|
|
|
}
|
2009-04-18 11:31:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!input_name.empty())
|
|
|
|
{
|
2009-06-11 07:11:05 +00:00
|
|
|
printf("ERROR: Can only take one input file.\n");
|
2009-04-18 11:31:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
input_name = argv[i];
|
2011-03-01 03:06:14 +00:00
|
|
|
if (!File::Exists(input_name))
|
2009-05-15 18:50:38 +00:00
|
|
|
{
|
2009-06-11 07:11:05 +00:00
|
|
|
printf("ERROR: Input path does not exist.\n");
|
2009-05-15 18:50:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-04-18 11:31:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (multiple && (compare || disassemble || !output_name.empty() || input_name.empty()))
|
2009-06-11 07:11:05 +00:00
|
|
|
{
|
|
|
|
printf("ERROR: Multiple files can only be used with assembly "
|
|
|
|
"and must compile a header file.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-04-18 12:27:24 +00:00
|
|
|
if (compare)
|
|
|
|
{
|
2022-06-14 00:56:49 +00:00
|
|
|
return PerformBinaryComparison(input_name, output_name) ? 0 : 1;
|
2009-04-18 12:27:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-07-19 20:14:09 +00:00
|
|
|
if (print_results)
|
|
|
|
{
|
2018-06-17 22:05:58 +00:00
|
|
|
PrintResults(input_name, output_name, print_results_srhack, print_results_prodhack);
|
2009-07-19 20:14:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-04-18 11:31:37 +00:00
|
|
|
if (disassemble)
|
|
|
|
{
|
2018-06-17 22:05:58 +00:00
|
|
|
if (!PerformDisassembly(input_name, output_name))
|
2009-04-18 11:31:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-17 22:05:58 +00:00
|
|
|
if (!PerformAssembly(input_name, output_name, output_header_name, multiple, force, outputSize))
|
2009-04-18 12:27:24 +00:00
|
|
|
return 1;
|
2014-03-09 19:01:56 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-04-12 10:21:40 +00:00
|
|
|
return 0;
|
2009-06-11 07:11:05 +00:00
|
|
|
}
|