Added Poll AddressWithOffset
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2020-12-28 22:54:01 +01:00
parent 0135a5fa37
commit 0823e1e78c
2 changed files with 16 additions and 19 deletions

View file

@ -37,11 +37,11 @@ void Instruction::Poll::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
uint32_t command = bytes[offset++];
equality = (command >> 2) & 0b1;
addressOffset = command & 0b11;
address.offset = command & 0b11;
address = bytes[offset++] << 16;
address |= bytes[offset++] << 8;
address |= bytes[offset++];
address.address = bytes[offset++] << 16;
address.address |= bytes[offset++] << 8;
address.address |= bytes[offset++];
value = bytes[offset++] << 24;
value |= bytes[offset++] << 16;
@ -71,7 +71,7 @@ void Instruction::Poll::fromBytes(uint32_t offset, const std::vector<uint8_t> &b
std::string Instruction::Poll::toString() const {
std::stringstream op;
op << "POLL IF (" << getAddressRegisterName(address, addressOffset) << " & 0x" << std::hex << std::setw(8)
op << "POLL IF (" << getAddressRegisterName(address) << " & 0x" << std::hex << std::setw(8)
<< std::setfill('0') << mask << ")";
if (equality) {
op << " != ";
@ -87,7 +87,7 @@ std::string Instruction::Poll::toString() const {
std::vector<Instruction::OutputFormat> Instruction::Poll::toOutputFormat(const OutputContext &context) const {
return std::vector<OutputFormat>{
OutputFormat{getAddress(), dynamic_cast<std::stringstream&>(std::stringstream("") << "POLL" << " " << getAddressRegisterName(address, addressOffset) << (equality ? " == " : " != ")).str()},
OutputFormat{getAddress(), dynamic_cast<std::stringstream&>(std::stringstream("") << "POLL" << " " << getAddressRegisterName(address) << (equality ? " == " : " != ")).str()},
OutputFormat{getAddress() + 4, dynamic_cast<std::stringstream&>(std::stringstream("") << " VALUE 0x" << std::hex << std::setw(8) << std::setfill('0') << value).str()},
OutputFormat{getAddress() + 8, dynamic_cast<std::stringstream&>(std::stringstream("") << " MASK 0x" << std::hex << std::setw(8) << std::setfill('0') << mask).str()},
OutputFormat{getAddress() + 12, dynamic_cast<std::stringstream&>(std::stringstream("") << " RETRY MAX " << std::dec << maxRetry << " INTERVAL " << std::dec << retryInterval).str()},
@ -103,21 +103,19 @@ 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);
if ((state.getRegister(memoryOffset + address) & mask) == value) {
if ((state.getRegister(address) & mask) == value) {
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[state.getAddressWithOffset(address)] =
state.getRegister(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[state.getAddressWithOffset(address)] =
state.getRegister(address) | (equality ? ~value & mask : value);
branches.emplace_back(equality ? _endAddress : jumpAddress, std::move(branchedState));
}
@ -130,11 +128,11 @@ Instruction::Poll::execute(AnalysisState &state) const {
std::vector<uint8_t> Instruction::Poll::toBytes() const {
std::vector<uint8_t> bytes;
bytes.emplace_back((uint8_t) getCommand() | (equality << 2) | addressOffset);
bytes.emplace_back((uint8_t) getCommand() | (equality << 2) | address.offset);
bytes.emplace_back((address >> 16) & 0xFF);
bytes.emplace_back((address >> 8) & 0xFF);
bytes.emplace_back(address & 0xFF);
bytes.emplace_back((address.address >> 16) & 0xFF);
bytes.emplace_back((address.address >> 8) & 0xFF);
bytes.emplace_back(address.address & 0xFF);
bytes.emplace_back((value >> 24) & 0xFF);
bytes.emplace_back((value >> 16) & 0xFF);

View file

@ -53,9 +53,8 @@ namespace Instruction {
execute(AnalysisState &state) const override;
uint8_t addressOffset;
uint8_t equality;
uint32_t address;
AddressWithOffset address;
uint32_t value;
uint32_t mask;
uint16_t maxRetry;