fxos/include/fxos/vspace.h

94 lines
2.9 KiB
C
Raw Normal View History

//---------------------------------------------------------------------------//
// 1100101 |_ mov #0, r4 __ //
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
// |_ base# + offset |_| /_\_\___/__/ //
//---------------------------------------------------------------------------//
// fxos/vspace: Virtual address space with loaded code and analyses
//
// This is the main structure/entry point of fxos. A Virtu
//---
2021-03-16 14:43:43 +01:00
// fxos.vspace: A virtual space where code is being studied
//---
#ifndef FXOS_VSPACE_H
#define FXOS_VSPACE_H
#include <fxos/memory.h>
#include <fxos/os.h>
#include <fxos/symbols.h>
#include <fxos/AbstractMemory.h>
2022-03-27 13:12:53 +02:00
#include <fxos/util/Buffer.h>
#include <fxos/util/Addressable.h>
#include <optional>
#include <vector>
#include <cstdint>
#include <memory>
namespace FxOS {
/* A binding of a data buffer into a memory region of the target. */
struct Binding: public AbstractMemory
{
/* Constructor from data buffer. An error is raised if the buffer is
not at least of the size of the region. In this case, a new buffer
can be constructed with the required size. */
Binding(MemoryRegion region, Buffer buffer);
/* Targeted region, might overlap with other bindings */
MemoryRegion region;
/* Underlying buffer (copy of the original one) */
Buffer buffer;
char const *translate_dynamic(uint32_t addr, int *size) override;
};
2021-03-16 14:43:43 +01:00
/* A composite space where regions can be bound dynamically */
class VirtualSpace: public AbstractMemory
{
public:
/* Create an empty space with no regions */
VirtualSpace();
/* MPU used by this target, or an empty string if unspecified */
std::string mpu;
/* List of bindings (most recent first) */
std::vector<Binding> bindings;
/* OS analysis; performed on-demand. Returns the new or cached OS analysis,
and nullptr only if OS cannot be analyzed */
OS *os_analysis(bool force=false);
/* Cursor position, used by the interactive shell */
uint32_t cursor;
/* Symbol table */
SymbolTable symbols;
/* Bind a memory region from a buffer. The region can either be
standard (see <fxos/memory.h>) or custom.
If several loaded regions overlap on some addresses, *the last
loaded region will be used*. Thus, new regions can be loaded to
selectively override parts of the target.
An error is raised if the buffer is smaller than the region being
bound. */
void bind_region(MemoryRegion const &region, Buffer const &buffer);
/* Implementation of AbstractMemory primitives */
char const *translate_dynamic(uint32_t addr, int *size) override;
private:
/* OS analysis results */
std::unique_ptr<OS> m_os;
};
} /* namespace FxOS */
#endif /* FXOS_VSPACE_H */