2022-03-24 19:17:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
2022-03-31 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
#include "src/Targets/TargetMemory.hpp"
|
|
|
|
|
|
2022-03-31 16:05:39 +01:00
|
|
|
namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
2022-03-24 19:17:41 +00:00
|
|
|
{
|
|
|
|
|
/**
|
2022-04-03 20:35:53 +01:00
|
|
|
* The MemoryAccessCommandPacket class is a base class for memory access GDB commands that are specific to the AVR
|
|
|
|
|
* architecture.
|
|
|
|
|
*
|
|
|
|
|
* With the GDB implementation for the AVR architecture, read/write memory commands include a special memory
|
|
|
|
|
* address. The memory type (FLASH, RAM, EEPROM, etc) is embedded within the 7 most significant bits of the memory
|
|
|
|
|
* address.
|
|
|
|
|
*
|
|
|
|
|
* This class provides functions to extract and remove the memory type from a given memory address.
|
2022-03-24 19:17:41 +00:00
|
|
|
*/
|
2022-04-03 20:35:53 +01:00
|
|
|
class MemoryAccessCommandPacket: public Bloom::DebugServer::Gdb::CommandPackets::CommandPacket
|
2022-03-24 19:17:41 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2022-04-03 20:35:53 +01:00
|
|
|
explicit MemoryAccessCommandPacket(const std::vector<unsigned char>& rawPacket)
|
|
|
|
|
: CommandPacket(rawPacket)
|
|
|
|
|
{};
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* The mask used by the AVR GDB client to encode the memory type into memory addresses.
|
|
|
|
|
*/
|
|
|
|
|
static constexpr std::uint32_t AVR_GDB_MEMORY_ADDRESS_MASK = 0xFE0000U;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* avr-gdb uses the most significant 15 bits in memory addresses to indicate the type of memory being
|
|
|
|
|
* addressed.
|
|
|
|
|
*
|
|
|
|
|
* @param address
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
Targets::TargetMemoryType getMemoryTypeFromGdbAddress(std::uint32_t address) {
|
2022-04-03 20:35:53 +01:00
|
|
|
if ((address & MemoryAccessCommandPacket::AVR_GDB_MEMORY_ADDRESS_MASK) != 0U) {
|
2022-03-24 19:17:41 +00:00
|
|
|
return Targets::TargetMemoryType::RAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Targets::TargetMemoryType::FLASH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Strips the most significant 15 bits from a GDB memory address.
|
|
|
|
|
*
|
|
|
|
|
* @param address
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
std::uint32_t removeMemoryTypeIndicatorFromGdbAddress(std::uint32_t address) {
|
2022-04-03 20:35:53 +01:00
|
|
|
return (address & MemoryAccessCommandPacket::AVR_GDB_MEMORY_ADDRESS_MASK) != 0U
|
|
|
|
|
? (address & ~(MemoryAccessCommandPacket::AVR_GDB_MEMORY_ADDRESS_MASK))
|
2022-03-24 19:17:41 +00:00
|
|
|
: address;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|