/* This file is part of the dynarmic project. * Copyright (c) 2018 MerryMage * SPDX-License-Identifier: 0BSD */ #pragma once #include #include #include #include #include #include namespace Dynarmic { namespace A64 { struct Context; class Jit final { public: explicit Jit(UserConfig conf); ~Jit(); /** * Runs the emulated CPU. * Cannot be recursively called. */ void Run(); /** * Step the emulated CPU for one instruction. * Cannot be recursively called. */ void Step(); /** * Clears the code cache of all compiled code. * Can be called at any time. Halts execution if called within a callback. */ void ClearCache(); /** * Invalidate the code cache at a range of addresses. * @param start_address The starting address of the range to invalidate. * @param length The length (in bytes) of the range to invalidate. */ void InvalidateCacheRange(std::uint64_t start_address, std::size_t length); /** * Reset CPU state to state at startup. Does not clear code cache. * Cannot be called from a callback. */ void Reset(); /** * Stops execution in Jit::Run. * Can only be called from a callback. */ void HaltExecution(); /** * Exits execution from a callback, the callback must rewind the stack or * never return to dynarmic from it's current stack. */ void ExceptionalExit(); /// Read Stack Pointer std::uint64_t GetSP() const; /// Modify Stack Pointer void SetSP(std::uint64_t value); /// Read Program Counter std::uint64_t GetPC() const; /// Modify Program Counter void SetPC(std::uint64_t value); /// Read general-purpose register. std::uint64_t GetRegister(std::size_t index) const; /// Modify general-purpose register. void SetRegister(size_t index, std::uint64_t value); /// Read all general-purpose registers. std::array GetRegisters() const; /// Modify all general-purpose registers. void SetRegisters(const std::array& value); /// Read floating point and SIMD register. Vector GetVector(std::size_t index) const; /// Modify floating point and SIMD register. void SetVector(std::size_t index, Vector value); /// Read all floating point and SIMD registers. std::array GetVectors() const; /// Modify all floating point and SIMD registers. void SetVectors(const std::array& value); /// View FPCR. std::uint32_t GetFpcr() const; /// Modify FPCR. void SetFpcr(std::uint32_t value); /// View FPSR. std::uint32_t GetFpsr() const; /// Modify FPSR. void SetFpsr(std::uint32_t value); /// View PSTATE std::uint32_t GetPstate() const; /// Modify PSTATE void SetPstate(std::uint32_t value); void ChangeProcessorID(std::size_t new_processor); /// Clears exclusive state for this core. void ClearExclusiveState(); /** * Returns true if Jit::Run was called but hasn't returned yet. * i.e.: We're in a callback. */ bool IsExecuting() const; /** * Debugging: Disassemble all of compiled code. * @return A string containing disassembly of all host machine code produced. */ std::string Disassemble() const; private: struct Impl; std::unique_ptr impl; }; } // namespace A64 } // namespace Dynarmic