From e52b8411b38f4256b25de466a9296c8949615ff5 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 23 Sep 2023 21:37:01 +0200 Subject: [PATCH] fix my damn protocol for testing builds I consistently checked that commits built by stashing all other changes... but forgot to stash untracked files. --- include/fxos/binary.h | 178 ++++++++++++++++++++++++++++++++++++++ include/fxos/util/types.h | 26 ++++++ 2 files changed, 204 insertions(+) create mode 100644 include/fxos/binary.h create mode 100644 include/fxos/util/types.h diff --git a/include/fxos/binary.h b/include/fxos/binary.h new file mode 100644 index 0000000..919f315 --- /dev/null +++ b/include/fxos/binary.h @@ -0,0 +1,178 @@ +//---------------------------------------------------------------------------// +// 1100101 |_ mov #0, r4 __ // +// 11 |_ <0xb380 %5c4> / _|_ _____ ___ // +// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< // +// |_ base# + offset |_| /_\_\___/__/ // +//---------------------------------------------------------------------------// +// fxos/binary: Main object for working with programs +// +// This header defines the main structures that combine to form the Binary +// object, which is the main access point for analyzing a program. The Binary +// structure references a VirtualSpace which emulates memory and can be used to +// read raw data. It then lists every Variable and Function that has been +// marked out in the program, either manually or by an analysis. +//--- + +#ifndef FXOS_BINARY_H +#define FXOS_BINARY_H + +#include +#include +// #include +#include +#include +#include + +namespace FxOS { + +class VirtualSpace; +struct Mark; +struct Variable; +struct Function; + +struct Binary +{ + Binary(VirtualSpace &vpsace); + + // TODO: Constructors to load project files into a binary + + VirtualSpace &vspace() + { + return m_vspace; + } + VirtualSpace const &vspace() const + { + return m_vspace; + } + + // TODO: OS analysis in a binary + // TODO: Platform information in a binary + +private: + VirtualSpace &m_vspace; +}; + +/* Base structure for all /binary objets/, ie. program objects that can be + declared in the program space. */ +struct BinaryObject +{ + enum Type : u8 { Mark, Variable, Function }; + + BinaryObject(Binary &binary, Type type, u32 address, u32 size): + m_binary {binary}, m_address {address}, m_size {size}, m_type {type} + { + } + + /* Location and size in the address space. */ + u32 address() const + { + return m_address; + } + u32 size() const + { + return m_size; + } + void setSize(u32 size) + { + m_size = size; + } + + /* Binary that owns the object. */ + Binary &parentBinary() + { + return m_binary; + } + Binary const &parentBinary() const + { + return m_binary; + } + + /* Symbol name, no requirements on uniqueness or character set. */ + std::string const &name() const + { + return m_name; + } + void setName(std::string const &name) + { + m_name = name; + } + /* User comment. */ + std::string const &comment() const + { + return m_comment; + } + void setComment(std::string const &comment) + { + m_comment = comment; + } + + /* Check for a non-empty intersection between two objects. */ + bool intersects(BinaryObject const &other) const; + + /* Check whether this object contains another object. */ + bool contains(BinaryObject const &other) const; + + /* User-readable string representation: "object at " */ + std::string str() const; + + // TODO: BinaryObject serialization + + /* Polymorphic accessors */ + bool isMark() const + { + return m_type == Type::Mark; + } + bool isVariable() const + { + return m_type == Type::Variable; + } + bool isFunction() const + { + return m_type == Type::Function; + } + FxOS::Mark &getMark() const + { + assert(isMark() && "wrong BinaryObject accessor: not a Mark"); + return *(FxOS::Mark *)this; + } + FxOS::Variable &getVariable() const + { + assert(isVariable() && "wrong BinaryObject accessor: not a Variable"); + return *(FxOS::Variable *)this; + } + FxOS::Function &getFunction() const + { + assert(isFunction() && "wrong BinaryObject accessor: not a Function"); + return *(FxOS::Function *)this; + } + +private: + Binary &m_binary; + u32 m_address; + u32 m_size; + Type const m_type; + + std::string m_name; + /* TODO: BinaryObject: don't reserve 32 bytes for empty comments */ + std::string m_comment; +}; + +/* Basic, unattributed binary object used to mark out regions of code (eg. + "kernel", "timer driver", "LINK app", "zero", "interrupt handlers"...). May + alias with other binary objects. */ +struct Mark: public BinaryObject +{ + // TODO: Tags/colors in marks + + // TODO: BinaryObject serialization +}; + +/* Binary object representing a non-empty piece of data. */ +struct Variable: public BinaryObject +{ + // TODO: Variable types +}; + +} /* namespace FxOS */ + +#endif /* FXOS_BINARY_H */ diff --git a/include/fxos/util/types.h b/include/fxos/util/types.h new file mode 100644 index 0000000..0cae554 --- /dev/null +++ b/include/fxos/util/types.h @@ -0,0 +1,26 @@ +//---------------------------------------------------------------------------// +// 1100101 |_ mov #0, r4 __ // +// 11 |_ <0xb380 %5c4> / _|_ _____ ___ // +// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< // +// |_ base# + offset |_| /_\_\___/__/ // +//---------------------------------------------------------------------------// +// fxos/util/types: Common type definitions + +#ifndef FXOS_UTIL_TYPES_H +#define FXOS_UTIL_TYPES_H + +#include + +typedef unsigned int uint; + +/* Fixed-width integer types */ +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; + +#endif /* FXOS_UTIL_TYPES_H */