Massive refactor to accommodate RISC-V targets

- Refactored entire codebase (excluding the Insight component) to accommodate multiple target architectures (no longer specific to AVR)
- Deleted 'generate SVD' GDB monitor command - I will eventually move this functionality to the Bloom website
- Added unit size property to address spaces
- Many other changes which I couldn't be bothered to describe here
This commit is contained in:
Nav
2024-07-23 21:14:22 +01:00
parent 2986934485
commit 6cdbfbe950
331 changed files with 8815 additions and 8565 deletions

View File

@@ -9,85 +9,61 @@
#include "src/Helpers/BiMap.hpp"
#include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "RegisterDescriptor.hpp"
namespace DebugServer::Gdb
{
using GdbMemoryAddress = std::uint32_t;
/**
* GDB target descriptor.
*/
class TargetDescriptor
{
public:
Targets::TargetDescriptor targetDescriptor;
std::map<GdbRegisterId, RegisterDescriptor> gdbRegisterDescriptorsById;
explicit TargetDescriptor(
const Targets::TargetDescriptor& targetDescriptor,
const BiMap<Targets::TargetMemoryType, std::uint32_t>& memoryOffsetsByType,
std::map<GdbRegisterId, RegisterDescriptor> gdbRegisterDescriptorsById,
std::map<Targets::TargetRegisterDescriptorId, GdbRegisterId> gdbRegisterIdsByTargetRegisterDescriptorId,
std::map<GdbRegisterId, Targets::TargetRegisterDescriptorId> targetRegisterDescriptorIdsByGdbRegisterId
);
std::map<GdbRegisterId, const Targets::TargetRegisterDescriptor*> targetRegisterDescriptorsByGdbId;
virtual ~TargetDescriptor() = default;
std::uint32_t getMemoryOffset(Targets::TargetMemoryType memoryType) const;
/**
* Helper method to extract the target memory type (Flash, RAM, etc) from a GDB memory address.
* For targets with multiple address spaces (e.g. AVR), GDB encodes address space information into memory
* addresses, by applying a mask.
*
* This function should identify the encoded address space within a GDB memory address, and return the
* relevant address space descriptor.
*
* @param address
* @return
*/
Targets::TargetMemoryType getMemoryTypeFromGdbAddress(std::uint32_t address) const;
virtual const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptorFromGdbAddress(
GdbMemoryAddress address
) const = 0;
/**
* Should retrieve the GDB register ID, given a target register descriptor ID. Or std::nullopt if the
* target register descriptor ID isn't mapped to any GDB register.
* This function should translate a GDB memory address to a target memory address. This should strip any
* GDB-specific masks and return an address that can be used within Bloom.
*
* @param registerDescriptorId
* @param address
* @return
*/
std::optional<GdbRegisterId> getGdbRegisterIdFromTargetRegisterDescriptorId(
Targets::TargetRegisterDescriptorId targetRegisterDescriptorId
) const;
virtual Targets::TargetMemoryAddress translateGdbAddress(GdbMemoryAddress address) const = 0;
/**
* Should retrieve the mapped target register descriptor ID for a given GDB register ID.
* This function should translate a target memory address to a GDB memory address. It should encode any
* additional data expected by GDB.
*
* This function may return std::nullopt if the GDB register ID maps to something that isn't considered a
* register on our end. For example, for AVR targets, the GDB register ID 34 maps to the program counter. But
* the program counter is not treated like any other register in Bloom (there's no TargetRegisterDescriptor for
* it). So in that case, the GDB register ID is not mapped to any target register descriptor ID.
*
* @param gdbRegisterId
* @param address
* @param addressSpaceDescriptor
* @param memorySegmentDescriptor
* @return
*/
std::optional<Targets::TargetRegisterDescriptorId> getTargetRegisterDescriptorIdFromGdbRegisterId(
GdbRegisterId gdbRegisterId
) const;
protected:
/**
* When GDB sends us a memory address, the memory type (Flash, RAM, EEPROM, etc) is embedded within. This is
* done by ORing the address with some constant. For example, for AVR targets, RAM addresses are ORed with
* 0x00800000. Flash addresses are left unchanged. EEPROM addressing is not supported in GDB (for AVR targets).
*
* memoryOffsetsByType is a mapping of memory types to these known constants (which we're calling offsets).
* Because these offsets vary by target, the mapping lives here, in the GDB target descriptor.
*/
BiMap<Targets::TargetMemoryType, std::uint32_t> memoryOffsetsByType;
/**
* Sorted set of the known memory offsets (see memoryOffsetsByType).
*/
std::set<std::uint32_t> memoryOffsets;
std::map<Targets::TargetRegisterDescriptorId, GdbRegisterId> gdbRegisterIdsByTargetRegisterDescriptorId;
std::map<GdbRegisterId, Targets::TargetRegisterDescriptorId> targetRegisterDescriptorIdsByGdbRegisterId;
virtual GdbMemoryAddress translateTargetMemoryAddress(
Targets::TargetMemoryAddress address,
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor
) const = 0;
};
}