Bit field struct and TDF extraction
This commit is contained in:
13
src/Targets/TargetDescription/BitField.hpp
Normal file
13
src/Targets/TargetDescription/BitField.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace Bloom::Targets::TargetDescription
|
||||
{
|
||||
struct BitField
|
||||
{
|
||||
std::string name;
|
||||
std::uint8_t mask;
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
#include "BitField.hpp"
|
||||
|
||||
namespace Bloom::Targets::TargetDescription
|
||||
{
|
||||
struct Register
|
||||
@@ -14,6 +16,7 @@ namespace Bloom::Targets::TargetDescription
|
||||
std::uint16_t offset;
|
||||
std::uint16_t size;
|
||||
std::optional<std::string> readWriteAccess;
|
||||
std::map<std::string, BitField> bitFieldsMappedByName;
|
||||
};
|
||||
|
||||
struct RegisterGroup
|
||||
|
||||
@@ -238,9 +238,48 @@ namespace Bloom::Targets::TargetDescription
|
||||
throw Exception("Invalid register offset");
|
||||
}
|
||||
|
||||
auto& bitFields = reg.bitFieldsMappedByName;
|
||||
auto bitFieldNodes = xmlElement.elementsByTagName("bitfield");
|
||||
for (int bitFieldIndex = 0; bitFieldIndex < bitFieldNodes.count(); bitFieldIndex++) {
|
||||
try {
|
||||
auto bitField = TargetDescriptionFile::generateBitFieldFromXml(
|
||||
bitFieldNodes.item(bitFieldIndex).toElement()
|
||||
);
|
||||
bitFields.insert(std::pair(bitField.name, bitField));
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::debug("Failed to extract bit field from register target description element - "
|
||||
+ exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return reg;
|
||||
}
|
||||
|
||||
BitField TargetDescriptionFile::generateBitFieldFromXml(const QDomElement& xmlElement) {
|
||||
if (!xmlElement.hasAttribute("name") || !xmlElement.hasAttribute("mask")) {
|
||||
throw Exception("Missing bit field name/mask attribute");
|
||||
}
|
||||
|
||||
auto bitField = BitField();
|
||||
bitField.name = xmlElement.attribute("name").toLower().toStdString();
|
||||
|
||||
auto maskConversion = false;
|
||||
bitField.mask = static_cast<std::uint8_t>(
|
||||
xmlElement.attribute("mask").toUShort(&maskConversion, 16)
|
||||
);
|
||||
|
||||
if (!maskConversion) {
|
||||
throw Exception("Failed to convert bit field mask to integer (from hex string)");
|
||||
}
|
||||
|
||||
if (bitField.name.empty()) {
|
||||
throw Exception("Empty bit field name");
|
||||
}
|
||||
|
||||
return bitField;
|
||||
}
|
||||
|
||||
void TargetDescriptionFile::loadAddressSpaces() {
|
||||
|
||||
auto addressSpaceNodes = this->deviceElement.elementsByTagName("address-spaces").item(0).toElement()
|
||||
|
||||
@@ -164,6 +164,14 @@ namespace Bloom::Targets::TargetDescription
|
||||
*/
|
||||
static Register generateRegisterFromXml(const QDomElement& xmlElement);
|
||||
|
||||
/**
|
||||
* Consturcts a BitField object from an XML element.
|
||||
*
|
||||
* @param xmlElement
|
||||
* @return
|
||||
*/
|
||||
static BitField generateBitFieldFromXml(const QDomElement& xmlElement);
|
||||
|
||||
/**
|
||||
* Extracts all address spaces and loads them into this->addressSpacesMappedById.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user