Files
BloomPatched/src/Targets/TargetMemory.hpp

89 lines
2.7 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 <optional>
2021-04-04 21:04:12 +01:00
namespace Bloom::Targets
{
using TargetMemoryAddress = std::uint32_t;
using TargetMemorySize = std::uint32_t;
using TargetProgramCounter = TargetMemoryAddress;
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,
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)
{};
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.endAddress >= this->endAddress && other.startAddress <= this->endAddress)
;
}
[[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;
}
};
2021-10-09 19:17:58 +01:00
struct TargetMemoryDescriptor
{
TargetMemoryType type;
TargetMemoryAddressRange addressRange;
std::optional<TargetMemorySize> pageSize;
2021-10-09 19:17:58 +01:00
TargetMemoryDescriptor(
TargetMemoryType type,
TargetMemoryAddressRange addressRange,
std::optional<TargetMemorySize> pageSize = std::nullopt
)
: type(type)
, addressRange(addressRange)
, pageSize(pageSize)
{};
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
}