2022-03-27 18:32:19 +02:00
|
|
|
//---------------------------------------------------------------------------//
|
|
|
|
// 1100101 |_ mov #0, r4 __ //
|
|
|
|
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
|
|
|
|
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
|
|
|
|
// |_ base# + offset |_| /_\_\___/__/ //
|
|
|
|
//---------------------------------------------------------------------------//
|
|
|
|
// fxos/os: Operating system models and primitives
|
2022-03-27 13:12:53 +02:00
|
|
|
//
|
|
|
|
// 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
|
2022-03-27 18:32:19 +02:00
|
|
|
// code to be mapped and cannot provide partial information.
|
2022-03-27 13:12:53 +02:00
|
|
|
//
|
2022-03-27 18:32:19 +02:00
|
|
|
// To access OS information, use VirtualSpace::os_analysis() which caches
|
|
|
|
// results instead of building OS objects directly.
|
2019-12-14 22:33:57 +01:00
|
|
|
//---
|
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
#ifndef FXOS_OS_H
|
|
|
|
#define FXOS_OS_H
|
2019-12-14 22:33:57 +01:00
|
|
|
|
2022-03-27 13:12:53 +02:00
|
|
|
#include <fxos/util/Addressable.h>
|
|
|
|
#include <string>
|
2019-12-14 22:33:57 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2022-03-27 18:32:19 +02:00
|
|
|
#include <memory>
|
2019-12-14 22:33:57 +01:00
|
|
|
|
|
|
|
namespace FxOS {
|
|
|
|
|
2022-03-04 12:29:33 +01:00
|
|
|
class VirtualSpace;
|
|
|
|
|
2019-12-14 22:33:57 +01:00
|
|
|
class OS
|
|
|
|
{
|
|
|
|
public:
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Create an OS interface for this virtual space. If there is no data
|
2023-08-20 16:11:57 +02:00
|
|
|
loaded in ROM or the OS can't be identified, the type os OS is set to
|
|
|
|
UNKNOWN and no information is provided. */
|
2022-03-27 18:32:19 +02:00
|
|
|
OS(VirtualSpace &space);
|
|
|
|
|
|
|
|
/* Type of OS, determined at construction */
|
|
|
|
enum Type { UNKNOWN, 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;
|
2019-12-14 22:33:57 +01:00
|
|
|
|
|
|
|
private:
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Virtual space being analyzed */
|
|
|
|
VirtualSpace &m_space;
|
2019-12-28 17:18:13 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* 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();
|
2019-12-14 22:33:57 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Locate and parse the syscall table. */
|
|
|
|
void parse_syscall_table();
|
2019-12-14 22:33:57 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Locate and parse the footer. */
|
|
|
|
void parse_footer();
|
2019-12-14 22:33:57 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Compute OS checkum .*/
|
|
|
|
uint32_t compute_checksum() const;
|
2022-03-06 23:50:48 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
//---
|
|
|
|
// OS information
|
|
|
|
//---
|
2019-12-14 22:33:57 +01:00
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
/* Syscall table, in order of syscall IDs */
|
|
|
|
std::vector<uint32_t> m_syscall_table;
|
|
|
|
/* Bimap converse, syscalls sorted by address */
|
2022-04-14 13:30:43 +02:00
|
|
|
std::map<uint32_t, int> m_syscall_addresses;
|
2019-12-14 22:33:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace FxOS */
|
|
|
|
|
2022-03-27 18:32:19 +02:00
|
|
|
#endif /* FXOS_OS_H */
|