2023-09-07 23:31:29 +01:00
|
|
|
#include "Avr8InstructionService.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Services
|
|
|
|
|
{
|
2024-07-23 21:14:22 +01:00
|
|
|
using Targets::Microchip::Avr8::OpcodeDecoder::Decoder;
|
2023-09-07 23:31:29 +01:00
|
|
|
|
|
|
|
|
std::optional<Targets::TargetMemoryAddress> Avr8InstructionService::resolveProgramDestinationAddress(
|
2024-07-23 21:14:22 +01:00
|
|
|
const Targets::Microchip::Avr8::OpcodeDecoder::Instruction& instruction,
|
2023-09-07 23:31:29 +01:00
|
|
|
Targets::TargetMemoryAddress instructionAddress,
|
|
|
|
|
const Decoder::InstructionMapping& instructions
|
|
|
|
|
) {
|
|
|
|
|
assert(instruction.canChangeProgramFlow);
|
|
|
|
|
|
|
|
|
|
if (instruction.programWordAddress.has_value()) {
|
|
|
|
|
return *(instruction.programWordAddress) * 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instruction.programWordAddressOffset.has_value()) {
|
|
|
|
|
return static_cast<std::int64_t>(instructionAddress) + (*(instruction.programWordAddressOffset) * 2) + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instruction.canSkipNextInstruction) {
|
|
|
|
|
const auto subsequentInstructionAddress = instructionAddress + instruction.byteSize;
|
|
|
|
|
const auto subsequentInstructionIt = instructions.find(subsequentInstructionAddress);
|
|
|
|
|
|
|
|
|
|
if (subsequentInstructionIt != instructions.end() && subsequentInstructionIt->second.has_value()) {
|
|
|
|
|
return subsequentInstructionAddress + subsequentInstructionIt->second->byteSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
}
|