2023-11-22 00:38:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
2023-11-23 12:56:26 +00:00
|
|
|
#include <set>
|
2023-11-24 15:19:52 +00:00
|
|
|
#include <map>
|
2023-11-22 00:38:40 +00:00
|
|
|
|
|
|
|
|
#include "src/Targets/Target.hpp"
|
|
|
|
|
#include "src/DebugToolDrivers/DebugTool.hpp"
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
#include "RiscVTargetConfig.hpp"
|
|
|
|
|
#include "TargetDescriptionFile.hpp"
|
2023-12-17 18:12:53 +00:00
|
|
|
|
2023-11-22 00:38:40 +00:00
|
|
|
#include "src/DebugToolDrivers/TargetInterfaces/RiscV/RiscVDebugInterface.hpp"
|
2023-12-08 23:04:04 +00:00
|
|
|
#include "src/DebugToolDrivers/TargetInterfaces/RiscV/RiscVProgramInterface.hpp"
|
2024-07-23 21:14:22 +01:00
|
|
|
#include "src/DebugToolDrivers/TargetInterfaces/RiscV/RiscVIdentificationInterface.hpp"
|
2023-11-24 15:19:52 +00:00
|
|
|
|
2023-11-22 00:38:40 +00:00
|
|
|
namespace Targets::RiscV
|
|
|
|
|
{
|
|
|
|
|
class RiscV: public Target
|
|
|
|
|
{
|
|
|
|
|
public:
|
2024-07-23 21:14:22 +01:00
|
|
|
RiscV(const TargetConfig& targetConfig, TargetDescriptionFile&& targetDescriptionFile);
|
2023-11-22 00:38:40 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The functions below implement the Target interface for RISC-V targets.
|
|
|
|
|
*
|
|
|
|
|
* See the Targets::Target abstract class for documentation on the expected behaviour of
|
|
|
|
|
* each function.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bool supportsDebugTool(DebugTool* debugTool) override;
|
|
|
|
|
void setDebugTool(DebugTool* debugTool) override;
|
|
|
|
|
|
|
|
|
|
void activate() override;
|
|
|
|
|
void deactivate() override;
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
TargetDescriptor targetDescriptor() override;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
|
|
|
|
void run(std::optional<TargetMemoryAddress> toAddress = std::nullopt) override;
|
|
|
|
|
void stop() override;
|
|
|
|
|
void step() override;
|
|
|
|
|
void reset() override;
|
|
|
|
|
|
|
|
|
|
void setSoftwareBreakpoint(TargetMemoryAddress address) override;
|
|
|
|
|
void removeSoftwareBreakpoint(TargetMemoryAddress address) override;
|
|
|
|
|
|
|
|
|
|
void setHardwareBreakpoint(TargetMemoryAddress address) override;
|
|
|
|
|
void removeHardwareBreakpoint(TargetMemoryAddress address) override;
|
|
|
|
|
void clearAllBreakpoints() override;
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
TargetRegisterDescriptorAndValuePairs readRegisters(const TargetRegisterDescriptors& descriptors) override;
|
|
|
|
|
void writeRegisters(const TargetRegisterDescriptorAndValuePairs& registers) override;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
|
|
|
|
TargetMemoryBuffer readMemory(
|
2024-07-23 21:14:22 +01:00
|
|
|
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
|
|
|
|
|
const TargetMemorySegmentDescriptor& memorySegmentDescriptor,
|
2023-11-22 00:38:40 +00:00
|
|
|
TargetMemoryAddress startAddress,
|
|
|
|
|
TargetMemorySize bytes,
|
2023-11-25 23:18:50 +00:00
|
|
|
const std::set<TargetMemoryAddressRange>& excludedAddressRanges = {}
|
2023-11-22 00:38:40 +00:00
|
|
|
) override;
|
|
|
|
|
void writeMemory(
|
2024-07-23 21:14:22 +01:00
|
|
|
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
|
|
|
|
|
const TargetMemorySegmentDescriptor& memorySegmentDescriptor,
|
2023-11-22 00:38:40 +00:00
|
|
|
TargetMemoryAddress startAddress,
|
|
|
|
|
const TargetMemoryBuffer& buffer
|
|
|
|
|
) override;
|
2024-07-23 21:14:22 +01:00
|
|
|
bool isProgramMemory(
|
|
|
|
|
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
|
|
|
|
|
const TargetMemorySegmentDescriptor& memorySegmentDescriptor,
|
|
|
|
|
TargetMemoryAddress startAddress,
|
|
|
|
|
TargetMemorySize size
|
|
|
|
|
) override;
|
|
|
|
|
void eraseMemory(
|
|
|
|
|
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
|
|
|
|
|
const TargetMemorySegmentDescriptor& memorySegmentDescriptor
|
|
|
|
|
) override;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
TargetExecutionState getExecutionState() override;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
|
|
|
|
TargetMemoryAddress getProgramCounter() override;
|
|
|
|
|
void setProgramCounter(TargetMemoryAddress programCounter) override;
|
|
|
|
|
|
|
|
|
|
TargetStackPointer getStackPointer() override;
|
2024-07-23 21:14:22 +01:00
|
|
|
void setStackPointer(TargetStackPointer stackPointer) override;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
TargetGpioPinDescriptorAndStatePairs getGpioPinStates(
|
|
|
|
|
const TargetPinoutDescriptor& pinoutDescriptor
|
2023-11-22 00:38:40 +00:00
|
|
|
) override;
|
2024-07-23 21:14:22 +01:00
|
|
|
void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) override;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
|
|
|
|
void enableProgrammingMode() override;
|
|
|
|
|
|
|
|
|
|
void disableProgrammingMode() override;
|
|
|
|
|
|
|
|
|
|
bool programmingModeEnabled() override;
|
|
|
|
|
|
|
|
|
|
protected:
|
2024-07-23 21:14:22 +01:00
|
|
|
RiscVTargetConfig targetConfig;
|
|
|
|
|
TargetDescriptionFile targetDescriptionFile;
|
2023-11-24 15:19:52 +00:00
|
|
|
|
|
|
|
|
DebugToolDrivers::TargetInterfaces::RiscV::RiscVDebugInterface* riscVDebugInterface = nullptr;
|
2023-12-08 23:04:04 +00:00
|
|
|
DebugToolDrivers::TargetInterfaces::RiscV::RiscVProgramInterface* riscVProgramInterface = nullptr;
|
2024-07-23 21:14:22 +01:00
|
|
|
DebugToolDrivers::TargetInterfaces::RiscV::RiscVIdentificationInterface* riscVIdInterface = nullptr;
|
2023-11-22 00:38:40 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
/*
|
|
|
|
|
* On RISC-V targets, CPU registers are typically only accessible via the debug module (we can't access them
|
|
|
|
|
* via the system address space). So we use abstract commands to access these registers. This means we have to
|
|
|
|
|
* address these registers via their register numbers, as defined in the RISC-V debug spec.
|
|
|
|
|
*
|
|
|
|
|
* We effectively treat register numbers as a separate address space, with an addressable unit size of 4 bytes.
|
|
|
|
|
* The `cpuRegisterAddressSpaceDescriptor` member holds the descriptor for this address space.
|
|
|
|
|
*
|
|
|
|
|
* TODO: review this. This address space is specific to the RISC-V debug spec, but some debug tools may
|
|
|
|
|
* implement their own debug translator in firmware, and then provide a higher-level API to access the
|
|
|
|
|
* same registers. In that case, this address space may not be relevant. This may need to be moved.
|
|
|
|
|
* ATM all RISC-V debug tools supported by Bloom provide a DTM interface, so we use our own debug
|
|
|
|
|
* translator driver and this address space is, in fact, relevant. I will deal with this when it
|
|
|
|
|
* becomes a problem.
|
|
|
|
|
*/
|
|
|
|
|
TargetAddressSpaceDescriptor cpuRegisterAddressSpaceDescriptor;
|
|
|
|
|
const TargetMemorySegmentDescriptor& csrMemorySegmentDescriptor;
|
|
|
|
|
const TargetMemorySegmentDescriptor& gprMemorySegmentDescriptor;
|
2023-11-23 16:32:53 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
TargetPeripheralDescriptor cpuPeripheralDescriptor;
|
|
|
|
|
const TargetRegisterGroupDescriptor& csrGroupDescriptor;
|
|
|
|
|
const TargetRegisterGroupDescriptor& gprGroupDescriptor;
|
|
|
|
|
const TargetRegisterDescriptor& pcRegisterDescriptor;
|
|
|
|
|
const TargetRegisterDescriptor& spRegisterDescriptor;
|
2023-11-23 16:35:09 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
/*
|
|
|
|
|
* The "system" address space is the main address space on RISC-V targets.
|
|
|
|
|
*/
|
|
|
|
|
TargetAddressSpaceDescriptor sysAddressSpaceDescriptor;
|
2023-11-23 16:32:53 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
const TargetMemorySegmentDescriptor& resolveRegisterMemorySegmentDescriptor(
|
|
|
|
|
const TargetRegisterDescriptor& regDescriptor,
|
|
|
|
|
const TargetAddressSpaceDescriptor& addressSpaceDescriptor
|
|
|
|
|
);
|
2023-11-26 15:58:18 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
static TargetAddressSpaceDescriptor generateCpuRegisterAddressSpaceDescriptor();
|
|
|
|
|
static TargetPeripheralDescriptor generateCpuPeripheralDescriptor(
|
|
|
|
|
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
|
|
|
|
|
const TargetMemorySegmentDescriptor& csrMemorySegmentDescriptor,
|
|
|
|
|
const TargetMemorySegmentDescriptor& gprMemorySegmentDescriptor
|
|
|
|
|
);
|
2023-11-22 00:38:40 +00:00
|
|
|
};
|
|
|
|
|
}
|