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
|
|
|
|
2015-05-06 07:06:12 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2015-04-28 02:44:05 +00:00
|
|
|
#include "common/make_unique.h"
|
|
|
|
|
2015-07-26 01:10:41 +00:00
|
|
|
#include "core/arm/skyeye_common/armstate.h"
|
2015-07-26 00:19:39 +00:00
|
|
|
#include "core/arm/skyeye_common/armsupp.h"
|
2014-09-12 22:34:51 +00:00
|
|
|
#include "core/arm/skyeye_common/vfp/vfp.h"
|
|
|
|
|
|
|
|
#include "core/arm/dyncom/arm_dyncom.h"
|
|
|
|
#include "core/arm/dyncom/arm_dyncom_interpreter.h"
|
2015-02-12 20:11:39 +00:00
|
|
|
#include "core/arm/dyncom/arm_dyncom_run.h"
|
2014-09-12 22:34:51 +00:00
|
|
|
|
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"
|
|
|
|
|
2015-02-12 20:11:39 +00:00
|
|
|
ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) {
|
2015-07-26 09:39:54 +00:00
|
|
|
state = Common::make_unique<ARMul_State>(initial_mode);
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ARM_DynCom::~ARM_DynCom() {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:45:52 +00:00
|
|
|
void ARM_DynCom::AddTicks(u64 ticks) {
|
2015-01-06 01:17:49 +00:00
|
|
|
down_count -= ticks;
|
|
|
|
if (down_count < 0)
|
|
|
|
CoreTiming::Advance();
|
2014-12-24 03:45:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 22:34:51 +00:00
|
|
|
void ARM_DynCom::ExecuteInstructions(int num_instructions) {
|
|
|
|
state->NumInstrsToExecute = num_instructions;
|
2014-11-09 06:26:03 +00:00
|
|
|
|
|
|
|
// Dyncom only breaks on instruction dispatch. This only happens on every instruction when
|
2014-11-19 08:49:13 +00:00
|
|
|
// executing one instruction at a time. Otherwise, if a block is being executed, more
|
2014-11-09 06:26:03 +00:00
|
|
|
// instructions may actually be executed than specified.
|
2015-01-06 01:17:49 +00:00
|
|
|
unsigned ticks_executed = InterpreterMainLoop(state.get());
|
|
|
|
AddTicks(ticks_executed);
|
2014-09-12 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 06:56:17 +00:00
|
|
|
void ARM_DynCom::ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) {
|
|
|
|
memset(&context, 0, sizeof(Core::ThreadContext));
|
|
|
|
|
|
|
|
context.cpu_registers[0] = arg;
|
|
|
|
context.pc = entry_point;
|
|
|
|
context.sp = stack_top;
|
|
|
|
context.cpsr = 0x1F; // Usermode
|
|
|
|
}
|
|
|
|
|
2014-12-22 06:30:09 +00:00
|
|
|
void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) {
|
2015-07-26 15:39:57 +00: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-12 22:34:51 +00:00
|
|
|
|
|
|
|
ctx.sp = state->Reg[13];
|
|
|
|
ctx.lr = state->Reg[14];
|
2014-11-09 22:00:59 +00:00
|
|
|
ctx.pc = state->Reg[15];
|
2014-09-12 22:34:51 +00:00
|
|
|
ctx.cpsr = state->Cpsr;
|
|
|
|
|
|
|
|
ctx.fpscr = state->VFP[1];
|
|
|
|
ctx.fpexc = state->VFP[2];
|
|
|
|
}
|
|
|
|
|
2014-12-22 06:30:09 +00:00
|
|
|
void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) {
|
2015-07-26 15:39:57 +00: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-12 22:34:51 +00:00
|
|
|
|
|
|
|
state->Reg[13] = ctx.sp;
|
|
|
|
state->Reg[14] = ctx.lr;
|
2015-02-01 02:44:35 +00:00
|
|
|
state->Reg[15] = ctx.pc;
|
2014-09-12 22:34:51 +00:00
|
|
|
state->Cpsr = ctx.cpsr;
|
|
|
|
|
|
|
|
state->VFP[1] = ctx.fpscr;
|
|
|
|
state->VFP[2] = ctx.fpexc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::PrepareReschedule() {
|
|
|
|
state->NumInstrsToExecute = 0;
|
|
|
|
}
|