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