2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-11 18:52:39 +01:00
|
|
|
#include <cstdint>
|
2021-04-04 21:04:12 +01:00
|
|
|
#include <vector>
|
2022-05-14 22:39:37 +01:00
|
|
|
#include <optional>
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
namespace Bloom::Targets
|
|
|
|
|
{
|
2022-09-06 17:16:49 +01:00
|
|
|
using TargetMemoryAddress = std::uint32_t;
|
|
|
|
|
using TargetMemorySize = std::uint32_t;
|
|
|
|
|
using TargetProgramCounter = TargetMemoryAddress;
|
|
|
|
|
using TargetStackPointer = TargetMemoryAddress;
|
|
|
|
|
using TargetMemoryBuffer = std::vector<unsigned char>;
|
|
|
|
|
|
2022-02-02 21:52:31 +00:00
|
|
|
enum class TargetMemoryEndianness: std::uint8_t
|
|
|
|
|
{
|
|
|
|
|
BIG,
|
|
|
|
|
LITTLE,
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-11 18:52:39 +01:00
|
|
|
enum class TargetMemoryType: std::uint8_t
|
2021-04-04 21:04:12 +01:00
|
|
|
{
|
|
|
|
|
FLASH,
|
|
|
|
|
RAM,
|
|
|
|
|
EEPROM,
|
2021-09-11 18:52:39 +01:00
|
|
|
OTHER,
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
2021-09-11 18:52:39 +01:00
|
|
|
|
2021-09-11 20:39:31 +01:00
|
|
|
struct TargetMemoryAddressRange
|
|
|
|
|
{
|
2022-09-06 17:16:49 +01:00
|
|
|
TargetMemoryAddress startAddress = 0;
|
|
|
|
|
TargetMemoryAddress endAddress = 0;
|
2021-10-09 19:17:39 +01:00
|
|
|
|
|
|
|
|
TargetMemoryAddressRange() = default;
|
2022-09-06 17:16:49 +01:00
|
|
|
TargetMemoryAddressRange(TargetMemoryAddress startAddress, TargetMemoryAddress endAddress)
|
2022-05-14 22:39:37 +01:00
|
|
|
: startAddress(startAddress)
|
|
|
|
|
, endAddress(endAddress)
|
|
|
|
|
{};
|
2021-12-22 03:33:54 +00:00
|
|
|
|
2021-12-25 01:45:33 +00:00
|
|
|
bool operator == (const TargetMemoryAddressRange& rhs) const {
|
|
|
|
|
return this->startAddress == rhs.startAddress && this->endAddress == rhs.endAddress;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 20:54:02 +00:00
|
|
|
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.endAddress >= this->endAddress && other.startAddress <= this->endAddress)
|
|
|
|
|
;
|
|
|
|
|
}
|
2021-12-27 03:55:11 +00:00
|
|
|
|
2022-09-06 17:16:49 +01:00
|
|
|
[[nodiscard]] bool contains(TargetMemoryAddress address) const {
|
2021-12-30 13:28:58 +00:00
|
|
|
return address >= this->startAddress && address <= this->endAddress;
|
2021-12-27 03:55:11 +00:00
|
|
|
}
|
2022-01-16 18:50:12 +00:00
|
|
|
|
|
|
|
|
[[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const {
|
|
|
|
|
return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress;
|
|
|
|
|
}
|
2021-10-09 19:17:39 +01:00
|
|
|
};
|
2021-10-09 19:17:58 +01:00
|
|
|
|
|
|
|
|
struct TargetMemoryDescriptor
|
|
|
|
|
{
|
|
|
|
|
TargetMemoryType type;
|
|
|
|
|
TargetMemoryAddressRange addressRange;
|
2022-05-14 22:39:37 +01:00
|
|
|
std::optional<std::uint32_t> pageSize;
|
2021-10-09 19:17:58 +01:00
|
|
|
|
2022-05-14 22:39:37 +01:00
|
|
|
TargetMemoryDescriptor(
|
|
|
|
|
TargetMemoryType type,
|
|
|
|
|
TargetMemoryAddressRange addressRange,
|
|
|
|
|
std::optional<std::uint32_t> pageSize = std::nullopt
|
|
|
|
|
)
|
|
|
|
|
: type(type)
|
|
|
|
|
, addressRange(addressRange)
|
|
|
|
|
, pageSize(pageSize)
|
|
|
|
|
{};
|
2021-10-09 19:17:58 +01:00
|
|
|
|
2021-12-25 01:45:33 +00:00
|
|
|
bool operator == (const TargetMemoryDescriptor& rhs) const {
|
|
|
|
|
return this->type == rhs.type && this->addressRange == rhs.addressRange;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 17:16:49 +01:00
|
|
|
[[nodiscard]] TargetMemorySize size() const {
|
2021-12-24 14:35:11 +00:00
|
|
|
return (this->addressRange.endAddress - this->addressRange.startAddress) + 1;
|
2021-10-09 19:17:58 +01:00
|
|
|
}
|
2021-09-11 20:39:31 +01:00
|
|
|
};
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|