Files
BloomPatched/src/Targets/TargetMemory.hpp

121 lines
3.6 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <cstdint>
2021-04-04 21:04:12 +01:00
#include <vector>
#include <set>
#include <optional>
2021-04-04 21:04:12 +01:00
namespace Targets
2021-04-04 21:04:12 +01:00
{
using TargetMemoryAddress = std::uint32_t;
using TargetMemorySize = std::uint32_t;
using TargetStackPointer = TargetMemoryAddress;
using TargetMemoryBuffer = std::vector<unsigned char>;
enum class TargetMemoryEndianness: std::uint8_t
{
BIG,
LITTLE,
};
enum class TargetMemoryType: std::uint8_t
2021-04-04 21:04:12 +01:00
{
FLASH,
RAM,
EEPROM,
2023-05-07 16:49:45 +01:00
FUSES,
OTHER,
2021-04-04 21:04:12 +01:00
};
struct TargetMemoryAddressRange
{
TargetMemoryAddress startAddress = 0;
TargetMemoryAddress endAddress = 0;
TargetMemoryAddressRange() = default;
TargetMemoryAddressRange(TargetMemoryAddress startAddress, TargetMemoryAddress endAddress)
: startAddress(startAddress)
, endAddress(endAddress)
2024-02-25 16:41:57 +00:00
{}
2021-12-22 03:33:54 +00:00
bool operator == (const TargetMemoryAddressRange& rhs) const {
return this->startAddress == rhs.startAddress && this->endAddress == rhs.endAddress;
}
bool operator < (const TargetMemoryAddressRange& rhs) const {
return this->startAddress < rhs.startAddress;
}
2021-12-22 03:33:54 +00:00
[[nodiscard]] bool intersectsWith(const TargetMemoryAddressRange& other) const {
return
(other.startAddress <= this->startAddress && other.endAddress >= this->startAddress)
|| (other.startAddress >= this->startAddress && other.startAddress <= this->endAddress)
2021-12-22 03:33:54 +00:00
;
}
[[nodiscard]] bool contains(TargetMemoryAddress address) const {
return address >= this->startAddress && address <= this->endAddress;
}
[[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const {
return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress;
}
std::set<Targets::TargetMemoryAddress> addresses() const {
auto addresses = std::set<Targets::TargetMemoryAddress>();
auto addressesIt = addresses.end();
for (auto i = this->startAddress; i <= this->endAddress; ++i) {
addressesIt = addresses.insert(addressesIt, i);
}
return addresses;
}
};
2021-10-09 19:17:58 +01:00
struct TargetMemoryAccess
{
bool readable = false;
bool writeable = false;
bool writeableDuringDebugSession = false;
TargetMemoryAccess(
bool readable,
bool writeable,
bool writeableDuringDebugSession
)
: readable(readable)
, writeable(writeable)
, writeableDuringDebugSession(writeableDuringDebugSession)
{}
};
2021-10-09 19:17:58 +01:00
struct TargetMemoryDescriptor
{
TargetMemoryType type;
TargetMemoryAddressRange addressRange;
TargetMemoryAccess access;
std::optional<TargetMemorySize> pageSize;
2021-10-09 19:17:58 +01:00
TargetMemoryDescriptor(
TargetMemoryType type,
TargetMemoryAddressRange addressRange,
TargetMemoryAccess access,
std::optional<TargetMemorySize> pageSize = std::nullopt
)
: type(type)
, addressRange(addressRange)
, access(access)
, pageSize(pageSize)
2024-02-25 16:41:57 +00:00
{}
2021-10-09 19:17:58 +01:00
bool operator == (const TargetMemoryDescriptor& rhs) const {
return this->type == rhs.type && this->addressRange == rhs.addressRange;
}
[[nodiscard]] TargetMemorySize size() const {
return (this->addressRange.endAddress - this->addressRange.startAddress) + 1;
2021-10-09 19:17:58 +01:00
}
};
2021-04-04 21:04:12 +01:00
}