2014-09-12 22:34:51 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 08:49:13 +00:00
|
|
|
// Refer to the license.txt file included.
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2017-12-03 02:57:08 +00:00
|
|
|
#include <algorithm>
|
2015-05-06 07:06:12 +00:00
|
|
|
#include <cstring>
|
2016-04-05 12:29:55 +00:00
|
|
|
#include <memory>
|
2016-09-21 06:52:38 +00:00
|
|
|
#include "core/arm/dyncom/arm_dyncom.h"
|
2014-09-12 22:34:51 +00:00
|
|
|
#include "core/arm/dyncom/arm_dyncom_interpreter.h"
|
2016-06-27 18:38:49 +00:00
|
|
|
#include "core/arm/dyncom/arm_dyncom_trans.h"
|
2016-09-20 15:21:23 +00:00
|
|
|
#include "core/arm/skyeye_common/armstate.h"
|
2014-12-22 06:30:09 +00:00
|
|
|
#include "core/core.h"
|
2015-01-06 01:17:49 +00:00
|
|
|
#include "core/core_timing.h"
|
|
|
|
|
2017-12-12 19:12:03 +00:00
|
|
|
class DynComThreadContext final : public ARM_Interface::ThreadContext {
|
|
|
|
public:
|
|
|
|
DynComThreadContext() {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
~DynComThreadContext() override = default;
|
|
|
|
|
|
|
|
void Reset() override {
|
|
|
|
cpu_registers = {};
|
|
|
|
cpsr = 0;
|
|
|
|
fpu_registers = {};
|
|
|
|
fpscr = 0;
|
|
|
|
fpexc = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-06 20:03:28 +00:00
|
|
|
u32 GetCpuRegister(std::size_t index) const override {
|
2017-12-12 19:12:03 +00:00
|
|
|
return cpu_registers[index];
|
|
|
|
}
|
2018-09-06 20:03:28 +00:00
|
|
|
void SetCpuRegister(std::size_t index, u32 value) override {
|
2017-12-12 19:12:03 +00:00
|
|
|
cpu_registers[index] = value;
|
|
|
|
}
|
|
|
|
u32 GetCpsr() const override {
|
|
|
|
return cpsr;
|
|
|
|
}
|
|
|
|
void SetCpsr(u32 value) override {
|
|
|
|
cpsr = value;
|
|
|
|
}
|
2018-09-06 20:03:28 +00:00
|
|
|
u32 GetFpuRegister(std::size_t index) const override {
|
2017-12-12 19:12:03 +00:00
|
|
|
return fpu_registers[index];
|
|
|
|
}
|
2018-09-06 20:03:28 +00:00
|
|
|
void SetFpuRegister(std::size_t index, u32 value) override {
|
2017-12-12 19:12:03 +00:00
|
|
|
fpu_registers[index] = value;
|
|
|
|
}
|
|
|
|
u32 GetFpscr() const override {
|
|
|
|
return fpscr;
|
|
|
|
}
|
|
|
|
void SetFpscr(u32 value) override {
|
|
|
|
fpscr = value;
|
|
|
|
}
|
|
|
|
u32 GetFpexc() const override {
|
|
|
|
return fpexc;
|
|
|
|
}
|
|
|
|
void SetFpexc(u32 value) override {
|
|
|
|
fpexc = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ARM_DynCom;
|
|
|
|
|
|
|
|
std::array<u32, 16> cpu_registers;
|
|
|
|
u32 cpsr;
|
|
|
|
std::array<u32, 64> fpu_registers;
|
|
|
|
u32 fpscr;
|
|
|
|
u32 fpexc;
|
|
|
|
};
|
|
|
|
|
2015-02-12 20:11:39 +00:00
|
|
|
ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) {
|
2016-04-05 12:29:55 +00:00
|
|
|
state = std::make_unique<ARMul_State>(initial_mode);
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 01:01:46 +00:00
|
|
|
ARM_DynCom::~ARM_DynCom() {}
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2017-12-03 02:57:08 +00:00
|
|
|
void ARM_DynCom::Run() {
|
2018-10-27 19:53:20 +00:00
|
|
|
ExecuteInstructions(std::max<s64>(Core::System::GetInstance().CoreTiming().GetDowncount(), 0));
|
2017-12-03 02:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::Step() {
|
|
|
|
ExecuteInstructions(1);
|
|
|
|
}
|
|
|
|
|
2016-06-27 18:38:49 +00:00
|
|
|
void ARM_DynCom::ClearInstructionCache() {
|
|
|
|
state->instruction_cache.clear();
|
|
|
|
trans_cache_buf_top = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-06 20:03:28 +00:00
|
|
|
void ARM_DynCom::InvalidateCacheRange(u32, std::size_t) {
|
2017-09-11 11:54:14 +00:00
|
|
|
ClearInstructionCache();
|
|
|
|
}
|
|
|
|
|
2017-09-24 21:44:13 +00:00
|
|
|
void ARM_DynCom::PageTableChanged() {
|
|
|
|
ClearInstructionCache();
|
|
|
|
}
|
|
|
|
|
2014-09-12 22:34:51 +00:00
|
|
|
void ARM_DynCom::SetPC(u32 pc) {
|
2015-02-01 02:44:35 +00:00
|
|
|
state->Reg[15] = pc;
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_DynCom::GetPC() const {
|
2014-11-09 22:00:59 +00:00
|
|
|
return state->Reg[15];
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_DynCom::GetReg(int index) const {
|
|
|
|
return state->Reg[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetReg(int index, u32 value) {
|
|
|
|
state->Reg[index] = value;
|
|
|
|
}
|
|
|
|
|
2015-08-07 01:24:25 +00:00
|
|
|
u32 ARM_DynCom::GetVFPReg(int index) const {
|
|
|
|
return state->ExtReg[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetVFPReg(int index, u32 value) {
|
|
|
|
state->ExtReg[index] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_DynCom::GetVFPSystemReg(VFPSystemRegister reg) const {
|
|
|
|
return state->VFP[reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetVFPSystemReg(VFPSystemRegister reg, u32 value) {
|
|
|
|
state->VFP[reg] = value;
|
|
|
|
}
|
|
|
|
|
2014-09-12 22:34:51 +00:00
|
|
|
u32 ARM_DynCom::GetCPSR() const {
|
|
|
|
return state->Cpsr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetCPSR(u32 cpsr) {
|
|
|
|
state->Cpsr = cpsr;
|
|
|
|
}
|
|
|
|
|
2015-04-06 16:57:49 +00:00
|
|
|
u32 ARM_DynCom::GetCP15Register(CP15Register reg) {
|
|
|
|
return state->CP15[reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetCP15Register(CP15Register reg, u32 value) {
|
|
|
|
state->CP15[reg] = value;
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:08:14 +00:00
|
|
|
void ARM_DynCom::ExecuteInstructions(u64 num_instructions) {
|
2014-09-12 22:34:51 +00:00
|
|
|
state->NumInstrsToExecute = num_instructions;
|
2015-01-06 01:17:49 +00:00
|
|
|
unsigned ticks_executed = InterpreterMainLoop(state.get());
|
2018-10-27 19:53:20 +00:00
|
|
|
Core::System::GetInstance().CoreTiming().AddTicks(ticks_executed);
|
2018-08-16 18:44:31 +00:00
|
|
|
state->ServeBreak();
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 19:12:03 +00:00
|
|
|
std::unique_ptr<ARM_Interface::ThreadContext> ARM_DynCom::NewContext() const {
|
|
|
|
return std::make_unique<DynComThreadContext>();
|
|
|
|
}
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2017-12-12 19:12:03 +00:00
|
|
|
void ARM_DynCom::SaveContext(const std::unique_ptr<ThreadContext>& arg) {
|
|
|
|
DynComThreadContext* ctx = dynamic_cast<DynComThreadContext*>(arg.get());
|
|
|
|
ASSERT(ctx);
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2017-12-12 19:12:03 +00:00
|
|
|
ctx->cpu_registers = state->Reg;
|
|
|
|
ctx->cpsr = state->Cpsr;
|
|
|
|
ctx->fpu_registers = state->ExtReg;
|
|
|
|
ctx->fpscr = state->VFP[VFP_FPSCR];
|
|
|
|
ctx->fpexc = state->VFP[VFP_FPEXC];
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 19:12:03 +00:00
|
|
|
void ARM_DynCom::LoadContext(const std::unique_ptr<ThreadContext>& arg) {
|
|
|
|
DynComThreadContext* ctx = dynamic_cast<DynComThreadContext*>(arg.get());
|
|
|
|
ASSERT(ctx);
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2017-12-12 19:12:03 +00:00
|
|
|
state->Reg = ctx->cpu_registers;
|
|
|
|
state->Cpsr = ctx->cpsr;
|
|
|
|
state->ExtReg = ctx->fpu_registers;
|
|
|
|
state->VFP[VFP_FPSCR] = ctx->fpscr;
|
|
|
|
state->VFP[VFP_FPEXC] = ctx->fpexc;
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::PrepareReschedule() {
|
|
|
|
state->NumInstrsToExecute = 0;
|
|
|
|
}
|