Moved TargetRegisterDescriptor struct to separate file
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
#include "src/Services/StringService.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
@@ -14,7 +14,6 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
{
|
||||
using Services::TargetControllerService;
|
||||
|
||||
using Targets::TargetRegister;
|
||||
using Targets::TargetRegisterDescriptors;
|
||||
|
||||
using ResponsePackets::ResponsePacket;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
|
||||
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||
|
||||
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "src/DebugServer/Gdb/RegisterDescriptor.hpp"
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
|
||||
namespace DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "src/Helpers/BiMap.hpp"
|
||||
#include "src/Targets/TargetDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "TargetInterfaces/RiscV/RiscVDebugInterface.hpp"
|
||||
#include "TargetInterfaces/RiscV/RiscVProgramInterface.hpp"
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
/**
|
||||
* A debug tool can be any device that provides access to the connected target. Debug tools are usually connected
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "src/Targets/TargetPhysicalInterface.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/Microchip/AVR/AVR8/Family.hpp"
|
||||
#include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp"
|
||||
|
||||
#include "src/Targets/TargetState.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "src/Targets/TargetState.hpp"
|
||||
#include "src/Targets/TargetDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
#include "InsightWorker/Tasks/InsightWorkerTask.hpp"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "InsightWorkerTask.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
|
||||
class ReadTargetRegisters: public InsightWorkerTask
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <QEvent>
|
||||
#include <optional>
|
||||
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Targets/TargetState.hpp"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <QScrollArea>
|
||||
#include <optional>
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetState.hpp"
|
||||
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp"
|
||||
|
||||
#include "RegisterItem.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp"
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "TargetPinWidget.hpp"
|
||||
#include "src/Targets/TargetVariant.hpp"
|
||||
#include "src/Targets/TargetState.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
|
||||
namespace Widgets::InsightTargetWidgets
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "src/TargetController/AtomicSession.hpp"
|
||||
|
||||
#include "src/Targets/TargetState.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Targets/TargetBreakpoint.hpp"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Command.hpp"
|
||||
#include "src/TargetController/Responses/TargetRegistersRead.hpp"
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
namespace TargetController::Commands
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
#include "src/Targets/BriefTargetDescriptor.hpp"
|
||||
#include "src/Targets/Target.hpp"
|
||||
#include "src/Targets/Targets.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Targets/TargetMemoryCache.hpp"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ target_sources(
|
||||
Bloom
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegister.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryCache.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetPhysicalInterface.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/Avr8.cpp
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "src/Exceptions/InvalidConfig.hpp"
|
||||
#include "Exceptions/DebugWirePhysicalInterfaceError.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
|
||||
namespace Targets::Microchip::Avr::Avr8Bit
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "src/Targets/Microchip/AVR/Fuse.hpp"
|
||||
#include "src/Targets/TargetPhysicalInterface.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetBreakpoint.hpp"
|
||||
|
||||
#include "TargetDescription/TargetDescriptionFile.hpp"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "src/Targets/TargetDescription/TargetDescriptionFile.hpp"
|
||||
|
||||
#include "src/Targets/TargetVariant.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
#include "src/Targets/Microchip/AVR/TargetSignature.hpp"
|
||||
#include "src/Targets/Microchip/AVR/IspParameters.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
|
||||
#include "RiscVGeneric.hpp"
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "TargetDescriptor.hpp"
|
||||
#include "TargetState.hpp"
|
||||
#include "TargetRegisterDescriptor.hpp"
|
||||
#include "TargetRegister.hpp"
|
||||
#include "TargetMemory.hpp"
|
||||
#include "TargetBreakpoint.hpp"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "TargetFamily.hpp"
|
||||
#include "TargetMemory.hpp"
|
||||
#include "TargetRegister.hpp"
|
||||
#include "TargetRegisterDescriptor.hpp"
|
||||
#include "TargetVariant.hpp"
|
||||
#include "TargetBreakpoint.hpp"
|
||||
|
||||
|
||||
@@ -1,105 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "TargetRegisterDescriptor.hpp"
|
||||
#include "TargetMemory.hpp"
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
using TargetRegisterDescriptorId = std::uint32_t;
|
||||
using TargetRegisterDescriptorIds = std::set<Targets::TargetRegisterDescriptorId>;
|
||||
|
||||
enum class TargetRegisterType: std::uint8_t
|
||||
{
|
||||
GENERAL_PURPOSE_REGISTER,
|
||||
PROGRAM_COUNTER,
|
||||
STACK_POINTER,
|
||||
STATUS_REGISTER,
|
||||
PORT_REGISTER,
|
||||
OTHER,
|
||||
};
|
||||
|
||||
struct TargetRegisterAccess
|
||||
{
|
||||
bool readable = false;
|
||||
bool writable = false;
|
||||
|
||||
TargetRegisterAccess(
|
||||
bool readable,
|
||||
bool writable
|
||||
)
|
||||
: readable(readable)
|
||||
, writable(writable)
|
||||
{}
|
||||
};
|
||||
|
||||
struct TargetRegisterDescriptor
|
||||
{
|
||||
public:
|
||||
TargetRegisterDescriptorId id;
|
||||
TargetRegisterType type;
|
||||
std::optional<TargetMemoryAddress> startAddress;
|
||||
TargetMemorySize size;
|
||||
TargetMemoryType memoryType;
|
||||
|
||||
std::optional<std::string> name;
|
||||
std::optional<std::string> groupName;
|
||||
std::optional<std::string> description;
|
||||
|
||||
TargetRegisterAccess access;
|
||||
|
||||
TargetRegisterDescriptor(
|
||||
TargetRegisterType type,
|
||||
std::optional<TargetMemoryAddress> startAddress,
|
||||
TargetMemorySize size,
|
||||
TargetMemoryType memoryType,
|
||||
std::optional<std::string> name,
|
||||
std::optional<std::string> groupName,
|
||||
std::optional<std::string> description,
|
||||
TargetRegisterAccess access
|
||||
)
|
||||
: id(++(TargetRegisterDescriptor::lastRegisterDescriptorId))
|
||||
, type(type)
|
||||
, startAddress(startAddress)
|
||||
, size(size)
|
||||
, memoryType(memoryType)
|
||||
, name(name)
|
||||
, groupName(groupName)
|
||||
, description(description)
|
||||
, access(access)
|
||||
{};
|
||||
|
||||
bool operator == (const TargetRegisterDescriptor& other) const {
|
||||
return this->getHash() == other.getHash();
|
||||
}
|
||||
|
||||
bool operator < (const TargetRegisterDescriptor& other) const {
|
||||
if (this->type == other.type) {
|
||||
return this->startAddress.value_or(0) < other.startAddress.value_or(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the registers are of different type, there is no meaningful way to sort them, so we just use
|
||||
* the unique hash.
|
||||
*/
|
||||
return this->getHash() < other.getHash();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::optional<std::size_t> cachedHash;
|
||||
static inline std::atomic<TargetRegisterDescriptorId> lastRegisterDescriptorId = 0;
|
||||
std::size_t getHash() const;
|
||||
|
||||
friend std::hash<Targets::TargetRegisterDescriptor>;
|
||||
};
|
||||
|
||||
struct TargetRegister
|
||||
{
|
||||
TargetRegisterDescriptorId descriptorId;
|
||||
@@ -120,24 +29,4 @@ namespace Targets
|
||||
};
|
||||
|
||||
using TargetRegisters = std::vector<TargetRegister>;
|
||||
using TargetRegisterDescriptors = std::set<TargetRegisterDescriptor>;
|
||||
using TargetRegisterDescriptorMapping = std::map<TargetRegisterDescriptorId, TargetRegisterDescriptor>;
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
/**
|
||||
* Hashing function for TargetRegisterDescriptor type.
|
||||
*
|
||||
* This is required in order to use TargetRegisterDescriptor as a key in an std::unordered_map (see the BiMap
|
||||
* class)
|
||||
*/
|
||||
template<>
|
||||
class hash<Targets::TargetRegisterDescriptor>
|
||||
{
|
||||
public:
|
||||
std::size_t operator()(const Targets::TargetRegisterDescriptor& descriptor) const {
|
||||
return descriptor.getHash();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "TargetRegister.hpp"
|
||||
#include "TargetRegisterDescriptor.hpp"
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
125
src/Targets/TargetRegisterDescriptor.hpp
Normal file
125
src/Targets/TargetRegisterDescriptor.hpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "TargetMemory.hpp"
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
using TargetRegisterDescriptorId = std::uint32_t;
|
||||
using TargetRegisterDescriptorIds = std::set<Targets::TargetRegisterDescriptorId>;
|
||||
|
||||
enum class TargetRegisterType: std::uint8_t
|
||||
{
|
||||
GENERAL_PURPOSE_REGISTER,
|
||||
PROGRAM_COUNTER,
|
||||
STACK_POINTER,
|
||||
STATUS_REGISTER,
|
||||
PORT_REGISTER,
|
||||
OTHER,
|
||||
};
|
||||
|
||||
struct TargetRegisterAccess
|
||||
{
|
||||
bool readable = false;
|
||||
bool writable = false;
|
||||
|
||||
TargetRegisterAccess(
|
||||
bool readable,
|
||||
bool writable
|
||||
)
|
||||
: readable(readable)
|
||||
, writable(writable)
|
||||
{}
|
||||
};
|
||||
|
||||
struct TargetRegisterDescriptor
|
||||
{
|
||||
public:
|
||||
TargetRegisterDescriptorId id;
|
||||
TargetRegisterType type;
|
||||
std::optional<TargetMemoryAddress> startAddress;
|
||||
TargetMemorySize size;
|
||||
TargetMemoryType memoryType;
|
||||
|
||||
std::optional<std::string> name;
|
||||
std::optional<std::string> groupName;
|
||||
std::optional<std::string> description;
|
||||
|
||||
TargetRegisterAccess access;
|
||||
|
||||
TargetRegisterDescriptor(
|
||||
TargetRegisterType type,
|
||||
std::optional<TargetMemoryAddress> startAddress,
|
||||
TargetMemorySize size,
|
||||
TargetMemoryType memoryType,
|
||||
std::optional<std::string> name,
|
||||
std::optional<std::string> groupName,
|
||||
std::optional<std::string> description,
|
||||
TargetRegisterAccess access
|
||||
)
|
||||
: id(++(TargetRegisterDescriptor::lastRegisterDescriptorId))
|
||||
, type(type)
|
||||
, startAddress(startAddress)
|
||||
, size(size)
|
||||
, memoryType(memoryType)
|
||||
, name(name)
|
||||
, groupName(groupName)
|
||||
, description(description)
|
||||
, access(access)
|
||||
{};
|
||||
|
||||
bool operator == (const TargetRegisterDescriptor& other) const {
|
||||
return this->getHash() == other.getHash();
|
||||
}
|
||||
|
||||
bool operator < (const TargetRegisterDescriptor& other) const {
|
||||
if (this->type == other.type) {
|
||||
return this->startAddress.has_value() && other.startAddress.has_value()
|
||||
? this->startAddress < other.startAddress
|
||||
: this->name < other.name
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the registers are of different type, there is no meaningful way to sort them, so we just use
|
||||
* the unique hash.
|
||||
*/
|
||||
return this->getHash() < other.getHash();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::optional<std::size_t> cachedHash;
|
||||
static inline std::atomic<TargetRegisterDescriptorId> lastRegisterDescriptorId = 0;
|
||||
std::size_t getHash() const;
|
||||
|
||||
friend std::hash<Targets::TargetRegisterDescriptor>;
|
||||
};
|
||||
|
||||
using TargetRegisterDescriptors = std::set<TargetRegisterDescriptor>;
|
||||
using TargetRegisterDescriptorMapping = std::map<TargetRegisterDescriptorId, TargetRegisterDescriptor>;
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
/**
|
||||
* Hashing function for TargetRegisterDescriptor type.
|
||||
*
|
||||
* This is required in order to use TargetRegisterDescriptor as a key in an std::unordered_map (see the BiMap
|
||||
* class)
|
||||
*/
|
||||
template<>
|
||||
class hash<Targets::TargetRegisterDescriptor>
|
||||
{
|
||||
public:
|
||||
std::size_t operator()(const Targets::TargetRegisterDescriptor& descriptor) const {
|
||||
return descriptor.getHash();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user