Apply formatting rules.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
DataHoarder 2020-12-25 23:27:36 +01:00
parent 3d44e39c32
commit d40724c096
40 changed files with 565 additions and 452 deletions

View file

@ -44,7 +44,10 @@ public:
AnalysisState(uint32_t initial) : current(initial), previous(0) {
}
AnalysisState(const AnalysisState& oldState) : current(oldState.current), previous(oldState.previous), memory(oldState.memory), pciSPICOFirmware(oldState.pciSPICOFirmware), pciSerDesFirmware(oldState.pciSerDesFirmware){
AnalysisState(const AnalysisState &oldState) : current(oldState.current), previous(oldState.previous),
memory(oldState.memory), pciSPICOFirmware(oldState.pciSPICOFirmware),
pciSerDesFirmware(oldState.pciSerDesFirmware) {
}

View file

@ -137,7 +137,9 @@ const Configuration::ConfigurationNode &Configuration::getEntry(const std::strin
return mainNode;
}
void Configuration::getAllEntriesForNode(std::vector<std::string> &entries, const Configuration::ConfigurationNode &node, const std::string &key) const {
void
Configuration::getAllEntriesForNode(std::vector<std::string> &entries, const Configuration::ConfigurationNode &node,
const std::string &key) const {
for (const auto &n : node.possibleNodes) {
if (n.type != ConfigurationNode::Type::Node) {
entries.push_back(key + n.name + " " + n.getTypeString() + " " + n.value);

View file

@ -47,7 +47,8 @@ public:
ValueBool,
} type;
ConfigurationNode(std::string name, ConfigurationNode::Type type = ConfigurationNode::Type::Node) : name(std::move(name)), type(type){
ConfigurationNode(std::string name, ConfigurationNode::Type type = ConfigurationNode::Type::Node) : name(
std::move(name)), type(type) {
}
@ -92,7 +93,8 @@ public:
std::vector<std::string> getAllEntries() const;
void getAllEntriesForNode(std::vector<std::string>& entries, const ConfigurationNode& node, const std::string& key) const;
void getAllEntriesForNode(std::vector<std::string> &entries, const ConfigurationNode &node,
const std::string &key) const;
const ConfigurationNode &getEntry(const std::string &entry) const;

View file

@ -53,7 +53,8 @@ ImageFormat ImageFormat::fromBytes(const std::vector<uint8_t>& imageBytes) {
image.header.baseAddress |= imageBytes[offset++] << 8;
image.header.baseAddress |= imageBytes[offset++];
printf("SPEED: 0x%02x MODE: 0x%02x BOOT: 0x%08x\n", image.header.speed, image.header.mode, image.header.baseAddress);
printf("SPEED: 0x%02x MODE: 0x%02x BOOT: 0x%08x\n", image.header.speed, image.header.mode,
image.header.baseAddress);
offset = CFG_SIGNATURE;
uint8_t currentCharacter;
@ -124,7 +125,6 @@ std::vector<uint8_t> ImageFormat::toBytes() const {
uint32_t offset = 0;
bytes[offset++] = (header.reserved) | ((uint8_t) header.speed << 3) | ((uint8_t) header.mode << 6);
bytes[offset++] = (header.baseAddress >> 16) & 0xFF;
bytes[offset++] = (header.baseAddress >> 8) & 0xFF;
@ -183,7 +183,6 @@ std::vector<uint8_t> ImageFormat::toBytes() const {
}
void ImageFormat::decodeAnalyzeInstructionsAt(uint32_t offset) {
std::queue<AnalysisState> savedStates;
std::vector<AnalysisState> branchingStates;
@ -208,10 +207,13 @@ void ImageFormat::decodeAnalyzeInstructionsAt(uint32_t offset) {
jumpsUsed[state.current] = true;
if(state.current >= 0x100000 || (findInstructionByAddress(state.current) == nullptr && findInstructionByAddress(state.current, true) != nullptr)){ //Prevent arbitrary decoding in between decoded instructions
if (state.current >= 0x100000 || (findInstructionByAddress(state.current) == nullptr &&
findInstructionByAddress(state.current, true) !=
nullptr)) { //Prevent arbitrary decoding in between decoded instructions
break;
} else if (findInstructionByAddress(state.current) == nullptr) {
auto decodedInstruction = Instruction::Instruction::decodeInstructionFromBytes(state.current, baseImage);
auto decodedInstruction = Instruction::Instruction::decodeInstructionFromBytes(state.current,
baseImage);
instructions[decodedInstruction->getAddress()] = std::move(decodedInstruction);
}
@ -231,7 +233,9 @@ void ImageFormat::decodeAnalyzeInstructionsAt(uint32_t offset) {
auto possibleBranches = instruction->execute(state);
if((instruction->getCommand() == Instruction::Instruction::CommandOp::JUMP || instruction->getCommand() == Instruction::Instruction::CommandOp::RETURN) && jumpsUsed.find(instruction->getEndAddress()) == jumpsUsed.end()){
if ((instruction->getCommand() == Instruction::Instruction::CommandOp::JUMP ||
instruction->getCommand() == Instruction::Instruction::CommandOp::RETURN) &&
jumpsUsed.find(instruction->getEndAddress()) == jumpsUsed.end()) {
jumpsUsed[instruction->getEndAddress()] = false;
}
@ -244,12 +248,14 @@ void ImageFormat::decodeAnalyzeInstructionsAt(uint32_t offset) {
uint32_t nextAddress = instruction->getAddress() - 1;
while (true) {
const auto &previousInstruction = findInstructionByAddress(nextAddress, true);
if(previousInstruction != nullptr && previousInstruction->getCommand() == Instruction::Instruction::CommandOp::WRITE){
if (previousInstruction != nullptr &&
previousInstruction->getCommand() == Instruction::Instruction::CommandOp::WRITE) {
const auto &writeInstruction = reinterpret_cast<const std::unique_ptr<Instruction::Write> &>(previousInstruction);
if (
(
writeInstruction->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_1
|| (writeInstruction->address >= (uint32_t)KnownRegisters::BSM_SCRATCH_START && writeInstruction->address < (uint32_t)KnownRegisters::BSM_SCRATCH_END)
|| (writeInstruction->address >= (uint32_t) KnownRegisters::BSM_SCRATCH_START &&
writeInstruction->address < (uint32_t) KnownRegisters::BSM_SCRATCH_END)
)
&& writeInstruction->data.size() == 1
) { //This is commonly used before jumps to mark return values or switch statements
@ -299,6 +305,8 @@ void ImageFormat::decodeAnalyzeInstructionsAt(uint32_t offset) {
}
}
std::cerr << "Next state, branched states left: " << std::dec << savedStates.size() << /*", executed states: " << std::dec << createdStates.size() <<*/ ", total instructions decoded: " << std::dec << instructions.size() << "\n";
std::cerr << "Next state, branched states left: " << std::dec << savedStates.size()
<< /*", executed states: " << std::dec << createdStates.size() <<*/ ", total instructions decoded: "
<< std::dec << instructions.size() << "\n";
}
}

View file

@ -31,11 +31,12 @@
#include "Registers.h"
std::string getRegisterName(KnownRegisters addr) {
if((uint32_t)addr >= (uint32_t)KnownRegisters::BSM_SCRATCH_START && (uint32_t)addr <= (uint32_t)KnownRegisters::BSM_SCRATCH_END){
if ((uint32_t) addr >= (uint32_t) KnownRegisters::BSM_SCRATCH_START &&
(uint32_t) addr <= (uint32_t) KnownRegisters::BSM_SCRATCH_END) {
std::stringstream s;
s << "BSM_SCRATCH[0x" << std::hex << std::setw(3) << std::setfill('0') << (((uint32_t)addr) - (uint32_t)KnownRegisters::BSM_SCRATCH_START) << "]";
s << "BSM_SCRATCH[0x" << std::hex << std::setw(3) << std::setfill('0')
<< (((uint32_t) addr) - (uint32_t) KnownRegisters::BSM_SCRATCH_START) << "]";
return s.str();
}
switch (addr) {
@ -171,7 +172,8 @@ std::string getRegisterName(KnownRegisters addr) {
std::string getAddressRegisterName(uint32_t addr, uint8_t offset) {
std::stringstream s;
if (offset) {
s << getRegisterName(static_cast<KnownRegisters>((uint32_t)KnownRegisters::BSM_ADDR_OFFSET_0 + offset)) << " + " << "0x" << std::hex << std::setw(6) << std::setfill('0') << addr;
s << getRegisterName(static_cast<KnownRegisters>((uint32_t) KnownRegisters::BSM_ADDR_OFFSET_0 + offset))
<< " + " << "0x" << std::hex << std::setw(6) << std::setfill('0') << addr;
} else {
s << getRegisterName(static_cast<KnownRegisters>(addr));
}

View file

@ -27,7 +27,8 @@
#include "SmallFirmwareFormat.h"
SmallFirmwareFormat SmallFirmwareFormat::fromBSMLoad(const std::vector<uint32_t>& parameters, uint32_t parameterOffset) {
SmallFirmwareFormat
SmallFirmwareFormat::fromBSMLoad(const std::vector<uint32_t> &parameters, uint32_t parameterOffset) {
SmallFirmwareFormat fw;
for (auto it = parameters.begin() + parameterOffset; it != parameters.end(); ++it) {

View file

@ -39,6 +39,7 @@ public:
SmallFirmwareFormat() {
}
SmallFirmwareFormat(const SmallFirmwareFormat &other) : firmware(other.firmware) {
}

View file

@ -59,19 +59,20 @@ void Instruction::Branch::fromBytes(uint32_t offset, const std::vector<uint8_t>
jumpAddress |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::Branch::toString() const {
std::stringstream op;
op << "BRANCH IF (" << getAddressRegisterName(address, addressOffset) << " & 0x" << std::hex << std::setw(8) << std::setfill('0') << mask << ")";
op << "BRANCH IF (" << getAddressRegisterName(address, addressOffset) << " & 0x" << std::hex << std::setw(8)
<< std::setfill('0') << mask << ")";
if (equality) {
op << " == ";
} else {
op << " != ";
}
op << "0x" << std::hex << std::setw(8) << std::setfill('0') << value << " JUMP 0x" << std::hex << std::setw(6) << std::setfill('0') << jumpAddress;
op << "0x" << std::hex << std::setw(8) << std::setfill('0') << value << " JUMP 0x" << std::hex << std::setw(6)
<< std::setfill('0') << jumpAddress;
return op.str();
}
@ -80,7 +81,8 @@ std::vector<uint32_t> Instruction::Branch::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress, jumpAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Branch::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Branch::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> branches;
uint32_t memoryOffset = state.getAddressOffset(addressOffset);
@ -89,13 +91,15 @@ std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruc
state.current = equality ? jumpAddress : _endAddress;
std::unordered_map<uint32_t, uint32_t> branchedState;
branchedState[memoryOffset + address] = state.getRegister(memoryOffset + address) | (equality ? ~value & mask : value);
branchedState[memoryOffset + address] =
state.getRegister(memoryOffset + address) | (equality ? ~value & mask : value);
branches.emplace_back(equality ? _endAddress : jumpAddress, std::move(branchedState));
} else {
state.current = equality ? _endAddress : jumpAddress;
std::unordered_map<uint32_t, uint32_t> branchedState;
branchedState[memoryOffset + address] = state.getRegister(memoryOffset + address) | (equality ? value : ~value & mask);
branchedState[memoryOffset + address] =
state.getRegister(memoryOffset + address) | (equality ? value : ~value & mask);
branches.emplace_back(equality ? jumpAddress : _endAddress, std::move(branchedState));
}

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;

View file

@ -55,13 +55,13 @@ void Instruction::Calc::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
addressTarget |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::Calc::toString() const {
std::stringstream op;
op << "CALC " << getAddressRegisterName(addressDestination, addressOffset) << " = " << getAddressRegisterName(addressSource, addressOffset);
op << "CALC " << getAddressRegisterName(addressDestination, addressOffset) << " = "
<< getAddressRegisterName(addressSource, addressOffset);
switch (operation) {
case Operation::AND:
op << " & ";
@ -96,7 +96,8 @@ std::vector<uint32_t> Instruction::Calc::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Calc::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Calc::execute(AnalysisState &state) const {
uint32_t memoryOffset = state.getAddressOffset(addressOffset);

View file

@ -60,7 +60,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
Operation operation;

View file

@ -55,13 +55,13 @@ void Instruction::CalcImm::fromBytes(uint32_t offset, const std::vector<uint8_t>
value |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::CalcImm::toString() const {
std::stringstream op;
op << "CALC_IMM " << getAddressRegisterName(addressDestination, addressOffset) << " = " << getAddressRegisterName(addressSource, addressOffset);
op << "CALC_IMM " << getAddressRegisterName(addressDestination, addressOffset) << " = "
<< getAddressRegisterName(addressSource, addressOffset);
switch (operation) {
case Calc::Operation::AND:
op << " & ";
@ -96,7 +96,8 @@ std::vector<uint32_t> Instruction::CalcImm::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::CalcImm::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::CalcImm::execute(AnalysisState &state) const {
uint32_t memoryOffset = state.getAddressOffset(addressOffset);

View file

@ -50,7 +50,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
Calc::Operation operation;

View file

@ -50,13 +50,14 @@ void Instruction::Copy::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
addressBB |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::Copy::toString() const {
std::stringstream op;
op << "COPY " << std::dec << (uint32_t) count << " WORDS FROM " << getAddressRegisterName(addressAA, addressOffsetAA) << " TO " << getAddressRegisterName(addressBB, addressOffsetBB);
op << "COPY " << std::dec << (uint32_t) count << " WORDS FROM "
<< getAddressRegisterName(addressAA, addressOffsetAA) << " TO "
<< getAddressRegisterName(addressBB, addressOffsetBB);
return op.str();
}
@ -64,7 +65,8 @@ std::vector<uint32_t> Instruction::Copy::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Copy::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Copy::execute(AnalysisState &state) const {
uint32_t memoryOffsetAA = state.getAddressOffset(addressOffsetAA);
uint32_t memoryOffsetBB = state.getAddressOffset(addressOffsetBB);

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t count;

View file

@ -47,7 +47,8 @@ std::vector<uint32_t> Instruction::End::getPossibleBranches() const {
return std::vector<uint32_t>();
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::End::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::End::execute(AnalysisState &state) const {
state.current = 0;
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint32_t reserved = 0;
};

View file

@ -59,7 +59,6 @@ void Instruction::Init::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
data_add |= bytes[offset++];
_endAddress = offset;
}
@ -82,7 +81,8 @@ std::vector<uint32_t> Instruction::Init::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Init::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Init::execute(AnalysisState &state) const {
for (uint32_t i = 0; i < count; ++i) {
state.setRegister(address + (increment ? i : 0), data + data_add * i);
}

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;

View file

@ -44,7 +44,8 @@
namespace Instruction {
std::unique_ptr<Instruction> Instruction::Instruction::decodeInstructionFromBytes(uint32_t offset, const std::vector<uint8_t> &bytes) {
std::unique_ptr<Instruction>
Instruction::Instruction::decodeInstructionFromBytes(uint32_t offset, const std::vector<uint8_t> &bytes) {
auto result = std::unique_ptr<Instruction>(nullptr);
CommandOp command = getCommandFromByte(bytes[offset]);

View file

@ -72,7 +72,8 @@ namespace Instruction{
NOP = 0xFF
};
static std::unique_ptr<Instruction> decodeInstructionFromBytes(uint32_t offset, const std::vector<uint8_t>& bytes);
static std::unique_ptr<Instruction>
decodeInstructionFromBytes(uint32_t offset, const std::vector<uint8_t> &bytes);
static CommandOp getCommandFromByte(uint8_t command);
@ -89,7 +90,8 @@ namespace Instruction{
virtual std::vector<uint32_t> getPossibleBranches() const = 0;
virtual std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const = 0;
virtual std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const = 0;
virtual CommandOp getCommand() const = 0;

View file

@ -40,7 +40,6 @@ void Instruction::Jump::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
jumpAddress |= bytes[offset++];
_endAddress = offset;
}
@ -55,7 +54,8 @@ std::vector<uint32_t> Instruction::Jump::getPossibleBranches() const {
return std::vector<uint32_t>{jumpAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Jump::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Jump::execute(AnalysisState &state) const {
state.current = jumpAddress;
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint32_t jumpAddress;
};

View file

@ -58,15 +58,14 @@ void Instruction::Load::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
}
_endAddress = offset;
}
std::string Instruction::Load::toString() const {
std::stringstream op;
if(addressOffset == 0 && increment == 0 && address == (uint32_t)KnownRegisters::PCIE_MASTER_SPICO_FIRMWARE_SPECIAL_REGISTER){
if (addressOffset == 0 && increment == 0 &&
address == (uint32_t) KnownRegisters::PCIE_MASTER_SPICO_FIRMWARE_SPECIAL_REGISTER) {
op << "LOAD PCIE_MASTER_SPICO_FIRMWARE DATA 0x";
for (auto d : data) {
op << std::hex << std::setw(8) << std::setfill('0') << d;
@ -77,7 +76,8 @@ std::string Instruction::Load::toString() const {
op << " SPICO_FW[" << std::hex << std::setw(4) << std::setfill('0') << i << "]";
op << " = 0x" << std::hex << std::setw(3) << std::setfill('0') << fw.firmware[i] << "\n";
}
} else if(addressOffset == 0 && increment == 0 && address == (uint32_t)KnownRegisters::PCIE_BROADCAST_SERDES_FIRMWARE_SPECIAL_REGISTER){
} else if (addressOffset == 0 && increment == 0 &&
address == (uint32_t) KnownRegisters::PCIE_BROADCAST_SERDES_FIRMWARE_SPECIAL_REGISTER) {
op << "LOAD PCIE_BROADCAST_SERDES_FIRMWARE DATA 0x";
for (auto d : data) {
op << std::hex << std::setw(8) << std::setfill('0') << d;
@ -101,7 +101,8 @@ std::string Instruction::Load::toString() const {
if (data.size() > 1) {
for (uint32_t i = 0; i < data.size(); ++i) {
op << "\n " << getAddressRegisterName(address + (increment ? i : 0)) << " = 0x" << std::hex << std::setw(8) << std::setfill('0') << data[i];
op << "\n " << getAddressRegisterName(address + (increment ? i : 0)) << " = 0x" << std::hex
<< std::setw(8) << std::setfill('0') << data[i];
}
}
}
@ -114,11 +115,14 @@ std::vector<uint32_t> Instruction::Load::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Load::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Load::execute(AnalysisState &state) const {
if(addressOffset == 0 && increment == 0 && address == (uint32_t)KnownRegisters::PCIE_MASTER_SPICO_FIRMWARE_SPECIAL_REGISTER){
if (addressOffset == 0 && increment == 0 &&
address == (uint32_t) KnownRegisters::PCIE_MASTER_SPICO_FIRMWARE_SPECIAL_REGISTER) {
state.pciSPICOFirmware = SmallFirmwareFormat::fromBSMLoad(data, 0);
} else if(addressOffset == 0 && increment == 0 && address == (uint32_t)KnownRegisters::PCIE_BROADCAST_SERDES_FIRMWARE_SPECIAL_REGISTER){
} else if (addressOffset == 0 && increment == 0 &&
address == (uint32_t) KnownRegisters::PCIE_BROADCAST_SERDES_FIRMWARE_SPECIAL_REGISTER) {
state.pciSerDesFirmware = SmallFirmwareFormat::fromBSMLoad(data, 0);
} else {
for (uint32_t i = 0; i < data.size(); ++i) {

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;

View file

@ -42,13 +42,13 @@ void Instruction::Loop::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
jumpAddress |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::Loop::toString() const {
std::stringstream op;
op << "LOOP IF " << getRegisterName(static_cast<KnownRegisters>((uint32_t)KnownRegisters::BSM_COUNTER_0 + counter)) << " != 0 JUMP 0x" << std::hex << std::setw(6) << std::setfill('0') << jumpAddress;
op << "LOOP IF " << getRegisterName(static_cast<KnownRegisters>((uint32_t) KnownRegisters::BSM_COUNTER_0 + counter))
<< " != 0 JUMP 0x" << std::hex << std::setw(6) << std::setfill('0') << jumpAddress;
return op.str();
}
@ -56,7 +56,8 @@ std::vector<uint32_t> Instruction::Loop::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress, jumpAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Loop::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Loop::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> branches;
uint32_t counterAddress = (uint32_t) KnownRegisters::BSM_COUNTER_0 + counter;

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t counter;

View file

@ -65,19 +65,21 @@ void Instruction::Poll::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
jumpAddress |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::Poll::toString() const {
std::stringstream op;
op << "POLL IF (" << getAddressRegisterName(address, addressOffset) << " & 0x" << std::hex << std::setw(8) << std::setfill('0') << mask << ")";
op << "POLL IF (" << getAddressRegisterName(address, addressOffset) << " & 0x" << std::hex << std::setw(8)
<< std::setfill('0') << mask << ")";
if (equality) {
op << " != ";
} else {
op << " == ";
}
op << "0x" << std::hex << std::setw(8) << std::setfill('0') << value << " WAIT " << std::dec << retryInterval << " MAX " << std::dec << maxRetry << " EXCEED JUMP 0x" << std::hex << std::setw(6) << std::setfill('0') << jumpAddress;
op << "0x" << std::hex << std::setw(8) << std::setfill('0') << value << " WAIT " << std::dec << retryInterval
<< " MAX " << std::dec << maxRetry << " EXCEED JUMP 0x" << std::hex << std::setw(6) << std::setfill('0')
<< jumpAddress;
return op.str();
}
@ -86,7 +88,8 @@ std::vector<uint32_t> Instruction::Poll::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress, jumpAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Poll::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Poll::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> branches;
uint32_t memoryOffset = state.getAddressOffset(addressOffset);
@ -95,13 +98,15 @@ std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruc
state.current = equality ? _endAddress : jumpAddress;
std::unordered_map<uint32_t, uint32_t> branchedState;
branchedState[memoryOffset + address] = state.getRegister(memoryOffset + address) | (equality ? value : ~value & mask);
branchedState[memoryOffset + address] =
state.getRegister(memoryOffset + address) | (equality ? value : ~value & mask);
branches.emplace_back(equality ? jumpAddress : _endAddress, std::move(branchedState));
} else {
state.current = equality ? jumpAddress : _endAddress;
std::unordered_map<uint32_t, uint32_t> branchedState;
branchedState[memoryOffset + address] = state.getRegister(memoryOffset + address) | (equality ? ~value & mask : value);
branchedState[memoryOffset + address] =
state.getRegister(memoryOffset + address) | (equality ? ~value & mask : value);
branches.emplace_back(equality ? _endAddress : jumpAddress, std::move(branchedState));
}

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;

View file

@ -42,7 +42,6 @@ void Instruction::Return::fromBytes(uint32_t offset, const std::vector<uint8_t>
address |= bytes[offset++];
_endAddress = offset;
}
@ -57,7 +56,8 @@ std::vector<uint32_t> Instruction::Return::getPossibleBranches() const {
return std::vector<uint32_t>();
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Return::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Return::execute(AnalysisState &state) const {
uint32_t memoryOffset = state.getAddressOffset(addressOffset);
uint32_t jumpAddress = state.getRegister(memoryOffset + address);

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;
uint32_t address;

View file

@ -52,13 +52,14 @@ void Instruction::Set::fromBytes(uint32_t offset, const std::vector<uint8_t> &by
mask |= bytes[offset++];
_endAddress = offset;
}
std::string Instruction::Set::toString() const {
std::stringstream op;
op << "SET " << getAddressRegisterName(address, addressOffset) << " = (" << getAddressRegisterName(address, addressOffset) << " & ~0x" << std::hex << std::setw(8) << std::setfill('0') << mask << ") | " << "0x" << std::hex << std::setw(8) << std::setfill('0') << value;
op << "SET " << getAddressRegisterName(address, addressOffset) << " = ("
<< getAddressRegisterName(address, addressOffset) << " & ~0x" << std::hex << std::setw(8) << std::setfill('0')
<< mask << ") | " << "0x" << std::hex << std::setw(8) << std::setfill('0') << value;
return op.str();
}
@ -66,7 +67,8 @@ std::vector<uint32_t> Instruction::Set::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Set::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Set::execute(AnalysisState &state) const {
uint32_t memoryOffset = state.getAddressOffset(addressOffset);
state.setRegister(memoryOffset + address, (state.getRegister(memoryOffset + address) & ~mask) | value);

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;
uint32_t address;

View file

@ -40,7 +40,6 @@ void Instruction::Wait::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
time |= bytes[offset++];
_endAddress = offset;
}
@ -55,7 +54,8 @@ std::vector<uint32_t> Instruction::Wait::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Wait::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Wait::execute(AnalysisState &state) const {
//How to wait?
state.current = _endAddress;

View file

@ -48,7 +48,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint32_t time;
};

View file

@ -51,8 +51,6 @@ void Instruction::Write::fromBytes(uint32_t offset, const std::vector<uint8_t> &
}
_endAddress = offset;
}
@ -70,7 +68,8 @@ std::vector<uint32_t> Instruction::Write::getPossibleBranches() const {
return std::vector<uint32_t>{_endAddress};
}
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> Instruction::Write::execute(AnalysisState &state) const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Write::execute(AnalysisState &state) const {
auto memoryOffset = state.getAddressOffset(addressOffset);
for (uint32_t i = 0; i < data.size(); ++i) {

View file

@ -34,7 +34,9 @@
namespace Instruction {
class Write : public Instruction {
public:
Write(uint32_t address, uint8_t addressOffset, std::vector<uint32_t> data) : address(address), addressOffset(addressOffset), data(std::move(data)){
Write(uint32_t address, uint8_t addressOffset, std::vector<uint32_t> data) : address(address),
addressOffset(addressOffset),
data(std::move(data)) {
}
@ -54,7 +56,8 @@ namespace Instruction{
std::vector<uint32_t> getPossibleBranches() const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> execute(AnalysisState& state) const override;
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
execute(AnalysisState &state) const override;
uint8_t addressOffset;

View file

@ -53,8 +53,11 @@ void decodeImage(const std::string& fileName){
for (const auto &entry : imageObject.getInstructions()) {
const auto &instruction = entry.second;
if (instruction->getAddress() < prevAddress) {
std::cout << "====== DECODE ERROR? ========== " << std::hex << std::setw(8) << std::setfill('0') << prevAddress << " - " << std::hex << std::setw(8) << std::setfill('0') << instruction->getAddress() << "\n";
}else if((instruction->getAddress() - prevAddress) >= 4 && (instruction->getAddress() - prevAddress) < 1024){
std::cout << "====== DECODE ERROR? ========== " << std::hex << std::setw(8) << std::setfill('0')
<< prevAddress << " - " << std::hex << std::setw(8) << std::setfill('0')
<< instruction->getAddress() << "\n";
} else if ((instruction->getAddress() - prevAddress) >= 4 &&
(instruction->getAddress() - prevAddress) < 1024) {
for (uint32_t addr = prevAddress; addr < instruction->getAddress(); addr += 4) {
std::stringstream op;
std::string printable;
@ -72,7 +75,9 @@ void decodeImage(const std::string& fileName){
std::cout << op.str();
}
} else if ((instruction->getAddress() - prevAddress) >= 1024) {
std::cout << "================ " << std::hex << std::setw(8) << std::setfill('0') << prevAddress << " - " << std::hex << std::setw(8) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << "================ " << std::hex << std::setw(8) << std::setfill('0') << prevAddress
<< " - " << std::hex << std::setw(8) << std::setfill('0') << instruction->getAddress()
<< "\n";
}
std::cout << std::hex << std::setw(8) << std::setfill('0') << instruction->getAddress() << ": ";
std::cout << instruction->toString() << "\n";
@ -81,7 +86,8 @@ void decodeImage(const std::string& fileName){
}
}
void patchImage(const std::string& originalImage, const std::string& settingsFile, const std::string& patchedImageFile){
void
patchImage(const std::string &originalImage, const std::string &settingsFile, const std::string &patchedImageFile) {
std::ifstream image(originalImage);
if (image.is_open()) {
std::vector<uint8_t> bytes;
@ -103,8 +109,11 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
//Do patch
if(imageObject.imageSignature.find("Image Generated with rrcBig_02.22. EEPROM Image Version: 0x0222 PCIe Master SPICO FW Version: 0x10130001 PCIe SerDes SPICO FW Version: 0x30550043") == std::string::npos){
std::cout << "Could not find supported generation signature on original image. Patching will not proceed.\n";
if (imageObject.imageSignature.find(
"Image Generated with rrcBig_02.22. EEPROM Image Version: 0x0222 PCIe Master SPICO FW Version: 0x10130001 PCIe SerDes SPICO FW Version: 0x30550043") ==
std::string::npos) {
std::cout
<< "Could not find supported generation signature on original image. Patching will not proceed.\n";
return;
}
@ -186,7 +195,9 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
// 0x93f0 LOAD 1 = 0x000f000a PCIE_CLKMON_TOLERANCE_CFG = value
// 0x93fc LOAD 1 = 0x000a03e8 PCIE_CLKMON_DEADLINES_CFG = value
auto baseOffsets = std::vector<uint32_t>{imageObject.getHeader().baseAddress, (uint32_t) imageObject.getHeader().baseAddress + 0x40000}; //Target first and second bank
auto baseOffsets = std::vector<uint32_t>{imageObject.getHeader().baseAddress,
(uint32_t) imageObject.getHeader().baseAddress +
0x40000}; //Target first and second bank
{
auto entry = config.getEntry("api.platform.config.switch.0.bootCfg.mgmtPep");
@ -195,22 +206,27 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
auto value = entry.getInteger();
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x91f0);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD){
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x02e) && load->data.size() == 9) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".bar4Allowed";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".bar4Allowed";
auto testEntry = config.getEntry(key.str());
bool bar4allowed = true;
if(testEntry.type == Configuration::ConfigurationNode::Type::ValueBool && !testEntry.value.empty()) {
if (testEntry.type == Configuration::ConfigurationNode::Type::ValueBool &&
!testEntry.value.empty()) {
bar4allowed = testEntry.getBool();
}
load->data[pepOffset] = bar4allowed && (pepOffset == value || value == -1);
//std::cout << " Patched PEP " << std::dec << pepOffset << " = 0x" << std::hex << std::setw(8) << std::setfill('0') << load->data[pepOffset] << " @ " << std::hex << std::setw(8) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << " Patched PEP " << std::dec << pepOffset << " = " << (load->data[pepOffset] ? "true" : "false") << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << " Patched PEP " << std::dec << pepOffset << " = "
<< (load->data[pepOffset] ? "true" : "false") << " @ " << std::hex
<< std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
}
}
@ -221,19 +237,24 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
{
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9230);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x049) && load->data.size() == 9) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".vendorId";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".vendorId";
auto vendorIdEntry = config.getEntry(key.str());
if(vendorIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt && !vendorIdEntry.value.empty()) {
if (vendorIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt &&
!vendorIdEntry.value.empty()) {
uint16_t vendorId = vendorIdEntry.getInteger();
key.str("");
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".deviceId";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".deviceId";
auto deviceIdEntry = config.getEntry(key.str());
if(deviceIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt && !deviceIdEntry.value.empty()) {
if (deviceIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt &&
!deviceIdEntry.value.empty()) {
uint16_t deviceId = deviceIdEntry.getInteger();
load->data[pepOffset] = ((uint32_t) deviceId << 16) | vendorId;
@ -248,19 +269,24 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
{
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9260);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x052) && load->data.size() == 9) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".subVendorId";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".subVendorId";
auto subVendorIdEntry = config.getEntry(key.str());
if(subVendorIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt && !subVendorIdEntry.value.empty()) {
if (subVendorIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt &&
!subVendorIdEntry.value.empty()) {
uint16_t subVendorId = subVendorIdEntry.getInteger();
key.str("");
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".subDeviceId";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".subDeviceId";
auto subDeviceIdEntry = config.getEntry(key.str());
if(subDeviceIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt && !subDeviceIdEntry.value.empty()) {
if (subDeviceIdEntry.type == Configuration::ConfigurationNode::Type::ValueInt &&
!subDeviceIdEntry.value.empty()) {
uint16_t subDeviceId = subDeviceIdEntry.getInteger();
load->data[pepOffset] = ((uint32_t) subDeviceId << 16) | subVendorId;
@ -275,17 +301,21 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
{
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9130);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x01c) && load->data.size() == 9) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".numberOfLanes";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".numberOfLanes";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()) {
if (entry.type == Configuration::ConfigurationNode::Type::ValueInt &&
!entry.value.empty()) {
uint32_t value = entry.getInteger();
if (load->data[pepOffset] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[pepOffset]
std::cout << "Patching " << key.str() << " = " << std::dec
<< load->data[pepOffset]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
@ -300,17 +330,20 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
{
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x92f0);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x075) && load->data.size() == 9) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".gen";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueInt && !entry.value.empty()) {
if (entry.type == Configuration::ConfigurationNode::Type::ValueInt &&
!entry.value.empty()) {
uint32_t value = entry.getInteger();
if (load->data[pepOffset] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[pepOffset]
std::cout << "Patching " << key.str() << " = " << std::dec
<< load->data[pepOffset]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
@ -325,17 +358,21 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
{
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9380);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) getScratchRegister(0x096) && load->data.size() == 9) {
for (uint32_t pepOffset = 0; pepOffset < 9; ++pepOffset) {
std::stringstream key;
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset << ".ASPMEnable";
key << "api.platform.config.switch.0.bootCfg.pep." << std::dec << pepOffset
<< ".ASPMEnable";
auto entry = config.getEntry(key.str());
if(entry.type == Configuration::ConfigurationNode::Type::ValueBool && !entry.value.empty()) {
if (entry.type == Configuration::ConfigurationNode::Type::ValueBool &&
!entry.value.empty()) {
bool value = entry.getBool();
if (load->data[pepOffset] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[pepOffset]
std::cout << "Patching " << key.str() << " = " << std::dec
<< load->data[pepOffset]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
@ -356,12 +393,16 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
bool value = entry.getBool();
for (auto baseOffset : baseOffsets) {
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9050 + pepOffset * 0x10);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &instruction = imageObject.findInstructionByAddress(
baseOffset + 0x9050 + pepOffset * 0x10);
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 &&
load->data.size() == 1) {
if (load->data[0] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[0] << " -> "
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[0]
<< " -> "
<< std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
@ -382,12 +423,17 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
bool value = entry.getBool();
for (auto baseOffset : baseOffsets) {
auto& instruction = imageObject.findInstructionByAddress(baseOffset + 0x9010 + (pepOffset/2) * 0x10);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &instruction = imageObject.findInstructionByAddress(
baseOffset + 0x9010 + (pepOffset / 2) * 0x10);
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 &&
load->data.size() == 1) {
if (load->data[0] != value) {
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << "Patching " << key.str() << " = " << std::dec << load->data[0]
<< " -> " << std::dec << value << " @ " << std::hex << std::setw(6)
<< std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
@ -404,11 +450,14 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9000);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if (load->data[0] != value) {
std::cout << "Patching bootCfg.systimeClockSource" << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << "Patching bootCfg.systimeClockSource" << " = " << std::dec
<< load->data[0] << " -> " << std::dec << value << " @ " << std::hex
<< std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
@ -424,11 +473,14 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x90f0);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if (load->data[0] != value) {
std::cout << "Patching bootCfg.spiTransferMode" << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << "Patching bootCfg.spiTransferMode" << " = " << std::dec
<< load->data[0] << " -> " << std::dec << value << " @ " << std::hex
<< std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}
@ -444,11 +496,14 @@ void patchImage(const std::string& originalImage, const std::string& settingsFil
for (auto baseOffset : baseOffsets) {
auto &instruction = imageObject.findInstructionByAddress(baseOffset + 0x9100);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
if (instruction != nullptr &&
instruction->getCommand() == Instruction::Instruction::CommandOp::LOAD) {
auto &load = reinterpret_cast<std::unique_ptr<Instruction::Load> &>(instruction);
if (load->address == (uint32_t) KnownRegisters::MGMT_SCRATCH_0 && load->data.size() == 1) {
if (load->data[0] != value) {
std::cout << "Patching bootCfg.spiTransferSpeed" << " = " << std::dec << load->data[0] << " -> " << std::dec << value << " @ " << std::hex << std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
std::cout << "Patching bootCfg.spiTransferSpeed" << " = " << std::dec
<< load->data[0] << " -> " << std::dec << value << " @ " << std::hex
<< std::setw(6) << std::setfill('0') << instruction->getAddress() << "\n";
}
load->data[0] = value;
}