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
|
|
|
|
|
|
|
#include "core/arm/skyeye_common/armemu.h"
|
|
|
|
#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"
|
|
|
|
|
2014-09-12 22:34:51 +00:00
|
|
|
const static cpu_config_t s_arm11_cpu_info = {
|
|
|
|
"armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE
|
|
|
|
};
|
|
|
|
|
2015-02-12 20:11:39 +00:00
|
|
|
ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) {
|
2014-09-12 22:34:51 +00:00
|
|
|
state = std::unique_ptr<ARMul_State>(new ARMul_State);
|
|
|
|
|
2015-02-12 16:30:25 +00:00
|
|
|
ARMul_NewState(state.get());
|
2015-02-12 20:04:47 +00:00
|
|
|
ARMul_SelectProcessor(state.get(), ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2015-02-11 15:49:48 +00:00
|
|
|
state->abort_model = ABORT_BASE_RESTORED;
|
2014-09-12 22:34:51 +00:00
|
|
|
state->cpu = (cpu_config_t*)&s_arm11_cpu_info;
|
|
|
|
|
2015-02-12 20:04:47 +00:00
|
|
|
state->bigendSig = LOW;
|
2014-09-12 22:34:51 +00:00
|
|
|
state->lateabtSig = LOW;
|
2015-02-12 20:04:47 +00:00
|
|
|
state->NirqSig = HIGH;
|
2014-09-12 22:34:51 +00:00
|
|
|
|
|
|
|
// Reset the core to initial state
|
|
|
|
ARMul_Reset(state.get());
|
|
|
|
state->NextInstr = RESUME; // NOTE: This will be overwritten by LoadContext
|
2015-02-11 15:49:48 +00:00
|
|
|
state->Emulate = RUN;
|
2014-09-12 22:34:51 +00:00
|
|
|
|
2015-02-12 20:11:39 +00:00
|
|
|
// Switch to the desired privilege mode.
|
|
|
|
switch_mode(state.get(), initial_mode);
|
|
|
|
|
2014-09-12 22:34:51 +00:00
|
|
|
state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
|
2015-02-12 20:04:47 +00:00
|
|
|
state->Reg[15] = 0x00000000;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_DynCom::GetCPSR() const {
|
|
|
|
return state->Cpsr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::SetCPSR(u32 cpsr) {
|
|
|
|
state->Cpsr = cpsr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
context.mode = 8; // Instructs dyncom CPU core to start execution as if it's "resuming" a thread.
|
|
|
|
}
|
|
|
|
|
2014-12-22 06:30:09 +00:00
|
|
|
void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) {
|
2014-09-12 22:34:51 +00: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 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];
|
|
|
|
|
|
|
|
ctx.mode = state->NextInstr;
|
|
|
|
}
|
|
|
|
|
2014-12-22 06:30:09 +00:00
|
|
|
void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) {
|
2014-09-12 22:34:51 +00: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 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;
|
|
|
|
|
|
|
|
state->NextInstr = ctx.mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_DynCom::PrepareReschedule() {
|
|
|
|
state->NumInstrsToExecute = 0;
|
|
|
|
}
|