symbols: add os and mpu constraints to symbol tables
Each of these constraints is specified in the header by an [os] or [mpu] line. For the symbol table to be usable on a disassembly, both constraints must be met: * Either [os] is unset, no OS is used for disassembly, or the OS type is the same as the [os] constraint (either "fx" or "cg"); * Either [mpu] is unset, the disassembled target has no specified MPU, or the MPU type of the target is the same as the [mpu] constraint (eg "sh7305").
This commit is contained in:
parent
a572f20d4d
commit
9c49114928
|
@ -42,9 +42,11 @@ int load_asm(Buffer const &file, size_t offset, size_t line);
|
|||
the complete target description */
|
||||
TargetDescription load_target(Buffer const &file, size_t offset, size_t line);
|
||||
|
||||
/* Load a symbol table. This function returns the full table, which may contain
|
||||
/* Load a symbol table into a previously allocated SymbolTable object. This
|
||||
function populates the table by calls to add(), which may result in
|
||||
duplicates or unused syscall numbers and addresses. */
|
||||
SymbolTable load_symbols(Buffer const &file, size_t offset, size_t line);
|
||||
void load_symbols(Buffer const &file, size_t offset, size_t line,
|
||||
SymbolTable &table);
|
||||
|
||||
} /* namespace FxOS */
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fxos/os.h>
|
||||
#include <fxos/target.h>
|
||||
|
||||
namespace FxOS
|
||||
{
|
||||
|
||||
|
@ -28,11 +31,20 @@ struct Symbol
|
|||
};
|
||||
|
||||
/* A symbol table, essentially a set of symbols loaded from the same file */
|
||||
struct SymbolTable
|
||||
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 */
|
||||
|
@ -40,6 +52,10 @@ struct SymbolTable
|
|||
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 */
|
||||
|
|
|
@ -96,6 +96,8 @@ struct TargetDescription
|
|||
/* Just a list of bindings to be formed */
|
||||
using Binding = std::pair<MemoryRegion,std::string>;
|
||||
std::vector<Binding> bindings;
|
||||
/* Also the MPU to be set */
|
||||
std::string mpu;
|
||||
};
|
||||
|
||||
/* A composite target where regions can be bound dynamically */
|
||||
|
@ -110,6 +112,9 @@ public:
|
|||
Target(TargetDescription const &description,
|
||||
std::vector<std::string> folders);
|
||||
|
||||
/* MPU used by this target, or an empty string if unspecified */
|
||||
std::string mpu;
|
||||
|
||||
/* Bind a memory region from a buffer. The region can either be
|
||||
standard (see <fxos/memory.h>) or custom.
|
||||
|
||||
|
|
|
@ -79,11 +79,15 @@ void Library::load(std::string path)
|
|||
return;
|
||||
}
|
||||
|
||||
m_targets[h["name"]] = load_target(file, offset, line);
|
||||
TargetDescription t = load_target(file, offset, line);
|
||||
t.mpu = h["mpu"];
|
||||
m_targets[h["name"]] = t;
|
||||
}
|
||||
else if(type == "symbols")
|
||||
{
|
||||
SymbolTable st = load_symbols(file, offset, line);
|
||||
SymbolTable st(h["os"], h["mpu"]);
|
||||
load_symbols(file, offset, line, st);
|
||||
|
||||
m_symtables.push_back(st);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -60,16 +60,14 @@ space [ \t]+
|
|||
namespace FxOS {
|
||||
|
||||
/* Load a symbol table into the disassembler */
|
||||
SymbolTable load_symbols(Buffer const &file, size_t start_offset,
|
||||
size_t start_line)
|
||||
void load_symbols(Buffer const &file, size_t start_offset, size_t start_line,
|
||||
SymbolTable &table)
|
||||
{
|
||||
YY_BUFFER_STATE buf = yy_scan_bytes(file.data.get() + start_offset,
|
||||
file.size - start_offset);
|
||||
yylineno = start_line;
|
||||
filename = file.path;
|
||||
|
||||
SymbolTable table;
|
||||
|
||||
/* Current symbol and line */
|
||||
Symbol symbol;
|
||||
int line = -1;
|
||||
|
@ -108,7 +106,6 @@ SymbolTable load_symbols(Buffer const &file, size_t start_offset,
|
|||
}
|
||||
|
||||
yy_delete_buffer(buf);
|
||||
return table;
|
||||
}
|
||||
|
||||
} /* namespace FxOS */
|
||||
|
|
|
@ -109,7 +109,11 @@ std::optional<std::string> PrintPass::symquery(Symbol::Type type,
|
|||
{
|
||||
for(int i = m_symtables.size() - 1; i >= 0; i--)
|
||||
{
|
||||
auto maybe_str = m_symtables[i].query(type, value);
|
||||
SymbolTable const &st = m_symtables[i];
|
||||
if(!st.is_usable_on(m_disasm.target())) continue;
|
||||
if(m_os && !st.is_usable_on(*m_os)) continue;
|
||||
|
||||
auto maybe_str = st.query(type, value);
|
||||
if(maybe_str) return maybe_str;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,23 @@
|
|||
|
||||
namespace FxOS {
|
||||
|
||||
SymbolTable::SymbolTable(std::string os, std::string mpu):
|
||||
m_os_constraint(os), m_mpu_constraint(mpu)
|
||||
{
|
||||
}
|
||||
|
||||
bool SymbolTable::is_usable_on(OS &os) const noexcept
|
||||
{
|
||||
std::string constraint = (os.type == OS::FX) ? "fx" : "cg";
|
||||
return (m_os_constraint == "" || m_os_constraint == constraint);
|
||||
}
|
||||
|
||||
bool SymbolTable::is_usable_on(Target &target) const noexcept
|
||||
{
|
||||
return m_mpu_constraint == "" || target.mpu == "" ||
|
||||
m_mpu_constraint == target.mpu;
|
||||
}
|
||||
|
||||
void SymbolTable::add(Symbol s)
|
||||
{
|
||||
symbols.push_back(s);
|
||||
|
|
|
@ -127,6 +127,8 @@ Target::Target(TargetDescription const &descr,
|
|||
binding.second, folders, size);
|
||||
bind_region(region, *b);
|
||||
}
|
||||
|
||||
this->mpu = descr.mpu;
|
||||
}
|
||||
|
||||
void Target::bind_region(MemoryRegion const ®ion, Buffer const &buffer)
|
||||
|
|
Loading…
Reference in New Issue