2014-09-13 00:34:51 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 09:49:13 +01:00
|
|
|
// Refer to the license.txt file included.
|
2014-09-13 00:34:51 +02:00
|
|
|
|
2017-12-03 03:57:08 +01:00
|
|
|
#include <algorithm>
|
2015-05-06 09:06:12 +02:00
|
|
|
#include <cstring>
|
2016-04-05 14:29:55 +02:00
|
|
|
#include <memory>
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/arm/dyncom/arm_dyncom.h"
|
2014-09-13 00:34:51 +02:00
|
|
|
#include "core/arm/dyncom/arm_dyncom_interpreter.h"
|
2015-02-12 21:11:39 +01:00
|
|
|
#include "core/arm/dyncom/arm_dyncom_run.h"
|
2016-06-27 20:38:49 +02:00
|
|
|
#include "core/arm/dyncom/arm_dyncom_trans.h"
|
2016-09-20 17:21:23 +02:00
|
|
|
#include "core/arm/skyeye_common/armstate.h"
|
|
|
|
#include "core/arm/skyeye_common/armsupp.h"
|
|
|
|
#include "core/arm/skyeye_common/vfp/vfp.h"
|
2014-12-22 07:30:09 +01:00
|
|
|
#include "core/core.h"
|
2015-01-06 02:17:49 +01:00
|
|
|
#include "core/core_timing.h"
|
|
|
|
|
2015-02-12 21:11:39 +01:00
|
|
|
ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) {
|
2016-04-05 14:29:55 +02:00
|
|
|
state = std::make_unique<ARMul_State>(initial_mode);
|
2014-09-13 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
2016-09-19 03:01:46 +02:00
|
|
|
ARM_DynCom::~ARM_DynCom() {}
|
2014-09-13 00:34:51 +02:00
|
|
|
|
2017-12-03 03:57:08 +01:00
|
|
|
void ARM_DynCom::Run() {
|
|
|
|
ExecuteInstructions(std::max(CoreTiming::GetDowncount(), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::Step() {
|
|
|
|
ExecuteInstructions(1);
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:38:49 +02:00
|
|
|
void ARM_DynCom::ClearInstructionCache() {
|
|
|
|
state->instruction_cache.clear();
|
|
|
|
trans_cache_buf_top = 0;
|
|
|
|
}
|
|
|
|
|
2017-09-24 23:44:13 +02:00
|
|
|
void ARM_DynCom::PageTableChanged() {
|
|
|
|
ClearInstructionCache();
|
|
|
|
}
|
|
|
|
|
2014-09-13 00:34:51 +02:00
|
|
|
void ARM_DynCom::SetPC(u32 pc) {
|
2015-02-01 03:44:35 +01:00
|
|
|
state->Reg[15] = pc;
|
2014-09-13 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_DynCom::GetPC() const {
|
2014-11-09 23:00:59 +01:00
|
|
|
return state->Reg[15];
|
2014-09-13 00:34:51 +02: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 03:24:25 +02: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-13 00:34:51 +02:00
|
|
|
u32 ARM_DynCom::GetCPSR() const {
|
|
|
|
return state->Cpsr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetCPSR(u32 cpsr) {
|
|
|
|
state->Cpsr = cpsr;
|
|
|
|
}
|
|
|
|
|
2015-04-06 18:57:49 +02:00
|
|
|
u32 ARM_DynCom::GetCP15Register(CP15Register reg) {
|
|
|
|
return state->CP15[reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetCP15Register(CP15Register reg, u32 value) {
|
|
|
|
state->CP15[reg] = value;
|
|
|
|
}
|
|
|
|
|
2014-09-13 00:34:51 +02:00
|
|
|
void ARM_DynCom::ExecuteInstructions(int num_instructions) {
|
|
|
|
state->NumInstrsToExecute = num_instructions;
|
2015-01-06 02:17:49 +01:00
|
|
|
unsigned ticks_executed = InterpreterMainLoop(state.get());
|
2017-09-30 18:25:49 +02:00
|
|
|
CoreTiming::AddTicks(ticks_executed);
|
2014-09-13 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 06:08:09 +01:00
|
|
|
void ARM_DynCom::SaveContext(ThreadContext& ctx) {
|
2015-07-26 17:39:57 +02:00
|
|
|
memcpy(ctx.cpu_registers, state->Reg.data(), sizeof(ctx.cpu_registers));
|
|
|
|
memcpy(ctx.fpu_registers, state->ExtReg.data(), sizeof(ctx.fpu_registers));
|
2014-09-13 00:34:51 +02:00
|
|
|
|
|
|
|
ctx.sp = state->Reg[13];
|
|
|
|
ctx.lr = state->Reg[14];
|
2014-11-09 23:00:59 +01:00
|
|
|
ctx.pc = state->Reg[15];
|
2014-09-13 00:34:51 +02:00
|
|
|
ctx.cpsr = state->Cpsr;
|
|
|
|
|
2016-09-02 14:39:42 +02:00
|
|
|
ctx.fpscr = state->VFP[VFP_FPSCR];
|
|
|
|
ctx.fpexc = state->VFP[VFP_FPEXC];
|
2014-09-13 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 06:08:09 +01:00
|
|
|
void ARM_DynCom::LoadContext(const ThreadContext& ctx) {
|
2015-07-26 17:39:57 +02:00
|
|
|
memcpy(state->Reg.data(), ctx.cpu_registers, sizeof(ctx.cpu_registers));
|
|
|
|
memcpy(state->ExtReg.data(), ctx.fpu_registers, sizeof(ctx.fpu_registers));
|
2014-09-13 00:34:51 +02:00
|
|
|
|
|
|
|
state->Reg[13] = ctx.sp;
|
|
|
|
state->Reg[14] = ctx.lr;
|
2015-02-01 03:44:35 +01:00
|
|
|
state->Reg[15] = ctx.pc;
|
2014-09-13 00:34:51 +02:00
|
|
|
state->Cpsr = ctx.cpsr;
|
|
|
|
|
2016-09-02 14:39:42 +02:00
|
|
|
state->VFP[VFP_FPSCR] = ctx.fpscr;
|
|
|
|
state->VFP[VFP_FPEXC] = ctx.fpexc;
|
2014-09-13 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::PrepareReschedule() {
|
|
|
|
state->NumInstrsToExecute = 0;
|
|
|
|
}
|