From 71150163c44f62f1e0f0881344a43100473c4724 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 23 Nov 2024 23:12:38 +0000 Subject: [PATCH] Added abstract data register count check when identifying supported memory access strategies --- .../AbstractControlStatusRegister.hpp | 6 +-- .../RiscVDebugSpec/DebugModuleDescriptor.hpp | 1 + .../RiscVDebugSpec/DebugTranslator.cpp | 44 ++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModule/Registers/AbstractControlStatusRegister.hpp b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModule/Registers/AbstractControlStatusRegister.hpp index bb845be0..b063cdbe 100644 --- a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModule/Registers/AbstractControlStatusRegister.hpp +++ b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModule/Registers/AbstractControlStatusRegister.hpp @@ -8,7 +8,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec::DebugModule::Registers { struct AbstractControlStatusRegister { - std::uint8_t dataCount = 0; + std::uint8_t dataRegisterCount = 0; AbstractCommandError commandError = AbstractCommandError::NONE; bool relaxedPrivilege = false; bool busy = false; @@ -16,7 +16,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec::DebugModule::Registers static constexpr AbstractControlStatusRegister fromValue(RegisterValue value) { return { - .dataCount = static_cast(value & 0x0F), + .dataRegisterCount = static_cast(value & 0x0F), .commandError = static_cast((value >> 8) & 0x07), .relaxedPrivilege = static_cast(value & (0x01 << 11)), .busy = static_cast(value & (0x01 << 12)), @@ -26,7 +26,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec::DebugModule::Registers [[nodiscard]] constexpr RegisterValue value() const { return RegisterValue{0} - | static_cast(this->dataCount & 0x0F) + | static_cast(this->dataRegisterCount & 0x0F) | static_cast(this->commandError) << 8 | static_cast(this->relaxedPrivilege) << 11 | static_cast(this->busy) << 12 diff --git a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModuleDescriptor.hpp b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModuleDescriptor.hpp index 416f5629..9b98d1db 100644 --- a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModuleDescriptor.hpp +++ b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugModuleDescriptor.hpp @@ -19,6 +19,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec std::vector hartIndices; std::unordered_set memoryAccessStrategies; + std::uint8_t abstractDataRegisterCount = 0; std::uint8_t programBufferSize = 0; std::unordered_map triggerDescriptorsByIndex; diff --git a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp index fa163403..77d736a8 100644 --- a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp +++ b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp @@ -128,33 +128,37 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec this->initDebugControlStatusRegister(); const auto abstractControlStatusRegister = this->readDebugModuleAbstractControlStatusRegister(); + this->debugModuleDescriptor.abstractDataRegisterCount = abstractControlStatusRegister.dataRegisterCount; this->debugModuleDescriptor.programBufferSize = abstractControlStatusRegister.programBufferSize; + Logger::debug("Data register count: " + std::to_string(this->debugModuleDescriptor.abstractDataRegisterCount)); Logger::debug("Program buffer size: " + std::to_string(this->debugModuleDescriptor.programBufferSize)); - if (this->debugModuleDescriptor.programBufferSize >= 3) { - this->debugModuleDescriptor.memoryAccessStrategies.insert(MemoryAccessStrategy::PROGRAM_BUFFER); - } + if (this->debugModuleDescriptor.abstractDataRegisterCount > 0) { + if (this->debugModuleDescriptor.programBufferSize >= 3) { + this->debugModuleDescriptor.memoryAccessStrategies.insert(MemoryAccessStrategy::PROGRAM_BUFFER); + } - /* - * Attempt to read a single word from the start of the system address space, via a memory access abstract - * command. - */ - constexpr auto probingMemoryAccessCommand = AbstractCommandRegister{ - .control = MemoryAccessControlField{ - .postIncrement = true, - .size = MemoryAccessControlField::MemorySize::SIZE_32, - }.value(), - .commandType = AbstractCommandRegister::CommandType::MEMORY_ACCESS - }; + /* + * Attempt to read a single word from the start of the system address space, via a memory access abstract + * command. + */ + constexpr auto probingMemoryAccessCommand = AbstractCommandRegister{ + .control = MemoryAccessControlField{ + .postIncrement = true, + .size = MemoryAccessControlField::MemorySize::SIZE_32, + }.value(), + .commandType = AbstractCommandRegister::CommandType::MEMORY_ACCESS + }; - this->dtmInterface.writeDebugModuleRegister( - RegisterAddress::ABSTRACT_DATA_1, - this->targetDescriptionFile.getSystemAddressSpace().startAddress - ); + this->dtmInterface.writeDebugModuleRegister( + RegisterAddress::ABSTRACT_DATA_1, + this->targetDescriptionFile.getSystemAddressSpace().startAddress + ); - if (this->tryExecuteAbstractCommand(probingMemoryAccessCommand) == AbstractCommandError::NONE) { - this->debugModuleDescriptor.memoryAccessStrategies.insert(MemoryAccessStrategy::ABSTRACT_COMMAND); + if (this->tryExecuteAbstractCommand(probingMemoryAccessCommand) == AbstractCommandError::NONE) { + this->debugModuleDescriptor.memoryAccessStrategies.insert(MemoryAccessStrategy::ABSTRACT_COMMAND); + } } if (this->debugModuleDescriptor.memoryAccessStrategies.empty()) {