rpcsx/rpcs3/Emu/ARMv7/ARMv7Thread.cpp

163 lines
2.9 KiB
C++
Raw Normal View History

#include "stdafx.h"
2014-08-23 02:16:54 +02:00
#include "rpcs3/Ini.h"
#include "Utilities/Log.h"
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
#include "Emu/CPU/CPUThreadManager.h"
#include "ARMv7Thread.h"
#include "ARMv7Decoder.h"
#include "ARMv7DisAsm.h"
#include "ARMv7Interpreter.h"
2015-01-20 16:06:15 +01:00
void ARMv7Context::write_pc(u32 value)
{
thread.SetBranch(value);
}
u32 ARMv7Context::read_pc()
{
return thread.PC;
}
u32 ARMv7Context::get_stack_arg(u32 pos)
{
return vm::psv::read32(SP + sizeof(u32) * (pos - 5));
}
void ARMv7Context::fast_call(u32 addr)
{
return thread.FastCall(addr);
}
ARMv7Thread::ARMv7Thread()
: CPUThread(CPU_THREAD_ARMv7)
2015-01-20 16:06:15 +01:00
, context(*this)
//, m_arg(0)
//, m_last_instr_size(0)
//, m_last_instr_name("UNK")
{
}
void ARMv7Thread::InitRegs()
{
2015-01-20 16:06:15 +01:00
memset(context.GPR, 0, sizeof(context.GPR[0]) * 15);
context.APSR.APSR = 0;
context.IPSR.IPSR = 0;
context.ISET = Thumb;
context.ITSTATE.IT = 0;
context.SP = m_stack_addr + m_stack_size;
}
void ARMv7Thread::InitStack()
{
2013-11-06 02:01:15 +01:00
if(!m_stack_addr)
{
m_stack_size = 0x10000;
2014-09-15 00:17:24 +02:00
m_stack_addr = (u32)Memory.Alloc(0x10000, 1);
2013-11-06 02:01:15 +01:00
}
}
std::string ARMv7Thread::RegsToString()
{
std::string result = "Registers:\n=========\n";
2013-11-06 02:01:15 +01:00
for(int i=0; i<15; ++i)
{
2015-01-20 16:06:15 +01:00
result += fmt::Format("%s\t= 0x%08x\n", g_arm_reg_name[i], context.GPR[i]);
2013-11-06 02:01:15 +01:00
}
result += fmt::Format("APSR\t= 0x%08x [N: %d, Z: %d, C: %d, V: %d, Q: %d]\n",
2015-01-20 16:06:15 +01:00
context.APSR.APSR,
fmt::by_value(context.APSR.N),
fmt::by_value(context.APSR.Z),
fmt::by_value(context.APSR.C),
fmt::by_value(context.APSR.V),
fmt::by_value(context.APSR.Q));
2013-11-06 02:01:15 +01:00
return result;
}
std::string ARMv7Thread::ReadRegString(const std::string& reg)
{
return "";
}
bool ARMv7Thread::WriteRegString(const std::string& reg, std::string value)
{
return true;
}
void ARMv7Thread::DoReset()
{
}
void ARMv7Thread::DoRun()
{
switch(Ini.CPUDecoderMode.GetValue())
{
case 0:
//m_dec = new ARMv7Decoder(*new ARMv7DisAsm());
break;
case 1:
case 2:
2015-01-21 22:09:37 +01:00
m_dec = new ARMv7Decoder(context);
break;
}
}
void ARMv7Thread::DoPause()
{
}
void ARMv7Thread::DoResume()
{
}
void ARMv7Thread::DoStop()
{
}
void ARMv7Thread::DoCode()
{
}
void ARMv7Thread::FastCall(u32 addr)
{
auto old_status = m_status;
auto old_PC = PC;
2015-01-20 16:06:15 +01:00
auto old_stack = context.SP;
auto old_LR = context.LR;
auto old_thread = GetCurrentNamedThread();
m_status = Running;
PC = addr;
2015-01-20 16:06:15 +01:00
context.LR = Emu.GetCPUThreadStop();
SetCurrentNamedThread(this);
CPUThread::Task();
m_status = old_status;
PC = old_PC;
2015-01-20 16:06:15 +01:00
context.SP = old_stack;
context.LR = old_LR;
SetCurrentNamedThread(old_thread);
}
void ARMv7Thread::FastStop()
{
m_status = Stopped;
}
arm7_thread::arm7_thread(u32 entry, const std::string& name, u32 stack_size, u32 prio)
{
thread = &Emu.GetCPU().AddThread(CPU_THREAD_ARMv7);
thread->SetName(name);
thread->SetEntry(entry);
thread->SetStackSize(stack_size ? stack_size : Emu.GetInfo().GetProcParam().primary_stacksize);
thread->SetPrio(prio ? prio : Emu.GetInfo().GetProcParam().primary_prio);
argc = 0;
}