fxos/include/fxos/util/Addressable.h

48 lines
1.5 KiB
C++

//---------------------------------------------------------------------------//
// 1100101 |_ mov #0, r4 __ //
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
// |_ base# + offset |_| /_\_\___/__/ //
//---------------------------------------------------------------------------//
// fxos/util/Addressable: Object wrapper with both a value and an address
//
// This object is returned by memory access primitives. It contains both the
// value and the accessed address, which is useful when tracking particular
// blocks of memory within the OS (eg. checksum addresses). See for instance
// OS::compute_checksum() for a use case.
//
// The value is accessed with [.value] or implicitly by conversion to the
// underlying type, and the address is accessed with [.address].
//---
#ifndef FXOS_UTIL_ADDRESSABLE_H
#define FXOS_UTIL_ADDRESSABLE_H
#include <cstdint>
/* An object extracted from a target, which has a virtual address */
template<typename T>
struct Addressable
{
/* Value */
T value;
/* Original virtual address */
uint32_t address;
Addressable() = default;
Addressable(T value): value(value), address(-1)
{
}
Addressable(uint32_t addr, T value): value(value), address(addr)
{
}
/* Implicitly decay to the base type */
operator T() const
{
return value;
}
};
#endif /* FXOS_UTIL_ADDRESSABLE_H */