fxos/include/fxos/os.h

107 lines
3.0 KiB
C++

//---
// fxos.os: Operating system models and primitives
//
// This header describes a structure called [OS] which can be attached to a
// virtual space and gives information about the operating system.
//
// The OS structure can only be created for virtual spaces that have a mapping
// over ROM and if the OS is recognised. The OS structure requires the whole OS
// code to be mapped and cannot provide partial information. If a mapping is
// added to a virtual space, any existing OS structure is discarded.
//
// To access OS information for a virtual space, you should use
// VirtualSpace::os_analysis(), which caches results and doesn't raise
// exceptions.
//---
#ifndef LIBFXOS_OS_H
#define LIBFXOS_OS_H
#include <fxos/util/Addressable.h>
#include <string>
#include <vector>
#include <map>
namespace FxOS {
class VirtualSpace;
class OS
{
public:
/* Create an OS interface for this virtual space. If there is no data
loaded in ROM, this raises an exception. */
OS(VirtualSpace &space);
/* Type of OS, determined at construction */
enum Type { FX, CG };
Type type;
/* Bootcode timestamp and checksum */
Addressable<std::string> bootcode_timestamp;
Addressable<uint32_t> bootcode_checksum;
/* OS version, serial number, timestamp and checksum */
Addressable<std::string> version;
Addressable<std::string> serial_number;
Addressable<std::string> timestamp;
Addressable<uint32_t> checksum;
/* Separated version components */
int version_major, version_minor, version_patch;
/* Recomputed checksum */
uint32_t computed_checksum;
/* Get number of syscalls */
int syscall_count() const noexcept;
/* Get a syscall entry */
uint32_t syscall(int id) const;
/* Find a syscall entry. Returns -1 if syscall is not found */
int find_syscall(uint32_t entry) const noexcept;
/* Get address of syscall table */
uint32_t syscall_table_address() const noexcept;
/* Tests against the OS version */
bool version_lt(int major, int minor, int patch) const noexcept;
bool version_le(int major, int minor, int patch) const noexcept;
bool version_gt(int major, int minor, int patch) const noexcept;
bool version_ge(int major, int minor, int patch) const noexcept;
/* Footer address, or -1 if not found */
uint32_t footer;
/* Number of langdata entries */
int langdata;
private:
/* Virtual space being analyzed */
VirtualSpace &m_space;
/* Parse the OS header. This should be the first analysis function to
be called, because it determines the type of model (ie. fx9860g vs
fxcg50) thus the location of the syscall table and many more
important parameters. */
void parse_header();
/* Locate and parse the syscall table. */
void parse_syscall_table();
/* Locate and parse the footer. */
void parse_footer();
/* Compute OS checkum .*/
uint32_t compute_checksum() const;
//---
// OS information
//---
/* Syscall table, in order of syscall IDs */
std::vector<uint32_t> m_syscall_table;
/* Bimap converse, syscalls sorted by address */
std::map<uint32_t,int> m_syscall_addresses;
};
} /* namespace FxOS */
#endif /* LIBFXOS_OS_H */