From bcdae97638627beef3aba3331e214bcc5c65c65c Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 21 Dec 2024 02:11:13 +0000 Subject: [PATCH] Restricted memory access member function to `system` address space, in RISC-V debug translator --- .../Protocols/RiscVDebugSpec/DebugTranslator.cpp | 9 +++++++++ .../Protocols/RiscVDebugSpec/DebugTranslator.hpp | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp index 11a03457..302c7e0c 100644 --- a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp +++ b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.cpp @@ -77,6 +77,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec , config(config) , targetDescriptionFile(targetDescriptionFile) , targetConfig(targetConfig) + , sysAddressSpaceDescriptor(targetDescriptionFile.getSystemAddressSpaceDescriptor()) {} void DebugTranslator::activate() { @@ -437,6 +438,10 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec TargetMemorySize bytes, const std::set& excludedAddressRanges ) { + if (addressSpaceDescriptor != this->sysAddressSpaceDescriptor) { + throw Exceptions::TargetOperationFailure{"Unsupported address space"}; + } + // TODO: excluded addresses constexpr auto alignTo = DebugTranslator::WORD_BYTE_SIZE; @@ -474,6 +479,10 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec TargetMemoryAddress startAddress, TargetMemoryBufferSpan buffer ) { + if (addressSpaceDescriptor != this->sysAddressSpaceDescriptor) { + throw Exceptions::TargetOperationFailure{"Unsupported address space"}; + } + constexpr auto alignTo = DebugTranslator::WORD_BYTE_SIZE; const auto bytes = static_cast(buffer.size()); if ((startAddress % alignTo) != 0 || (bytes % alignTo) != 0) { diff --git a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.hpp b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.hpp index 0ab1ee8f..e05a32a9 100644 --- a/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.hpp +++ b/src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.hpp @@ -115,6 +115,8 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec const ::Targets::RiscV::TargetDescriptionFile& targetDescriptionFile; const ::Targets::RiscV::RiscVTargetConfig& targetConfig; + const ::Targets::TargetAddressSpaceDescriptor sysAddressSpaceDescriptor; + DebugModuleDescriptor debugModuleDescriptor = {}; DebugModule::HartIndex selectedHartIndex = 0;