64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
//---
|
|
// fxos.symbols: User-defined symbols for OS objects
|
|
//---
|
|
|
|
#ifndef LIBFXOS_SYMBOLS_H
|
|
#define LIBFXOS_SYMBOLS_H
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <fxos/os.h>
|
|
#include <fxos/target.h>
|
|
|
|
namespace FxOS
|
|
{
|
|
|
|
/* A named symbol that can be substituted to literal values in the code. */
|
|
struct Symbol
|
|
{
|
|
/* Syscall: The value is a syscall number. The syscall number for an
|
|
address is determined by querying the OS object.
|
|
Address: The value is a fixed 32-bit virtual address. */
|
|
enum Type { Syscall=1, Address=2 };
|
|
|
|
enum Type type;
|
|
uint32_t value;
|
|
|
|
/* Symbol name, no particular conventions */
|
|
std::string name;
|
|
};
|
|
|
|
/* A symbol table, essentially a set of symbols loaded from the same file */
|
|
class SymbolTable
|
|
{
|
|
public:
|
|
/* Construct a new symbol table for the specified OS and MPU; the two
|
|
constraints apply simultaneously. For both, an empty string
|
|
represents no constraint. */
|
|
SymbolTable(std::string os="", std::string mpu="");
|
|
|
|
std::string table_name;
|
|
std::vector<Symbol> symbols;
|
|
|
|
/* Validate constraints to see if table is usable */
|
|
bool is_usable_on(OS &os) const noexcept;
|
|
bool is_usable_on(Target &target) const noexcept;
|
|
/* Add a symbol to the table */
|
|
void add(Symbol s);
|
|
/* Query a value for a certain type of symbol */
|
|
std::optional<std::string> query(Symbol::Type type, uint32_t value)
|
|
const;
|
|
/* Lookup the symbol behind a given name */
|
|
std::optional<Symbol> lookup(std::string name) const;
|
|
|
|
private:
|
|
std::string m_os_constraint;
|
|
std::string m_mpu_constraint;
|
|
};
|
|
|
|
} /* namespace FxOS */
|
|
|
|
#endif /* LIBFXOS_SYMBOLS_H */
|