Added target address space and memory segment descriptor structs
This commit is contained in:
69
src/Targets/TargetAddressSpaceDescriptor.hpp
Normal file
69
src/Targets/TargetAddressSpaceDescriptor.hpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <atomic>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include "TargetMemory.hpp"
|
||||||
|
#include "TargetMemorySegmentDescriptor.hpp"
|
||||||
|
#include "src/Exceptions/InternalFatalErrorException.hpp"
|
||||||
|
|
||||||
|
namespace Targets
|
||||||
|
{
|
||||||
|
using TargetAddressSpaceDescriptorId = std::uint8_t;
|
||||||
|
|
||||||
|
struct TargetAddressSpaceDescriptor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const TargetAddressSpaceDescriptorId id;
|
||||||
|
std::string key;
|
||||||
|
TargetMemoryAddress startAddress;
|
||||||
|
TargetMemorySize size;
|
||||||
|
TargetMemoryEndianness endianness;
|
||||||
|
std::map<std::string, TargetMemorySegmentDescriptor> segmentDescriptorsByKey;
|
||||||
|
|
||||||
|
TargetAddressSpaceDescriptor(
|
||||||
|
const std::string& key,
|
||||||
|
TargetMemoryAddress startAddress,
|
||||||
|
TargetMemorySize size,
|
||||||
|
TargetMemoryEndianness endianness,
|
||||||
|
const std::map<std::string, TargetMemorySegmentDescriptor>& segmentDescriptorsByKey
|
||||||
|
)
|
||||||
|
: id(++(TargetAddressSpaceDescriptor::lastAddressSpaceDescriptorId))
|
||||||
|
, key(key)
|
||||||
|
, startAddress(startAddress)
|
||||||
|
, size(size)
|
||||||
|
, endianness(endianness)
|
||||||
|
, segmentDescriptorsByKey(segmentDescriptorsByKey)
|
||||||
|
{};
|
||||||
|
|
||||||
|
std::optional<std::reference_wrapper<const TargetMemorySegmentDescriptor>> tryGetMemorySegmentDescriptor(
|
||||||
|
const std::string& key
|
||||||
|
) const {
|
||||||
|
const auto segmentIt = this->segmentDescriptorsByKey.find(key);
|
||||||
|
|
||||||
|
if (segmentIt == this->segmentDescriptorsByKey.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::cref(segmentIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
const TargetMemorySegmentDescriptor& getMemorySegmentDescriptor(const std::string& key) const {
|
||||||
|
const auto segment = this->tryGetMemorySegmentDescriptor(key);
|
||||||
|
if (!segment.has_value()) {
|
||||||
|
throw Exceptions::InternalFatalErrorException(
|
||||||
|
"Failed to get memory segment descriptor \"" + key + "\" from address space \"" + this->key
|
||||||
|
+ "\" - segment not found"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return segment->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static inline std::atomic<TargetAddressSpaceDescriptorId> lastAddressSpaceDescriptorId = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -159,6 +159,20 @@ namespace Targets::TargetDescription
|
|||||||
return peripheral->get();
|
return peripheral->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<
|
||||||
|
TargetAddressSpaceDescriptorId,
|
||||||
|
TargetAddressSpaceDescriptor
|
||||||
|
> TargetDescriptionFile::targetAddressSpaceDescriptorsById() const {
|
||||||
|
auto output = std::map<TargetAddressSpaceDescriptorId, TargetAddressSpaceDescriptor>();
|
||||||
|
|
||||||
|
for (const auto& [key, addressSpace] : this->addressSpacesByKey) {
|
||||||
|
auto descriptor = this->targetAddressSpaceDescriptorFromAddressSpace(addressSpace);
|
||||||
|
output.emplace(descriptor.id, std::move(descriptor));
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
void TargetDescriptionFile::init(const std::string& xmlFilePath) {
|
void TargetDescriptionFile::init(const std::string& xmlFilePath) {
|
||||||
auto file = QFile(QString::fromStdString(xmlFilePath));
|
auto file = QFile(QString::fromStdString(xmlFilePath));
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@@ -675,4 +689,40 @@ namespace Targets::TargetDescription
|
|||||||
TargetDescriptionFile::getAttribute(xmlElement, "package")
|
TargetDescriptionFile::getAttribute(xmlElement, "package")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TargetAddressSpaceDescriptor TargetDescriptionFile::targetAddressSpaceDescriptorFromAddressSpace(
|
||||||
|
const AddressSpace& addressSpace
|
||||||
|
) {
|
||||||
|
auto output = TargetAddressSpaceDescriptor(
|
||||||
|
addressSpace.key,
|
||||||
|
addressSpace.startAddress,
|
||||||
|
addressSpace.size,
|
||||||
|
addressSpace.endianness.value_or(TargetMemoryEndianness::LITTLE),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const auto& [key, memorySegment] : addressSpace.memorySegmentsByKey) {
|
||||||
|
output.segmentDescriptorsByKey.emplace(
|
||||||
|
key,
|
||||||
|
TargetDescriptionFile::targetMemorySegmentDescriptorFromMemorySegment(memorySegment)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
TargetMemorySegmentDescriptor TargetDescriptionFile::targetMemorySegmentDescriptorFromMemorySegment(
|
||||||
|
const MemorySegment& memorySegment
|
||||||
|
) {
|
||||||
|
return TargetMemorySegmentDescriptor(
|
||||||
|
memorySegment.key,
|
||||||
|
memorySegment.name,
|
||||||
|
memorySegment.type,
|
||||||
|
memorySegment.startAddress,
|
||||||
|
memorySegment.size,
|
||||||
|
memorySegment.access,
|
||||||
|
memorySegment.access,
|
||||||
|
memorySegment.pageSize
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include "Variant.hpp"
|
#include "Variant.hpp"
|
||||||
|
|
||||||
#include "src/Targets/TargetFamily.hpp"
|
#include "src/Targets/TargetFamily.hpp"
|
||||||
|
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
|
||||||
|
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
|
||||||
#include "src/Targets/TargetPhysicalInterface.hpp"
|
#include "src/Targets/TargetPhysicalInterface.hpp"
|
||||||
|
|
||||||
namespace Targets::TargetDescription
|
namespace Targets::TargetDescription
|
||||||
@@ -103,6 +105,8 @@ namespace Targets::TargetDescription
|
|||||||
) const;
|
) const;
|
||||||
[[nodiscard]] const Peripheral& getPeripheral(std::string_view key) const;
|
[[nodiscard]] const Peripheral& getPeripheral(std::string_view key) const;
|
||||||
|
|
||||||
|
std::map<TargetAddressSpaceDescriptorId, TargetAddressSpaceDescriptor> targetAddressSpaceDescriptorsById() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<std::string, std::string> deviceAttributesByName;
|
std::map<std::string, std::string> deviceAttributesByName;
|
||||||
std::map<std::string, PropertyGroup, std::less<void>> propertyGroupsByKey;
|
std::map<std::string, PropertyGroup, std::less<void>> propertyGroupsByKey;
|
||||||
@@ -147,5 +151,13 @@ namespace Targets::TargetDescription
|
|||||||
static Pinout pinoutFromXml(const QDomElement& xmlElement);
|
static Pinout pinoutFromXml(const QDomElement& xmlElement);
|
||||||
static Pin pinFromXml(const QDomElement& xmlElement);
|
static Pin pinFromXml(const QDomElement& xmlElement);
|
||||||
static Variant variantFromXml(const QDomElement& xmlElement);
|
static Variant variantFromXml(const QDomElement& xmlElement);
|
||||||
|
|
||||||
|
static TargetAddressSpaceDescriptor targetAddressSpaceDescriptorFromAddressSpace(
|
||||||
|
const AddressSpace& addressSpace
|
||||||
|
);
|
||||||
|
|
||||||
|
static TargetMemorySegmentDescriptor targetMemorySegmentDescriptorFromMemorySegment(
|
||||||
|
const MemorySegment& memorySegment
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/Targets/TargetMemorySegmentDescriptor.hpp
Normal file
43
src/Targets/TargetMemorySegmentDescriptor.hpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include "TargetMemory.hpp"
|
||||||
|
#include "TargetMemorySegmentType.hpp"
|
||||||
|
|
||||||
|
namespace Targets
|
||||||
|
{
|
||||||
|
struct TargetMemorySegmentDescriptor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string key;
|
||||||
|
std::string name;
|
||||||
|
TargetMemorySegmentType type;
|
||||||
|
TargetMemoryAddress startAddress;
|
||||||
|
TargetMemorySize size;
|
||||||
|
TargetMemoryAccess debugModeAccess;
|
||||||
|
TargetMemoryAccess programmingModeAccess;
|
||||||
|
std::optional<TargetMemorySize> pageSize;
|
||||||
|
|
||||||
|
TargetMemorySegmentDescriptor(
|
||||||
|
const std::string& key,
|
||||||
|
const std::string& name,
|
||||||
|
TargetMemorySegmentType type,
|
||||||
|
TargetMemoryAddress startAddress,
|
||||||
|
TargetMemorySize size,
|
||||||
|
const TargetMemoryAccess& debugModeAccess,
|
||||||
|
const TargetMemoryAccess& programmingModeAccess,
|
||||||
|
std::optional<TargetMemorySize> pageSize
|
||||||
|
)
|
||||||
|
: key(key)
|
||||||
|
, name(name)
|
||||||
|
, type(type)
|
||||||
|
, startAddress(startAddress)
|
||||||
|
, size(size)
|
||||||
|
, debugModeAccess(debugModeAccess)
|
||||||
|
, programmingModeAccess(programmingModeAccess)
|
||||||
|
, pageSize(pageSize)
|
||||||
|
{};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user